I found a solution to this issue and am sharing my findings:
With Xcode 16, swift-format
is included as part of the Xcode toolchain, eliminating the need for external libraries and making Swift file formatting more convenient.
You can lint your Swift package without third-party dependencies by:
Package.swift
fileswift-format
from Xcode 16When your package builds, Xcode will show warnings for formatting issues like the inconsistent indentation in my example:
struct MyPackage {
var a: Int
var b: Int // This will show a warning in Xcode
var c: Int
}
The warnings are displayed directly in Xcode’s issue navigator during the build process.
For a comprehensive guide with step-by-step instructions and sample code, refer to this article: Linting a Swift Package with swift-format
Note that while the article references adding swift-format
as a dependency, with Xcode 16 you can simplify this approach by using the built-in toolchain version instead.