Skip to content

Wrap multi-line function declarations before the last paren #306

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
45 changes: 22 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,17 +160,16 @@ _You can enable the following settings in Xcode by running [this script](resourc
public func executeRequest(
_ request: URLRequest,
onSuccess: @escaping (ModelType, Bool) -> Void,
onFailure: @escaping (Error) -> Void)
-> URLSessionCancellable
{
onFailure: @escaping (Error) -> Void
) -> URLSessionCancellable {
return _executeRequest(request, onSuccess, onFailure)
}

private let _executeRequest: (
URLRequest,
@escaping (ModelType, Bool) -> Void,
@escaping (Error) -> Void)
-> URLSessionCancellable
@escaping (Error) -> Void
) -> URLSessionCancellable
}
```

Expand Down Expand Up @@ -2041,7 +2040,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 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/main/Rules.md#wrapArguments) [![SwiftFormat: braces](https://img.shields.io/badge/SwiftFormat-braces-7B0051.svg)](https://github.com/nicklockwood/SwiftFormat/blob/main/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 closing parenthesis (`)`). [![SwiftFormat: wrapArguments](https://img.shields.io/badge/SwiftFormat-wrapArguments-7B0051.svg)](https://github.com/nicklockwood/SwiftFormat/blob/main/Rules.md#wrapArguments) [![SwiftFormat: braces](https://img.shields.io/badge/SwiftFormat-braces-7B0051.svg)](https://github.com/nicklockwood/SwiftFormat/blob/main/Rules.md#braces)

<details>

Expand Down Expand Up @@ -2097,9 +2096,8 @@ _You can enable the following settings in Xcode by running [this script](resourc
at location: Point,
count: Int,
color: StarColor,
withAverageDistance averageDistance: Float)
-> String
{
withAverageDistance averageDistance: Float
) -> String {
populateUniverse()
}

Expand All @@ -2108,9 +2106,8 @@ _You can enable the following settings in Xcode by running [this script](resourc
at location: Point,
count: Int,
color: StarColor,
withAverageDistance averageDistance: Float)
async throws -> String
{
withAverageDistance averageDistance: Float
) async throws -> String {
populateUniverse()
}
}
Expand Down Expand Up @@ -3427,9 +3424,10 @@ _You can enable the following settings in Xcode by running [this script](resourc
// WRONG
func spaceshipDashboard<WarpDriveView: View, CaptainsLogView: View>(
warpDrive: WarpDriveView,
captainsLog: CaptainsLogView)
-> some View
{ … }
captainsLog: CaptainsLogView
) -> some View {
}

func generate<Planets>(_ planets: Planets) where Planets: Collection, Planets.Element == Planet {
Expand All @@ -3438,9 +3436,10 @@ _You can enable the following settings in Xcode by running [this script](resourc
// RIGHT
func spaceshipDashboard(
warpDrive: some View,
captainsLog: some View)
-> some View
{ … }
captainsLog: some View
) -> some View {
}

func generate(_ planets: some Collection<Planet>) {
Expand All @@ -3453,7 +3452,7 @@ _You can enable the following settings in Xcode by running [this script](resourc
}

// Also fine, since the generic parameter name is referenced in the function body so can't be removed:
func terraform<Body: PlanetaryBody>(_ planetaryBody: Body) {
func terraform<Body: PlanetaryBody>(_ planetaryBody: Body) {
planetaryBody.generateAtmosphere(Body.idealAtmosphere)
}
```
Expand All @@ -3466,8 +3465,8 @@ _You can enable the following settings in Xcode by running [this script](resourc
func assertFailure<Value>(
_ result: Result<Value, Error>,
file: StaticString = #filePath,
line: UInt = #line)
{
line: UInt = #line
) {
if case .failure(let error) = result {
XCTFail(error.localizedDescription, file: file, line: line)
}
Expand All @@ -3477,8 +3476,8 @@ _You can enable the following settings in Xcode by running [this script](resourc
func assertFailure(
_ result: Result<some Any, Error>,
file: StaticString = #filePath,
line: UInt = #line)
{
line: UInt = #line
) {
if case .failure(let error) = result {
XCTFail(error.localizedDescription, file: file, line: line)
}
Expand Down
7 changes: 4 additions & 3 deletions Sources/AirbnbSwiftFormatTool/airbnb.swiftformat
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
--wrapparameters before-first # wrapArguments
--wrapcollections before-first # wrapArguments
--wrapconditions before-first # wrapArguments
--wrapreturntype if-multiline #wrapArguments
--wrapeffects if-multiline #wrapArguments
--closingparen same-line # wrapArguments
--wrapreturntype never #wrapArguments
--wrapeffects never #wrapArguments
--closingparen balanced # wrapArguments
--callsiteparen same-line # wrapArguments
--wraptypealiases before-first # wrapArguments
--funcattributes prev-line # wrapAttributes
--computedvarattrs prev-line # wrapAttributes
Expand Down
Loading