Skip to content

Commit

Permalink
Add rule to remove blank lines between chained functions (#272)
Browse files Browse the repository at this point in the history
  • Loading branch information
mannylopez authored Jun 14, 2024
1 parent 51f447c commit f37baa7
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.build
.swiftpm
.DS_Store
.DS_Store
.vscode
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2191,6 +2191,50 @@ _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)

<details>

#### Why?

Improves readability and maintainability, making it easier to see the sequence of functions that are applied to the object.

```swift
// WRONG
var innerPlanetNames: [String] {
planets
.filter { $0.isInnerPlanet }

.map { $0.name }
}

// WRONG
var innerPlanetNames: [String] {
planets
.filter { $0.isInnerPlanet }

// Gets the name of the inner planet
.map { $0.name }
}

// RIGHT
var innerPlanetNames: [String] {
planets
.filter { $0.isInnerPlanet }
.map { $0.name }
}

// RIGHT
var innerPlanetNames: [String] {
planets
.filter { $0.isInnerPlanet }
// Gets the name of the inner planet
.map { $0.name }
}
```

</details>

### 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
1 change: 1 addition & 0 deletions Sources/AirbnbSwiftFormatTool/airbnb.swiftformat
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,4 @@
--rules consistentSwitchCaseSpacing
--rules semicolons
--rules propertyType
--rules blankLinesBetweenChainedFunctions

0 comments on commit f37baa7

Please sign in to comment.