Skip to content

Match call-site paren on multi-line function calls #308

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,18 @@ let package = Package(
capability: .command(
intent: .custom(
verb: "format",
description: "Formats Swift source files according to the Airbnb Swift Style Guide"),
description: "Formats Swift source files according to the Airbnb Swift Style Guide"
),
permissions: [
.writeToPackageDirectory(reason: "Format Swift source files"),
]),
]
),
dependencies: [
"AirbnbSwiftFormatTool",
"swiftformat",
"SwiftLintBinary",
]),
]
),

.executableTarget(
name: "AirbnbSwiftFormatTool",
Expand All @@ -34,19 +37,24 @@ let package = Package(
resources: [
.process("airbnb.swiftformat"),
.process("swiftlint.yml"),
]),
]
),

.testTarget(
name: "AirbnbSwiftFormatToolTests",
dependencies: ["AirbnbSwiftFormatTool"]),
dependencies: ["AirbnbSwiftFormatTool"]
),

.binaryTarget(
name: "swiftformat",
url: "https://github.com/calda/SwiftFormat-nightly/releases/download/2025-05-15-b/SwiftFormat.artifactbundle.zip",
checksum: "0d6f365f00de0567c5a7a0caf33b593c2a9029cf27462c63879280839f5f2d9c"),
checksum: "0d6f365f00de0567c5a7a0caf33b593c2a9029cf27462c63879280839f5f2d9c"
),

.binaryTarget(
name: "SwiftLintBinary",
url: "https://github.com/realm/SwiftLint/releases/download/0.55.1/SwiftLintBinary-macos.artifactbundle.zip",
checksum: "722a705de1cf4e0e07f2b7d2f9f631f3a8b2635a0c84cce99f9677b38aa4a1d6"),
])
checksum: "722a705de1cf4e0e07f2b7d2f9f631f3a8b2635a0c84cce99f9677b38aa4a1d6"
),
]
)
12 changes: 8 additions & 4 deletions Plugins/FormatSwift/Plugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ extension AirbnbSwiftFormatPlugin: CommandPlugin {
try performCommand(
context: context,
inputPaths: inputPaths,
arguments: arguments)
arguments: arguments
)
}

// MARK: Private
Expand All @@ -125,7 +126,8 @@ extension AirbnbSwiftFormatPlugin: CommandPlugin {
let packageDirectoryContents = try FileManager.default.contentsOfDirectory(
at: URL(fileURLWithPath: package.directory.string),
includingPropertiesForKeys: nil,
options: [.skipsHiddenFiles])
options: [.skipsHiddenFiles]
)

let subdirectories = packageDirectoryContents.filter { $0.hasDirectoryPath }
let rootSwiftFiles = packageDirectoryContents.filter { $0.pathExtension.hasSuffix("swift") }
Expand Down Expand Up @@ -154,7 +156,8 @@ extension AirbnbSwiftFormatPlugin: XcodeCommandPlugin {
try performCommand(
context: context,
inputPaths: Array(inputPaths),
arguments: argumentExtractor.remainingArguments)
arguments: argumentExtractor.remainingArguments
)
}

}
Expand Down Expand Up @@ -212,7 +215,8 @@ extension Package {
// Look for all of the package manifest files in the directory root
let filesInRootDirectory = try? FileManager.default.contentsOfDirectory(
at: projectDirectory,
includingPropertiesForKeys: nil)
includingPropertiesForKeys: nil
)

for fileURL in filesInRootDirectory ?? [] {
let fileName = fileURL.lastPathComponent
Expand Down
77 changes: 46 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1633,7 +1633,8 @@ _You can enable the following settings in Xcode by running [this script](resourc
class Planet {
func terraform(
atmosphereOptions: AtmosphereOptions = .default,
oceanOptions: OceanOptions = .default) {
oceanOptions: OceanOptions = .default
) {
generateAtmosphere(atmosphereOptions)
generateOceans(oceanOptions)
}
Expand All @@ -1650,8 +1651,8 @@ _You can enable the following settings in Xcode by running [this script](resourc
class Planet {
func terraform(
atmosphereOptions: AtmosphereOptions = .default,
oceanOptions: OceanOptions = .default)
{
oceanOptions: OceanOptions = .default
) {
generateAtmosphere(atmosphereOptions)
generateOceans(oceanOptions)
}
Expand Down Expand Up @@ -2115,7 +2116,7 @@ _You can enable the following settings in Xcode by running [this script](resourc

</details>

* <a id='long-function-invocation'></a>(<a href='#long-function-invocation'>link</a>) **[Long](https://github.com/airbnb/swift#column-width) function invocations should also break on each argument.** Put the closing parenthesis on the last line of the invocation. [![SwiftFormat: wrapArguments](https://img.shields.io/badge/SwiftFormat-wrapArguments-7B0051.svg)](https://github.com/nicklockwood/SwiftFormat/blob/main/Rules.md#wrapArguments)
* <a id='long-function-invocation'></a>(<a href='#long-function-invocation'>link</a>) **[Long](https://github.com/airbnb/swift#column-width) function calls should also break on each argument.** Put the closing parenthesis on its own line. [![SwiftFormat: wrapArguments](https://img.shields.io/badge/SwiftFormat-wrapArguments-7B0051.svg)](https://github.com/nicklockwood/SwiftFormat/blob/main/Rules.md#wrapArguments)

<details>

Expand All @@ -2134,8 +2135,7 @@ _You can enable the following settings in Xcode by running [this script](resourc
at: location,
count: 5,
color: starColor,
withAverageDistance: 4
)
withAverageDistance: 4)

// WRONG
universe.generate(5,
Expand All @@ -2147,13 +2147,15 @@ _You can enable the following settings in Xcode by running [this script](resourc
at: location,
count: 5,
color: starColor,
withAverageDistance: 4)
withAverageDistance: 4
)

// RIGHT
universe.generate(
5,
.stars,
at: location)
at: location
)
```

</details>
Expand Down Expand Up @@ -2184,13 +2186,14 @@ _You can enable the following settings in Xcode by running [this script](resourc
at location: Point,
count: Int,
color: StarColor,
withAverageDistance averageDistance: Float)
{
withAverageDistance averageDistance: Float
) {
let universe = generateUniverse()
universe.generateStars(
at: location,
count: count,
withAverageDistance: averageDistance)
withAverageDistance: averageDistance
)
}
```

Expand All @@ -2213,13 +2216,14 @@ _You can enable the following settings in Xcode by running [this script](resourc
at location: Point,
count: Int,
color _: StarColor,
withAverageDistance averageDistance: Float)
{
withAverageDistance averageDistance: Float
) {
let universe = generateUniverse()
universe.generateStars(
at: location,
count: count,
withAverageDistance: averageDistance)
withAverageDistance: averageDistance
)
}
```

Expand Down Expand Up @@ -2424,16 +2428,18 @@ _You can enable the following settings in Xcode by running [this script](resourc

func colonizePlanet() {
spaceship.travel(to: planet, onArrival: { [weak self] in
guard let self else { return }
planet.colonize()
})
guard let self else { return }
planet.colonize()
}
)
}

func exploreSystem() {
spaceship.travel(to: planet, nextDestination: { [weak self] in
guard let self else { return nil }
return planet.moons?.first
})
guard let self else { return nil }
return planet.moons?.first
}
)
}
}
```
Expand All @@ -2448,14 +2454,16 @@ _You can enable the following settings in Xcode by running [this script](resourc

func colonizePlanet() {
spaceship.travel(to: planet, onArrival: { [planet] in
planet.colonize()
})
planet.colonize()
}
)
}

func exploreSystem() {
spaceship.travel(to: planet, nextDestination: { [planet] in
planet.moons?.first
})
planet.moons?.first
}
)
}
}
```
Expand Down Expand Up @@ -3201,14 +3209,16 @@ _You can enable the following settings in Xcode by running [this script](resourc
var size: CGSize {
return CGSize(
width: 100.0,
height: 100.0)
height: 100.0
)
}

func makeInfoAlert(message: String) -> UIAlertController {
return UIAlertController(
title: "ℹ️ Info",
message: message,
preferredStyle: .alert)
preferredStyle: .alert
)
}

var alertTitle: String {
Expand All @@ -3234,14 +3244,16 @@ _You can enable the following settings in Xcode by running [this script](resourc
var size: CGSize {
CGSize(
width: 100.0,
height: 100.0)
height: 100.0
)
}

func makeInfoAlert(message: String) -> UIAlertController {
UIAlertController(
title: "ℹ️ Info",
message: message,
preferredStyle: .alert)
preferredStyle: .alert
)
}

var alertTitle: String {
Expand Down Expand Up @@ -3371,7 +3383,8 @@ _You can enable the following settings in Xcode by running [this script](resourc
at: location,
count: 5,
color: starColor,
withAverageDistance: 4)
withAverageDistance: 4
)
}()

// RIGHT
Expand All @@ -3381,7 +3394,8 @@ _You can enable the following settings in Xcode by running [this script](resourc
at: location,
count: 5,
color: starColor,
withAverageDistance: 4)
withAverageDistance: 4
)
```

</details>
Expand Down Expand Up @@ -4267,7 +4281,8 @@ _You can enable the following settings in Xcode by running [this script](resourc
acceptButton.addTarget(
self,
action: #selector(didTapAcceptButton),
forControlEvents: .touchUpInside)
forControlEvents: .touchUpInside
)
}

@objc
Expand Down
6 changes: 4 additions & 2 deletions Sources/AirbnbSwiftFormatTool/AirbnbSwiftFormatTool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ struct AirbnbSwiftFormatTool: ParsableCommand {
return Command(
log: log,
launchPath: swiftFormatPath,
arguments: arguments)
arguments: arguments
)
}

/// Builds a command that runs the SwiftLint tool
Expand All @@ -140,7 +141,8 @@ struct AirbnbSwiftFormatTool: ParsableCommand {
return Command(
log: log,
launchPath: swiftLintPath,
arguments: arguments)
arguments: arguments
)
}

private func log(_ string: String) {
Expand Down
2 changes: 1 addition & 1 deletion Sources/AirbnbSwiftFormatTool/airbnb.swiftformat
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
--wrapreturntype never #wrapArguments
--wrapeffects never #wrapArguments
--closingparen balanced # wrapArguments
--callsiteparen same-line # wrapArguments
--callsiteparen balanced # wrapArguments
--wraptypealiases before-first # wrapArguments
--funcattributes prev-line # wrapAttributes
--computedvarattrs prev-line # wrapAttributes
Expand Down
Loading