Skip to content

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

Merged
allevato merged 1 commit intoswiftlang:masterfrom
dylansturg:no_lonely_commas
Feb 26, 2020
Merged

Absorb trailing comma of function call args in grouped exprs.#151
allevato merged 1 commit intoswiftlang:masterfrom
dylansturg:no_lonely_commas

Conversation

@dylansturg
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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