Skip to content

Commit

Permalink
Update rule for long function declarations to specify effects (`async…
Browse files Browse the repository at this point in the history
…`, `throws`) should be written on the line after the closing paren (#205)
  • Loading branch information
calda authored Nov 11, 2022
1 parent 9ea3428 commit 07bb2e0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ let package = Package(

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

.binaryTarget(
name: "SwiftLintBinary",
Expand Down
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1152,7 +1152,7 @@ _You can enable the following settings in Xcode by running [this script](resourc

</details>

* <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)
* <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)

<details>

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

// WRONG
func generateStars(
at location: Point,
count: Int,
color: StarColor,
withAverageDistance averageDistance: Float) async throws // these effects are easy to miss since they're visually associated with the last parameter
-> String
{
populateUniverse()
}

// RIGHT
func generateStars(
at location: Point,
Expand All @@ -1209,7 +1220,7 @@ _You can enable the following settings in Xcode by running [this script](resourc
count: Int,
color: StarColor,
withAverageDistance averageDistance: Float)
throws -> String
async throws -> String
{
populateUniverse()
}
Expand Down
1 change: 1 addition & 0 deletions Sources/AirbnbSwiftFormatTool/airbnb.swiftformat
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
--wrapcollections before-first # wrapArguments
--wrapconditions before-first # wrapArguments
--wrapreturntype if-multiline #wrapArguments
--wrapeffects if-multiline #wrapArguments
--closingparen same-line # wrapArguments
--wraptypealiases before-first # wrapArguments
--funcattributes prev-line # wrapAttributes
Expand Down

0 comments on commit 07bb2e0

Please sign in to comment.