Skip to content
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
46 changes: 46 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2196,6 +2196,52 @@ _You can enable the following settings in Xcode by running [this script](resourc

</details>

- <a id='wrap-single-line-declaration-bodies'></a>(<a href='#wrap-single-line-declaration-bodies'>link</a>) **Wrap single-line function, init, subscript, and computed property bodies onto multiple lines.**
Copy link
Member

Choose a reason for hiding this comment

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

Wording like this might be more "style advice" oriented as opposed to imperative "code formatter" oriented.

Suggested change
- <a id='wrap-single-line-declaration-bodies'></a>(<a href='#wrap-single-line-declaration-bodies'>link</a>) **Wrap single-line function, init, subscript, and computed property bodies onto multiple lines.**
- <a id='wrap-single-line-declaration-bodies'></a>(<a href='#wrap-single-line-declaration-bodies'>link</a>) **Always wrap function and property bodies onto multiple lines.**


<details>

[![SwiftFormat: wrapSingleLineBodies](https://img.shields.io/badge/SwiftFormat-wrapSingleLineBodies-7B0051.svg)](https://github.com/nicklockwood/SwiftFormat/blob/main/Rules.md#wrapSingleLineBodies)

```swift
// WRONG
func foo() { print("bar") }
Copy link
Member

Choose a reason for hiding this comment

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

Since we try to avoid foo / bar in the style guide document, what do you think about updating this to the space theme? Claude should be able to think of a good example


init() { self.value = 0 }

subscript(index: Int) -> Int { array[index] }

var bar: String { "bar" }
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we put the var example first since var and func are the most common examples


// RIGHT
func foo() {
print("bar")
}

init() {
self.value = 0
}

subscript(index: Int) -> Int {
array[index]
}

var bar: String {
"bar"
}
```

_Exception: This rule does not affect protocol definitions._

```swift
// RIGHT
protocol SpaceshipEngine {
func engage() -> Bool
var fuelLevel: Double { get }
}
```

</details>

### Functions

- <a id='omit-function-void-return'></a>(<a href='#omit-function-void-return'>link</a>) **Omit `Void` return types from function definitions.**
Copy link
Member

Choose a reason for hiding this comment

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

Can we put the new rule after the "long function declarations" rule?

Expand Down
1 change: 1 addition & 0 deletions Sources/AirbnbSwiftFormatTool/airbnb.swiftformat
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@
--rules preferForLoop
--rules conditionalAssignment
--rules wrapMultilineConditionalAssignment
--rules wrapSingleLineBodies
--rules void
--rules blankLineAfterSwitchCase
--rules consistentSwitchCaseSpacing
Expand Down
Loading