From c3ed2d715eb6578509f215741707678ce2792d3b Mon Sep 17 00:00:00 2001 From: Paul Dingemans Date: Tue, 28 May 2024 17:12:06 +0200 Subject: [PATCH] Promote experimental rules to non-experimental (#2674) * Promote experimental rules to non-experimental * `backing-property-naming` (rule was defined as non-experimental starting from introduction but was documented as experimental) * `binary-expression-wrapping` * `chain-method-continuation` * `class-signature` * `condition-wrapping` * `function-expression-body` * `function-literal` * `function-type-modifier-spacing` * `multiline-loop` Closes #2673 --- .../snapshot/docs/rules/experimental.md | 581 +----------------- documentation/snapshot/docs/rules/standard.md | 561 +++++++++++++++++ .../api/ktlint-ruleset-standard.api | 16 +- .../rules/BackingPropertyNamingRule.kt | 4 +- .../rules/BinaryExpressionWrappingRule.kt | 8 +- .../rules/ChainMethodContinuationRule.kt | 5 +- .../standard/rules/ClassSignatureRule.kt | 8 +- .../standard/rules/ConditionWrappingRule.kt | 4 +- .../rules/FunctionExpressionBodyRule.kt | 8 +- .../standard/rules/FunctionLiteralRule.kt | 8 +- .../rules/FunctionTypeModifierSpacingRule.kt | 9 +- .../standard/rules/MultilineLoopRule.kt | 8 +- 12 files changed, 601 insertions(+), 619 deletions(-) diff --git a/documentation/snapshot/docs/rules/experimental.md b/documentation/snapshot/docs/rules/experimental.md index c3c661f887..98817733be 100644 --- a/documentation/snapshot/docs/rules/experimental.md +++ b/documentation/snapshot/docs/rules/experimental.md @@ -8,73 +8,6 @@ ktlint_experimental=enabled ``` Also see [enable/disable specific rules](../configuration-ktlint/#disabled-rules). -### Backing property naming - -Allows property names to start with `_` in case the property is a backing property. `ktlint_official` and `android_studio` code styles require the correlated property/function to be defined as `public`. - -=== "[:material-heart:](#) Ktlint" - - ```kotlin - class Bar { - // Backing property - private val _elementList = mutableListOf() - val elementList: List - get() = _elementList - } - ``` -=== "[:material-heart-off-outline:](#) Disallowed" - - ```kotlin - class Bar { - // Incomplete backing property as public property 'elementList1' is missing - private val _elementList1 = mutableListOf() - - // Invalid backing property as '_elementList2' is not a private property - val _elementList2 = mutableListOf() - val elementList2: List - get() = _elementList2 - } - ``` - -Rule id: `backing-property-naming` (`standard` rule set) - -## Binary expression wrapping - -Wraps binary expression at the operator reference whenever the binary expression does not fit on the line. In case the binary expression is nested, the expression is evaluated from outside to inside. If the left and right hand sides of the binary expression, after wrapping, fit on a single line then the inner binary expressions will not be wrapped. If one or both inner binary expression still do not fit on a single after wrapping of the outer binary expression, then each of those inner binary expressions will be wrapped. - -=== "[:material-heart:](#) Ktlint" - - ```kotlin - fun foo() { - // Assume that the last allowed character is - // at the X character on the right X - if ((leftHandSideExpression && rightHandSideExpression) || - ( - leftHandSideLongExpression && - rightHandSideExpression - ) - ) { - // do something - } - } - ``` - -=== "[:material-heart-off-outline:](#) Disallowed" - - ```kotlin - fun foo() { - // Assume that the last allowed character is - // at the X character on the right X - if ((leftHandSideExpression && rightHandSideExpression) || - (leftHandSideLongExpression && rightHandSideExpression) - ) { - // do something - } - } - ``` - -Rule id: `binary-expression-wrapping` (`standard` rule set) - ## Blank lines between when-conditions Consistently add or remove blank lines between when-conditions in a when-statement. A blank line is only added between when-conditions if the when-statement contains at lease one multiline when-condition. If a when-statement only contains single line when-conditions, then the blank lines between the when-conditions are removed. @@ -176,508 +109,12 @@ Consistently add or remove blank lines between when-conditions in a when-stateme Rule id: `blank-lines-between-when-conditions` (`standard` rule set) -## Chain method continuation - -In a multiline method chain, the chain operators (`.` or `?.`) have to be aligned with each other. - -Multiple chained methods on a single line are allowed as long as the maximum line length, and the maximum number of chain operators are not exceeded. Under certain conditions, it is allowed that the expression before the first and/or the expression after the last chain operator is a multiline expression. - -The `.` in `java.class` is ignored when wrapping on chain operators. - -This rule can be configured with `.editorconfig` property [`ktlint_chain_method_rule_force_multiline_when_chain_operator_count_greater_or_equal_than`](../configuration-ktlint/#force-multiline-chained-methods-based-on-number-of-chain-operators). - -!!! warning - Binary expression for which the left and/or right operand consist of method chain are currently being ignored by this rule. Please reach out, if you can help to determine what the best strategy is to deal with such kind of expressions. - -=== "[:material-heart:](#) Ktlint" - - ```kotlin - val foo1 = - listOf(1, 2, 3) - .filter { it > 2 }!! - .takeIf { it > 2 } - .map { - it * it - }?.map { - it * it - } - val foo2 = - listOf(1, 2, 3) - .filter { - it > 2 - }.map { - 2 * it - }?.map { - 2 * it - } - val foo3 = - foo().bar().map { - it.foobar() - } - val foo4 = - """ - Some text - """.trimIndent().foo().bar() - ``` - -=== "[:material-heart-off-outline:](#) Disallowed" - - ```kotlin - val foo1 = - listOf(1, 2, 3). - filter { it > 2 }!!. - takeIf { it > 2 }. - map { - it * it - }?. - map { - it * it - } - val foo2 = - listOf(1, 2, 3) - .filter { - it > 2 - } - .map { - 2 * it - } - ?.map { - 2 * it - } - val foo3 = - foo() - .bar().map { - it.foobar() - } - val foo4 = - """ - Some text - """.trimIndent().foo() - .bar() - ``` - -| Configuration setting | ktlint_official | intellij_idea | android_studio | -|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:---------------:|:-------------:|:--------------:| -| `ktlint_chain_method_rule_force_multiline_when_chain_operator_count_greater_or_equal_than`
Force wrapping of chained methods in case an expression contains at least the specified number of chain operators. If a chained method contains nested expressions, the chain operators of the inner expression are not taken into account. Use value `unset` (default) to disable this setting. | 4 | 4 | 4 | - - -Rule id: `chain-method-continuation` (`standard` rule set) - -!!! Note - This rule is only run when `ktlint_code_style` is set to `ktlint_official` or when the rule is enabled explicitly. - -## Class signature - -Rewrites the class signature to a consistent format respecting the `.editorconfig` property `max_line_length` if set. In the `ktlint_official` code style all class parameters are wrapped by default. Set `.editorconfig` property `ktlint_class_signature_rule_force_multiline_when_parameter_count_greater_or_equal_than` to a value greater than 1 to allow class with a few parameters to be placed on a single line. -The other code styles allow an infinite amount of parameters on the same line (as long as the `max_line_length` is not exceeded) unless `.editorconfig` property `ktlint_class_signature_rule_force_multiline_when_parameter_count_greater_or_equal_than` is set explicitly. - -=== "[:material-heart:](#) Ktlint (ktlint_official)" - - ```kotlin - // Assume that max_line_length is not exceeded when written as single line - class Foo0 - - class Foo1( - a: Any, - ) - - class Foo2( - a: Any, - b: Any, - ) - - class Foo3( - @Foo a: Any, - b: Any, - c: Any, - ) - - class Foo4( - a: Any, - b: Any, - c: Any, - ) : FooBar(a, c) - - class Foo5 : - FooBar( - "bar1", - "bar2", - ) { - // body - } - - class Foo6( - val bar1: Bar, - val bar2: Bar, - ) : FooBar( - bar1, - bar2, - ) { - // body - } - - class Foo7( - val bar1: Bar, - val bar2: Bar, - ) : FooBar( - bar1, - bar2, - ), - BarFoo1, - BarFoo2 { - // body - } - - class Foo8 - constructor( - val bar1: Bar, - val bar2: Bar, - ) : FooBar(bar1, bar2), - BarFoo1, - BarFoo2 { - // body - } - ``` - -=== "[:material-heart-off-outline:](#) Disallowed (ktlint_official)" - - ```kotlin - // Assume that max_line_length is not exceeded when written as single line - class Foo0() - - class Foo1(a: Any) - - class Foo2(a: Any, b: Any) - - class Foo3(@Foo a: Any, b: Any, c: Any) - - class Foo4(a: Any, b: Any, c: Any) : FooBar(a, c) - - class Foo5 : FooBar( - "bar1", - "bar2", - ) { - // body - } - - class Foo6( - val bar1: Bar, - val bar2: Bar, - ) : FooBar( - bar1, - bar2, - ) { - // body - } - - class Foo7( - val bar1: Bar, - val bar2: Bar, - ) : FooBar( - bar1, - bar2, - ), - BarFoo1, - BarFoo2 { - // body - } - - class Foo8 - constructor( - val bar1: Bar, - val bar2: Bar, - ) : FooBar(bar1, bar2), - BarFoo1, - BarFoo2 { - // body - } - ``` - -=== "[:material-heart:](#) Ktlint (non ktlint_official)" - - ```kotlin - // Assume that the last allowed character is - // at the X character on the right X - class Foo0 - - class Foo1( - a: Any, - ) - - class Foo2(a: Any) - - class Foo3( - a: Any, - b: Any, - ) - - class Foo4(a: Any, b: Any) - - class Foo5(@Foo a: Any, b: Any, c: Any) - - class Foo6(a: Any, b: Any, c: Any) : - FooBar(a, c) - - class Foo7 : FooBar( - "bar1", - "bar2", - ) { - // body - } - class Foo8( - val bar1: Bar, - val bar2: Bar, - ) : FooBar( - bar1, - bar2 - ) { - // body - } - - class Foo9( - val bar1: Bar, - val bar2: Bar, - ) : FooBar( - bar1, - bar2 - ), - BarFoo1, - BarFoo2 { - // body - } - - class Foo10 - constructor( - val bar1: Bar, - val bar2: Bar, - ) : FooBar(bar1, bar2), - BarFoo1, - BarFoo2 { - // body - } - ``` - -=== "[:material-heart-off-outline:](#) Disallowed (non ktlint_official)" - - ```kotlin - // Assume that the last allowed character is - // at the X character on the right X - class Foo0() - - class Foo6(a: Any, b: Any, c: Any) : FooBar(a, c) - ``` - -| Configuration setting | ktlint_official | intellij_idea | android_studio | -|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:---------------:|:-------------:|:--------------:| -| `ktlint_class_signature_rule_force_multiline_when_parameter_count_greater_or_equal_than`
Force wrapping of the parameters of the class signature in case it contains at least the specified number of parameters, even in case the entire class signature would fit on a single line. Use value `unset` to disable this setting. | 1 | `unset` | `unset` | - -Rule id: `class-signature` (`standard` rule set) - -## Condition wrapping - -Wraps each operand in a multiline condition to a separate line. - -=== "[:material-heart:](#) Ktlint" - - ```kotlin - val foo = bar || baz - if (bar1 || - bar2 || - baz1 || - (baz2 && baz3) - ) { - // do something - } - ``` - -=== "[:material-heart-off-outline:](#) Disallowed" - - ```kotlin - val foo = - multiLineOperand( - "bar" - ) || baz - if (bar1 || bar2 || - baz1 || (baz2 && baz3) - ) { - // do something - } - ``` - -Rule id: `condition-wrapping` (`standard` rule set) - -## Function expression body - -Rewrites a function body only containing a `return` or `throw` expression to an expression body. - -!!! note - If the function body contains a comment, it is not rewritten to an expression body. - -=== "[:material-heart:](#) Ktlint" - - ```kotlin - fun foo1() = "foo" - - fun foo2(): String = "foo" - - fun foo3(): Unit = throw IllegalArgumentException("some message") - - fun foo4(): Foo = throw IllegalArgumentException("some message") - - fun foo5() { - return "foo" // some comment - } - - fun foo6(): String { - /* some comment */ - return "foo" - } - - fun foo7() { - throw IllegalArgumentException("some message") - /* some comment */ - } - - fun foo8(): Foo { - throw IllegalArgumentException("some message") - // some comment - } - ``` -=== "[:material-heart-off-outline:](#) Disallowed" - - ```kotlin - fun foo1() { - return "foo" - } - - fun foo2(): String { - return "foo" - } - - fun foo3() { - throw IllegalArgumentException("some message") - } - - fun foo4(): Foo { - throw IllegalArgumentException("some message") - } - ``` - -Rule id: `function-expression-body` (`standard` rule set) - -## Function literal - -Enforces the parameters of a function literal and the arrow to be written on the same line as the opening brace if the maximum line length is not exceeded. In case the parameters are wrapped to multiple lines then this is respected. - -If the function literal contains multiple parameter and at least one parameter other than the first parameter starts on a new line than all parameters and the arrow are wrapped to separate lines. - -=== "[:material-heart:](#) Ktlint" - - ```kotlin - val foobar1 = { foo + bar } - val foobar2 = - { - foo + bar - } - val foobar3 = - { foo: Foo -> - foo.repeat(2) - } - val foobar4 = - { foo: Foo, bar: Bar -> - foo + bar - } - val foobar5 = { foo: Foo, bar: Bar -> foo + bar } - val foobar6 = - { - foo: Foo, - bar: Bar, - -> - foo + bar - } - - // Assume that the last allowed character is - // at the X character on the right X - val foobar7 = - barrrrrrrrrrrrrr { - fooooooooooooooo: Foo - -> - foo.repeat(2) - } - ``` - -=== "[:material-heart-off-outline:](#) Disallowed" - - ```kotlin - val foobar3 = - { - foo: Foo -> - foo.repeat(2) - } - val foobar6 = - { foo: Foo, - bar: Bar -> - foo + bar - } - // Assume that the last allowed character is - // at the X character on the right X - val foobar7 = - barrrrrrrrrrrrrr { fooooooooooooooo: Foo -> - foo.repeat(2) - } - ``` - -Rule id: `function-literal` (`standard` rule set) - -## Function type modifier spacing - -Enforce a single whitespace between the modifier list and the function type. - -=== "[:material-heart:](#) Ktlint" - - ```kotlin - val foo: suspend () -> Unit = {} - - suspend fun bar(baz: suspend () -> Unit) = baz() - ``` - -=== "[:material-heart-off-outline:](#) Disallowed" - - ```kotlin - val foo: suspend() -> Unit = {} - - suspend fun bar(baz: suspend () -> Unit) = baz() - ``` - -Rule id: `function-type-modifier-spacing` (`standard` rule set) - -## Mixed condition operators - -Conditions should not use a both `&&` and `||` operators between operators at the same level. By using parenthesis the expression is to be clarified. - -=== "[:material-heart:](#) Ktlint" - - ```kotlin - val foo = bar1 && (bar2 || bar3) && bar4 - ``` - -=== "[:material-heart-off-outline:](#) Disallowed" - - ```kotlin - val foo = bar1 && - bar2 || - bar3 - val foo = bar1 && (bar2 || bar3 && bar4) && bar5 - ``` - -Rule id: `mixed-condition-operators` (`standard` rule set) - ## KDoc KDoc's should only be used on elements for which KDoc is to be transformed to documentation. Normal block comments should be used in other cases. !!! note: - Access modifiers are ignored. Strictly speaking, one could argue that private declarations should not have a KDoc as no documentation will be generated for it. However, for internal use of developers the KDoc still serves documentation purposes. +Access modifiers are ignored. Strictly speaking, one could argue that private declarations should not have a KDoc as no documentation will be generated for it. However, for internal use of developers the KDoc still serves documentation purposes. === "[:material-heart:](#) Ktlint" @@ -729,26 +166,26 @@ KDoc's should only be used on elements for which KDoc is to be transformed to do Rule id: `kdoc` (`standard` rule set) -## Multiline loop +## Mixed condition operators -Braces required for multiline for, while, and do statements. +Conditions should not use a both `&&` and `||` operators between operators at the same level. By using parenthesis the expression is to be clarified. === "[:material-heart:](#) Ktlint" ```kotlin - for (i in 1..10) { - println(i) - } + val foo = bar1 && (bar2 || bar3) && bar4 ``` === "[:material-heart-off-outline:](#) Disallowed" ```kotlin - for (i in 1..10) - println(i) + val foo = bar1 && + bar2 || + bar3 + val foo = bar1 && (bar2 || bar3 && bar4) && bar5 ``` -Rule id: `multiline-loop` (`standard` rule set) +Rule id: `mixed-condition-operators` (`standard` rule set) ## Square brackets spacing diff --git a/documentation/snapshot/docs/rules/standard.md b/documentation/snapshot/docs/rules/standard.md index 212820fa44..0b5689d685 100644 --- a/documentation/snapshot/docs/rules/standard.md +++ b/documentation/snapshot/docs/rules/standard.md @@ -52,6 +52,43 @@ Multiple annotations should be on a separate line than the annotated declaration Rule-id: `annotation` (`standard` rule set) +## Binary expression wrapping + +Wraps binary expression at the operator reference whenever the binary expression does not fit on the line. In case the binary expression is nested, the expression is evaluated from outside to inside. If the left and right hand sides of the binary expression, after wrapping, fit on a single line then the inner binary expressions will not be wrapped. If one or both inner binary expression still do not fit on a single after wrapping of the outer binary expression, then each of those inner binary expressions will be wrapped. + +=== "[:material-heart:](#) Ktlint" + + ```kotlin + fun foo() { + // Assume that the last allowed character is + // at the X character on the right X + if ((leftHandSideExpression && rightHandSideExpression) || + ( + leftHandSideLongExpression && + rightHandSideExpression + ) + ) { + // do something + } + } + ``` + +=== "[:material-heart-off-outline:](#) Disallowed" + + ```kotlin + fun foo() { + // Assume that the last allowed character is + // at the X character on the right X + if ((leftHandSideExpression && rightHandSideExpression) || + (leftHandSideLongExpression && rightHandSideExpression) + ) { + // do something + } + } + ``` + +Rule id: `binary-expression-wrapping` (`standard` rule set) + ## Blank line before declarations Requires a blank line before any class or function declaration. No blank line is required between the class signature and the first declaration in the class. In a similar way, a blank line is required before any list of top level or class properties. No blank line is required before local properties or between consecutive properties. @@ -124,6 +161,301 @@ Lines in a block comment which (exclusive the indentation) start with a `*` shou Rule id: `block-comment-initial-star-alignment` (`standard` rule set) +## Chain method continuation + +In a multiline method chain, the chain operators (`.` or `?.`) have to be aligned with each other. + +Multiple chained methods on a single line are allowed as long as the maximum line length, and the maximum number of chain operators are not exceeded. Under certain conditions, it is allowed that the expression before the first and/or the expression after the last chain operator is a multiline expression. + +The `.` in `java.class` is ignored when wrapping on chain operators. + +!!! warning + A binary expression for which the left and/or right operand consist of a method chain are currently being ignored by this rule. Please reach out, if you can help to determine what the best strategy is to deal with such kind of expressions. + +=== "[:material-heart:](#) Ktlint" + + ```kotlin + val foo1 = + listOf(1, 2, 3) + .filter { it > 2 }!! + .takeIf { it > 2 } + .map { + it * it + }?.map { + it * it + } + val foo2 = + listOf(1, 2, 3) + .filter { + it > 2 + }.map { + 2 * it + }?.map { + 2 * it + } + val foo3 = + foo().bar().map { + it.foobar() + } + val foo4 = + """ + Some text + """.trimIndent().foo().bar() + ``` + +=== "[:material-heart-off-outline:](#) Disallowed" + + ```kotlin + val foo1 = + listOf(1, 2, 3). + filter { it > 2 }!!. + takeIf { it > 2 }. + map { + it * it + }?. + map { + it * it + } + val foo2 = + listOf(1, 2, 3) + .filter { + it > 2 + } + .map { + 2 * it + } + ?.map { + 2 * it + } + val foo3 = + foo() + .bar().map { + it.foobar() + } + val foo4 = + """ + Some text + """.trimIndent().foo() + .bar() + ``` + +| Configuration setting | ktlint_official | intellij_idea | android_studio | +|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:---------------:|:-------------:|:--------------:| +| `ktlint_chain_method_rule_force_multiline_when_chain_operator_count_greater_or_equal_than`
Force wrapping of chained methods in case an expression contains at least the specified number of chain operators. If a chained method contains nested expressions, the chain operators of the inner expression are not taken into account. Use value `unset` (default) to disable this setting. | 4 | 4 | 4 | + + +Rule id: `chain-method-continuation` (`standard` rule set) + +!!! Note + This rule is only run when `ktlint_code_style` is set to `ktlint_official` or when the rule is enabled explicitly. + +## Class signature + +Rewrites the class signature to a consistent format respecting the `.editorconfig` property `max_line_length` if set. In the `ktlint_official` code style all class parameters are wrapped by default. Set `.editorconfig` property `ktlint_class_signature_rule_force_multiline_when_parameter_count_greater_or_equal_than` to a value greater than 1 to allow classes with a few parameters to be placed on a single line. +The other code styles allow an infinite amount of parameters on the same line (as long as the `max_line_length` is not exceeded) unless `.editorconfig` property `ktlint_class_signature_rule_force_multiline_when_parameter_count_greater_or_equal_than` is set explicitly. + +=== "[:material-heart:](#) Ktlint (ktlint_official)" + + ```kotlin + // Assume that max_line_length is not exceeded when written as single line + class Foo0 + + class Foo1( + a: Any, + ) + + class Foo2( + a: Any, + b: Any, + ) + + class Foo3( + @Foo a: Any, + b: Any, + c: Any, + ) + + class Foo4( + a: Any, + b: Any, + c: Any, + ) : FooBar(a, c) + + class Foo5 : + FooBar( + "bar1", + "bar2", + ) { + // body + } + + class Foo6( + val bar1: Bar, + val bar2: Bar, + ) : FooBar( + bar1, + bar2, + ) { + // body + } + + class Foo7( + val bar1: Bar, + val bar2: Bar, + ) : FooBar( + bar1, + bar2, + ), + BarFoo1, + BarFoo2 { + // body + } + + class Foo8 + constructor( + val bar1: Bar, + val bar2: Bar, + ) : FooBar(bar1, bar2), + BarFoo1, + BarFoo2 { + // body + } + ``` + +=== "[:material-heart-off-outline:](#) Disallowed (ktlint_official)" + + ```kotlin + // Assume that max_line_length is not exceeded when written as single line + class Foo0() + + class Foo1(a: Any) + + class Foo2(a: Any, b: Any) + + class Foo3(@Foo a: Any, b: Any, c: Any) + + class Foo4(a: Any, b: Any, c: Any) : FooBar(a, c) + + class Foo5 : FooBar( + "bar1", + "bar2", + ) { + // body + } + + class Foo6( + val bar1: Bar, + val bar2: Bar, + ) : FooBar( + bar1, + bar2, + ) { + // body + } + + class Foo7( + val bar1: Bar, + val bar2: Bar, + ) : FooBar( + bar1, + bar2, + ), + BarFoo1, + BarFoo2 { + // body + } + + class Foo8 + constructor( + val bar1: Bar, + val bar2: Bar, + ) : FooBar(bar1, bar2), + BarFoo1, + BarFoo2 { + // body + } + ``` + +=== "[:material-heart:](#) Ktlint (non ktlint_official)" + + ```kotlin + // Assume that the last allowed character is + // at the X character on the right X + class Foo0 + + class Foo1( + a: Any, + ) + + class Foo2(a: Any) + + class Foo3( + a: Any, + b: Any, + ) + + class Foo4(a: Any, b: Any) + + class Foo5(@Foo a: Any, b: Any, c: Any) + + class Foo6(a: Any, b: Any, c: Any) : + FooBar(a, c) + + class Foo7 : FooBar( + "bar1", + "bar2", + ) { + // body + } + class Foo8( + val bar1: Bar, + val bar2: Bar, + ) : FooBar( + bar1, + bar2 + ) { + // body + } + + class Foo9( + val bar1: Bar, + val bar2: Bar, + ) : FooBar( + bar1, + bar2 + ), + BarFoo1, + BarFoo2 { + // body + } + + class Foo10 + constructor( + val bar1: Bar, + val bar2: Bar, + ) : FooBar(bar1, bar2), + BarFoo1, + BarFoo2 { + // body + } + ``` + +=== "[:material-heart-off-outline:](#) Disallowed (non ktlint_official)" + + ```kotlin + // Assume that the last allowed character is + // at the X character on the right X + class Foo0() + + class Foo6(a: Any, b: Any, c: Any) : FooBar(a, c) + ``` + +| Configuration setting | ktlint_official | intellij_idea | android_studio | +|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:---------------:|:-------------:|:--------------:| +| `ktlint_class_signature_rule_force_multiline_when_parameter_count_greater_or_equal_than`
Force wrapping of the parameters of the class signature in case it contains at least the specified number of parameters, even in case the entire class signature would fit on a single line. Use value `unset` to disable this setting. | 1 | `unset` | `unset` | + +Rule id: `class-signature` (`standard` rule set) + ## Enum entry Enum entry names should be uppercase underscore-separated or upper camel-case separated. @@ -166,6 +498,129 @@ Ensures consistent usage of a newline at the end of each file. Rule id: `final-newline` (`standard` rule set) +## Function expression body + +Rewrites a function body only containing a `return` or `throw` expression to an expression body. + +!!! note + If the function body contains a comment, it is not rewritten to an expression body. + +=== "[:material-heart:](#) Ktlint" + + ```kotlin + fun foo1() = "foo" + + fun foo2(): String = "foo" + + fun foo3(): Unit = throw IllegalArgumentException("some message") + + fun foo4(): Foo = throw IllegalArgumentException("some message") + + fun foo5() { + return "foo" // some comment + } + + fun foo6(): String { + /* some comment */ + return "foo" + } + + fun foo7() { + throw IllegalArgumentException("some message") + /* some comment */ + } + + fun foo8(): Foo { + throw IllegalArgumentException("some message") + // some comment + } + ``` +=== "[:material-heart-off-outline:](#) Disallowed" + + ```kotlin + fun foo1() { + return "foo" + } + + fun foo2(): String { + return "foo" + } + + fun foo3() { + throw IllegalArgumentException("some message") + } + + fun foo4(): Foo { + throw IllegalArgumentException("some message") + } + ``` + +Rule id: `function-expression-body` (`standard` rule set) + +## Function literal + +Enforces the parameters of a function literal and the arrow to be written on the same line as the opening brace if the maximum line length is not exceeded. In case the parameters are wrapped to multiple lines then this is respected. + +If the function literal contains multiple parameters and at least one parameter other than the first parameter starts on a new line than all parameters and the arrow are wrapped to separate lines. + +=== "[:material-heart:](#) Ktlint" + + ```kotlin + val foobar1 = { foo + bar } + val foobar2 = + { + foo + bar + } + val foobar3 = + { foo: Foo -> + foo.repeat(2) + } + val foobar4 = + { foo: Foo, bar: Bar -> + foo + bar + } + val foobar5 = { foo: Foo, bar: Bar -> foo + bar } + val foobar6 = + { + foo: Foo, + bar: Bar, + -> + foo + bar + } + + // Assume that the last allowed character is + // at the X character on the right X + val foobar7 = + barrrrrrrrrrrrrr { + fooooooooooooooo: Foo + -> + foo.repeat(2) + } + ``` + +=== "[:material-heart-off-outline:](#) Disallowed" + + ```kotlin + val foobar3 = + { + foo: Foo -> + foo.repeat(2) + } + val foobar6 = + { foo: Foo, + bar: Bar -> + foo + bar + } + // Assume that the last allowed character is + // at the X character on the right X + val foobar7 = + barrrrrrrrrrrrrr { fooooooooooooooo: Foo -> + foo.repeat(2) + } + ``` + +Rule id: `function-literal` (`standard` rule set) + ## Function signature Rewrites the function signature to a single line when possible (e.g. when not exceeding the `max_line_length` property) or a multiline signature otherwise. @@ -320,6 +775,28 @@ Rewrites the function signature to a single line when possible (e.g. when not ex Rule id: `function-signature` (`standard` rule set) +## Function type modifier spacing + +Enforce a single whitespace between the modifier list and the function type. + +=== "[:material-heart:](#) Ktlint" + + ```kotlin + val foo: suspend () -> Unit = {} + + suspend fun bar(baz: suspend () -> Unit) = baz() + ``` + +=== "[:material-heart-off-outline:](#) Disallowed" + + ```kotlin + val foo: suspend() -> Unit = {} + + suspend fun bar(baz: suspend () -> Unit) = baz() + ``` + +Rule id: `function-type-modifier-spacing` (`standard` rule set) + ## If else bracing If at least one branch of an if-else statement or an if-else-if statement is wrapped between curly braces then all branches should be wrapped between braces. @@ -418,6 +895,36 @@ Rule id: `indent` (`standard` rule set) ## Naming +### Backing property naming + +Allows property names to start with `_` in case the property is a backing property. `ktlint_official` and `android_studio` code styles require the correlated property/function to be defined as `public`. + +=== "[:material-heart:](#) Ktlint" + + ```kotlin + class Bar { + // Backing property + private val _elementList = mutableListOf() + val elementList: List + get() = _elementList + } + ``` +=== "[:material-heart-off-outline:](#) Disallowed" + + ```kotlin + class Bar { + // Incomplete backing property as public property 'elementList1' is missing + private val _elementList1 = mutableListOf() + + // Invalid backing property as '_elementList2' is not a private property + val _elementList2 = mutableListOf() + val elementList2: List + get() = _elementList2 + } + ``` + +Rule id: `backing-property-naming` (`standard` rule set) + ### Class naming Enforce naming of class and objects. @@ -999,6 +1506,27 @@ Braces required for multiline if/else statements. Rule id: `multiline-if-else` (`standard` rule set) +## Multiline loop + +Braces required for multiline for, while, and do statements. + +=== "[:material-heart:](#) Ktlint" + + ```kotlin + for (i in 1..10) { + println(i) + } + ``` + +=== "[:material-heart-off-outline:](#) Disallowed" + + ```kotlin + for (i in 1..10) + println(i) + ``` + +Rule id: `multiline-loop` (`standard` rule set) + ## No blank lines before `}` No blank lines before `}`. @@ -2364,6 +2892,39 @@ A block comment should start and end on a line that does not contain any other e Rule id: `comment-wrapping` (`standard` rule set) +### Condition wrapping + +Wraps each operand in a multiline condition to a separate line. + +=== "[:material-heart:](#) Ktlint" + + ```kotlin + val foo = bar || baz + if (bar1 || + bar2 || + baz1 || + (baz2 && baz3) + ) { + // do something + } + ``` + +=== "[:material-heart-off-outline:](#) Disallowed" + + ```kotlin + val foo = + multiLineOperand( + "bar" + ) || baz + if (bar1 || bar2 || + baz1 || (baz2 && baz3) + ) { + // do something + } + ``` + +Rule id: `condition-wrapping` (`standard` rule set) + ### Content receiver wrapping Wraps the content receiver list to a separate line regardless of maximum line length. If the maximum line length is configured and is exceeded, wrap the context receivers and if needed its projection types to separate lines. diff --git a/ktlint-ruleset-standard/api/ktlint-ruleset-standard.api b/ktlint-ruleset-standard/api/ktlint-ruleset-standard.api index 9952db820e..e3ef3b0894 100644 --- a/ktlint-ruleset-standard/api/ktlint-ruleset-standard.api +++ b/ktlint-ruleset-standard/api/ktlint-ruleset-standard.api @@ -55,7 +55,7 @@ public final class com/pinterest/ktlint/ruleset/standard/rules/BackingPropertyNa public static final fun getBACKING_PROPERTY_NAMING_RULE_ID ()Lcom/pinterest/ktlint/rule/engine/core/api/RuleId; } -public final class com/pinterest/ktlint/ruleset/standard/rules/BinaryExpressionWrappingRule : com/pinterest/ktlint/ruleset/standard/StandardRule, com/pinterest/ktlint/rule/engine/core/api/Rule$Experimental { +public final class com/pinterest/ktlint/ruleset/standard/rules/BinaryExpressionWrappingRule : com/pinterest/ktlint/ruleset/standard/StandardRule { public fun ()V public fun beforeFirstNode (Lcom/pinterest/ktlint/rule/engine/core/api/editorconfig/EditorConfig;)V public fun beforeVisitChildNodes (Lorg/jetbrains/kotlin/com/intellij/lang/ASTNode;Lkotlin/jvm/functions/Function3;)V @@ -98,7 +98,7 @@ public final class com/pinterest/ktlint/ruleset/standard/rules/BlockCommentIniti public static final fun getBLOCK_COMMENT_INITIAL_STAR_ALIGNMENT_RULE_ID ()Lcom/pinterest/ktlint/rule/engine/core/api/RuleId; } -public final class com/pinterest/ktlint/ruleset/standard/rules/ChainMethodContinuationRule : com/pinterest/ktlint/ruleset/standard/StandardRule, com/pinterest/ktlint/rule/engine/core/api/Rule$Experimental, com/pinterest/ktlint/rule/engine/core/api/Rule$OfficialCodeStyle { +public final class com/pinterest/ktlint/ruleset/standard/rules/ChainMethodContinuationRule : com/pinterest/ktlint/ruleset/standard/StandardRule, com/pinterest/ktlint/rule/engine/core/api/Rule$OfficialCodeStyle { public static final field Companion Lcom/pinterest/ktlint/ruleset/standard/rules/ChainMethodContinuationRule$Companion; public fun ()V public fun beforeFirstNode (Lcom/pinterest/ktlint/rule/engine/core/api/editorconfig/EditorConfig;)V @@ -132,7 +132,7 @@ public final class com/pinterest/ktlint/ruleset/standard/rules/ClassNamingRuleKt public static final fun getCLASS_NAMING_RULE_ID ()Lcom/pinterest/ktlint/rule/engine/core/api/RuleId; } -public final class com/pinterest/ktlint/ruleset/standard/rules/ClassSignatureRule : com/pinterest/ktlint/ruleset/standard/StandardRule, com/pinterest/ktlint/rule/engine/core/api/Rule$Experimental { +public final class com/pinterest/ktlint/ruleset/standard/rules/ClassSignatureRule : com/pinterest/ktlint/ruleset/standard/StandardRule { public static final field Companion Lcom/pinterest/ktlint/ruleset/standard/rules/ClassSignatureRule$Companion; public fun ()V public fun beforeFirstNode (Lcom/pinterest/ktlint/rule/engine/core/api/editorconfig/EditorConfig;)V @@ -165,7 +165,7 @@ public final class com/pinterest/ktlint/ruleset/standard/rules/CommentWrappingRu public static final fun getCOMMENT_WRAPPING_RULE_ID ()Lcom/pinterest/ktlint/rule/engine/core/api/RuleId; } -public final class com/pinterest/ktlint/ruleset/standard/rules/ConditionWrappingRule : com/pinterest/ktlint/ruleset/standard/StandardRule, com/pinterest/ktlint/rule/engine/core/api/Rule$Experimental { +public final class com/pinterest/ktlint/ruleset/standard/rules/ConditionWrappingRule : com/pinterest/ktlint/ruleset/standard/StandardRule { public fun ()V public fun beforeFirstNode (Lcom/pinterest/ktlint/rule/engine/core/api/editorconfig/EditorConfig;)V public fun beforeVisitChildNodes (Lorg/jetbrains/kotlin/com/intellij/lang/ASTNode;Lkotlin/jvm/functions/Function3;)V @@ -241,7 +241,7 @@ public final class com/pinterest/ktlint/ruleset/standard/rules/FunKeywordSpacing public static final fun getFUN_KEYWORD_SPACING_RULE ()Lcom/pinterest/ktlint/rule/engine/core/api/RuleId; } -public final class com/pinterest/ktlint/ruleset/standard/rules/FunctionExpressionBodyRule : com/pinterest/ktlint/ruleset/standard/StandardRule, com/pinterest/ktlint/rule/engine/core/api/Rule$Experimental { +public final class com/pinterest/ktlint/ruleset/standard/rules/FunctionExpressionBodyRule : com/pinterest/ktlint/ruleset/standard/StandardRule { public fun ()V public fun beforeFirstNode (Lcom/pinterest/ktlint/rule/engine/core/api/editorconfig/EditorConfig;)V public fun beforeVisitChildNodes (Lorg/jetbrains/kotlin/com/intellij/lang/ASTNode;Lkotlin/jvm/functions/Function3;)V @@ -251,7 +251,7 @@ public final class com/pinterest/ktlint/ruleset/standard/rules/FunctionExpressio public static final fun getFUNCTION_EXPRESSION_BODY_RULE_ID ()Lcom/pinterest/ktlint/rule/engine/core/api/RuleId; } -public final class com/pinterest/ktlint/ruleset/standard/rules/FunctionLiteralRule : com/pinterest/ktlint/ruleset/standard/StandardRule, com/pinterest/ktlint/rule/engine/core/api/Rule$Experimental { +public final class com/pinterest/ktlint/ruleset/standard/rules/FunctionLiteralRule : com/pinterest/ktlint/ruleset/standard/StandardRule { public fun ()V public fun beforeFirstNode (Lcom/pinterest/ktlint/rule/engine/core/api/editorconfig/EditorConfig;)V public fun beforeVisitChildNodes (Lorg/jetbrains/kotlin/com/intellij/lang/ASTNode;Lkotlin/jvm/functions/Function3;)V @@ -320,7 +320,7 @@ public final class com/pinterest/ktlint/ruleset/standard/rules/FunctionStartOfBo public static final fun getFUNCTION_START_OF_BODY_SPACING_RULE_ID ()Lcom/pinterest/ktlint/rule/engine/core/api/RuleId; } -public final class com/pinterest/ktlint/ruleset/standard/rules/FunctionTypeModifierSpacingRule : com/pinterest/ktlint/ruleset/standard/StandardRule, com/pinterest/ktlint/rule/engine/core/api/Rule$Experimental { +public final class com/pinterest/ktlint/ruleset/standard/rules/FunctionTypeModifierSpacingRule : com/pinterest/ktlint/ruleset/standard/StandardRule { public fun ()V public fun beforeVisitChildNodes (Lorg/jetbrains/kotlin/com/intellij/lang/ASTNode;Lkotlin/jvm/functions/Function3;)V } @@ -467,7 +467,7 @@ public final class com/pinterest/ktlint/ruleset/standard/rules/MultilineExpressi public static final fun getMULTILINE_EXPRESSION_WRAPPING_RULE_ID ()Lcom/pinterest/ktlint/rule/engine/core/api/RuleId; } -public final class com/pinterest/ktlint/ruleset/standard/rules/MultilineLoopRule : com/pinterest/ktlint/ruleset/standard/StandardRule, com/pinterest/ktlint/rule/engine/core/api/Rule$Experimental { +public final class com/pinterest/ktlint/ruleset/standard/rules/MultilineLoopRule : com/pinterest/ktlint/ruleset/standard/StandardRule { public fun ()V public fun beforeFirstNode (Lcom/pinterest/ktlint/rule/engine/core/api/editorconfig/EditorConfig;)V public fun beforeVisitChildNodes (Lorg/jetbrains/kotlin/com/intellij/lang/ASTNode;Lkotlin/jvm/functions/Function3;)V diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/BackingPropertyNamingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/BackingPropertyNamingRule.kt index 709f104dae..cc81eda298 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/BackingPropertyNamingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/BackingPropertyNamingRule.kt @@ -11,7 +11,7 @@ import com.pinterest.ktlint.rule.engine.core.api.ElementType.VALUE_PARAMETER import com.pinterest.ktlint.rule.engine.core.api.ElementType.VALUE_PARAMETER_LIST import com.pinterest.ktlint.rule.engine.core.api.RuleId import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint -import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.EXPERIMENTAL +import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE import com.pinterest.ktlint.rule.engine.core.api.children import com.pinterest.ktlint.rule.engine.core.api.editorconfig.CODE_STYLE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.editorconfig.CodeStyleValue.android_studio @@ -25,7 +25,7 @@ import org.jetbrains.kotlin.com.intellij.lang.ASTNode * https://kotlinlang.org/docs/coding-conventions.html#property-names * https://developer.android.com/kotlin/style-guide#backing_properties */ -@SinceKtlint("1.2.0", EXPERIMENTAL) +@SinceKtlint("1.2.0", STABLE) public class BackingPropertyNamingRule : StandardRule( id = "backing-property-naming", diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/BinaryExpressionWrappingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/BinaryExpressionWrappingRule.kt index 523bc933cf..0f9895b9c1 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/BinaryExpressionWrappingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/BinaryExpressionWrappingRule.kt @@ -17,10 +17,9 @@ import com.pinterest.ktlint.rule.engine.core.api.ElementType.PROPERTY import com.pinterest.ktlint.rule.engine.core.api.ElementType.RBRACE import com.pinterest.ktlint.rule.engine.core.api.ElementType.VALUE_ARGUMENT import com.pinterest.ktlint.rule.engine.core.api.IndentConfig -import com.pinterest.ktlint.rule.engine.core.api.Rule import com.pinterest.ktlint.rule.engine.core.api.RuleId import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint -import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.EXPERIMENTAL +import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE import com.pinterest.ktlint.rule.engine.core.api.children import com.pinterest.ktlint.rule.engine.core.api.editorconfig.EditorConfig import com.pinterest.ktlint.rule.engine.core.api.editorconfig.INDENT_SIZE_PROPERTY @@ -51,7 +50,7 @@ import org.jetbrains.kotlin.com.intellij.psi.tree.IElementType * Wraps a binary expression whenever the expression does not fit on the line. Wrapping a binary expression should take precedence before * argument of function calls inside that binary expression are wrapped. */ -@SinceKtlint("0.50", EXPERIMENTAL) +@SinceKtlint("0.50", STABLE) public class BinaryExpressionWrappingRule : StandardRule( id = "binary-expression-wrapping", @@ -61,8 +60,7 @@ public class BinaryExpressionWrappingRule : INDENT_STYLE_PROPERTY, MAX_LINE_LENGTH_PROPERTY, ), - ), - Rule.Experimental { + ) { private var indentConfig = IndentConfig.DEFAULT_INDENT_CONFIG private var maxLineLength = MAX_LINE_LENGTH_PROPERTY.defaultValue diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ChainMethodContinuationRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ChainMethodContinuationRule.kt index 4cfa164f6d..e7e51314b4 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ChainMethodContinuationRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ChainMethodContinuationRule.kt @@ -30,7 +30,7 @@ import com.pinterest.ktlint.rule.engine.core.api.Rule.VisitorModifier.RunAfterRu import com.pinterest.ktlint.rule.engine.core.api.Rule.VisitorModifier.RunAfterRule.Mode.REGARDLESS_WHETHER_RUN_AFTER_RULE_IS_LOADED_OR_DISABLED import com.pinterest.ktlint.rule.engine.core.api.RuleId import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint -import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.EXPERIMENTAL +import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE import com.pinterest.ktlint.rule.engine.core.api.children import com.pinterest.ktlint.rule.engine.core.api.editorconfig.CODE_STYLE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.editorconfig.EditorConfig @@ -69,7 +69,7 @@ import org.jetbrains.kotlin.com.intellij.psi.tree.TokenSet * * As of that the rule is restricted to ktlint_official code style unless explicitly enabled. */ -@SinceKtlint("1.0", EXPERIMENTAL) +@SinceKtlint("1.0", STABLE) public class ChainMethodContinuationRule : StandardRule( id = "chain-method-continuation", @@ -83,7 +83,6 @@ public class ChainMethodContinuationRule : MAX_LINE_LENGTH_PROPERTY, ), ), - Rule.Experimental, Rule.OfficialCodeStyle { private var indentConfig = IndentConfig.DEFAULT_INDENT_CONFIG private var maxLineLength: Int = MAX_LINE_LENGTH_PROPERTY.defaultValue diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ClassSignatureRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ClassSignatureRule.kt index fbef559758..c2d074a3c7 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ClassSignatureRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ClassSignatureRule.kt @@ -20,13 +20,12 @@ import com.pinterest.ktlint.rule.engine.core.api.ElementType.VALUE_PARAMETER_LIS import com.pinterest.ktlint.rule.engine.core.api.ElementType.WHITE_SPACE import com.pinterest.ktlint.rule.engine.core.api.IndentConfig import com.pinterest.ktlint.rule.engine.core.api.IndentConfig.Companion.DEFAULT_INDENT_CONFIG -import com.pinterest.ktlint.rule.engine.core.api.Rule import com.pinterest.ktlint.rule.engine.core.api.Rule.VisitorModifier.RunAfterRule import com.pinterest.ktlint.rule.engine.core.api.Rule.VisitorModifier.RunAfterRule.Mode.REGARDLESS_WHETHER_RUN_AFTER_RULE_IS_LOADED_OR_DISABLED import com.pinterest.ktlint.rule.engine.core.api.Rule.VisitorModifier.RunAsLateAsPossible import com.pinterest.ktlint.rule.engine.core.api.RuleId import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint -import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.EXPERIMENTAL +import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE import com.pinterest.ktlint.rule.engine.core.api.children import com.pinterest.ktlint.rule.engine.core.api.editorconfig.CODE_STYLE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.editorconfig.CodeStyleValue.ktlint_official @@ -61,7 +60,7 @@ import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.LeafElement * In code style `ktlint_official` class headers containing 2 or more parameters are formatted as multiline signature. As the Kotlin Coding * conventions do not specify what is meant with a "few parameters", no default is set for other code styles. */ -@SinceKtlint("1.0", EXPERIMENTAL) +@SinceKtlint("1.0", STABLE) public class ClassSignatureRule : StandardRule( id = "class-signature", @@ -85,8 +84,7 @@ public class ClassSignatureRule : MAX_LINE_LENGTH_PROPERTY, FORCE_MULTILINE_WHEN_PARAMETER_COUNT_GREATER_OR_EQUAL_THAN_PROPERTY, ), - ), - Rule.Experimental { + ) { private var codeStyle = CODE_STYLE_PROPERTY.defaultValue private var indentConfig = DEFAULT_INDENT_CONFIG private var maxLineLength = MAX_LINE_LENGTH_PROPERTY.defaultValue diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ConditionWrappingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ConditionWrappingRule.kt index 8a68041cdc..ea27a4e07f 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ConditionWrappingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ConditionWrappingRule.kt @@ -6,7 +6,6 @@ import com.pinterest.ktlint.rule.engine.core.api.ElementType.BINARY_EXPRESSION import com.pinterest.ktlint.rule.engine.core.api.ElementType.OPERATION_REFERENCE import com.pinterest.ktlint.rule.engine.core.api.ElementType.OROR import com.pinterest.ktlint.rule.engine.core.api.IndentConfig -import com.pinterest.ktlint.rule.engine.core.api.Rule import com.pinterest.ktlint.rule.engine.core.api.RuleId import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.EXPERIMENTAL @@ -40,8 +39,7 @@ public class ConditionWrappingRule : INDENT_SIZE_PROPERTY, INDENT_STYLE_PROPERTY, ), - ), - Rule.Experimental { + ) { private var indentConfig = IndentConfig.DEFAULT_INDENT_CONFIG override fun beforeFirstNode(editorConfig: EditorConfig) { diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FunctionExpressionBodyRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FunctionExpressionBodyRule.kt index 176ba5f1bb..1f1a6860af 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FunctionExpressionBodyRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FunctionExpressionBodyRule.kt @@ -12,10 +12,9 @@ import com.pinterest.ktlint.rule.engine.core.api.ElementType.RETURN_KEYWORD import com.pinterest.ktlint.rule.engine.core.api.ElementType.THROW import com.pinterest.ktlint.rule.engine.core.api.ElementType.TYPE_REFERENCE import com.pinterest.ktlint.rule.engine.core.api.IndentConfig -import com.pinterest.ktlint.rule.engine.core.api.Rule import com.pinterest.ktlint.rule.engine.core.api.RuleId import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint -import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.EXPERIMENTAL +import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE import com.pinterest.ktlint.rule.engine.core.api.children import com.pinterest.ktlint.rule.engine.core.api.editorconfig.CODE_STYLE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.editorconfig.EditorConfig @@ -66,7 +65,7 @@ import org.jetbrains.kotlin.psi.psiUtil.getChildOfType * } * ``` */ -@SinceKtlint("1.0", EXPERIMENTAL) +@SinceKtlint("1.0", STABLE) public class FunctionExpressionBodyRule : StandardRule( id = "function-expression-body", @@ -77,8 +76,7 @@ public class FunctionExpressionBodyRule : INDENT_STYLE_PROPERTY, MAX_LINE_LENGTH_PROPERTY, ), - ), - Rule.Experimental { + ) { private var codeStyle = CODE_STYLE_PROPERTY.defaultValue private var indentConfig = IndentConfig.DEFAULT_INDENT_CONFIG diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FunctionLiteralRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FunctionLiteralRule.kt index 97d8f08a24..805fe9329c 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FunctionLiteralRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FunctionLiteralRule.kt @@ -12,11 +12,10 @@ import com.pinterest.ktlint.rule.engine.core.api.ElementType.RBRACE import com.pinterest.ktlint.rule.engine.core.api.ElementType.VALUE_PARAMETER import com.pinterest.ktlint.rule.engine.core.api.ElementType.VALUE_PARAMETER_LIST import com.pinterest.ktlint.rule.engine.core.api.IndentConfig -import com.pinterest.ktlint.rule.engine.core.api.Rule import com.pinterest.ktlint.rule.engine.core.api.Rule.VisitorModifier.RunAfterRule.Mode.REGARDLESS_WHETHER_RUN_AFTER_RULE_IS_LOADED_OR_DISABLED import com.pinterest.ktlint.rule.engine.core.api.RuleId import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint -import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.EXPERIMENTAL +import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE import com.pinterest.ktlint.rule.engine.core.api.children import com.pinterest.ktlint.rule.engine.core.api.editorconfig.CODE_STYLE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.editorconfig.EditorConfig @@ -71,7 +70,7 @@ private val LOGGER = KotlinLogging.logger {}.initKtLintKLogger() * } * ``` */ -@SinceKtlint("1.0", EXPERIMENTAL) +@SinceKtlint("1.0", STABLE) public class FunctionLiteralRule : StandardRule( id = "function-literal", @@ -86,8 +85,7 @@ public class FunctionLiteralRule : INDENT_STYLE_PROPERTY, MAX_LINE_LENGTH_PROPERTY, ), - ), - Rule.Experimental { + ) { private var codeStyle = CODE_STYLE_PROPERTY.defaultValue private var indentConfig = IndentConfig.DEFAULT_INDENT_CONFIG private var maxLineLength = MAX_LINE_LENGTH_PROPERTY.defaultValue diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FunctionTypeModifierSpacingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FunctionTypeModifierSpacingRule.kt index a67760e135..f581aede14 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FunctionTypeModifierSpacingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FunctionTypeModifierSpacingRule.kt @@ -4,10 +4,9 @@ import com.pinterest.ktlint.rule.engine.core.api.AutocorrectDecision import com.pinterest.ktlint.rule.engine.core.api.ElementType.FUNCTION_TYPE import com.pinterest.ktlint.rule.engine.core.api.ElementType.MODIFIER_LIST import com.pinterest.ktlint.rule.engine.core.api.ElementType.WHITE_SPACE -import com.pinterest.ktlint.rule.engine.core.api.Rule import com.pinterest.ktlint.rule.engine.core.api.RuleId import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint -import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.EXPERIMENTAL +import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed import com.pinterest.ktlint.rule.engine.core.api.nextCodeSibling import com.pinterest.ktlint.rule.engine.core.api.prevSibling @@ -18,10 +17,8 @@ import org.jetbrains.kotlin.com.intellij.lang.ASTNode /** * Lints and formats a single space between the modifier list and the function type */ -@SinceKtlint("1.0", EXPERIMENTAL) -public class FunctionTypeModifierSpacingRule : - StandardRule("function-type-modifier-spacing"), - Rule.Experimental { +@SinceKtlint("1.0", STABLE) +public class FunctionTypeModifierSpacingRule : StandardRule("function-type-modifier-spacing") { override fun beforeVisitChildNodes( node: ASTNode, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> AutocorrectDecision, diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/MultilineLoopRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/MultilineLoopRule.kt index a99684531f..84a45960c8 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/MultilineLoopRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/MultilineLoopRule.kt @@ -8,10 +8,9 @@ import com.pinterest.ktlint.rule.engine.core.api.ElementType.LBRACE import com.pinterest.ktlint.rule.engine.core.api.ElementType.RBRACE import com.pinterest.ktlint.rule.engine.core.api.ElementType.RPAR import com.pinterest.ktlint.rule.engine.core.api.IndentConfig -import com.pinterest.ktlint.rule.engine.core.api.Rule import com.pinterest.ktlint.rule.engine.core.api.RuleId import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint -import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.EXPERIMENTAL +import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE import com.pinterest.ktlint.rule.engine.core.api.editorconfig.EditorConfig import com.pinterest.ktlint.rule.engine.core.api.editorconfig.INDENT_SIZE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.editorconfig.INDENT_STYLE_PROPERTY @@ -32,7 +31,7 @@ import org.jetbrains.kotlin.psi.psiUtil.leaves /** * https://developer.android.com/kotlin/style-guide#braces */ -@SinceKtlint("1.0", EXPERIMENTAL) +@SinceKtlint("1.0", STABLE) public class MultilineLoopRule : StandardRule( id = "multiline-loop", @@ -41,8 +40,7 @@ public class MultilineLoopRule : INDENT_SIZE_PROPERTY, INDENT_STYLE_PROPERTY, ), - ), - Rule.Experimental { + ) { private var indentConfig = IndentConfig.DEFAULT_INDENT_CONFIG override fun beforeFirstNode(editorConfig: EditorConfig) {