-
Notifications
You must be signed in to change notification settings - Fork 28.7k
[packages] Add support for swift-format #41129
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
Comments
Actually running this in CI is still problematic:
|
Now that we are migrating iOS to swift, we may want to consider bumping up the priority of this?
Can you explain more about this? What is the "project"?
Did you mean https://github.com/apple/swift-format#matching-swift-format-to-your-swift-version-swift-57-and-earlier. Are we using, or plan to use different versions of Swift for different plugins. Can we query the swift version used in build setting and download the formatter accordingly? |
That was referring to apple/swift-format.
Yes, but it looks like it's resolved now! That "Note" section was only added a couple of days ago, and unless I'm misreading it, it's saying we won't have this problem going forward.
The problem was that the version they were referring to there wasn't the Swift syntax version, it was the (And anyone wanting to format locally would have had to figure all of this out as well, to get and build just the right version.) |
It also says swift-format can be used as an API from another swift script, as opposed to using it as a command line tool https://github.com/apple/swift-format#api-usage. That would allow us to use Swift Package Manager to manage the version resolution. That may be easier than building from source https://github.com/apple/swift-format#getting-swift-format |
In case it's helpful, if you also contribute to the flutter engine, there is an issue with the swift-format under depot_tools. The current workaround is to install and run swift-format on your local machines ( Make sure to set up the export path properly to run your own copy of swift-format instead of the one under depot_tools. |
Now that we're using LUCI, we could probably just by making a cipd package of swift-format, and add it to the dependencies in |
cc @tarrinneal |
Adds support for swift-format in the `format` command. For now this is optional, so is only triggered if the flag is explictly passed. In the future, once we have CI support for swift-format, we will likely want to make it on-by-default as with the other formatters. Part of flutter/flutter#41129
Adds support for swift-format in the `format` command. For now this is optional, so is only triggered if the flag is explictly passed. In the future, once we have CI support for swift-format, we will likely want to make it on-by-default as with the other formatters. Part of flutter/flutter#41129
The packages tooling is now set up to handle swift-format as of flutter/packages#5204, but it still needs to be put into CI. I see there's already a CIPD package at
|
Recipe change to add the CIPD package as a dependency: https://flutter-review.googlesource.com/c/recipes/+/54020 |
That package only runs on macOS. That means we'll need a |
swift-format also works on Ubuntu, but not on Alpine, e.g. https://hub.docker.com/r/mtgto/swift-format/ |
Understood. The version we easily have available to us in CI from chromium is only built for Mac. I'd rather rearrange our test than maintain our own versions of this package, if possible. |
🤦🏻 I forgot to check non-Flutter packages. Thanks for finding that!
Agreed, I was just looking at your other PR and wondering if we should combine it with something else. We'll probably want to adjust the tooling to allow disabling formatting of each language so that we don't have two failures every time file in any other language fails, but I can add that easily. I'll take a look next week. |
`swift-format` alphabetizes imports. Alphabetize them in swift template files and integration tests. I found this as part of #41129 running `swift-import` on packages.
…#5905) Get ready for a world where `swift-format` is available on the `PATH` https://flutter-review.googlesource.com/c/recipes/+/54020 1. Add `format --clang-format --java --kotlin --swift --dart` flags to decide whether to run specific formatters, as opposed to using the `path`. Keep `swift-format` optional but default the others to run. This matches the current behavior on Linux. 2. Add `*-path` variants of each. This will allow us to run `format --swift --no-clang-format --no-java --no-kotlin --no-dart` on the macOS bot so it doesn't duplicate same `format` call run on Linux. Part of flutter/flutter#41129
Make `swift-format` CIPD package available on the `PATH` https://flutter-review.googlesource.com/c/recipes/+/54020 Run `format --no-clang-format --no-java --no-kotlin --no-dart` on the macOS builder so it doesn't duplicate same `format` call run on Linux. Filter out generated files until flutter/flutter#141799 is done. Also add `swift-format lint` call during `format` command. Fix the one casing issue it found in a test file. Failing run: https://logs.chromium.org/logs/flutter/buildbucket/cr-buildbucket/8758535881172004177/+/u/Run_package_tests/Swift_format/stdout Successful run: https://logs.chromium.org/logs/flutter/buildbucket/cr-buildbucket/8758492350529121249/+/u/Run_package_tests/Swift_format/stdout Fixes flutter/flutter#41129
Reworks Pigeon's CI validation of generated files to support multiple hosts, rather than only Linux, with the ability to set specific languages per host, to allow us to run validation for each language on whatever host it is most convenient to set up a formatter for that language, rather than having to support all languages on Linux. See discussion in #5928 Part of flutter/flutter#41129
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of |
flutter_plugins supports Dart, Java, and Objective-C formatting. Since we'll be using Swift preferentially for macOS plugins (and probably someday for iOS, even if not yet), we should add support for swift-format too. (There are several Swift formatters, but based on internal discussions that's the one we should use.)
It's a bit fiddly to set up at the moment, but we should at least check if it's on the path and run it if so.
The text was updated successfully, but these errors were encountered: