Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SwiftLint 0.16.1 incorrectly converting legacy constant for Swift 2.3 #1238

Closed
raid5 opened this issue Jan 23, 2017 · 8 comments
Closed

SwiftLint 0.16.1 incorrectly converting legacy constant for Swift 2.3 #1238

raid5 opened this issue Jan 23, 2017 · 8 comments
Labels
bug Unexpected and reproducible misbehavior. repro-needed Issues that cannot be reproduced or miss proper descriptive examples.

Comments

@raid5
Copy link

raid5 commented Jan 23, 2017

I have a project using Swift 2.3 and have installed version 0.16.1 of SwiftLint. When I run swiftlint autocorrect, it's incorrectly replacing CGFloat(M_PI) with CGFloat.pi. In the logs I see the output of Corrected Legacy Constant where it made the change to my code and the project won't compile due to this error.

@marcelofabri
Copy link
Collaborator

I've tried to reproduce it and couldn't. The implementation seems correct too.

The only reason that could make this happen seems to be the wrong toolchain being used (see https://github.com/jpsim/SourceKitten#how-is-sourcekit-resolved).

Using TOOLCHAINS=com.apple.dt.toolchain.Swift_2_3 swiftlint autocorrect should work. Can you test this?

@marcelofabri marcelofabri added bug Unexpected and reproducible misbehavior. repro-needed Issues that cannot be reproduced or miss proper descriptive examples. labels Jan 23, 2017
@jpsim
Copy link
Collaborator

jpsim commented Jan 23, 2017

I think the issue might be that since CGFloat(M_PI) is valid in both Swift 2 and 3, that it doesn't need to be fenced in a version compile-guard (#if swift(>=3.0)), so if you're running SwiftLint in Swift 3 mode, it'll gladly "correct" it to something that doesn't compile in Swift 2.x.

It's not a great experience, but I'd still consider it a "user error".

@raid5
Copy link
Author

raid5 commented Jan 23, 2017

@marcelofabri, yes specifying the TOOLCHAINS works and does not make the adjustment to CGFloat(M_PI). I wasn't aware this needed to be done as I figured SwiftLint would know what version of Swift to target.

@marcelofabri
Copy link
Collaborator

In general this shouldn't be needed. Do you have more than one Xcode installed?

@jpsim
Copy link
Collaborator

jpsim commented Jan 23, 2017

I wasn't aware this needed to be done as I figured SwiftLint would know what version of Swift to target.

SwiftLint doesn't check the version specified in your Xcode project, or a .swift-version file at the root of your repo. It does leave code alone if it wouldn't compile under its current Swift version (determined via https://github.com/jpsim/SourceKitten#how-is-sourcekit-resolved).

In general this shouldn't be needed. Do you have more than one Xcode installed?

This can happen even with just a single version of Xcode installed, since Xcode 8.x ships with both Swift 3 and Swift 3 toolchains

@raid5
Copy link
Author

raid5 commented Jan 23, 2017

@marcelofabri, yes I have 7.3.1 and 8.2.1 as I need both for client work.

@raid5
Copy link
Author

raid5 commented Jan 23, 2017

@jpsim, that makes sense. I may suggest adding something about that to the README.

@jpsim
Copy link
Collaborator

jpsim commented Jan 23, 2017

See #1239.

@jpsim jpsim closed this as completed Jan 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Unexpected and reproducible misbehavior. repro-needed Issues that cannot be reproduced or miss proper descriptive examples.
Projects
None yet
Development

No branches or pull requests

3 participants