From e47d805320fab7f099276f081061faa548cb2ac1 Mon Sep 17 00:00:00 2001 From: Matthew Haughton <3flex@users.noreply.github.com> Date: Fri, 7 Oct 2022 17:01:55 +1100 Subject: [PATCH 1/4] Enforce trailing commas at declaration site by default --- .../ruleset/standard/TrailingCommaOnDeclarationSiteRule.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/TrailingCommaOnDeclarationSiteRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/TrailingCommaOnDeclarationSiteRule.kt index ea5233fb61..d1240439d2 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/TrailingCommaOnDeclarationSiteRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/TrailingCommaOnDeclarationSiteRule.kt @@ -448,7 +448,7 @@ public class TrailingCommaOnDeclarationSiteRule : PropertyValueParser.BOOLEAN_VALUE_PARSER, BOOLEAN_VALUES_SET, ), - defaultValue = false, + defaultValue = true, ) private val TYPES_ON_DECLARATION_SITE = TokenSet.create( From 0789fab31d83e6681fbb2b47571821b45865f8cc Mon Sep 17 00:00:00 2001 From: paul-dingemans Date: Sun, 6 Nov 2022 17:58:24 +0100 Subject: [PATCH 2/4] Change default value for trailing comma on declaration site for default kotlin codestyle only. --- CHANGELOG.md | 1 + .../ruleset/standard/TrailingCommaOnDeclarationSiteRule.kt | 1 + 2 files changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1384a85958..6ac57c5b5e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ Calling this API with a file path results in the `.editorconfig` files that will ### Changed * Update Kotlin development version to `1.7.20` and Kotlin version to `1.7.20`. +* The default value for trailing comma's on declaration site is changed to `true` unless the `android codestyle` is enabled. Note that KtLint from a consistency viewpoint *enforces* the trailing comma on declaration site while default IntelliJ IDEA formatting only *allows* the trailing comma but leaves it up to the developer's discretion. ([#1669](https://github.com/pinterest/ktlint/pull/1669)) ## [0.47.1] - 2022-09-07 diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/TrailingCommaOnDeclarationSiteRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/TrailingCommaOnDeclarationSiteRule.kt index d1240439d2..45132d5dfa 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/TrailingCommaOnDeclarationSiteRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/TrailingCommaOnDeclarationSiteRule.kt @@ -449,6 +449,7 @@ public class TrailingCommaOnDeclarationSiteRule : BOOLEAN_VALUES_SET, ), defaultValue = true, + defaultAndroidValue = false ) private val TYPES_ON_DECLARATION_SITE = TokenSet.create( From e733d74eb15c837bb5419e02dce6455479f406e7 Mon Sep 17 00:00:00 2001 From: paul-dingemans Date: Sun, 6 Nov 2022 18:32:37 +0100 Subject: [PATCH 3/4] Update docs --- docs/rules/standard.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/docs/rules/standard.md b/docs/rules/standard.md index 03c2caa0b4..4cab778ddf 100644 --- a/docs/rules/standard.md +++ b/docs/rules/standard.md @@ -176,6 +176,18 @@ Rule id: `trailing-comma-on-call-site` Consistent removal (default) or adding of trailing comma's on declaration site. +!!! important +KtLint uses the IntelliJ IDEA `.editorconfig` property `ij_kotlin_allow_trailing_comma` to configure the rule. When this property is enabled, KtLint *enforces* the usage of the trailing comma at declaration site while IntelliJ IDEA default formatter only *allows* to use the trailing comma but leaves it to the developer's discretion to actually use it (or not). KtLint values *consistent* formatting more than a per-situation decision. + +!!! note +In KtLint 0.48.x the default value for using the trailing comma on declaration site has been changed to `true` except when codestyle `android` is used. + + The Kotlin coding conventions](https://kotlinlang.org/docs/reference/coding-conventions.html#names-for-test-methods) encourages the usage of trailing comma's on the declaration site, but leaves it to the developer's discretion to use trailing comma's on the call site. But next to this, it also states that usage of trailing commas has several benefits: + + * It makes version-control diffs cleaner – as all the focus is on the changed value. + * It makes it easy to add and reorder elements – there is no need to add or delete the comma if you manipulate elements. + * It simplifies code generation, for example, for object initializers. The last element can also have a comma. + Rule id: `trailing-comma-on-declaration-site` ## Wrapping From 3e1eb4315b8a45e4037312b4e829a043fd4cc93c Mon Sep 17 00:00:00 2001 From: paul-dingemans Date: Sun, 6 Nov 2022 19:57:26 +0100 Subject: [PATCH 4/4] Fix rule violation --- .../ruleset/standard/TrailingCommaOnDeclarationSiteRule.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/TrailingCommaOnDeclarationSiteRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/TrailingCommaOnDeclarationSiteRule.kt index 357dd56f6f..0cef61c999 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/TrailingCommaOnDeclarationSiteRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/TrailingCommaOnDeclarationSiteRule.kt @@ -437,7 +437,7 @@ public class TrailingCommaOnDeclarationSiteRule : BOOLEAN_VALUES_SET, ), defaultValue = true, - defaultAndroidValue = false + defaultAndroidValue = false, ) private val TYPES_ON_DECLARATION_SITE = TokenSet.create(