Skip to content
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

Split TrailingCommaRule #1555

Merged
merged 8 commits into from Aug 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -130,6 +130,7 @@ The callback function provided as parameter to the format function is now called
* Fix multiline if-statements `multiline-if-else` ([#828](https://github.com/pinterest/ktlint/issues/828))
* Prevent class cast exception on ".editorconfig" property `ktlint_code_style` ([#1559](https://github.com/pinterest/ktlint/issues/1559))
* Handle trailing comma in enums `trailing-comma` ([#1542](https://github.com/pinterest/ktlint/pull/1542))
* Split rule `trailing-comma` into `trailing-comma-on-call-site` and `trailing-comma-on-declaration-site` ([#1555](https://github.com/pinterest/ktlint/pull/1555))

### Changed

Expand Down
2 changes: 1 addition & 1 deletion docs/faq.md
Expand Up @@ -91,7 +91,7 @@ import package.b.*
An error for a specific rule on a specific line can be disabled with a `@Suppress` annotation:

```kotlin
@Suppress("ktlint:max-line-length","ktlint:experimental:trailing-comma")
@Suppress("ktlint:max-line-length","ktlint:experimental:trailing-comma-on-call-site")
val foo = listOf(
"some really looooooooooooooooong string exceeding the max line length",
)
Expand Down
19 changes: 15 additions & 4 deletions docs/rules/configuration.md
Expand Up @@ -176,18 +176,29 @@ max_line_length = -1 # Use "off" (or -1) to ignore max line length or a positive

This setting is used by multiple rules of which rule `max-line-length` is the most important.

## Trailing comma
## Trailing comma on call site

Trailing comma's (both on call and declaration site) are disabled (e.g. not allowed) by. When enabling the properties, the trailing becomes mandatory where applicable.
By default, trailing comma's on call site are not allowed. When enabling the property, the trailing comma becomes mandatory where applicable.

Example:
```ini
[*.{kt,kts}]
ij_kotlin_allow_trailing_comma = false
ij_kotlin_allow_trailing_comma_on_call_site = false
```

This setting only takes effect when rule `trailing-comma` is enabled.
This setting only takes effect when rule `trailing-comma-on-call-site` is enabled.

## Trailing comma on declaration site

By default, trailing comma's on declaration site are not allowed. When enabling the property, the trailing comma becomes mandatory where applicable.

Example:
```ini
[*.{kt,kts}]
ij_kotlin_allow_trailing_comma = false # Only used for declaration site
```

This setting only takes effect when rule `trailing-comma-on-declaration-site` is enabled.

## Overriding Editorconfig properties for specific directories

Expand Down
14 changes: 10 additions & 4 deletions docs/rules/standard.md
Expand Up @@ -106,7 +106,7 @@ When a line is broken at an assignment (`=`) operator the break comes after the

Rule id: `no-line-break-before-assignment`

## Nu multi spaces
## No multi spaces

Except in indentation and in KDoc's it is not allowed to have multiple consecutive spaces.

Expand Down Expand Up @@ -166,11 +166,17 @@ Consistent string templates (`$v` instead of `${v}`, `${p.v}` instead of `${p.v.

Rule id: `string-template`

## Trailing comma
## Trailing comma on call site

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

Rule id: `trailing-comma`
Rule id: `trailing-comma-on-call-site`

## Trailing comma on declaration site

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

Rule id: `trailing-comma-on-declaration-site`

## Spacing

Expand Down
Expand Up @@ -28,7 +28,15 @@ class MaxLineLengthRule :
// This rule should run after all other rules. Each time a rule visitor is modified with
// RunAsLateAsPossible, it needs to be checked that this rule still runs after that new rule or that it
// won't be affected by that rule.
ruleId = "trailing-comma",
ruleId = "trailing-comma-on-call-site",
loadOnlyWhenOtherRuleIsLoaded = false,
runOnlyWhenOtherRuleIsEnabled = false
),
VisitorModifier.RunAfterRule(
// This rule should run after all other rules. Each time a rule visitor is modified with
// RunAsLateAsPossible, it needs to be checked that this rule still runs after that new rule or that it
// won't be affected by that rule.
ruleId = "trailing-comma-on-declaration-site",
loadOnlyWhenOtherRuleIsLoaded = false,
runOnlyWhenOtherRuleIsEnabled = false
),
Expand Down
Expand Up @@ -2,7 +2,6 @@ package com.pinterest.ktlint.ruleset.standard

import com.pinterest.ktlint.core.RuleProvider
import com.pinterest.ktlint.core.RuleSetProviderV2
import com.pinterest.ktlint.ruleset.experimental.trailingcomma.TrailingCommaRule

public class StandardRuleSetProvider :
RuleSetProviderV2(
Expand Down Expand Up @@ -59,7 +58,8 @@ public class StandardRuleSetProvider :
RuleProvider { SpacingBetweenDeclarationsWithAnnotationsRule() },
RuleProvider { SpacingBetweenDeclarationsWithCommentsRule() },
RuleProvider { StringTemplateRule() },
RuleProvider { TrailingCommaRule() },
RuleProvider { TrailingCommaOnCallSiteRule() },
RuleProvider { TrailingCommaOnDeclarationSiteRule() },
RuleProvider { WrappingRule() }
)
}