Skip to content

Commit 07bb2e0

Browse files
authored
Update rule for long function declarations to specify effects (async, throws) should be written on the line after the closing paren (#205)
1 parent 9ea3428 commit 07bb2e0

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

Package.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ let package = Package(
3838

3939
.binaryTarget(
4040
name: "SwiftFormat",
41-
url: "https://github.com/calda/SwiftFormat/releases/download/0.51-beta-3/SwiftFormat.artifactbundle.zip",
42-
checksum: "4b0516d911258b55c3960949f4a516a246f35a1dc7647a6440c66e1f1fe1a32e"),
41+
url: "https://github.com/calda/SwiftFormat/releases/download/0.51-beta-6/SwiftFormat.artifactbundle.zip",
42+
checksum: "8583456d892c99f970787b4ed756a7e0c83a0d9645e923bb4dae10d581c59bc3"),
4343

4444
.binaryTarget(
4545
name: "SwiftLintBinary",

README.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,7 +1152,7 @@ _You can enable the following settings in Xcode by running [this script](resourc
11521152

11531153
</details>
11541154

1155-
* <a id='long-function-declaration'></a>(<a href='#long-function-declaration'>link</a>) **Separate [long](https://github.com/airbnb/swift#column-width) function declarations with line breaks before each argument label and before the return signature.** Put the open curly brace on the next line so the first executable line doesn't look like it's another parameter. [![SwiftFormat: wrapArguments](https://img.shields.io/badge/SwiftFormat-wrapArguments-7B0051.svg)](https://github.com/nicklockwood/SwiftFormat/blob/master/Rules.md#wrapArguments) [![SwiftFormat: braces](https://img.shields.io/badge/SwiftFormat-braces-7B0051.svg)](https://github.com/nicklockwood/SwiftFormat/blob/master/Rules.md#braces)
1155+
* <a id='long-function-declaration'></a>(<a href='#long-function-declaration'>link</a>) **Separate [long](https://github.com/airbnb/swift#column-width) function declarations with line breaks before each argument label, and before the return signature or any effects (`async`, `throws`).** Put the open curly brace on the next line so the first executable line doesn't look like it's another parameter. [![SwiftFormat: wrapArguments](https://img.shields.io/badge/SwiftFormat-wrapArguments-7B0051.svg)](https://github.com/nicklockwood/SwiftFormat/blob/master/Rules.md#wrapArguments) [![SwiftFormat: braces](https://img.shields.io/badge/SwiftFormat-braces-7B0051.svg)](https://github.com/nicklockwood/SwiftFormat/blob/master/Rules.md#braces)
11561156

11571157
<details>
11581158

@@ -1192,6 +1192,17 @@ _You can enable the following settings in Xcode by running [this script](resourc
11921192
populateUniverse() // this line blends in with the argument list
11931193
}
11941194

1195+
// WRONG
1196+
func generateStars(
1197+
at location: Point,
1198+
count: Int,
1199+
color: StarColor,
1200+
withAverageDistance averageDistance: Float) async throws // these effects are easy to miss since they're visually associated with the last parameter
1201+
-> String
1202+
{
1203+
populateUniverse()
1204+
}
1205+
11951206
// RIGHT
11961207
func generateStars(
11971208
at location: Point,
@@ -1209,7 +1220,7 @@ _You can enable the following settings in Xcode by running [this script](resourc
12091220
count: Int,
12101221
color: StarColor,
12111222
withAverageDistance averageDistance: Float)
1212-
throws -> String
1223+
async throws -> String
12131224
{
12141225
populateUniverse()
12151226
}

Sources/AirbnbSwiftFormatTool/airbnb.swiftformat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
--wrapcollections before-first # wrapArguments
1313
--wrapconditions before-first # wrapArguments
1414
--wrapreturntype if-multiline #wrapArguments
15+
--wrapeffects if-multiline #wrapArguments
1516
--closingparen same-line # wrapArguments
1617
--wraptypealiases before-first # wrapArguments
1718
--funcattributes prev-line # wrapAttributes

0 commit comments

Comments
 (0)