Skip to content

[packages] Add support for swift-format #41129

Description

@stuartmorgan-g

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.

Activity

  1. added
    P3Issues that are less important to the Flutter project
    on May 24, 2021
  2. stuartmorgan-g commented on Sep 8, 2022

    @stuartmorgan-g
    ContributorAuthor

    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.
  3. cyanglaz commented on Sep 22, 2022

    @cyanglaz

    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?

  4. stuartmorgan-g commented on Sep 22, 2022

    @stuartmorgan-g
    ContributorAuthor

    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 swift toolchain 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.)

  5. jmagman commented on Sep 22, 2022

    @jmagman
    Member

    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

  6. self-assigned this
    on Dec 14, 2022
  7. changed the title [-]Add support for swift-format[/-] [+][plugins] Add support for swift-format[/+] on Jan 18, 2023
  8. hellohuanlin commented on Jan 23, 2023

    @hellohuanlin
    Contributor

    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.

  9. added
    packageflutter/packages repository. See also p: labels.
    and removed on Mar 5, 2023
  10. changed the title [-][plugins] Add support for swift-format[/-] [+][packages] Add support for swift-format[/+] on Mar 21, 2023
  11. stuartmorgan-g commented on Jul 6, 2023

    @stuartmorgan-g
    ContributorAuthor

    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.

  12. 10 remaining items

  13. Gustl22 commented on Jan 13, 2024

    @Gustl22
    Contributor

    swift-format also works on Ubuntu, but not on Alpine, e.g. https://hub.docker.com/r/mtgto/swift-format/

  14. jmagman commented on Jan 13, 2024

    @jmagman
    Member

    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.

  15. stuartmorgan-g commented on Jan 13, 2024

    @stuartmorgan-g
    ContributorAuthor

    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_podspecs into a more generic repo_checks that also calls swift-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.

  16. github-actions commented on Feb 2, 2024

    @github-actions

    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 -v and a minimal reproduction of the issue.

  17. locked as resolved and limited conversation to collaborators on Feb 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projectc: contributor-productivityTeam-specific productivity, code health, technical debt.p: toolingAffects the flutter_plugin_tools packagepackageflutter/packages repository. See also p: labels.team-ecosystemOwned by Ecosystem teamtriaged-ecosystemTriaged by Ecosystem team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions