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

Add support for --swiftversion latest #1227

Closed
wants to merge 1 commit into from

Conversation

calda
Copy link
Collaborator

@calda calda commented Jul 20, 2022

This PR adds support for specifying --swiftversion latest, to automatically use the most recent language version supported by SwiftFormat. Implements #1226.

@bachand
Copy link

bachand commented Jul 21, 2022

@calda thanks for adding this. When we use SwiftFormat in our project I think it's still best to specify the Swift version manually since we may not always be on the latest version of Swift supported by SwiftFormat. What do you think?

@calda
Copy link
Collaborator Author

calda commented Jul 21, 2022

Either is fine with me

@bachand
Copy link

bachand commented Jul 21, 2022

I feel like what would be nice is if we could pass the Swift version to the SwiftFormat tool at runtime (maybe we can?). Then our tooling that wraps SwiftFormat can determine the current version of Xcode we're using and pass it to SwiftFormat.

@nicklockwood
Copy link
Owner

@calda hmm, I realize the concept of stable vs beta Swift versions complicates this more than I anticipated. I assumed latest would just be the most recent version that SwiftFormat knows about.

I did previously have an idea to try to automatically detect the Swift version, either by inspecting the files for modern features, or looking for a .xcodeproj or some other source of info. Maybe that's a better way to go?

@calda
Copy link
Collaborator Author

calda commented Jul 22, 2022

If you prefer to just use swiftVersions.last (5.7) instead, that's fine with me.

@calda
Copy link
Collaborator Author

calda commented Jul 22, 2022

or looking for a .xcodeproj or some other source of info

This is an interesting idea. For packages with a Package.swift I wonder if the swift-tools-version would be a good source for this info. As far as I can tell .xcodeproj config files don't include info about the minimum Swift version.

@bachand
Copy link

bachand commented Jul 23, 2022

I feel like what would be nice is if we could pass the Swift version to the SwiftFormat tool at runtime (maybe we can?). Then our tooling that wraps SwiftFormat can determine the current version of Xcode we're using and pass it to SwiftFormat.

It looks like this is already supported 👍
Screen Shot 2022-07-23 at 2 18 01 PM

or looking for a .xcodeproj or some other source of info

This is an interesting idea. For packages with a Package.swift I wonder if the swift-tools-version would be a good source for this info. As far as I can tell .xcodeproj config files don't include info about the minimum Swift version.

I also agree that an .xcodeproj may not have enough information for inferring the Swift version since you could be opening the project in different versions of Xcode with different Swift versions. Unless the .xcodeproj file stored the latest Xcode version with which it was saved?

When you point SwiftFormat at a directory corresponding to a Swift package using the swift-tools-version is a cool idea.

@calda calda closed this Jul 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants