Skip to content

Conversation

@mattt
Copy link
Collaborator

@mattt mattt commented Sep 2, 2025

The format workflow currently defines the current SwiftFormat version as an environment variable:

env:
SWIFTFORMAT_VERSION: "0.54.6"

As we see in #223, defining a constant here creates drift over time.

This PR proposes to declare SwiftFormat as a package dependency and call it as a Swift Package Manager plugin. This approach defines a single source of truth for managing the development dependency, and provide developers and CI a unified way to apply and lint project standards.

Before

brew install swiftformat # or curl && unzip && etc.
swiftformat --config .swiftformat .

After

swift package plugin --allow-writing-to-package-directory swiftformat --config .swiftformat .

dependencies: [
.package(url: "https://github.com/apple/swift-argument-parser.git", .upToNextMinor(from: "1.4.0")),
.package(url: "https://github.com/johnmai-dev/Jinja", .upToNextMinor(from: "1.2.1")),
.package(url: "https://github.com/nicklockwood/SwiftFormat", from: "0.57.0"),
Copy link
Member

Choose a reason for hiding this comment

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

So this would unconditionally download the dependency and compile it on the fly when swift package plugin is invoked?

Could download be potentially avoided hiding it behind an opt-in traits wall? (Just to understand it better, still testing that approach in its PR)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Swift Package Manager automatically downloads all declared dependencies whenever it resolves the dependency graph — so, anytime you run swift build and swift package plugin. My understanding is that it's built on-demand only when you invoke swift package plugin. Unfortunately, I don't believe traits would help us here.

@mattt
Copy link
Collaborator Author

mattt commented Sep 19, 2025

Closing in favor of #248

@mattt mattt closed this Sep 19, 2025
@mattt mattt deleted the mattt/swiftformat-plugin branch September 19, 2025 08:20
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