Rule idea: redundantSwiftVersionCheck
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.
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).
There is now 😄: https://github.com/nicklockwood/SwiftFormat/issues/1880
--swiftversion 6.0 --languagemode 5
In what ways does the #if swift condition interact with the compiler version / language mode distinction?
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