-
Notifications
You must be signed in to change notification settings - Fork 506
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Trailing commas in enums #1542
Trailing commas in enums #1542
Conversation
It is okay to add a trailing comma in enumerations although this is not yet handled correctly by IntelliJ IDEA default formatter (for example see https://youtrack.jetbrains.com/issue/KTIJ-19916/Enabledisable-trailing-comma-in-the-formatter-intention-is-not-provided-when-trailing-comma-is-used-in-enumerations). The reason that it is okay to add in Ktlint is that IntelliJ does accept enums with or without trailing comma's regardless of the settings. So implementing it correctly in Ktlint will not lead to a conflict with de default IntelliJ IDEA formatter. |
...eset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/TrailingCommaRuleTest.kt
Outdated
Show resolved
Hide resolved
...eset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/TrailingCommaRuleTest.kt
Outdated
Show resolved
Hide resolved
...eset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/TrailingCommaRuleTest.kt
Outdated
Show resolved
Hide resolved
Please mind handling of enum which also contain addition declarations. Add/remove trailing commain case below depending on setting:
Note that the
Finnally do not add a trailing comma in case the one-but-last and the last enumeration value are on the same line. |
Having issues with PSI not containing the semicolon element
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.
Thanks for your contribution. Please address the issues.
...-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/TrailingCommaRule.kt
Outdated
Show resolved
Hide resolved
...-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/TrailingCommaRule.kt
Outdated
Show resolved
Hide resolved
...-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/TrailingCommaRule.kt
Outdated
Show resolved
Hide resolved
...-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/TrailingCommaRule.kt
Outdated
Show resolved
Hide resolved
...-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/TrailingCommaRule.kt
Outdated
Show resolved
Hide resolved
...eset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/TrailingCommaRuleTest.kt
Outdated
Show resolved
Hide resolved
...eset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/TrailingCommaRuleTest.kt
Outdated
Show resolved
Hide resolved
...eset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/TrailingCommaRuleTest.kt
Outdated
Show resolved
Hide resolved
...eset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/TrailingCommaRuleTest.kt
Outdated
Show resolved
Hide resolved
Sorry for blocking. I've been zoned out a bit from coding, but I'll put in some effort to get this done to unblock the other things. |
29baa22
to
305f9d6
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.
Code is looking good. I have simplied the code a bit and made it more consistent with other parts of the code base.
Description
I noticed trailing commas in enums seems to be unhandled by the trialing-comma rule. Added tests to verify that it is unhandled at the moment. I would be up for trying to add handling for enums as well, if you agree that it should be handled.
Checklist
CHANGELOG.md
is updated