File tree Expand file tree Collapse file tree 3 files changed +19
-1
lines changed
Sources/AirbnbSwiftFormatTool Expand file tree Collapse file tree 3 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -84,10 +84,17 @@ extension AirbnbSwiftFormatPlugin: CommandPlugin {
8484 } )
8585 }
8686
87+ // When running on a SPM package we infer the minimum Swift version from the
88+ // `swift-tools-version` in `Package.swift`
89+ let additionalArguments = [
90+ " --swift-version " ,
91+ " \( context. package . toolsVersion. major) . \( context. package . toolsVersion. minor) " ,
92+ ] + argumentExtractor. remainingArguments
93+
8794 try performCommand (
8895 context: context,
8996 inputPaths: inputPaths,
90- additionalArguments: argumentExtractor . remainingArguments )
97+ additionalArguments: additionalArguments )
9198 }
9299
93100 // MARK: Private
Original file line number Diff line number Diff line change @@ -59,6 +59,10 @@ $ swift package format --exclude Tests
5959# Alternatively you can explicitly list the set of paths and/or SPM targets:
6060$ swift package format --paths Sources Tests Package.swift
6161$ swift package format --targets AirbnbSwiftFormatTool
62+
63+ # The plugin infers your package's minimum Swift version from the `swift-tools-version`
64+ # in your `Package.swift`, but you can provide a custom value with `--swift-version`:
65+ $ swift package format --swift-version 5.3
6266```
6367
6468</details >
Original file line number Diff line number Diff line change @@ -37,6 +37,9 @@ struct AirbnbSwiftFormatTool: ParsableCommand {
3737 @Option ( help: " The absolute path to the SwiftLint config file " )
3838 var swiftLintConfig = Bundle . module. path ( forResource: " swiftlint " , ofType: " yml " ) !
3939
40+ @Option ( help: " The project's minimum Swift version " )
41+ var swiftVersion : String ?
42+
4043 mutating func run( ) throws {
4144 try swiftFormat. run ( )
4245 swiftFormat. waitUntilExit ( )
@@ -83,6 +86,10 @@ struct AirbnbSwiftFormatTool: ParsableCommand {
8386 arguments += [ " --lint " ]
8487 }
8588
89+ if let swiftVersion = swiftVersion {
90+ arguments += [ " --swiftversion " , swiftVersion]
91+ }
92+
8693 let swiftFormat = Process ( )
8794 swiftFormat. launchPath = swiftFormatPath
8895 swiftFormat. arguments = arguments
You can’t perform that action at this time.
0 commit comments