-
Notifications
You must be signed in to change notification settings - Fork 344
Add wrapSingleLineBodies #352
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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.** | ||
|
|
||
| <details> | ||
|
|
||
| [](https://github.com/nicklockwood/SwiftFormat/blob/main/Rules.md#wrapSingleLineBodies) | ||
|
|
||
| ```swift | ||
| // WRONG | ||
| func foo() { print("bar") } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we try to avoid |
||
|
|
||
| init() { self.value = 0 } | ||
|
|
||
| subscript(index: Int) -> Int { array[index] } | ||
|
|
||
| var bar: String { "bar" } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we put the |
||
|
|
||
| // 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.** | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we put the new rule after the "long function declarations" rule? |
||
|
|
||
There was a problem hiding this comment.
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.