nicklockwood / SwiftFormat

A command-line tool and Xcode Extension for formatting Swift code
MIT License
7.9k stars 639 forks source link

`--swiftversion latest` option to automatically format according to the most recent available language version? #1226

Closed calda closed 2 years ago

calda commented 2 years ago

We specify a --swiftversion flag in our airbnb.swiftformat file so that version-dependent format rule implementations use all of the latest language features. We have to periodically update this, so it can drift out of date.

Any thoughts on including a --swiftversion latest option, to automatically format according to the most recent available language version?

nicklockwood commented 2 years ago

Seems reasonable, although I think you could probably just set it to 999 or something and have the same effect?

calda commented 2 years ago

Good idea, if --swiftversion 999 works then we probably don't need a latest option

nicklockwood commented 2 years ago

It might be worth adding an explicit "latest" option anyway, otherwise it would prohibit me from adding a warning for unknown swift version in future.

calda commented 2 years ago

Cool, I do prefer --swiftformat latest from a semantic / self-documenting perspective. I'll make a PR.

nicklockwood commented 2 years ago

@calda I think based on the PR discussion we're not doing this, right?

calda commented 2 years ago

Yeah, I figured we can just leave it as-is since there isn't a clear / simple direction for inferring this. In our SPM package plugin that wraps SwiftFormat I did start grabbing the Package.swift swift-tools-version (https://github.com/airbnb/swift/pull/180) which I think works nicely for SPM packages, but there isn't a clean / simple way to do this for other types of projects.