Skip to content

Conversation

mattt
Copy link
Collaborator

@mattt mattt commented Sep 19, 2025

SwiftFormat is a fantastic tool. But because it's not built-in to the Swift toolchain, adopting it for the project introduces friction. I've seen formatting issues creep up in several PR review threads (and not just from external contributors). To put some numbers behind that: GitHub says that the format workflow fails 23% of the time (compared to 35% for unit tests)

Me, I'll never remember to run this myself before committing changes, which is why I opened #216 to configure my editor to do this for me automatically. However, the suggested extension for SwiftFormat requires the user to have swiftformat available in PATH.

Even when swiftformat is available, it's difficult to manage versions — as we saw in #212. I attempted to solve that by managing and running SwiftFormat via Swift Package Manager, but I don't like the ergonomics (swift package plugin --allow-writing-to-package-directory swiftformat --config .swiftformat . 😵‍💫) and I especially don't like how it introduces a transitive dependency to all downstream consumers.

So faced with these challenges, I propose that we go with the flow and standardize on swift format, which is built into the Swift toolchain.

I did my best to make .swift-format match the existing project settings as closely as possible. The resulting diff (97ad29f) is admittedly large, but I don't think it's too onerous (especially since we can ignore with .git-blame-ignore-revs). To my eyes, the formatting diff seems limited to:

  1. Removing spaces in empty braces ({ } -> {})
  2. Indentation of chained methods and conditional statements

On the plus side, swift format has a lint subcommand that greatly simplifies our existing format checking workflow, and provides some helpful checks. For example, it flagged a few instances where documentation comments for a method were out of sync with the signature (e4f76dd).

I understand and acknowledge that issues of project standards can be simultaneously contentious and banal. So I appreciate your taking the time to hear me out 🫶

@FL33TW00D
Copy link
Contributor

Tagging @ZachNagengast as he gave us good guidance on formatting last time.

100% agree these things are usually banal yet contentious. Any solution that works and causes minimal friction is fine with me.

/// - Parameters:
/// - localDir: The local directory where metadata files are downloaded.
/// - filePath: The path of the file for which metadata is being read.
/// - Parameter metadataPath: The path of the metadata file to read.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol nice

Copy link
Member

@pcuenca pcuenca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dislike the unnecessary burden formatters impose, creating friction that in my opinion is artificial.

I'm happy to go with any solution that:

  • Works for the team.
  • Is acceptable / consistent with the community, especially projects in the neighborhood such as argmax's and mlx-swift.

@mattt mattt force-pushed the mattt/swift-format branch from ea8e0c5 to 66c4a66 Compare September 23, 2025 16:46
@mattt mattt merged commit d907980 into main Sep 23, 2025
1 check passed
@mattt mattt deleted the mattt/swift-format branch September 23, 2025 20:24
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