Skip to content

Commit

Permalink
Enforce trailing commas at call site by default for Official Kotlin c…
Browse files Browse the repository at this point in the history
…odestyle (#1670)

Co-authored-by: paul-dingemans <paul-dingemans@users.noreply.github.com>
  • Loading branch information
3flex and paul-dingemans committed Nov 6, 2022
1 parent 362fa8c commit 758708d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -45,6 +45,7 @@ if (node.isRoot()) {

### Changed
* Update Kotlin development version to `1.7.20` and Kotlin version to `1.7.20`.
* The default value for trailing comma's on call site is changed to `true` unless the `android codestyle` is enabled. Note that KtLint from a consistency viewpoint *enforces* the trailing comma on call site while default IntelliJ IDEA formatting only *allows* the trailing comma but leaves it up to the developer's discretion. ([#1670](https://github.com/pinterest/ktlint/pull/1670))
* 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))
* CLI options `--debug`, `--trace`, `--verbose` and `-v` are replaced with `--log-level=<level>` or the short version `-l=<level>, see [CLI log-level](https://pinterest.github.io/ktlint/install/cli/#logging). ([#1632](https://github.com/pinterest/ktlint/issue/1632))
* In CLI, disable logging entirely by setting `--log-level=none` or `-l=none` ([#1652](https://github.com/pinterest/ktlint/issue/1652))
Expand Down
12 changes: 12 additions & 0 deletions docs/rules/standard.md
Expand Up @@ -170,6 +170,18 @@ Rule id: `string-template`

Consistent removal (default) or adding of trailing comma's on call site.

!!! important
KtLint uses the IntelliJ IDEA `.editorconfig` property `ij_kotlin_allow_trailing_comma_on_call_site` to configure the rule. When this property is enabled, KtLint *enforces* the usage of the trailing comma at call 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 call site has been changed to `true` except when codestyle `android` is used.

Although the Kotlin coding conventions](https://kotlinlang.org/docs/reference/coding-conventions.html#names-for-test-methods) leaves it to the developer's discretion to use trailing comma's on the call site, 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-call-site`

## Trailing comma on declaration site
Expand Down
Expand Up @@ -247,7 +247,8 @@ public class TrailingCommaOnCallSiteRule :
PropertyValueParser.BOOLEAN_VALUE_PARSER,
BOOLEAN_VALUES_SET,
),
defaultValue = false,
defaultValue = true,
defaultAndroidValue = false,
)

private val TYPES_ON_CALL_SITE = TokenSet.create(
Expand Down

0 comments on commit 758708d

Please sign in to comment.