Wrap multi-line function declarations before the last paren #306
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR updates our Swift formatting rules for multiline function declarations to place the closing parenthesis and return type on the same line, immediately followed by the opening brace. This format aligns with Swift community conventions, improves readability, and results in cleaner diffs during edits and refactors.
(Note: this PR does not address call-site wrapping, which will be addressed in another proposal)
Reasoning
The current style:
is replaced with:
Benefits
Converting this:
With the old format:
With the new format:
Using trailing commas avoids touching unrelated lines:
Adding a parameter:
public func createUser( name: String, email: String, + age: Int, ) -> User
Removing a parameter:
public func createUser( name: String, - email: String, ) -> User
This keeps multiline functions visually consistent with non-wrapped ones:
This style is the default in tools like
swift-format
and increasingly the standard in open source Swift projects.Conclusion
This change brings us in line with community norms and improves the day-to-day development experience — especially when editing, reviewing, and refactoring function declarations.