Skip to content
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

Add option to disable trailing commas on multi-line collections #619

Merged
merged 4 commits into from
Sep 13, 2023

Conversation

mlavergn
Copy link
Contributor

@mlavergn mlavergn commented Sep 7, 2023

Extends the configuration options to allow disabling the addtion of trailing commas on multi-line collections.

Extends the configuration options to allow disabling the addtion of trailing commas on multi-line collections.
@mlavergn
Copy link
Contributor Author

mlavergn commented Sep 7, 2023

I gleaned the name multilineCollectionTrailingCommas from an older PR, but since this does affect single line dictionaries, I wonder if collectionTrailingCommas would be more appropriate.

@allevato
Copy link
Member

allevato commented Sep 8, 2023

I gleaned the name multilineCollectionTrailingCommas from an older PR, but since this does affect single line dictionaries, I wonder if collectionTrailingCommas would be more appropriate.

Yeah, "line" is the wrong word here, because the logic isn't based on whether the collection wraps across multiple lines, it's about whether it has multiple elements—single element arrays/dictionaries never have a trailing comma inserted, even if they wrap (because of Swift parser subtleties around how collection types are parsed in expression contexts). I think there are other places in swift-format where we use "line" when we really mean "statement" or "element", but fixing those up require ensuring compatibility with older configs.

How do you feel about multiElementCollectionTrailingCommas?

@mlavergn
Copy link
Contributor Author

mlavergn commented Sep 9, 2023

I gleaned the name multilineCollectionTrailingCommas from an older PR, but since this does affect single line dictionaries, I wonder if collectionTrailingCommas would be more appropriate.

Yeah, "line" is the wrong word here, because the logic isn't based on whether the collection wraps across multiple lines, it's about whether it has multiple elements—single element arrays/dictionaries never have a trailing comma inserted, even if they wrap (because of Swift parser subtleties around how collection types are parsed in expression contexts). I think there are other places in swift-format where we use "line" when we really mean "statement" or "element", but fixing those up require ensuring compatibility with older configs.

How do you feel about multiElementCollectionTrailingCommas?

It's a mouthful, but it certainly self-documents what the setting is for. I'll refactor it.

@mlavergn
Copy link
Contributor Author

mlavergn commented Sep 9, 2023

Refactored the setting name to multiElementCollectionTrailingCommas and use literal rather than initializer in the docs.

@mlavergn
Copy link
Contributor Author

Added a DocC header to auto-gen proper documentation based on the styling of indentSwitchCaseLabels

Copy link
Member

@allevato allevato left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great. Thanks for your contribution!

@allevato allevato merged commit e1b18cf into swiftlang:main Sep 13, 2023
allevato added a commit to allevato/swift-format that referenced this pull request Sep 14, 2023
Add option to disable trailing commas on multi-line collections
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