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

Prettier style trailing commas #1284

Merged
merged 14 commits into from
Jun 16, 2024
Merged

Conversation

dawust
Copy link
Contributor

@dawust dawust commented Jun 8, 2024

This pull request addresses the issue described in Issue #668 and Issue #1285 .
A flag UsePrettierStyleTrailingCommas is introduced which ensures a trailing comma for anonymous object/collection/initializer/switch expressions, list patterns and enum declarations in the case a line break occurs.

I hope the implementation of the feature isn't too invasive. Obviously it would be easier to implement the feature non-configurable.

I'm not sure how to deal with the tests, for now I enabled the flag and adjusted the corresponding tests.

Thanks for any feedback!

Copy link
Owner

@belav belav left a comment

Choose a reason for hiding this comment

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

Looking good so far! Thanks for taking this on.

The one big piece missing, is making sure SyntaxNodeComparer doesn't report the added/removed comma as a warning along with adding some tests in SyntaxNodeComparerTests.

I'm hoping the logic can go into one of the methods in SyntaxNodeComparer that compares lists.

Src/CSharpier.Cli/Options/ConfigurationFileOptions.cs Outdated Show resolved Hide resolved
Src/CSharpier/SyntaxPrinter/TrailingComma.cs Outdated Show resolved Hide resolved
Src/CSharpier/SyntaxPrinter/TrailingComma.cs Show resolved Hide resolved
@dawust
Copy link
Contributor Author

dawust commented Jun 8, 2024

I'm hoping the logic can go into one of the methods in SyntaxNodeComparer that compares lists.

I guess it's ok to just omit the last separator (expression count - 1) when comparing the separators of the original node and the formatted node!?

@belav
Copy link
Owner

belav commented Jun 16, 2024

I guess it's ok to just omit the last separator (expression count - 1) when comparing the separators of the original node and the formatted node!?

Yeah that seems good enough, I don't see the csharpier code somehow being so screwed up that it replaces the last comma with a different separator.... and if it did then I don't think we could actually generate a syntax tree from the result.

# Conflicts:
#	Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/InitializerExpression.cs
Copy link
Owner

@belav belav left a comment

Choose a reason for hiding this comment

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

Nice work on all the tests, thanks for the contribution!

@belav belav merged commit bc331cd into belav:main Jun 16, 2024
3 checks passed
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