-
-
Notifications
You must be signed in to change notification settings - Fork 390
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
Kotlin - Enable trailing comma #3959
Conversation
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.
If I've understood this correctly (I've tried it locally to confirm) this will allow a mix of trailing and non-trailing commas in future code, with no clean way to migrate naturally as the relevant files get modified over time.
Can this be done so that existing non-trailing-comma usage is grandfathered in, but new usage is forbidden?
E.g., in .editorconfig
have:
ktlint_code_style = intellij_idea
ij_kotlin_allow_trailing_comma = true
ij_kotlin_allow_trailing_comma_on_call_site = true
and then create a baseline that includes all the lint "violations" that this will introduce (per the discussion of the baseline file, in https://pinterest.github.io/ktlint/0.50.0/install/cli/#violation-reporting).
Over time violations would shrink, and the baseline file will get smaller (every time it's regenerated) until there are none (or only a handful) to clean up.
For this to work ktlintFormat would need to ignore violations in the baseline file too. I haven't tested that.
IMO it should be situation dependent - neither mandated nor forbidden. |
These changes don't affect single-line usage, the rule / format change is only triggered on multi-line call sites and declarations.
|
Yes, let's merge this one, thank you. |
Trailing commas on Kotlin sources has many advantages:
This PR doesn't go as far as require it, but tweaks KtLint to at least allow it.
The two
.kt
files prove that the KtLint rules have been properly disabled.