Repository navigation
[packages] Add support for swift-format #41129
Description
Activity
- addedp: toolingAffects the flutter_plugin_tools packageAffects the flutter_plugin_tools package
on Sep 23, 2019 - addedc: contributor-productivityTeam-specific productivity, code health, technical debt.Team-specific productivity, code health, technical debt.
on Sep 23, 2019 - addedP3Issues that are less important to the Flutter projectIssues that are less important to the Flutter project
on May 24, 2021 Actually running this in CI is still problematic:
- There are still no binaries provided by the project.
- The version-locking could make it more difficult for us to update the version of Xcode we're using in CI.
Now that we are migrating iOS to swift, we may want to consider bumping up the priority of this?
There are still no binaries provided by the project.
Can you explain more about this? What is the "project"?
The version-locking could make it more difficult for us to update the version of Xcode we're using in CI.
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?
There are still no binaries provided by the project.
Can you explain more about this? What is the "project"?
That was referring to apple/swift-format.
The version-locking could make it more difficult for us to update the version of Xcode we're using in CI.
Did you mean https://github.com/apple/swift-format#matching-swift-format-to-your-swift-version-swift-57-and-earlier.
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.
Are we using, or plan to use different versions of Swift for different plugins.
The problem was that the version they were referring to there wasn't the Swift syntax version, it was the
swifttoolchain version. Meaning that it used to be the case that you had to build the specific version of the former for the exact version of Xcode you had. So any time we wanted to update Xcode we would have had to update the formatter. And if there wasn't a formater version yet, we would actually be blocked from updating Xcode temporarily.(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
- changed the title
[-]Add support for swift-format[/-][+][plugins] Add support for swift-format[/+]on Jan 18, 2023 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 (
swift-format format -i -r /path/to/your/code).Make sure to set up the export path properly to run your own copy of swift-format instead of the one under depot_tools.
- addedpackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.and removed
on Mar 5, 2023 - changed the title
[-][plugins] Add support for swift-format[/-][+][packages] Add support for swift-format[/+]on Mar 21, 2023 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
.ci.yaml.Reacted by hellohuanlin and August10 remaining items
swift-format also works on Ubuntu, but not on Alpine, e.g. https://hub.docker.com/r/mtgto/swift-format/
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.
Recipe change to add the CIPD package as a dependency: https://flutter-review.googlesource.com/c/recipes/+/54020
🤦🏻 I forgot to check non-Flutter packages. Thanks for finding that!
We could make
check_podspecsinto a more genericrepo_checksthat also callsswift-format(it runs really fast).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.
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 doctor -vand a minimal reproduction of the issue.- locked as resolved and limited conversation to collaborators
on Feb 2, 2024 - added a parent issue
on Sep 23, 2025 - added a commit that references this issue
on Jun 10, 2026 - added a commit that references this issue
on Jun 19, 2026
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.