I wish the trailing-comma rule defaulted to adding a redundant trailing comma. It makes it easier to add items later on, and such changes only shows a diff on the actual changed line. Basically just benefits of having the comma there. 🙂
07/06/2022, 6:31 AM
It does do that for us with this .editorconfig.
We just merged a PR with this exact change here. You can see where I edit the .editorconfig in the first commit then just let ktlint format and it adds redundant trailing commas everywhere.
07/06/2022, 6:41 AM
Yeah, I get that you can configure it but I wish the default was the other way 🙂 One thing I like a lot with Ktlint so far is that I never felt the need to configure it
But thx for the link, it'll save me some time ❤️
07/06/2022, 6:43 AM
Ah the default, now I understood what you were looking for. I personally would like it to be that way too, but apparently I’ve figured out that there’s plenty of people who actually don’t like trailing commas that much 😅 It was a surprise to me for sure.
07/06/2022, 7:04 AM
Rationale behind this is that the trailing comma is a feature which was added in a later kotlin version. Defaulting it to true would force all existing code bases to accept that as well. Also it might force code bases to be upgraded to kotlin versions that would accept trailing comma. That should be considered a breaking change which we try to avoid.
07/06/2022, 7:07 AM
Right, and having a different set of “defaults” for different Kotlin versions isn’t something that would be very fun either I suppose. Considering the case where someone upgrades their Kotlin version and then suddenly ktlint is screaming all over the code base about something they didn’t expect.
07/06/2022, 7:07 AM
I see.. that's a strong argument 🙂 Would be nice of Jetbrains to release some usage statistics so one can reason a bit more about such things (e.g. if <1% of users are still on Kotlin 1.3 then perhaps they can live with a stale version of Ktlint as well, but if they're 50% then it wouldn't make sense)
Maybe it’d be worth it to provide a link to this discussion in there to bring in a use case of how this data would be useful. Always easier to reason about and discuss among themselves regarding such a decision.