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

Rule idea: redundantSwiftVersionCheck #1842

Open
nicklockwood opened this issue Aug 31, 2024 · 4 comments
Open

Rule idea: redundantSwiftVersionCheck #1842

nicklockwood opened this issue Aug 31, 2024 · 4 comments

Comments

@nicklockwood
Copy link
Owner

If SwiftFormat's --swiftversion is set to (say) 5.2 then it implies that all the code in the codebase being formatted must be Swift 5.2+ compliant. In which case any conditional compilation checks like this are redundant :

#if swift(>=5.2)
   ...
#endif

We could add a rule that removes these. Potentially we could also add a similar rule for minimum deployment targets, but that would require additional configuration.

@jshier
Copy link

jshier commented Sep 25, 2024

One complication for such a rule would be distinguishing between Swift 6 in Swift 6 mode and Swift 6 in Swift 5 mode, as there's no --swiftversion which refers to Swift 6 in Swift 5 mode (AFAIK).

@calda
Copy link
Collaborator

calda commented Sep 25, 2024

There is now 😄: #1880

--swiftversion 6.0 --languagemode 5

@calda
Copy link
Collaborator

calda commented Sep 25, 2024

In what ways does the #if swift condition interact with the compiler version / language mode distinction?

@jshier
Copy link

jshier commented Sep 25, 2024

It allows you to detect enumerated versions directly, otherwise you need to have other checks.

#if swift(>=6)
  // Swift 6+ compiler in Swift 6 mode.
#elseif compiler(>=6)
  // Swift 6+ compiler in Swift 5 mode.
#else
  // Earlier Swift version.
#endif

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants