-
Notifications
You must be signed in to change notification settings - Fork 250
Introduce trailingCommasInMultilineLists
configuration
#1044
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
base: main
Are you sure you want to change the base?
Conversation
f712fd2
to
c5fb5d2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there an abstraction we can come up to reduce the repetition in the individual visitors? Something like a helper function that accepts a generic parameter constrained to a collection of WithTrailingCommaSyntax
elements and does the actual work.
c5fb5d2
to
a3de557
Compare
I was struggling because the point where a comma needs to be inserted differs for each syntax, but as I came to know about |
case .ignore: | ||
isCollection ? configuration.multiElementCollectionTrailingCommas : nil | ||
} | ||
if let shouldHandleCommaDelimitedRegion, shouldHandleCommaDelimitedRegion { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could just be if shouldHandleCommaDelimitedRegion == true
. Being written twice made me have to reread it a couple times to make sure they were referring to the same thing.
protocol CommaSeparatedListSyntaxProtocol: SyntaxCollection where Element: WithTrailingCommaSyntax & Equatable { | ||
/// Indicates whether the list should be treated as a collection for formatting. | ||
/// If `true`, the list is affected by the `multiElementCollectionTrailingCommas` configuration. | ||
var isCollection: Bool { get } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hate to be nitpicky, but can you change this to isCollectionLiteral
? isCollection
feels like it could be talking about the node itself (which are all Collection
s).
Or... does this have to be a protocol requirement at all? It looks like you could just pass it in as another parameter to markCommaDelimitedRegion
, since it has to be called individually for each node type anyway. That might be cleaner (but the rename is still valid elsewhere that it's referenced in the pretty printer).
/// for collections only. In all other cases, existing trailing commas are preserved as-is and not modified. | ||
/// If set to `.always` or `.never`, that behavior is applied uniformly across all list types, | ||
/// regardless of `multiElementCollectionTrailingCommas`. | ||
public var trailingCommasInMultilineLists: TrailingCommasInMultilineLists |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at this more closely, this feels too similar to the name of the other property below. I don't know if multilineLists
really communicates the bit about parameter lists, tuples, closure captures, etc.
What about multilineTrailingCommaBehavior
? Then, let's rename the enum to MultilineTrailingCommaBehavior
and have the cases be alwaysUsed
, neverUsed
, and keptAsWritten
. I think that helps to better document what's going on.
Later on (not in this PR), we could add a fourth case: onlyCollectionLiterals
, which could take over the behavior of the other Boolean setting, and deprecate that one.
Resolve #946
Added a configuration to support the use of trailing commas extended by SE-0439.
This configuration supports three values:
always
: always insert trailing commas in multiline listsnever
: always remove trailing commasignore
: preserve existing commas as-isThe default value is
ignore
.The main concern was how to integrate this with the existing
multiElementCollectionTrailingCommas
configuration.For now,
trailingCommasInMultilineLists
takes higher precedence, but to minimize its impact onmultiElementCollectionTrailingCommas
, it is implemented so that when set to the default valueignore
, the behavior ofmultiElementCollectionTrailingCommas
is preserved.I’d appreciate any suggestions or feedback you may have.