Skip to content

Commit 0f7a388

Browse files
authored
Match call-site paren on multi-line function calls (#308)
1 parent 7499eeb commit 0f7a388

File tree

6 files changed

+100
-55
lines changed

6 files changed

+100
-55
lines changed

Package.swift

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,18 @@ let package = Package(
1616
capability: .command(
1717
intent: .custom(
1818
verb: "format",
19-
description: "Formats Swift source files according to the Airbnb Swift Style Guide"),
19+
description: "Formats Swift source files according to the Airbnb Swift Style Guide"
20+
),
2021
permissions: [
2122
.writeToPackageDirectory(reason: "Format Swift source files"),
22-
]),
23+
]
24+
),
2325
dependencies: [
2426
"AirbnbSwiftFormatTool",
2527
"swiftformat",
2628
"SwiftLintBinary",
27-
]),
29+
]
30+
),
2831

2932
.executableTarget(
3033
name: "AirbnbSwiftFormatTool",
@@ -34,19 +37,24 @@ let package = Package(
3437
resources: [
3538
.process("airbnb.swiftformat"),
3639
.process("swiftlint.yml"),
37-
]),
40+
]
41+
),
3842

3943
.testTarget(
4044
name: "AirbnbSwiftFormatToolTests",
41-
dependencies: ["AirbnbSwiftFormatTool"]),
45+
dependencies: ["AirbnbSwiftFormatTool"]
46+
),
4247

4348
.binaryTarget(
4449
name: "swiftformat",
4550
url: "https://github.com/calda/SwiftFormat-nightly/releases/download/2025-05-15-b/SwiftFormat.artifactbundle.zip",
46-
checksum: "0d6f365f00de0567c5a7a0caf33b593c2a9029cf27462c63879280839f5f2d9c"),
51+
checksum: "0d6f365f00de0567c5a7a0caf33b593c2a9029cf27462c63879280839f5f2d9c"
52+
),
4753

4854
.binaryTarget(
4955
name: "SwiftLintBinary",
5056
url: "https://github.com/realm/SwiftLint/releases/download/0.55.1/SwiftLintBinary-macos.artifactbundle.zip",
51-
checksum: "722a705de1cf4e0e07f2b7d2f9f631f3a8b2635a0c84cce99f9677b38aa4a1d6"),
52-
])
57+
checksum: "722a705de1cf4e0e07f2b7d2f9f631f3a8b2635a0c84cce99f9677b38aa4a1d6"
58+
),
59+
]
60+
)

Plugins/FormatSwift/Plugin.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ extension AirbnbSwiftFormatPlugin: CommandPlugin {
106106
try performCommand(
107107
context: context,
108108
inputPaths: inputPaths,
109-
arguments: arguments)
109+
arguments: arguments
110+
)
110111
}
111112

112113
// MARK: Private
@@ -125,7 +126,8 @@ extension AirbnbSwiftFormatPlugin: CommandPlugin {
125126
let packageDirectoryContents = try FileManager.default.contentsOfDirectory(
126127
at: URL(fileURLWithPath: package.directory.string),
127128
includingPropertiesForKeys: nil,
128-
options: [.skipsHiddenFiles])
129+
options: [.skipsHiddenFiles]
130+
)
129131

130132
let subdirectories = packageDirectoryContents.filter { $0.hasDirectoryPath }
131133
let rootSwiftFiles = packageDirectoryContents.filter { $0.pathExtension.hasSuffix("swift") }
@@ -154,7 +156,8 @@ extension AirbnbSwiftFormatPlugin: XcodeCommandPlugin {
154156
try performCommand(
155157
context: context,
156158
inputPaths: Array(inputPaths),
157-
arguments: argumentExtractor.remainingArguments)
159+
arguments: argumentExtractor.remainingArguments
160+
)
158161
}
159162

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

217221
for fileURL in filesInRootDirectory ?? [] {
218222
let fileName = fileURL.lastPathComponent

README.md

Lines changed: 46 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1633,7 +1633,8 @@ _You can enable the following settings in Xcode by running [this script](resourc
16331633
class Planet {
16341634
func terraform(
16351635
atmosphereOptions: AtmosphereOptions = .default,
1636-
oceanOptions: OceanOptions = .default) {
1636+
oceanOptions: OceanOptions = .default
1637+
) {
16371638
generateAtmosphere(atmosphereOptions)
16381639
generateOceans(oceanOptions)
16391640
}
@@ -1650,8 +1651,8 @@ _You can enable the following settings in Xcode by running [this script](resourc
16501651
class Planet {
16511652
func terraform(
16521653
atmosphereOptions: AtmosphereOptions = .default,
1653-
oceanOptions: OceanOptions = .default)
1654-
{
1654+
oceanOptions: OceanOptions = .default
1655+
) {
16551656
generateAtmosphere(atmosphereOptions)
16561657
generateOceans(oceanOptions)
16571658
}
@@ -2115,7 +2116,7 @@ _You can enable the following settings in Xcode by running [this script](resourc
21152116

21162117
</details>
21172118

2118-
* <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)
2119+
* <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)
21192120

21202121
<details>
21212122

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

21402140
// WRONG
21412141
universe.generate(5,
@@ -2147,13 +2147,15 @@ _You can enable the following settings in Xcode by running [this script](resourc
21472147
at: location,
21482148
count: 5,
21492149
color: starColor,
2150-
withAverageDistance: 4)
2150+
withAverageDistance: 4
2151+
)
21512152

21522153
// RIGHT
21532154
universe.generate(
21542155
5,
21552156
.stars,
2156-
at: location)
2157+
at: location
2158+
)
21572159
```
21582160

21592161
</details>
@@ -2184,13 +2186,14 @@ _You can enable the following settings in Xcode by running [this script](resourc
21842186
at location: Point,
21852187
count: Int,
21862188
color: StarColor,
2187-
withAverageDistance averageDistance: Float)
2188-
{
2189+
withAverageDistance averageDistance: Float
2190+
) {
21892191
let universe = generateUniverse()
21902192
universe.generateStars(
21912193
at: location,
21922194
count: count,
2193-
withAverageDistance: averageDistance)
2195+
withAverageDistance: averageDistance
2196+
)
21942197
}
21952198
```
21962199

@@ -2213,13 +2216,14 @@ _You can enable the following settings in Xcode by running [this script](resourc
22132216
at location: Point,
22142217
count: Int,
22152218
color _: StarColor,
2216-
withAverageDistance averageDistance: Float)
2217-
{
2219+
withAverageDistance averageDistance: Float
2220+
) {
22182221
let universe = generateUniverse()
22192222
universe.generateStars(
22202223
at: location,
22212224
count: count,
2222-
withAverageDistance: averageDistance)
2225+
withAverageDistance: averageDistance
2226+
)
22232227
}
22242228
```
22252229

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

24252429
func colonizePlanet() {
24262430
spaceship.travel(to: planet, onArrival: { [weak self] in
2427-
guard let self else { return }
2428-
planet.colonize()
2429-
})
2431+
guard let self else { return }
2432+
planet.colonize()
2433+
}
2434+
)
24302435
}
24312436

24322437
func exploreSystem() {
24332438
spaceship.travel(to: planet, nextDestination: { [weak self] in
2434-
guard let self else { return nil }
2435-
return planet.moons?.first
2436-
})
2439+
guard let self else { return nil }
2440+
return planet.moons?.first
2441+
}
2442+
)
24372443
}
24382444
}
24392445
```
@@ -2448,14 +2454,16 @@ _You can enable the following settings in Xcode by running [this script](resourc
24482454

24492455
func colonizePlanet() {
24502456
spaceship.travel(to: planet, onArrival: { [planet] in
2451-
planet.colonize()
2452-
})
2457+
planet.colonize()
2458+
}
2459+
)
24532460
}
24542461

24552462
func exploreSystem() {
24562463
spaceship.travel(to: planet, nextDestination: { [planet] in
2457-
planet.moons?.first
2458-
})
2464+
planet.moons?.first
2465+
}
2466+
)
24592467
}
24602468
}
24612469
```
@@ -3201,14 +3209,16 @@ _You can enable the following settings in Xcode by running [this script](resourc
32013209
var size: CGSize {
32023210
return CGSize(
32033211
width: 100.0,
3204-
height: 100.0)
3212+
height: 100.0
3213+
)
32053214
}
32063215

32073216
func makeInfoAlert(message: String) -> UIAlertController {
32083217
return UIAlertController(
32093218
title: "ℹ️ Info",
32103219
message: message,
3211-
preferredStyle: .alert)
3220+
preferredStyle: .alert
3221+
)
32123222
}
32133223

32143224
var alertTitle: String {
@@ -3234,14 +3244,16 @@ _You can enable the following settings in Xcode by running [this script](resourc
32343244
var size: CGSize {
32353245
CGSize(
32363246
width: 100.0,
3237-
height: 100.0)
3247+
height: 100.0
3248+
)
32383249
}
32393250

32403251
func makeInfoAlert(message: String) -> UIAlertController {
32413252
UIAlertController(
32423253
title: "ℹ️ Info",
32433254
message: message,
3244-
preferredStyle: .alert)
3255+
preferredStyle: .alert
3256+
)
32453257
}
32463258

32473259
var alertTitle: String {
@@ -3371,7 +3383,8 @@ _You can enable the following settings in Xcode by running [this script](resourc
33713383
at: location,
33723384
count: 5,
33733385
color: starColor,
3374-
withAverageDistance: 4)
3386+
withAverageDistance: 4
3387+
)
33753388
}()
33763389

33773390
// RIGHT
@@ -3381,7 +3394,8 @@ _You can enable the following settings in Xcode by running [this script](resourc
33813394
at: location,
33823395
count: 5,
33833396
color: starColor,
3384-
withAverageDistance: 4)
3397+
withAverageDistance: 4
3398+
)
33853399
```
33863400

33873401
</details>
@@ -4267,7 +4281,8 @@ _You can enable the following settings in Xcode by running [this script](resourc
42674281
acceptButton.addTarget(
42684282
self,
42694283
action: #selector(didTapAcceptButton),
4270-
forControlEvents: .touchUpInside)
4284+
forControlEvents: .touchUpInside
4285+
)
42714286
}
42724287

42734288
@objc

Sources/AirbnbSwiftFormatTool/AirbnbSwiftFormatTool.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ struct AirbnbSwiftFormatTool: ParsableCommand {
116116
return Command(
117117
log: log,
118118
launchPath: swiftFormatPath,
119-
arguments: arguments)
119+
arguments: arguments
120+
)
120121
}
121122

122123
/// Builds a command that runs the SwiftLint tool
@@ -140,7 +141,8 @@ struct AirbnbSwiftFormatTool: ParsableCommand {
140141
return Command(
141142
log: log,
142143
launchPath: swiftLintPath,
143-
arguments: arguments)
144+
arguments: arguments
145+
)
144146
}
145147

146148
private func log(_ string: String) {

Sources/AirbnbSwiftFormatTool/airbnb.swiftformat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
--wrapreturntype never #wrapArguments
1919
--wrapeffects never #wrapArguments
2020
--closingparen balanced # wrapArguments
21-
--callsiteparen same-line # wrapArguments
21+
--callsiteparen balanced # wrapArguments
2222
--wraptypealiases before-first # wrapArguments
2323
--funcattributes prev-line # wrapAttributes
2424
--computedvarattrs prev-line # wrapAttributes

0 commit comments

Comments
 (0)