Ktlint: Rule to mandate/forbid trailing commas

Created on 4 Mar 2020  ·  10Comments  ·  Source: pinterest/ktlint

Expected Behavior

ktlint offers a rule that enforces a particular code style regarding trailing commas, which are now permitted by the Kotlin compiler as of 1.3.70, see https://youtrack.jetbrains.com/issue/KT-34743 for more details.

This may not be a good fit for ktlint as it's too opinionated and no conventions exist yet, but if it's suitable it's a better fit here than in detekt where it was originally proposed.

Observed Behavior

No such rule exists.

Steps to Reproduce

N/A, new rule required.

Your Environment

  • Version of ktlint used:
  • Name and version (or code for custom task) of integration used (Gradle plugin, Maven plugin, command line, custom Gradle task):
  • Version of Gradle used (if applicable):
  • Operating System and version:
  • Link to your project (if it's a public repository):
proposal rule

Most helpful comment

@3flex you are more than welcome to contribute this to ktlint directly and utilize it in detekt afterwards 👀 it is certainly on the roadmap, just the maintainers were sidetracked by the day jobs and we had other priorities in ktlint, but I see this one indeed has a high demand so we'll re-prioritize

All 10 comments

Ideally this rule could be as flexible as something like ESLint's comma dangling rule, which would allow specifying when trailing commas must be used (never, always, multiline-only, when entry, etc.)

Edit: Perhaps supporting that feature set would better live elsewhere?

Probably related to #701 to control enable/disable state for cases, though initial rule implementation could just enforce trailing commas and be in experimental set.

Any update?

Is this on ktlint's roadmap? If not, we could implement in detekt instead. I don't think it makes sense to do that though if ktlint will implement the rule so we can avoid duplication of effort, but I think there's demand for it (I'm sure this is my most 👍 issue ever!)

Hopefully is or it will be 🤞, for now I'm trying to implement my own rule from the link above. I can confirm there is a high demand. Will be nice to autocorrect with ktlint...

@3flex you are more than welcome to contribute this to ktlint directly and utilize it in detekt afterwards 👀 it is certainly on the roadmap, just the maintainers were sidetracked by the day jobs and we had other priorities in ktlint, but I see this one indeed has a high demand so we'll re-prioritize

Is this is getting released soon?

Is this is getting released soon?

Maybe try using your own ruleset
https://stackoverflow.com/a/65449838/3438335

Oui oumême iii

Le jeu. 11 mars 2021 à 09:40, Christian Dehning @.*>
a écrit :

Is this is getting released soon?


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/pinterest/ktlint/issues/709#issuecomment-796568044,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AR6FQKW2WTD3JDHQ4AAU2DLTDB6V7ANCNFSM4LBDHE4Q
.

Was this page helpful?
0 / 5 - 0 ratings