Skip to content

Conversation

@mannylopez
Copy link
Contributor

@mannylopez mannylopez commented Dec 12, 2025

Summary

AddwrapSingleLineBodies rule to

Wrap single-line function, init, subscript, and computed property bodies onto multiple lines.

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

init() { self.value = 0 }

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

var bar: String { "bar" }

// 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.

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

Reasoning

@mannylopez mannylopez changed the title Add wrapSingleLineDeclarationBodies Add wrapSingleLineBodies Dec 12, 2025

```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


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


</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.**


### 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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants