Skip to content

Absorb trailing comma of function call args in grouped exprs. #151

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

Merged
merged 1 commit into from
Feb 26, 2020

Conversation

dylansturg
Copy link
Contributor

Previously, these trailing commas could be placed on a new line after the expression because the close break after the expression would fire if the comma landed exactly 1 over the column limit. Now the comma is moved inside of the group and breaks around the expr so that a break inside of the expr fires instead of the close break.

@allevato
Copy link
Member

Are there other trailing commas that pose similar problems that we should knock out while we're in here? For example, array/dictionary/tuple literals with element expressions ending in a close break?

When a trailing comma occurs after an expression that's wrapped in open/close breaks, the comma can be moved to a new line if it happens to exceed the column limit. By marking these as closing delimiters, they're absorbed into the grouped expressions.
@dylansturg
Copy link
Contributor Author

Are there other trailing commas that pose similar problems that we should knock out while we're in here? For example, array/dictionary/tuple literals with element expressions ending in a close break?

Good point - I reproduced the issue in arrays, dictionaries, tuples and pattern binding. I updated TokenStreamCreator to handle those trailing commas too.

@allevato allevato merged commit 200fa5a into swiftlang:master Feb 26, 2020
@dylansturg dylansturg deleted the no_lonely_commas branch February 26, 2020 22:08
aaditya-chandrasekhar pushed a commit to val-verde/swift-format that referenced this pull request May 20, 2021
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.

2 participants