Skip to content
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

Add rule to remove blank lines between chained functions #272

Merged
merged 9 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
28 changes: 28 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"configurations": [
{
"type": "lldb",
"request": "launch",
"sourceLanguages": [
"swift"
],
"args": [],
"cwd": "${workspaceFolder:swift}",
"name": "Debug AirbnbSwiftFormatTool",
"program": "${workspaceFolder:swift}/.build/debug/AirbnbSwiftFormatTool",
"preLaunchTask": "swift: Build Debug AirbnbSwiftFormatTool"
},
{
"type": "lldb",
"request": "launch",
"sourceLanguages": [
"swift"
],
"args": [],
"cwd": "${workspaceFolder:swift}",
"name": "Release AirbnbSwiftFormatTool",
"program": "${workspaceFolder:swift}/.build/release/AirbnbSwiftFormatTool",
"preLaunchTask": "swift: Build Release AirbnbSwiftFormatTool"
}
]
}
mannylopez marked this conversation as resolved.
Show resolved Hide resolved
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2091,6 +2091,27 @@ _You can enable the following settings in Xcode by running [this script](resourc

</details>

* <a id='remove-blank-lines-between-chained-functions'></a>(<a href='#remove-blank-lines-between-chained-functions'>link</a>) **Remove blank lines between chained functions.** [![SwiftFormat: blanklinesbetweenchainedfunctions](https://img.shields.io/badge/SwiftFormat-blankLinesBetweenChainedFunctions-7B0051.svg)](https://github.com/nicklockwood/SwiftFormat/blob/main/Rules.md#blanklinesbetweenchainedfunctions)
mannylopez marked this conversation as resolved.
Show resolved Hide resolved
mannylopez marked this conversation as resolved.
Show resolved Hide resolved

<details>

```swift
// WRONG
mannylopez marked this conversation as resolved.
Show resolved Hide resolved
[0, 1, 2]
mannylopez marked this conversation as resolved.
Show resolved Hide resolved
.map { $0 * 2 }



.map { $0 * 3 }
mannylopez marked this conversation as resolved.
Show resolved Hide resolved

// RIGHT
[0, 1, 2]
.map { $0 * 2 }
.map { $0 * 3 }
```

</details>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rule does not remove this empty space if there is a comment in between chained functions. Running the linter will leave this code as-is.

let planets = ["Mercury", "Venus", "Earth", "Mars"]

var transformedPlanetNames: [String] {
   planets
     .map { $0.uppercased() } // Making names uppercase

     // Adding excitement with an exclamation mark
     .map { $0 + "!" }
}

Is this exception necessary? I'd prefer we not allow this, and for consistency remove the blank line here as well.

Looking at the PR that introduced this SwiftFormat rule, I don't see any indication that this behavior was implemented intentionally. It would be easy to update the SwiftFormat rule to handle this case and remove this blank line as well.

What do you think @mannylopez?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the help updating the rule. Here's the SwiftFormat PR to get rid of this exception: nicklockwood/SwiftFormat#1723


### Closures

* <a id='favor-void-closure-return'></a>(<a href='#favor-void-closure-return'>link</a>) **Favor `Void` return types over `()` in closure declarations.** If you must specify a `Void` return type in a function declaration, use `Void` rather than `()` to improve readability. [![SwiftLint: void_return](https://img.shields.io/badge/SwiftLint-void__return-007A87.svg)](https://realm.github.io/SwiftLint/void_return)
Expand Down
3 changes: 2 additions & 1 deletion Sources/AirbnbSwiftFormatTool/airbnb.swiftformat
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,5 @@
--rules wrapMultilineConditionalAssignment
--rules blankLineAfterMultilineSwitchCase
mannylopez marked this conversation as resolved.
Show resolved Hide resolved
--rules consistentSwitchStatementSpacing
--rules semicolons
--rules semicolons
mannylopez marked this conversation as resolved.
Show resolved Hide resolved
--rules blankLinesBetweenChainedFunctions
Loading