diff --git a/CHANGELOG.md b/CHANGELOG.md index 284372037c..0fc7ce00e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,34 @@ IMPORTANT: Maven coordinates have been changed for some module. Be sure to updat | com.pinterest.ktlint. | com.pinterest.ktlint. | | com.pinterest.ktlint. | com.pinterest.ktlint. | +### Promote experimental rules to non-experimental + +The rules below have been promoted to non-experimental rules: +* [blank-line-before-declaration](https://pinterest.github.io/ktlint/rules/standard/#blank-line-before-declarations) +* [context-receiver-wrapping](https://pinterest.github.io/ktlint/rules/standard/#content-receiver-wrapping) +* [discouraged-comment-location](https://pinterest.github.io/ktlint/rules/standard/#discouraged-comment-location) +* [enum-wrapping](https://pinterest.github.io/ktlint/rules/standard/#enum-wrapping) +* [function-naming](https://pinterest.github.io/ktlint/rules/standard/#function-naming) +* [function-signature](https://pinterest.github.io/ktlint/rules/standard/#function-signature) +* [if-else-bracing](https://pinterest.github.io/ktlint/rules/standard/#if-else-bracing) +* [multiline-expression-wrapping](https://pinterest.github.io/ktlint/rules/standard/#multiline-expression-wrapping) +* [if-else-wrapping](https://pinterest.github.io/ktlint/rules/standard/#if-else-wrapping) +* [no-blank-line-in-list](https://pinterest.github.io/ktlint/rules/standard/#no-blank-line-in-list) +* [no-consecutive-comments](https://pinterest.github.io/ktlint/rules/standard/#no-consecutive-comments) +* [no-empty-file](https://pinterest.github.io/ktlint/rules/standard/#no-empty-file) +* [no-empty-first-line-in-class-body](https://pinterest.github.io/ktlint/rules/standard/#no-empty-first-line-in-class-body) +* [no-single-line-block-comment](https://pinterest.github.io/ktlint/rules/standard/#no-single-line-block-comment) +* [parameter-list-spacing](https://pinterest.github.io/ktlint/rules/standard/#parameter-list-spacing) +* [property-naming](https://pinterest.github.io/ktlint/rules/standard/#property-naming) +* [statement-wrapping](https://pinterest.github.io/ktlint/rules/standard/#statement-wrapping) +* [string-template-indent](https://pinterest.github.io/ktlint/rules/standard/#string-template-indent) +* [try-catch-finally-spacing](https://pinterest.github.io/ktlint/rules/standard/#try-catch-finally-spacing) +* [type-argument-list-spacing](https://pinterest.github.io/ktlint/rules/standard/#type-argument-list-spacing) +* [type-parameter-list-spacing](https://pinterest.github.io/ktlint/rules/standard/#type-parameter-list-spacing) +* [unnecessary-parentheses-before-trailing-lambda](https://pinterest.github.io/ktlint/rules/standard/#unnecessary-parentheses-before-trailing-lambda) + +Note that this only affects users that have enabled the `standard` ruleset while having the `experimental` rules disabled. + ### API changes * As a part of public API stabilization, data classes are no longer used in the public API. As of that, functions like `copy()` or `componentN()` (used for destructuring declarations) are not available anymore. This is a binary incompatible change, breaking backwards compatibility. ([#2133](https://github.com/pinterest/ktlint/issues/2133)) diff --git a/documentation/snapshot/docs/rules/experimental.md b/documentation/snapshot/docs/rules/experimental.md index 027360e259..4b31b1bd00 100644 --- a/documentation/snapshot/docs/rules/experimental.md +++ b/documentation/snapshot/docs/rules/experimental.md @@ -40,57 +40,7 @@ Wraps binary expression at the operator reference whenever the binary expression 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. - -=== "[:material-heart:](#) Ktlint" - - ```kotlin - const val foo1 = "foo1" - - class FooBar { - val foo2 = "foo2" - val foo3 = "foo3" - - fun bar1() { - val foo4 = "foo4" - val foo5 = "foo5" - } - - fun bar2() = "bar" - - val foo6 = "foo3" - val foo7 = "foo4" - - enum class Foo {} - } - ``` - -=== "[:material-heart-off-outline:](#) Disallowed" - - ```kotlin - const val foo1 = "foo1" - class FooBar { - val foo2 = "foo2" - val foo3 = "foo3" - fun bar1() { - val foo4 = "foo4" - val foo5 = "foo5" - } - fun bar2() = "bar" - val foo6 = "foo3" - val foo7 = "foo4" - enum class Foo {} - } - ``` - -Rule id: `blank-line-before-declaration` (`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. - -### Chain method continuation +## Chain method continuation In a multiline method chain, the chain operators (`.` or `?.`) have to be aligned with each other. @@ -350,103 +300,54 @@ The other code styles allow an infinite amount of parameters on the same line (a Rule id: `class-signature` (`standard` rule set) -## Discouraged comment location +## Function expression body -Detect discouraged comment locations (no autocorrect). +Rewrites a function body only containing a `return` or `throw` expression to an expression body. !!! note - Kotlin allows comments to be placed almost everywhere. As this can lead to code which is hard to read, most of them will never be used in practice. Ideally each rule takes comments at all possible locations into account. Sometimes this is really hard and not worth the effort. By explicitly forbidding such comment locations, the development of those rules becomes a bit easier. - -=== "[:material-heart-off-outline:](#) Disallowed" - - ```kotlin - fun /* some comment */ foo(t: T) = "some-result" - - fun foo() { - if (true) - // some comment - bar() - } - ``` - -Rule id: `discouraged-comment-location` (`standard` rule set) - -## Disallow empty lines at start of class body - -Detect blank lines at start of a class body. + If the function body contains a comment, it is not rewritten to an expression body. === "[:material-heart:](#) Ktlint" ```kotlin - class Foo { - val foo = "foo" + 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 } - ``` - -=== "[:material-heart-off-outline:](#) Disallowed" - - ```kotlin - class Foo { - - val foo = "foo" + fun foo6(): String { + /* some comment */ + return "foo" + } + fun foo7() { + throw IllegalArgumentException("some message") + /* some comment */ + } + fun foo8(): Foo { + throw IllegalArgumentException("some message") + // some comment } ``` - -Rule id: `no-empty-first-line-in-class-body` (`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. - -## Disallow consecutive comments - -Consecutive comments are disallowed in following cases: -- Any mix of a consecutive kdoc, a block comment or an EOL comment unless separated by a blank line in between -- Consecutive KDocs (even when separated by a blank line) -- Consecutive block comments (even when separated by a blank line) - -Consecutive EOL comments are always allowed as they are often used instead of a block comment. - -=== "[:material-heart:](#) Ktlint" - - ```kotlin - // An EOL comment - // may be followed by another EOL comment - val foo = "foo" - - // Different comment types (including KDoc) may be consecutive .. - - /* - * ... but do need to be separated by a blank line ... - */ - - /** - * ... but a KDoc can not be followed by an EOL or a block comment or another KDoc - */ - fun bar() = "bar" - ``` - === "[:material-heart-off-outline:](#) Disallowed" ```kotlin - /* - * Block comments can not be consecutive ... - */ - /* - * ... even not when separated by a new line. - */ - val bar = "bar" - - /** - * A KDoc can not be followed by a block comment or an EOL comment or another KDOC - */ - - // ... even not when separated by a new line. + fun foo1() { + return "foo" + } + fun foo2(): String { + return "foo" + } + fun foo3() { + throw IllegalArgumentException("some message") + } + fun foo4(): Foo { + throw IllegalArgumentException("some message") + } ``` -Rule id: `no-consecutive-comments` (`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. +Rule id: `function-expression-body` (`standard` rule set) ## Function literal @@ -512,235 +413,30 @@ If the function literal contains multiple parameter and at least one parameter o Rule id: `function-literal` (`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. - -## Function signature - -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 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. In case of function with a body expression, the body expression is placed on the same line as the function signature when not exceeding the `max_line_length` property. Optionally the function signature can be forced to be written as a multiline signature in case the function has more than a specified number of parameters (`.editorconfig` property `ktlint_function_signature_wrapping_rule_always_with_minimum_parameters`) - -=== "[:material-heart:](#) Ktlint" - - ```kotlin - // Assume that the last allowed character is - // at the X character on the right X - fun foooooooo( - a: Any, - b: Any, - c: Any - ): String { - // body - } - - // Assume that the last allowed character is - // at the X character on the right X - fun bar(a: Any, b: Any, c: Any): String { - // body - } - - // When wrapping of body is set to 'default'. - // Assume that the last allowed character is - // at the X character on the right X - fun f(a: Any, b: Any): String = "some-result" - .uppercase() - - // When wrapping of body is set to 'multiline' - // or 'always'. - // Assume that the last allowed character is - // at the X character on the right X - fun f(a: Any, b: Any): String = - "some-result" - .uppercase() - ``` -=== "[:material-heart-off-outline:](#) Disallowed" - - ```kotlin - // Assume that the last allowed character is - // at the X character on the right X - fun foooooooo(a: Any, b: Any, c: Any): String { - // body - } - - // Assume that the last allowed character is - // at the X character on the right X - fun bar( - a: Any, - b: Any, - c: Any - ): String { - // body - } - - // When wrapping of body is set to 'default'. - // Assume that the last allowed character is - // at the X character on the right X - fun f(a: Any, b: Any): String = - "some-result" - .uppercase() - - // When wrapping of body is set to 'multiline' - // or 'always'. - // Assume that the last allowed character is - // at the X character on the right X - fun f(a: Any, b: Any): String = "some-result" - .uppercase() - ``` - -Rule id: `function-signature` (`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. - -=== "[:material-heart:](#) Ktlint" - - ```kotlin - fun foo(value: int) { - if (value > 0) { - doSomething() - } else if (value < 0) { - doSomethingElse() - } else { - doSomethingElse2() - } - } - ``` - -=== "[:material-heart-off-outline:](#) Disallowed" - - ```kotlin - fun foo(value: int) { - if (value > 0) - doSomething() - else if (value < 0) { - doSomethingElse() - } else - doSomethingElse2() - } - ``` - -Rule id: `if-else-bracing` (`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. - -## If else wrapping - -A single line if-statement should be kept simple. It may contain no more than one else-branch. The branches may not be wrapped in a block. - -=== "[:material-heart:](#) Ktlint" - - ```kotlin - fun foobar() { - if (true) foo() - if (true) foo() else bar() - } - ``` - -=== "[:material-heart-off-outline:](#) Disallowed" - - ```kotlin - fun foobar() { - if (true) if (false) foo() else bar() - if (true) bar() else if (false) foo() else bar() - if (true) { foo() } else bar() - if (true) bar() else { if (false) foo() else bar() } - } - ``` - -Rule id: `if-else-wrapping` (`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. -## Naming +## Function type modifier spacing -### Function naming - -Enforce naming of function. +Enforce a single whitespace between the modifier list and the function type. === "[:material-heart:](#) Ktlint" ```kotlin - fun foo() {} - fun fooBar() {} - ``` -=== "[:material-heart:](#) Ktlint Test" - - ```kotlin - @Test - fun `Some name`() {} - - @Test - fun do_something() {} + val foo: suspend () -> Unit = {} + suspend fun bar(baz: suspend () -> Unit) = baz() ``` === "[:material-heart-off-outline:](#) Disallowed" ```kotlin - fun Foo() {} - fun Foo_Bar() {} - fun `Some name`() {} - fun do_something() {} + val foo: suspend() -> Unit = {} + suspend fun bar(baz: suspend () -> Unit) = baz() ``` -!!! note - Functions in files which import a class from package `org.junit`, `org.testng` or `kotlin.test` are considered to be test functions. Functions in such classes are allowed to have underscores in the name. Or function names can be specified between backticks and do not need to adhere to the normal naming convention. - -This rule can also be suppressed with the IntelliJ IDEA inspection suppression `FunctionName`. - -Rule id: `function-naming` (`standard` rule set) +Rule id: `function-type-modifier-spacing` (`standard` rule set) -### Package naming +## Package naming Enforce naming of package. @@ -764,567 +460,3 @@ This rule can also be suppressed with the IntelliJ IDEA inspection suppression ` ``` Rule id: `package-naming` (`standard` rule set) - -### Property naming - -Enforce naming of property. - -!!! note - This rule can not reliably detect all situations in which incorrect property naming is used. So it only detects in which it is certain that naming is incorrect. - -=== "[:material-heart:](#) Ktlint" - - ```kotlin - val foo1 = Foo() // In case developer want to communicate that Foo is mutable - val FOO1 = Foo() // In case developer want to communicate that Foo is deeply immutable - - const val FOO_BAR = "FOO-BAR" // By definition deeply immutable - - var foo2: Foo = Foo() // By definition not immutable - - class Bar { - val foo1 = Foo() // In case developer want to communicate that Foo is mutable - val FOO1 = Foo() // In case developer want to communicate that Foo is deeply immutable - - const val FOO_BAR = "FOO-BAR" // By definition deeply immutable - - var foo2: Foo = Foo() // By definition not immutable - - // Backing property - private val _elementList = mutableListOf() - val elementList: List - get() = _elementList - } - ``` -=== "[:material-heart-off-outline:](#) Disallowed" - - ```kotlin - const val fooBar = "FOO-BAR" // By definition deeply immutable - - var FOO2: Foo = Foo() // By definition not immutable - - class Bar { - val FOO_BAR = "FOO-BAR" // Class properties always start with lowercase, const is not allowed - - // 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 - } - ``` - -This rule can also be suppressed with the IntelliJ IDEA inspection suppression `PropertyName`. - -Rule id: `property-naming` (`standard` rule set) - -## No empty file - -A kotlin (script) file should not be empty. It needs to contain at least one declaration. Files only contain a package and/or import statements are as of that disallowed. - -Rule id: `no-empty-file` - -## No single line block comments - -A single line block comment should be replaced with an EOL comment when possible. - -=== "[:material-heart:](#) Ktlint" - - ```kotlin - /* - * Some comment - */ - val foo = "foo" // Some comment - val foo = { /* no-op */ } - ``` -=== "[:material-heart-off-outline:](#) Disallowed" - - ```kotlin - /* Some comment */ - val foo = "foo" /* Some comment */ - ``` - -Rule id: `no-single-line-block-comment` (`standard` rule set) - -## Spacing - -### 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) - -### No blank lines in list - -Disallow blank lines to be used in lists before the first element, between elements, and after the last element. - -*Super type* - -=== "[:material-heart:](#) Ktlint" - - ```kotlin - class FooBar: - Foo, - Bar { - // body - } - ``` - -=== "[:material-heart-off-outline:](#) Disallowed" - - ```kotlin - class FooBar: - - Foo, - - Bar - - { - // body - } - ``` - -*Type argument list* - -=== "[:material-heart:](#) Ktlint" - - ```kotlin - val foobar: FooBar< - Foo, - Bar, - > = FooBar(Foo(), Bar()) - ``` - -=== "[:material-heart-off-outline:](#) Disallowed" - - ```kotlin - val foobar: FooBar< - - Foo, - - Bar, - - > = FooBar(Foo(), Bar()) - ``` - -*Type constraint list* - -=== "[:material-heart:](#) Ktlint" - - ```kotlin - class BiAdapter( - val adapter1: A1, - val adapter2: A2 - ) : RecyclerView.Adapter() - where A1 : RecyclerView.Adapter, A1 : ComposableAdapter.ViewTypeProvider, - A2 : RecyclerView.Adapter, A2 : ComposableAdapter.ViewTypeProvider { - // body - } - ``` - -=== "[:material-heart-off-outline:](#) Disallowed" - - ```kotlin - class BiAdapter( - val adapter1: A1, - val adapter2: A2 - ) : RecyclerView.Adapter() - where - A1 : RecyclerView.Adapter, A1 : ComposableAdapter.ViewTypeProvider, - - A2 : RecyclerView.Adapter, A2 : ComposableAdapter.ViewTypeProvider - { - // body - } - ``` - -*Type parameter list* - -=== "[:material-heart:](#) Ktlint" - - ```kotlin - fun < - Foo, - Bar, - > foobar() - ``` - -=== "[:material-heart-off-outline:](#) Disallowed" - - ```kotlin - fun < - - Foo, - - Bar, - - > foobar() - ``` - -*Value argument list* - -=== "[:material-heart:](#) Ktlint" - - ```kotlin - val foobar = foobar( - "foo", - "bar", - ) - ``` - -=== "[:material-heart-off-outline:](#) Disallowed" - - ```kotlin - val foobar = foobar( - - "foo", - - "bar", - - ) - ``` - -*Value parameter list* - -=== "[:material-heart:](#) Ktlint" - - ```kotlin - fun foobar( - foo: String, - bar: String, - ) - ``` - -=== "[:material-heart-off-outline:](#) Disallowed" - - ```kotlin - fun foobar( - - foo: String, - - bar: String, - - ) - ``` - -Rule id: `no-blank-line-in-list` (`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. - -### Parameter list spacing - -Consistent spacing inside the parameter list. - -=== "[:material-heart:](#) Ktlint" - - ```kotlin - fun foo(a: Any ) = "some-result" - fun foo() = "some-result" - ``` -=== "[:material-heart-off-outline:](#) Disallowed" - - ```kotlin - fun foo( a : Any ) = "some-result" - fun foo( - ) = "some-result" - ``` - -Rule id: `parameter-list-spacing` (`standard` rule set) - -### String template indent - -Enforce consistent string template indentation for multiline string templates which are post-fixed with `.trimIndent()`. The opening and closing `"""` are placed on separate lines and the indentation of the content of the template is aligned with the `"""`. - -=== "[:material-heart:](#) Ktlint" - - ```kotlin - val foo = - """ - line1 - line2 - """.trimIndent() - fun foo() { - // The opening """ can not be wrapped to next line as that would result in a compilation error - return """ - line1 - line2 - """.trimIndent() - } - ``` -=== "[:material-heart-off-outline:](#) Disallowed" - - ```kotlin - val foo = """ - line1 - line2 - """.trimIndent() - fun foo() { - return """ - line1 - line2 - """.trimIndent() - } - ``` - -Rule id: `string-template-indent` (`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. - -### Try catch finally spacing - -Enforce consistent spacing in `try { .. } catch { .. } finally { .. }`. - -=== "[:material-heart:](#) Ktlint" - - ```kotlin - fun foo() = - try { - // do something - } catch (exception: Exception) { - // handle exception - } finally { - // clean up - } - ``` -=== "[:material-heart-off-outline:](#) Disallowed" - - ```kotlin - fun foo1() = try { /* ... */ } catch (exception: Exception) { /* ... */ } finally { /* ... */ } - fun foo2() = - try { - // do something - } - catch (exception: Exception) { - // handle exception - } - finally { - // clean up - } - ``` - -Rule id: `try-catch-finally-spacing` (`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. - -### Type argument list spacing - -Spacing before and after the angle brackets of a type argument list. - -=== "[:material-heart:](#) Ktlint" - - ```kotlin - val res = ArrayList() - class B : A() { - override fun x() = super.x() - } - ``` -=== "[:material-heart-off-outline:](#) Disallowed" - - ```kotlin - val res = ArrayList < LintError > () - class B : A< T >() { - override fun x() = super< A >.x() - } - ``` - -Rule id: `type-argument-list-spacing` (`standard` rule set) - -### Type parameter list spacing - -Spacing after a type parameter list in function and class declarations. - -=== "[:material-heart:](#) Ktlint" - - ```kotlin - fun foo1(t: T) = "some-result" - fun foo2(t: T) = "some-result" - fun foo3(t: T) = "some-result" - ``` -=== "[:material-heart-off-outline:](#) Disallowed" - - ```kotlin - fun foo1(t: T) = "some-result" - fun foo2(t: T) = "some-result" - funfoo3(t: T) = "some-result" - ``` - -Rule id: `type-parameter-list-spacing` (`standard` rule set) - -## Wrapping - -### 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. - -=== "[:material-heart:](#) Ktlint" - - ```kotlin - // ALways wrap regardless of whether max line length is set - context(Foo) - fun fooBar() - - // Wrap each context receiver to a separate line when the - // entire context receiver list does not fit on a single line - context( - Fooooooooooooooooooo1, - Foooooooooooooooooooooooooooooo2 - ) - fun fooBar() - - // Wrap each context receiver to a separate line when the - // entire context receiver list does not fit on a single line. - // Also, wrap each of it projection types in case a context - // receiver does not fit on a single line after it has been - // wrapped. - context( - Foooooooooooooooo< - Foo, - Bar - > - ) - fun fooBar() - ``` - -=== "[:material-heart-off-outline:](#) Disallowed" - - ```kotlin - // Should be wrapped regardless of whether max line length is set - context(Foo) fun fooBar() - - // Should be wrapped when the entire context receiver list does not - // fit on a single line - context(Fooooooooooooooooooo1, Foooooooooooooooooooooooooooooo2) - fun fooBar() - - // Should be wrapped when the entire context receiver list does not - // fit on a single line. Also, it should wrap each of it projection - // type in case a context receiver does not fit on a single line - // after it has been wrapped. - context(Foooooooooooooooo) - fun fooBar() - ``` - -Rule id: `context-receiver-wrapping` (`standard` rule set) - -### Enum wrapping - -An enum should be a single line, or each enum entry has to be placed on a separate line. In case the enumeration contains enum entries and declarations those are to be separated by a blank line. - -=== "[:material-heart:](#) Ktlint" - - ```kotlin - enum class Foo { A, B, C, D } - - enum class Foo { - A, - B, - C, - D, - ; - - fun foo() = "foo" - } - ``` - -=== "[:material-heart-off-outline:](#) Disallowed" - - ```kotlin - enum class Foo { - A, - B, C, - D - } - - enum class Foo { - A; - fun foo() = "foo" - } - ``` - -Rule id: `enum-wrapping` (`standard` rule set) - -### Multiline expression wrapping - -Multiline expression on the right hand side of an expression are forced to start on a separate line. Expressions in return statement are excluded as that would result in a compilation error. - -=== "[:material-heart:](#) Ktlint" - - ```kotlin - val foo = - foo( - parameterName = - "The quick brown fox " - .plus("jumps ") - .plus("over the lazy dog"), - ) - ``` - -=== "[:material-heart-off-outline:](#) Disallowed" - - ```kotlin - val foo = foo( - parameterName = "The quick brown fox " - .plus("jumps ") - .plus("over the lazy dog"), - ) - ``` - -Rule id: `multiline-expression-wrapping` (`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. - -### Statement wrapping - -A function, class/object body or other block body statement has to be placed on different line than the braces of the body block. - -=== "[:material-heart:](#) Ktlint" - - ```kotlin - fun foo() { - if (true) { - // do something - } - } - class A { - val a = 0 - val b = 1 - } - enum class FooBar1 { FOO, BAR } - enum class FooBar2 { - FOO, - BAR, - } - ``` - -=== "[:material-heart-off-outline:](#) Disallowed" - - ```kotlin - fun foo() { if (true) { - // do something - } - } - class A { val a = 0 - val b = 1 } - ``` - -Rule id: `statement-wrapping` diff --git a/documentation/snapshot/docs/rules/standard.md b/documentation/snapshot/docs/rules/standard.md index 1711bcfe42..f172c4bac1 100644 --- a/documentation/snapshot/docs/rules/standard.md +++ b/documentation/snapshot/docs/rules/standard.md @@ -47,29 +47,55 @@ Multiple annotations should be on a separate line than the annotated declaration Rule-id: `annotation` (`standard` rule set) -## Argument list wrapping +## Blank line before declarations -All arguments should be on the same line, or every argument should be on a separate line. +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. === "[:material-heart:](#) Ktlint" ```kotlin - val x = f( - a, - b, - c - ) + const val foo1 = "foo1" + + class FooBar { + val foo2 = "foo2" + val foo3 = "foo3" + + fun bar1() { + val foo4 = "foo4" + val foo5 = "foo5" + } + + fun bar2() = "bar" + + val foo6 = "foo3" + val foo7 = "foo4" + + enum class Foo {} + } ``` + === "[:material-heart-off-outline:](#) Disallowed" ```kotlin - val x = f( - a, - b, c - ) + const val foo1 = "foo1" + class FooBar { + val foo2 = "foo2" + val foo3 = "foo3" + fun bar1() { + val foo4 = "foo4" + val foo5 = "foo5" + } + fun bar2() = "bar" + val foo6 = "foo3" + val foo7 = "foo4" + enum class Foo {} + } ``` -Rule-id: `argument-list-wrapping` (`standard` rule set) +Rule id: `blank-line-before-declaration` (`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. ## Block comment initial star alignment @@ -92,69 +118,26 @@ Lines in a block comment which (exclusive the indentation) start with a `*` shou Rule id: `block-comment-initial-star-alignment` (`standard` rule set) -## Chain wrapping +## Discouraged comment location -When wrapping chained calls `.`, `?.` and `?:` should be placed on the next line +Detect discouraged comment locations (no autocorrect). -=== "[:material-heart:](#) Ktlint" +!!! note + Kotlin allows comments to be placed almost everywhere. As this can lead to code which is hard to read, most of them will never be used in practice. Ideally each rule takes comments at all possible locations into account. Sometimes this is really hard and not worth the effort. By explicitly forbidding such comment locations, the development of those rules becomes a bit easier. - ```kotlin - val foo = listOf(1, 2, 3) - .filter { it > 2 }!! - .takeIf { it.count() > 100 } - ?.sum() - val foobar = foo() - ?: bar - ``` === "[:material-heart-off-outline:](#) Disallowed" ```kotlin - val foo = listOf(1, 2, 3). - filter { it > 2 }!!. - takeIf { it.count() > 100 }?. - sum() - val foobar = foo() ?: - bar - ``` - -Rule id: `chain-wrapping` (`standard` rule set) - -## Class/object naming - -Enforce naming of class. - -=== "[:material-heart:](#) Ktlint" - - ```kotlin - class Foo - class Foo1 - ``` -=== "[:material-heart:](#) Ktlint JUnit Test" + fun /* some comment */ foo(t: T) = "some-result" - ```kotlin - @Nested - inner class `Some descriptive class name` { - @Test - fun `Some descriptive test name`() { - // do something - } + fun foo() { + if (true) + // some comment + bar() } ``` -=== "[:material-heart-off-outline:](#) Disallowed" - - ```kotlin - class foo - class Foo_Bar - class `Some class in the production code` - ``` - -!!! note - Functions in files which import a class from package `org.junit.jupiter.api` are considered to be test functions and are allowed to have a name specified between backticks and do not need to adhere to the normal naming convention. Although, the [Kotlin coding conventions](https://kotlinlang.org/docs/coding-conventions.html) does not allow this explicitly for class identifiers, `ktlint` does allow it. - -This rule can also be suppressed with the IntelliJ IDEA inspection suppression `ClassName`. - -Rule id: `class-naming` (`standard` rule set) +Rule id: `discouraged-comment-location` (`standard` rule set) ## Enum entry @@ -196,6 +179,115 @@ This rule can be configured with `.editorconfig` property [`insert_final_newline Rule id: `final-newline` (`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. In case of function with a body expression, the body expression is placed on the same line as the function signature when not exceeding the `max_line_length` property. Optionally the function signature can be forced to be written as a multiline signature in case the function has more than a specified number of parameters (`.editorconfig` property `ktlint_function_signature_wrapping_rule_always_with_minimum_parameters`) + +=== "[:material-heart:](#) Ktlint" + + ```kotlin + // Assume that the last allowed character is + // at the X character on the right X + fun foooooooo( + a: Any, + b: Any, + c: Any + ): String { + // body + } + + // Assume that the last allowed character is + // at the X character on the right X + fun bar(a: Any, b: Any, c: Any): String { + // body + } + + // When wrapping of body is set to 'default'. + // Assume that the last allowed character is + // at the X character on the right X + fun f(a: Any, b: Any): String = "some-result" + .uppercase() + + // When wrapping of body is set to 'multiline' + // or 'always'. + // Assume that the last allowed character is + // at the X character on the right X + fun f(a: Any, b: Any): String = + "some-result" + .uppercase() + ``` +=== "[:material-heart-off-outline:](#) Disallowed" + + ```kotlin + // Assume that the last allowed character is + // at the X character on the right X + fun foooooooo(a: Any, b: Any, c: Any): String { + // body + } + + // Assume that the last allowed character is + // at the X character on the right X + fun bar( + a: Any, + b: Any, + c: Any + ): String { + // body + } + + // When wrapping of body is set to 'default'. + // Assume that the last allowed character is + // at the X character on the right X + fun f(a: Any, b: Any): String = + "some-result" + .uppercase() + + // When wrapping of body is set to 'multiline' + // or 'always'. + // Assume that the last allowed character is + // at the X character on the right X + fun f(a: Any, b: Any): String = "some-result" + .uppercase() + ``` + +Rule id: `function-signature` (`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. + +=== "[:material-heart:](#) Ktlint" + + ```kotlin + fun foo(value: int) { + if (value > 0) { + doSomething() + } else if (value < 0) { + doSomethingElse() + } else { + doSomethingElse2() + } + } + ``` + +=== "[:material-heart-off-outline:](#) Disallowed" + + ```kotlin + fun foo(value: int) { + if (value > 0) + doSomething() + else if (value < 0) { + doSomethingElse() + } else + doSomethingElse2() + } + ``` + +Rule id: `if-else-bracing` (`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. + ## Import ordering Ensures that imports are ordered consistently (see [Import Layouts](../configuration-ktlint/#import-layouts) for configuration). @@ -251,1257 +343,2030 @@ Indentation formatting - respects `.editorconfig` `indent_size` with no continua Rule id: `indent` (`standard` rule set) -## Ktlint-suppression rule +## Naming -The `ktlint-disable` and `ktlint-enable` directives are no longer supported as of ktlint version `0.50.0`. This rule migrates the directives to Suppress or SuppressWarnings annotations. +### Class naming -Identifiers in the @Suppress and @SuppressWarnings annotations to suppress ktlint rules are checked for validity and autocorrected when possible. +Enforce naming of class and objects. === "[:material-heart:](#) Ktlint" ```kotlin - @file:Suppress("ktlint:standard:no-wildcard-imports") - - class FooBar { - @Suppress("ktlint:standard:max-line-length") - val foo = "some longggggggggggggggggggg text" + class Foo + class Foo1 + ``` +=== "[:material-heart:](#) Ktlint JUnit Test" - fun bar() = - @Suppress("ktlint:standard:no-multi-spaces") - listOf( - "1 One", - "10 Ten", - "100 Hundred", - ) + ```kotlin + @Nested + inner class `Some descriptive class name` { + @Test + fun `Some descriptive test name`() { + // do something + } } ``` + === "[:material-heart-off-outline:](#) Disallowed" ```kotlin - /* ktlint-disable standard:no-wildcard-imports */ - - class FooBar { - val foo = "some longggggggggggggggggggg text" // ktlint-disable standard:max-line-length - - fun bar() = - listOf( - /* ktlint-disable standard:no-multi-spaces */ - "1 One", - "10 Ten", - "100 Hundred", - /* ktlint-enable standard:no-multi-spaces */ - ) - } + class foo + class Foo_Bar + class `Some class in the production code` ``` -Rule id: `ktlint-suppression` (`standard` rule set) - !!! note - This rule can not be disabled in the `.editorconfig`. + Functions in files which import a class from package `org.junit.jupiter.api` are considered to be test functions and are allowed to have a name specified between backticks and do not need to adhere to the normal naming convention. Although, the [Kotlin coding conventions](https://kotlinlang.org/docs/coding-conventions.html) does not allow this explicitly for class identifiers, `ktlint` does allow it. -## Max line length +This rule can also be suppressed with the IntelliJ IDEA inspection suppression `ClassName`. -Ensures that lines do not exceed the given length of `.editorconfig` property `max_line_length` (see [EditorConfig](../configuration-ktlint/) section for more). This rule does not apply in a number of situations. For example, in the case a line exceeds the maximum line length due to a comment that disables ktlint rules then that comment is being ignored when validating the length of the line. The `.editorconfig` property `ktlint_ignore_back_ticked_identifier` can be set to ignore identifiers which are enclosed in backticks, which for example is very useful when you want to allow longer names for unit tests. +Rule id: `class-naming` (`standard` rule set) + +### Function naming + +Enforce naming of function. === "[:material-heart:](#) Ktlint" ```kotlin - // Assume that the last allowed character is - // at the X character on the right X - // Lines below are accepted although the max - // line length is exceeded. - package com.toooooooooooooooooooooooooooo.long - import com.tooooooooooooooooooooooooooooo.long - val foo = - """ - fooooooooooooooooooooooooooooooooooooooooo - """ + fun foo() {} + fun fooBar() {} + ``` +=== "[:material-heart:](#) Ktlint Test" + + ```kotlin @Test - fun `Test description which is toooooooooooo long`() { - } + fun `Some name`() {} + + @Test + fun do_something() {} ``` + === "[:material-heart-off-outline:](#) Disallowed" ```kotlin - // Assume that the last allowed character is - // at the X character on the right X - val fooooooooooooooo = "fooooooooooooooooooooo" - val foooooooooooooo = "foooooooooooooooooooo" // some comment - val fooooooooooooo = - "foooooooooooooooooooooooooooooooooooooooo" + fun Foo() {} + fun Foo_Bar() {} + fun `Some name`() {} + fun do_something() {} ``` -Rule id: `max-line-length` (`standard` rule set) +!!! note + Functions in files which import a class from package `org.junit`, `org.testng` or `kotlin.test` are considered to be test functions. Functions in such classes are allowed to have underscores in the name. Or function names can be specified between backticks and do not need to adhere to the normal naming convention. -## Modifier order +This rule can also be suppressed with the IntelliJ IDEA inspection suppression `FunctionName`. -Consistent order of modifiers +Rule id: `function-naming` (`standard` rule set) + +### Package name + +Validates that the package name matches the regular expression `[a-z][a-zA-Z\d]*(\.[a-z][a-zA-Z\d]*)*`. === "[:material-heart:](#) Ktlint" ```kotlin - abstract class A { - protected open val v = "" - internal open suspend fun f(v: Any): Any = "" - protected lateinit var lv: String - } + package foo + package foo.bar ``` === "[:material-heart-off-outline:](#) Disallowed" ```kotlin - abstract class A { - open protected val v = "" - open suspend internal fun f(v: Any): Any = "" - lateinit protected var lv: String - } + package Foo + package foo.Foo + package `foo bar` + package foo.`foo bar` ``` -Rule id: `modifier-order` (`standard` rule set) +Rule id: `package-name` (`standard` rule set) -## Multiline if-else +### Property naming -Braces required for multiline if/else statements. +Enforce naming of property. + +!!! note + This rule can not reliably detect all situations in which incorrect property naming is used. So it only detects in which it is certain that naming is incorrect. === "[:material-heart:](#) Ktlint" ```kotlin - val foo = - if (true) { - return 0 - } else { - return 1 - } - ``` -=== "[:material-heart-off-outline:](#) Disallowed" + val foo1 = Foo() // In case developer want to communicate that Foo is mutable + val FOO1 = Foo() // In case developer want to communicate that Foo is deeply immutable - ```kotlin - val foo = - if (true) - return 0 - else - return 1 - ``` + const val FOO_BAR = "FOO-BAR" // By definition deeply immutable -Rule id: `multiline-if-else` (`standard` rule set) + var foo2: Foo = Foo() // By definition not immutable -## No blank lines before `}` + class Bar { + val foo1 = Foo() // In case developer want to communicate that Foo is mutable + val FOO1 = Foo() // In case developer want to communicate that Foo is deeply immutable -No blank lines before `}`. + const val FOO_BAR = "FOO-BAR" // By definition deeply immutable -=== "[:material-heart:](#) Ktlint" + var foo2: Foo = Foo() // By definition not immutable - ```kotlin - fun main() { - fun a() { - } - fun b() + // Backing property + private val _elementList = mutableListOf() + val elementList: List + get() = _elementList } ``` === "[:material-heart-off-outline:](#) Disallowed" ```kotlin - fun main() { - fun a() { - - } - fun b() - - } - ``` + const val fooBar = "FOO-BAR" // By definition deeply immutable -Rule id: `no-blank-line-before-rbrace` (`standard` rule set) + var FOO2: Foo = Foo() // By definition not immutable -## No blank lines in chained method calls + class Bar { + val FOO_BAR = "FOO-BAR" // Class properties always start with lowercase, const is not allowed -=== "[:material-heart:](#) Ktlint" + // Incomplete backing property as public property 'elementList1' is missing + private val _elementList1 = mutableListOf() - ```kotlin - fun foo(inputText: String) { - inputText - .lowercase(Locale.getDefault()) + // Invalid backing property as '_elementList2' is not a private property + val _elementList2 = mutableListOf() + val elementList2: List + get() = _elementList2 } ``` -=== "[:material-heart-off-outline:](#) Disallowed" - ```kotlin - fun foo(inputText: String) { - inputText +This rule can also be suppressed with the IntelliJ IDEA inspection suppression `PropertyName`. - .lowercase(Locale.getDefault()) - } - ``` +Rule id: `property-naming` (`standard` rule set) -Rule id: `no-blank-lines-in-chained-method-calls` (`standard` rule set) +## No blank lines in list -## No consecutive blank lines +Disallow blank lines to be used in lists before the first element, between elements, and after the last element. + +*Super type* === "[:material-heart:](#) Ktlint" ```kotlin - package com.test - - import com.test.util - - val a = "a" - - fun b() { + class FooBar: + Foo, + Bar { + // body } - - fun c() ``` + === "[:material-heart-off-outline:](#) Disallowed" ```kotlin - package com.test - - - import com.test.util - + class FooBar: - val a = "a" + Foo, + Bar - fun b() { + { + // body } - - - fun c() ``` - -Rule id: `no-consecutive-blank-lines` (`standard` rule set) -## No empty (`{}`) class bodies +*Type argument list* === "[:material-heart:](#) Ktlint" ```kotlin - class C - data class DC(val v: Any) - interface I - object O + val foobar: FooBar< + Foo, + Bar, + > = FooBar(Foo(), Bar()) ``` + === "[:material-heart-off-outline:](#) Disallowed" ```kotlin - class C {} - data class DC(val v: Any) { } - interface I { - } - object O{} - ``` + val foobar: FooBar< -Rule id: `no-empty-class-body` (`standard` rule set) + Foo, -## No leading empty lines in method blocks + Bar, + + > = FooBar(Foo(), Bar()) + ``` + +*Type constraint list* === "[:material-heart:](#) Ktlint" ```kotlin - fun bar() { - val a = 2 + class BiAdapter( + val adapter1: A1, + val adapter2: A2 + ) : RecyclerView.Adapter() + where A1 : RecyclerView.Adapter, A1 : ComposableAdapter.ViewTypeProvider, + A2 : RecyclerView.Adapter, A2 : ComposableAdapter.ViewTypeProvider { + // body } ``` + === "[:material-heart-off-outline:](#) Disallowed" ```kotlin - fun bar() { + class BiAdapter( + val adapter1: A1, + val adapter2: A2 + ) : RecyclerView.Adapter() + where + A1 : RecyclerView.Adapter, A1 : ComposableAdapter.ViewTypeProvider, - val a = 2 + A2 : RecyclerView.Adapter, A2 : ComposableAdapter.ViewTypeProvider + { + // body } ``` -Rule id: `no-empty-first-line-in-method-block` (`standard` rule set) - -## No line break after else - -Disallows line breaks after the else keyword if that could lead to confusion, for example: +*Type parameter list* === "[:material-heart:](#) Ktlint" ```kotlin - fun funA() { - if (conditionA()) { - doSomething() - } else if (conditionB()) { - doAnotherThing() - } - } + fun < + Foo, + Bar, + > foobar() ``` + === "[:material-heart-off-outline:](#) Disallowed" ```kotlin - fun funA() { - if (conditionA()) { - doSomething() - } else - if (conditionB()) { - doAnotherThing() - } - } - ``` + fun < -Rule id: `no-line-break-after-else` (`standard` rule set) + Foo, -## No line break before assignment + Bar, -When a line is broken at an assignment (`=`) operator the break comes after the symbol. + > foobar() + ``` + +*Value argument list* === "[:material-heart:](#) Ktlint" ```kotlin - val valA = - "" + val foobar = foobar( + "foo", + "bar", + ) ``` + === "[:material-heart-off-outline:](#) Disallowed" ```kotlin - val valA - = "" - ``` + val foobar = foobar( -Rule id: `no-line-break-before-assignment` (`standard` rule set) + "foo", -## No multi spaces + "bar", -Except in indentation and in KDoc's it is not allowed to have multiple consecutive spaces. + ) + ``` + +*Value parameter list* === "[:material-heart:](#) Ktlint" ```kotlin - fun main() { - x(1, 3) - } + fun foobar( + foo: String, + bar: String, + ) ``` + === "[:material-heart-off-outline:](#) Disallowed" ```kotlin - fun main() { - x(1, 3) - } + fun foobar( + + foo: String, + + bar: String, + + ) ``` -Rule id: `no-multi-spaces` (`standard` rule set) +Rule id: `no-blank-line-in-list` (`standard` rule set) -## No semicolons +!!! Note + This rule is only run when `ktlint_code_style` is set to `ktlint_official` or when the rule is enabled explicitly. -No semicolons (unless used to separate multiple statements on the same line). +## No consecutive comments + +Consecutive comments are disallowed in following cases: +- Any mix of a consecutive kdoc, a block comment or an EOL comment unless separated by a blank line in between +- Consecutive KDocs (even when separated by a blank line) +- Consecutive block comments (even when separated by a blank line) + +Consecutive EOL comments are always allowed as they are often used instead of a block comment. === "[:material-heart:](#) Ktlint" ```kotlin - fun foo() { - bar() + // An EOL comment + // may be followed by another EOL comment + val foo = "foo" - bar() - } + // Different comment types (including KDoc) may be consecutive .. + + /* + * ... but do need to be separated by a blank line ... + */ + + /** + * ... but a KDoc can not be followed by an EOL or a block comment or another KDoc + */ + fun bar() = "bar" ``` + === "[:material-heart-off-outline:](#) Disallowed" ```kotlin - fun foo() { - ; - bar() - ; + /* + * Block comments can not be consecutive ... + */ + /* + * ... even not when separated by a new line. + */ + val bar = "bar" - bar() + /** + * A KDoc can not be followed by a block comment or an EOL comment or another KDOC + */ - ; - } + // ... even not when separated by a new line. ``` -Rule id: `no-semi` (`standard` rule set) +Rule id: `no-consecutive-comments` (`standard` rule set) -## No trailing whitespaces +!!! Note + This rule is only run when `ktlint_code_style` is set to `ktlint_official` or when the rule is enabled explicitly. -Rule id: `no-trailing-spaces` (`standard` rule set) +## No empty file -## No `Unit` as return type +A kotlin (script) file should not be empty. It needs to contain at least one declaration. Files only contain a package and/or import statements are as of that disallowed. -The `Unit` type is not allowed as return type of a function. -returns (`fun fn {}` instead of `fun fn: Unit {}`) +Rule id: `no-empty-file` + +## No empty first line at start in class body + +Detect blank lines at start of a class body. === "[:material-heart:](#) Ktlint" ```kotlin - fun fn() {} + class Foo { + val foo = "foo" + } ``` + === "[:material-heart-off-outline:](#) Disallowed" ```kotlin - fun fn(): Unit {} - ``` + class Foo { -Rule id: `no-unit-return` (`standard` rule set) + val foo = "foo" + } + ``` -## No unused imports +Rule id: `no-empty-first-line-in-class-body` (`standard` rule set) -!!! warning - This rule is not able to detect *all* unused imports as mentioned in this [issue comment](https://github.com/pinterest/ktlint/issues/1754#issuecomment-1368201667). +!!! Note + This rule is only run when `ktlint_code_style` is set to `ktlint_official` or when the rule is enabled explicitly. -Rule id: `no-unused-imports` (`standard` rule set) -## No wildcard imports +## No single line block comment -No wildcard imports except imports listed in `.editorconfig` property `ij_kotlin_packages_to_use_import_on_demand`. +A single line block comment should be replaced with an EOL comment when possible. === "[:material-heart:](#) Ktlint" ```kotlin - import foobar.Bar - import foobar.Foo + /* + * Some comment + */ + val foo = "foo" // Some comment + val foo = { /* no-op */ } ``` === "[:material-heart-off-outline:](#) Disallowed" ```kotlin - import foobar.* + /* Some comment */ + val foo = "foo" /* Some comment */ ``` -!!! warning - In case property `ij_kotlin_packages_to_use_import_on_demand` is not explicitly set, it allows wildcards imports like `java.util.*` by default to keep in sync with IntelliJ IDEA behavior. To disallow *all* wildcard imports, add property below to your `.editorconfig`: - ```editorconfig - [*.{kt,kts}] - ij_kotlin_packages_to_use_import_on_demand = unset - ``` +Rule id: `no-single-line-block-comment` (`standard` rule set) -Rule id: `no-wildcard-imports` (`standard` rule set) +## Ktlint-suppression rule -## Package name +The `ktlint-disable` and `ktlint-enable` directives are no longer supported as of ktlint version `0.50.0`. This rule migrates the directives to Suppress or SuppressWarnings annotations. -Validates that the package name matches the regular expression `[a-z][a-zA-Z\d]*(\.[a-z][a-zA-Z\d]*)*`. +Identifiers in the @Suppress and @SuppressWarnings annotations to suppress ktlint rules are checked for validity and autocorrected when possible. === "[:material-heart:](#) Ktlint" ```kotlin - package foo - package foo.bar + @file:Suppress("ktlint:standard:no-wildcard-imports") + + class FooBar { + @Suppress("ktlint:standard:max-line-length") + val foo = "some longggggggggggggggggggg text" + + fun bar() = + @Suppress("ktlint:standard:no-multi-spaces") + listOf( + "1 One", + "10 Ten", + "100 Hundred", + ) + } ``` === "[:material-heart-off-outline:](#) Disallowed" ```kotlin - package Foo - package foo.Foo - package `foo bar` - package foo.`foo bar` - ``` - -Rule id: `package-name` (`standard` rule set) + /* ktlint-disable standard:no-wildcard-imports */ -## Parameter list wrapping + class FooBar { + val foo = "some longggggggggggggggggggg text" // ktlint-disable standard:max-line-length -When class/function signature doesn't fit on a single line, each parameter must be on a separate line + fun bar() = + listOf( + /* ktlint-disable standard:no-multi-spaces */ + "1 One", + "10 Ten", + "100 Hundred", + /* ktlint-enable standard:no-multi-spaces */ + ) + } + ``` -=== "[:material-heart:](#) Ktlint" +Rule id: `ktlint-suppression` (`standard` rule set) + +!!! note + This rule can not be disabled in the `.editorconfig`. + +## Max line length + +Ensures that lines do not exceed the given length of `.editorconfig` property `max_line_length` (see [EditorConfig](../configuration-ktlint/) section for more). This rule does not apply in a number of situations. For example, in the case a line exceeds the maximum line length due to a comment that disables ktlint rules then that comment is being ignored when validating the length of the line. The `.editorconfig` property `ktlint_ignore_back_ticked_identifier` can be set to ignore identifiers which are enclosed in backticks, which for example is very useful when you want to allow longer names for unit tests. + +=== "[:material-heart:](#) Ktlint" + + ```kotlin + // Assume that the last allowed character is + // at the X character on the right X + // Lines below are accepted although the max + // line length is exceeded. + package com.toooooooooooooooooooooooooooo.long + import com.tooooooooooooooooooooooooooooo.long + val foo = + """ + fooooooooooooooooooooooooooooooooooooooooo + """ + @Test + fun `Test description which is toooooooooooo long`() { + } + ``` +=== "[:material-heart-off-outline:](#) Disallowed" + + ```kotlin + // Assume that the last allowed character is + // at the X character on the right X + val fooooooooooooooo = "fooooooooooooooooooooo" + val foooooooooooooo = "foooooooooooooooooooo" // some comment + val fooooooooooooo = + "foooooooooooooooooooooooooooooooooooooooo" + ``` + +Rule id: `max-line-length` (`standard` rule set) + +## Modifier order + +Consistent order of modifiers + +=== "[:material-heart:](#) Ktlint" + + ```kotlin + abstract class A { + protected open val v = "" + internal open suspend fun f(v: Any): Any = "" + protected lateinit var lv: String + } + ``` +=== "[:material-heart-off-outline:](#) Disallowed" + + ```kotlin + abstract class A { + open protected val v = "" + open suspend internal fun f(v: Any): Any = "" + lateinit protected var lv: String + } + ``` + +Rule id: `modifier-order` (`standard` rule set) + +## Multiline if-else + +Braces required for multiline if/else statements. + +=== "[:material-heart:](#) Ktlint" + + ```kotlin + val foo = + if (true) { + return 0 + } else { + return 1 + } + ``` +=== "[:material-heart-off-outline:](#) Disallowed" + + ```kotlin + val foo = + if (true) + return 0 + else + return 1 + ``` + +Rule id: `multiline-if-else` (`standard` rule set) + +## No blank lines before `}` + +No blank lines before `}`. + +=== "[:material-heart:](#) Ktlint" + + ```kotlin + fun main() { + fun a() { + } + fun b() + } + ``` +=== "[:material-heart-off-outline:](#) Disallowed" + + ```kotlin + fun main() { + fun a() { + + } + fun b() + + } + ``` + +Rule id: `no-blank-line-before-rbrace` (`standard` rule set) + +## No blank lines in chained method calls + +=== "[:material-heart:](#) Ktlint" + + ```kotlin + fun foo(inputText: String) { + inputText + .lowercase(Locale.getDefault()) + } + ``` +=== "[:material-heart-off-outline:](#) Disallowed" + + ```kotlin + fun foo(inputText: String) { + inputText + + .lowercase(Locale.getDefault()) + } + ``` + +Rule id: `no-blank-lines-in-chained-method-calls` (`standard` rule set) + +## No consecutive blank lines + +=== "[:material-heart:](#) Ktlint" + + ```kotlin + package com.test + + import com.test.util + + val a = "a" + + fun b() { + } + + fun c() + ``` +=== "[:material-heart-off-outline:](#) Disallowed" + + ```kotlin + package com.test + + + import com.test.util + + + val a = "a" + + + fun b() { + } + + + fun c() + ``` + +Rule id: `no-consecutive-blank-lines` (`standard` rule set) + +## No empty (`{}`) class bodies + +=== "[:material-heart:](#) Ktlint" + + ```kotlin + class C + data class DC(val v: Any) + interface I + object O + ``` +=== "[:material-heart-off-outline:](#) Disallowed" + + ```kotlin + class C {} + data class DC(val v: Any) { } + interface I { + } + object O{} + ``` + +Rule id: `no-empty-class-body` (`standard` rule set) + +## No leading empty lines in method blocks + +=== "[:material-heart:](#) Ktlint" + + ```kotlin + fun bar() { + val a = 2 + } + ``` +=== "[:material-heart-off-outline:](#) Disallowed" + + ```kotlin + fun bar() { + + val a = 2 + } + ``` + +Rule id: `no-empty-first-line-in-method-block` (`standard` rule set) + +## No line break after else + +Disallows line breaks after the else keyword if that could lead to confusion, for example: + +=== "[:material-heart:](#) Ktlint" + + ```kotlin + fun funA() { + if (conditionA()) { + doSomething() + } else if (conditionB()) { + doAnotherThing() + } + } + ``` +=== "[:material-heart-off-outline:](#) Disallowed" + + ```kotlin + fun funA() { + if (conditionA()) { + doSomething() + } else + if (conditionB()) { + doAnotherThing() + } + } + ``` + +Rule id: `no-line-break-after-else` (`standard` rule set) + +## No line break before assignment + +When a line is broken at an assignment (`=`) operator the break comes after the symbol. + +=== "[:material-heart:](#) Ktlint" + + ```kotlin + val valA = + "" + ``` +=== "[:material-heart-off-outline:](#) Disallowed" + + ```kotlin + val valA + = "" + ``` + +Rule id: `no-line-break-before-assignment` (`standard` rule set) + +## No multi spaces + +Except in indentation and in KDoc's it is not allowed to have multiple consecutive spaces. + +=== "[:material-heart:](#) Ktlint" + + ```kotlin + fun main() { + x(1, 3) + } + ``` +=== "[:material-heart-off-outline:](#) Disallowed" + + ```kotlin + fun main() { + x(1, 3) + } + ``` + +Rule id: `no-multi-spaces` (`standard` rule set) + +## No semicolons + +No semicolons (unless used to separate multiple statements on the same line). + +=== "[:material-heart:](#) Ktlint" + + ```kotlin + fun foo() { + bar() + + bar() + } + ``` +=== "[:material-heart-off-outline:](#) Disallowed" + + ```kotlin + fun foo() { + ; + bar() + ; + + bar() + + ; + } + ``` + +Rule id: `no-semi` (`standard` rule set) + +## No trailing whitespaces + +Rule id: `no-trailing-spaces` (`standard` rule set) + +## No `Unit` as return type + +The `Unit` type is not allowed as return type of a function. +returns (`fun fn {}` instead of `fun fn: Unit {}`) + +=== "[:material-heart:](#) Ktlint" + + ```kotlin + fun fn() {} + ``` +=== "[:material-heart-off-outline:](#) Disallowed" + + ```kotlin + fun fn(): Unit {} + ``` + +Rule id: `no-unit-return` (`standard` rule set) + +## No unused imports + +!!! warning + This rule is not able to detect *all* unused imports as mentioned in this [issue comment](https://github.com/pinterest/ktlint/issues/1754#issuecomment-1368201667). + +Rule id: `no-unused-imports` (`standard` rule set) + +## No wildcard imports + +No wildcard imports except imports listed in `.editorconfig` property `ij_kotlin_packages_to_use_import_on_demand`. + +=== "[:material-heart:](#) Ktlint" + + ```kotlin + import foobar.Bar + import foobar.Foo + ``` +=== "[:material-heart-off-outline:](#) Disallowed" + + ```kotlin + import foobar.* + ``` + +!!! warning + In case property `ij_kotlin_packages_to_use_import_on_demand` is not explicitly set, it allows wildcards imports like `java.util.*` by default to keep in sync with IntelliJ IDEA behavior. To disallow *all* wildcard imports, add property below to your `.editorconfig`: + ```editorconfig + [*.{kt,kts}] + ij_kotlin_packages_to_use_import_on_demand = unset + ``` + +Rule id: `no-wildcard-imports` (`standard` rule set) + +## Spacing + +### Angle bracket spacing + +No spaces around angle brackets when used for typing. + +=== "[:material-heart:](#) Ktlint" + + ```kotlin + val a: Map = mapOf() + val b: Map = mapOf() + val c: Map = mapOf() + ``` +=== "[:material-heart-off-outline:](#) Disallowed" + + ```kotlin + val a: Map< Int, String> = mapOf() + val b: Map = mapOf() + val c: Map = mapOf() + ``` + +Rule id: `spacing-around-angle-brackets` (`standard` rule set) + +### Annotation spacing + +Annotations should be separated by a single line break. + +=== "[:material-heart:](#) Ktlint" + + ```kotlin + @JvmField + fun foo() {} + + /** + * block comment + */ + @Foo @Bar + class FooBar { + } + ``` +=== "[:material-heart-off-outline:](#) Disallowed" + + ```kotlin + @JvmField + + fun foo() {} + + @Foo @Bar + /** + * block comment + */ + class FooBar { + } + ``` + +Rule id: `annotation-spacing` (`standard` rule set) + +### Blank line between declarations with annotations + +Declarations with annotations should be separated by a blank line. + +=== "[:material-heart:](#) Ktlint" ```kotlin - class ClassA(paramA: String, paramB: String, paramC: String) - class ClassA( - paramA: String, - paramB: String, - paramC: String - ) - fun f(a: Any, b: Any, c: Any) - fun f( - a: Any, - b: Any, - c: Any - ) - fun foo( - @Bar fooBar: FooBar - ) + fun a() + + @Bar + fun b() ``` -=== "[:material-heart-off-outline:](#) Disallowed (ktlint_official)" +=== "[:material-heart-off-outline:](#) Disallowed" ```kotlin - class ClassA( - paramA: String, paramB: String, - paramC: String - ) - fun f( - a: Any, - b: Any, c: Any - ) - fun foo(@Bar fooBar: FooBar) + fun a() + @Bar + fun b() ``` -=== "[:material-heart-off-outline:](#) Disallowed (non ktlint_official)"" + +Rule id: `spacing-between-declarations-with-annotations` (`standard` rule set) + +### Blank line between declaration with comments + +Declarations with comments should be separated by a blank line. + +=== "[:material-heart:](#) Ktlint" ```kotlin - class ClassA( - paramA: String, paramB: String, - paramC: String - ) - fun f( - a: Any, - b: Any, c: Any - ) + // some comment 1 + bar() + + /* + * some comment 2 + */ + foo() + ``` +=== "[:material-heart-off-outline:](#) Disallowed" + + ```kotlin + // some comment 1 + bar() + /* + * some comment 2 + */ + foo() + ``` + +Rule id: `spacing-between-declarations-with-comments` (`standard` rule set) + +### Colon spacing + +Consistent spacing around colon. + +=== "[:material-heart:](#) Ktlint" + + ```kotlin + class A : B + class A2 : B2 + ``` +=== "[:material-heart-off-outline:](#) Disallowed" + + ```kotlin + class A:B + class A2 : B2 + ``` + +Rule id: `colon-spacing` (`standard` rule set) + +### Comma spacing + +Consistent spacing around comma. + +=== "[:material-heart:](#) Ktlint" + + ```kotlin + val foo1 = Foo(1, 3) + val foo2 = Foo(1, 3) + ``` +=== "[:material-heart-off-outline:](#) Disallowed" + + ```kotlin + val foo1 = Foo(1 ,3) + val foo2 = Foo(1,3) + ``` + +Rule id: `comma-spacing` (`standard` rule set) + +### Comment spacing + +The end of line comment sign `//` should be preceded and followed by exactly a space. + +=== "[:material-heart:](#) Ktlint" + + ```kotlin + // comment + var debugging = false // comment + var debugging = false // comment + var debugging = false // comment + fun main() { + System.out.println( // 123 + "test" + ) + } + // comment + ``` + +=== "[:material-heart-off-outline:](#) Disallowed" + + ```kotlin + //comment + var debugging = false// comment + var debugging = false //comment + var debugging = false//comment + fun main() { + System.out.println(//123 + "test" + ) + } + //comment + ``` + +Rule id: `comment-spacing` (`standard` rule set) + +### Curly spacing + +Consistent spacing around curly braces. + +=== "[:material-heart:](#) Ktlint" + + ```kotlin + val foo = if (true) { 0 } else { 1 } + ``` +=== "[:material-heart-off-outline:](#) Disallowed" + + ```kotlin + val foo = if (true){0}else{1} + ``` + +Rule id: `curly-spacing` (`standard` rule set) + +### Dot spacing + +Consistent spacing around dots. + +=== "[:material-heart:](#) Ktlint" + + ```kotlin + fun String.foo() = "foo" + ``` +=== "[:material-heart-off-outline:](#) Disallowed" + + ```kotlin + fun String . foo() = "foo" + ``` + +Rule id: `dot-spacing` (`standard` rule set) + +### Double colon spacing + +No spaces around `::`. + +=== "[:material-heart:](#) Ktlint" + + ```kotlin + val foo = Foo::class + ``` +=== "[:material-heart-off-outline:](#) Disallowed" + + ```kotlin + val foo1 = Foo ::class + val foo2 = Foo:: class + val foo3 = Foo :: class + val foo4 = Foo:: + class + ``` + +Rule id: `double-colon-spacing` (`standard` rule set) + +### Function return type spacing + +Consistent spacing around the function return type. + +=== "[:material-heart:](#) Ktlint" + + ```kotlin + fun foo(): String = "some-result" + ``` +=== "[:material-heart-off-outline:](#) Disallowed" + + ```kotlin + fun foo1() : String = "some-result" + fun foo2(): String = "some-result" + fun foo3():String = "some-result" + fun foo4(): + String = "some-result" + ``` + +Rule id: `function-return-type-spacing` (`standard` rule set) + +### Function start of body spacing + +Consistent spacing before start of function body. + +=== "[:material-heart:](#) Ktlint" + + ```kotlin + fun foo1() = "some-result" + fun foo2() = + "some-result" + fun foo3() { + // do something + } + fun bar1(): String = "some-result" + fun bar2(): String = + "some-result" + fun bar3(): String { + return "some-result" + } + ``` +=== "[:material-heart-off-outline:](#) Disallowed" + + ```kotlin + fun foo1()= "some-result" + fun foo2() + = "some-result" + fun foo3() + { + // do something + } + fun bar1(): String= "some-result" + fun bar2(): String + = "some-result" + fun bar3(): String + { + return "some-result" + } ``` -Rule id: `parameter-list-wrapping` (`standard` rule set) - -## Parameter wrapping +Rule id: `function-start-of-body-spacing` (`standard` rule set) -When a function or class parameter doesn't fit on a single line, wrap the type or value to a separate line +### Function type reference spacing -=== "[:material-heart:](#) Ktlint (ktlint_official)" +Consistent spacing in the type reference before a function. - ```kotlin - // Assume that the last allowed character is - // at the X character on the right X - class Bar( - val fooooooooooooooooooooooooTooLong: - Foo, - ) - fun bar( - fooooooooooooooooooooooooTooLong: - Foo, - ) - ``` -=== "[:material-heart:](#) Ktlint (non ktlint_official)" +=== "[:material-heart:](#) Ktlint" ```kotlin - // Assume that the last allowed character is - // at the X character on the right X - class Bar( - val fooooooooooooooooooooooooTooLong: - Foo, - ) - fun bar( - fooooooooooooooooooooooooTooLong: - Foo, - ) + fun String.foo() = "some-result" ``` === "[:material-heart-off-outline:](#) Disallowed" ```kotlin - // Assume that the last allowed character is - // at the X character on the right X - class Bar( - val fooooooooooooooooooooooooTooLong: Foo, - ) - fun bar( - fooooooooooooooooooooooooooooTooLong: Foo, - ) + fun String .foo() = "some-result" + fun String + .foo() = "some-result" + fun String? .foo() = "some-result" + fun String? + .foo() = "some-result" ``` -Rule id: `parameter-wrapping` (`standard` rule set) +Rule id: `function-type-reference-spacing` (`standard` rule set) -## Property wrapping +### Fun keyword spacing -When a property doesn't fit on a single line, wrap the type or value to a separate line +Consistent spacing after the fun keyword. === "[:material-heart:](#) Ktlint" ```kotlin - // Assume that the last allowed character is - // at the X character on the right X - val aVariableWithALooooooooooooongName: - String + fun foo() = "some-result" ``` === "[:material-heart-off-outline:](#) Disallowed" ```kotlin - // Assume that the last allowed character is - // at the X character on the right X - val aVariableWithALooooooooooooongName: String + fun foo() = "some-result" + fun + foo() = "some-result" ``` -Rule id: `property-wrapping` (`standard` rule set) +Rule id: `fun-keyword-spacing` (`standard` rule set) -## String template +### Kdoc wrapping -Consistent string templates (`$v` instead of `${v}`, `${p.v}` instead of `${p.v.toString()}`) +A KDoc comment should start and end on a line that does not contain any other element. === "[:material-heart:](#) Ktlint" ```kotlin - val foo = "$foo hello" + /** Some KDoc comment 1 */ + val foo1 = "foo1" ``` === "[:material-heart-off-outline:](#) Disallowed" ```kotlin - val foo = "${foo} hello" + /** Some KDoc comment 1 */ val foo1 = "foo1" + val foo2 = "foo2" /** Some KDoc comment + * with a newline + */ ``` -Rule id: `string-template` (`standard` rule set) - -## Trailing comma on call site +Rule id: `kdoc-wrapping` (`standard` rule set) -Consistent removal (default) or adding of trailing commas on call site. +### Keyword spacing -!!! 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. +Consistent spacing around keywords. === "[:material-heart:](#) Ktlint" ```kotlin - FooWrapper( - Foo( - a = 3, - b = 4, - ), - ) + fun main() { + if (true) {} + } ``` === "[:material-heart-off-outline:](#) Disallowed" ```kotlin - FooWrapper(Foo( - a = 3, - b = 4, - ),) // it's weird to insert "," between unwrapped (continued) parenthesis + fun main() { + if(true){} + } ``` -!!! 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#trailing-commas) leaves it to the developer's discretion to use trailing commas 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. - -!!! note - Trailing comma on call site is automatically disabled if the [Wrapping](#wrapping) rule (or, before version `0.45.0`, the [Indentation](#indentation) rule) is disabled or not loaded. Because it cannot provide proper formatting with unwrapped calls. (see [dependencies](./dependencies.md)). - -Rule id: `trailing-comma-on-call-site` (`standard` rule set) - -## Trailing comma on declaration site +Rule id: `keyword-spacing` (`standard` rule set) -Consistent removal (default) or adding of trailing commas on declaration site. +### Modifier list spacing -!!! 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. +Consistent spacing between modifiers in and after the last modifier in a modifier list. === "[:material-heart:](#) Ktlint" ```kotlin - class FooWrapper( - val foo = Foo( - a = 3, - b = 4, - ), - ) + abstract class Foo { + protected abstract suspend fun execute() + } ``` === "[:material-heart-off-outline:](#) Disallowed" ```kotlin - class FooWrapper(val foo = Foo( - a = 3, - b = 4, - ),) // it's weird to insert "," between unwrapped (continued) parenthesis + abstract class Foo { + protected abstract suspend fun execute() + } + abstract + class Foo { + protected + abstract + suspend + fun execute() + } ``` -!!! 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. +Rule id: `modifier-list-spacing` (`standard` rule set) - The [Kotlin coding conventions](https://kotlinlang.org/docs/reference/coding-conventions.html#trailing-commas) encourages the usage of trailing commas on the declaration site, but leaves it to the developer's discretion to use trailing commas 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. +### Nullable type spacing -!!! note - Trailing comma on declaration site is automatically disabled if the [Wrapping](#wrapping) rule (or, before version `0.45.0`, the [Indentation](#indentation) rule) is disabled or not loaded. Because it cannot provide proper formatting with unwrapped declarations. (see [dependencies](./dependencies.md)). +No spaces in a nullable type. -Rule id: `trailing-comma-on-declaration-site` (`standard` rule set) +=== "[:material-heart:](#) Ktlint" -## Unnecessary parenthesis before trailing lambda + ```kotlin + val foo: String? = null + val foo: List = listOf(null) + ``` +=== "[:material-heart-off-outline:](#) Disallowed" -An empty parentheses block before a lambda is redundant. + ```kotlin + val foo: String ? = null + val foo: List = listOf(null) + ``` + +Rule id: `nullable-type-spacing` (`standard` rule set) + +### Operator spacing + +Consistent spacing around operators. === "[:material-heart:](#) Ktlint" ```kotlin - "some-string".count { it == '-' } + val foo1 = 1 + 2 + val foo2 = 1 - 2 + val foo3 = 1 * 2 + val foo4 = 1 / 2 ``` - === "[:material-heart-off-outline:](#) Disallowed" ```kotlin - "some-string".count() { it == '-' } + val foo1 = 1+2 + val foo2 = 1- 2 + val foo3 = 1 *2 + val foo4 = 1 / 2 ``` -Rule id: `unnecessary-parentheses-before-trailing-lambda` (`standard` rule set) - -## Wrapping +Rule id: `op-spacing` (`standard` rule set) -### Wrapping +### Parameter list spacing -Inserts missing newlines (for example between parentheses of a multi-line function call). +Consistent spacing inside the parameter list. === "[:material-heart:](#) Ktlint" ```kotlin - val x = f( - a, - b, - c - ) + fun foo(a: Any ) = "some-result" + fun foo() = "some-result" ``` - === "[:material-heart-off-outline:](#) Disallowed" ```kotlin - val x = f( - a, - b, - c) + fun foo( a : Any ) = "some-result" + fun foo( + ) = "some-result" ``` -Rule id: `wrapping` (`standard` rule set) +Rule id: `parameter-list-spacing` (`standard` rule set) -### Comment wrapping +### Parenthesis spacing -A block comment should start and end on a line that does not contain any other element. +Consistent spacing around parenthesis. === "[:material-heart:](#) Ktlint" ```kotlin - /* Some comment 1 */ - val foo1 = "foo1" - val foo2 = "foo" // Some comment - val foo3 = { /* no-op */ } + class Foo : Bar { + constructor(string: String) : super() + } + val foo1 = ((1 + 2) / 3) ``` === "[:material-heart-off-outline:](#) Disallowed" ```kotlin - /* Some comment 1 */ val foo1 = "foo1" - val foo2 = "foo" /* Block comment instead of end-of-line comment */ - val foo3 = "foo" /* Some comment - * with a newline - */ + class Foo : Bar { + constructor(string: String) : super () + } + val foo1 = ( (1 + 2 ) / 3) ``` -Rule id: `comment-wrapping` (`standard` rule set) - -## Spacing +Rule id: `paren-spacing` (`standard` rule set) -### Angle bracket spacing +### Range spacing -No spaces around angle brackets when used for typing. +Consistent spacing around range operators. === "[:material-heart:](#) Ktlint" ```kotlin - val a: Map = mapOf() - val b: Map = mapOf() - val c: Map = mapOf() + val foo1 = (1..12 step 2).last + val foo2 = (1..12 step 2).last + val foo3 = (1..12 step 2).last ``` === "[:material-heart-off-outline:](#) Disallowed" ```kotlin - val a: Map< Int, String> = mapOf() - val b: Map = mapOf() - val c: Map = mapOf() + val foo1 = (1.. 12 step 2).last + val foo2 = (1 .. 12 step 2).last + val foo3 = (1 ..12 step 2).last ``` -Rule id: `spacing-around-angle-brackets` (`standard` rule set) +Rule id: `range-spacing` (`standard` rule set) -### Annotation spacing +### Spacing between function name and opening parenthesis -Annotations should be separated by a single line break. +Consistent spacing between function name and opening parenthesis. === "[:material-heart:](#) Ktlint" ```kotlin - @JvmField - fun foo() {} - - /** - * block comment - */ - @Foo @Bar - class FooBar { - } + fun foo() = "foo" ``` === "[:material-heart-off-outline:](#) Disallowed" ```kotlin - @JvmField - - fun foo() {} - - @Foo @Bar - /** - * block comment - */ - class FooBar { - } + fun foo () = "foo" ``` -Rule id: `annotation-spacing` (`standard` rule set) +Rule id: `spacing-between-function-name-and-opening-parenthesis` (`standard` rule set) -### Blank line between declarations with annotations +### Try catch finally spacing -Declarations with annotations should be separated by a blank line. +Enforce consistent spacing in `try { .. } catch { .. } finally { .. }`. === "[:material-heart:](#) Ktlint" ```kotlin - fun a() - - @Bar - fun b() + fun foo() = + try { + // do something + } catch (exception: Exception) { + // handle exception + } finally { + // clean up + } ``` === "[:material-heart-off-outline:](#) Disallowed" ```kotlin - fun a() - @Bar - fun b() + fun foo1() = try { /* ... */ } catch (exception: Exception) { /* ... */ } finally { /* ... */ } + fun foo2() = + try { + // do something + } + catch (exception: Exception) { + // handle exception + } + finally { + // clean up + } ``` -Rule id: `spacing-between-declarations-with-annotations` (`standard` rule set) +Rule id: `try-catch-finally-spacing` (`standard` rule set) -### Blank line between declaration with comments +!!! Note + This rule is only run when `ktlint_code_style` is set to `ktlint_official` or when the rule is enabled explicitly. -Declarations with comments should be separated by a blank line. +### Type argument list spacing + +Spacing before and after the angle brackets of a type argument list. === "[:material-heart:](#) Ktlint" ```kotlin - // some comment 1 - bar() - - /* - * some comment 2 - */ - foo() + val res = ArrayList() + class B : A() { + override fun x() = super.x() + } ``` === "[:material-heart-off-outline:](#) Disallowed" ```kotlin - // some comment 1 - bar() - /* - * some comment 2 - */ - foo() + val res = ArrayList < LintError > () + class B : A< T >() { + override fun x() = super< A >.x() + } ``` -Rule id: `spacing-between-declarations-with-comments` (`standard` rule set) +Rule id: `type-argument-list-spacing` (`standard` rule set) -### Colon spacing +### Type parameter list spacing -Consistent spacing around colon. +Spacing after a type parameter list in function and class declarations. === "[:material-heart:](#) Ktlint" ```kotlin - class A : B - class A2 : B2 + fun foo1(t: T) = "some-result" + fun foo2(t: T) = "some-result" + fun foo3(t: T) = "some-result" ``` === "[:material-heart-off-outline:](#) Disallowed" ```kotlin - class A:B - class A2 : B2 + fun foo1(t: T) = "some-result" + fun foo2(t: T) = "some-result" + funfoo3(t: T) = "some-result" ``` -Rule id: `colon-spacing` (`standard` rule set) +Rule id: `type-parameter-list-spacing` (`standard` rule set) -### Comma spacing +### Unary operator spacing -Consistent spacing around comma. +No spaces around unary operators. === "[:material-heart:](#) Ktlint" ```kotlin - val foo1 = Foo(1, 3) - val foo2 = Foo(1, 3) + fun foo1(i: Int) = i++ + fun foo2(i: Int) = ++i + fun foo3(i: Int) = ++i ``` === "[:material-heart-off-outline:](#) Disallowed" ```kotlin - val foo1 = Foo(1 ,3) - val foo2 = Foo(1,3) + fun foo1(i: Int) = i ++ + fun foo2(i: Int) = ++ i + fun foo3(i: Int) = ++ + i ``` -Rule id: `comma-spacing` (`standard` rule set) +Rule id: `unary-op-spacing` (`standard` rule set) -### Comment spacing +## String template -The end of line comment sign `//` should be preceded and followed by exactly a space. +Consistent string templates (`$v` instead of `${v}`, `${p.v}` instead of `${p.v.toString()}`) === "[:material-heart:](#) Ktlint" ```kotlin - // comment - var debugging = false // comment - var debugging = false // comment - var debugging = false // comment - fun main() { - System.out.println( // 123 - "test" - ) - } - // comment + val foo = "$foo hello" ``` - === "[:material-heart-off-outline:](#) Disallowed" ```kotlin - //comment - var debugging = false// comment - var debugging = false //comment - var debugging = false//comment - fun main() { - System.out.println(//123 - "test" - ) - } - //comment + val foo = "${foo} hello" ``` -Rule id: `comment-spacing` (`standard` rule set) +Rule id: `string-template` (`standard` rule set) -### Curly spacing +## String template indent -Consistent spacing around curly braces. +Enforce consistent string template indentation for multiline string templates which are post-fixed with `.trimIndent()`. The opening and closing `"""` are placed on separate lines and the indentation of the content of the template is aligned with the `"""`. === "[:material-heart:](#) Ktlint" ```kotlin - val foo = if (true) { 0 } else { 1 } + val foo = + """ + line1 + line2 + """.trimIndent() + fun foo() { + // The opening """ can not be wrapped to next line as that would result in a compilation error + return """ + line1 + line2 + """.trimIndent() + } ``` === "[:material-heart-off-outline:](#) Disallowed" ```kotlin - val foo = if (true){0}else{1} + val foo = """ + line1 + line2 + """.trimIndent() + fun foo() { + return """ + line1 + line2 + """.trimIndent() + } ``` -Rule id: `curly-spacing` (`standard` rule set) +Rule id: `string-template-indent` (`standard` rule set) -### Dot spacing +!!! Note + This rule is only run when `ktlint_code_style` is set to `ktlint_official` or when the rule is enabled explicitly. -Consistent spacing around dots. +## Trailing comma on call site + +Consistent removal (default) or adding of trailing commas 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. === "[:material-heart:](#) Ktlint" ```kotlin - fun String.foo() = "foo" + FooWrapper( + Foo( + a = 3, + b = 4, + ), + ) ``` === "[:material-heart-off-outline:](#) Disallowed" ```kotlin - fun String . foo() = "foo" + FooWrapper(Foo( + a = 3, + b = 4, + ),) // it's weird to insert "," between unwrapped (continued) parenthesis ``` -Rule id: `dot-spacing` (`standard` rule set) +!!! 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. -### Double colon spacing + Although the [Kotlin coding conventions](https://kotlinlang.org/docs/reference/coding-conventions.html#trailing-commas) leaves it to the developer's discretion to use trailing commas 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. -No spaces around `::`. +!!! note + Trailing comma on call site is automatically disabled if the [Wrapping](#wrapping) rule (or, before version `0.45.0`, the [Indentation](#indentation) rule) is disabled or not loaded. Because it cannot provide proper formatting with unwrapped calls. (see [dependencies](./dependencies.md)). + +Rule id: `trailing-comma-on-call-site` (`standard` rule set) + +## Trailing comma on declaration site + +Consistent removal (default) or adding of trailing commas 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. === "[:material-heart:](#) Ktlint" ```kotlin - val foo = Foo::class + class FooWrapper( + val foo = Foo( + a = 3, + b = 4, + ), + ) ``` === "[:material-heart-off-outline:](#) Disallowed" ```kotlin - val foo1 = Foo ::class - val foo2 = Foo:: class - val foo3 = Foo :: class - val foo4 = Foo:: - class + class FooWrapper(val foo = Foo( + a = 3, + b = 4, + ),) // it's weird to insert "," between unwrapped (continued) parenthesis ``` -Rule id: `double-colon-spacing` (`standard` rule set) +!!! 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. -### Function return type spacing + The [Kotlin coding conventions](https://kotlinlang.org/docs/reference/coding-conventions.html#trailing-commas) encourages the usage of trailing commas on the declaration site, but leaves it to the developer's discretion to use trailing commas 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. -Consistent spacing around the function return type. +!!! note + Trailing comma on declaration site is automatically disabled if the [Wrapping](#wrapping) rule (or, before version `0.45.0`, the [Indentation](#indentation) rule) is disabled or not loaded. Because it cannot provide proper formatting with unwrapped declarations. (see [dependencies](./dependencies.md)). + +Rule id: `trailing-comma-on-declaration-site` (`standard` rule set) + +## Unnecessary parenthesis before trailing lambda + +An empty parentheses block before a lambda is redundant. === "[:material-heart:](#) Ktlint" ```kotlin - fun foo(): String = "some-result" + "some-string".count { it == '-' } ``` + === "[:material-heart-off-outline:](#) Disallowed" ```kotlin - fun foo1() : String = "some-result" - fun foo2(): String = "some-result" - fun foo3():String = "some-result" - fun foo4(): - String = "some-result" + "some-string".count() { it == '-' } ``` -Rule id: `function-return-type-spacing` (`standard` rule set) +Rule id: `unnecessary-parentheses-before-trailing-lambda` (`standard` rule set) -### Function start of body spacing +## Wrapping -Consistent spacing before start of function body. +### Argument list wrapping + +All arguments should be on the same line, or every argument should be on a separate line. === "[:material-heart:](#) Ktlint" ```kotlin - fun foo1() = "some-result" - fun foo2() = - "some-result" - fun foo3() { - // do something - } - fun bar1(): String = "some-result" - fun bar2(): String = - "some-result" - fun bar3(): String { - return "some-result" - } + val x = f( + a, + b, + c + ) ``` === "[:material-heart-off-outline:](#) Disallowed" ```kotlin - fun foo1()= "some-result" - fun foo2() - = "some-result" - fun foo3() - { - // do something - } - fun bar1(): String= "some-result" - fun bar2(): String - = "some-result" - fun bar3(): String - { - return "some-result" - } + val x = f( + a, + b, c + ) ``` -Rule id: `function-start-of-body-spacing` (`standard` rule set) +Rule-id: `argument-list-wrapping` (`standard` rule set) -### Function type reference spacing +### Chain wrapping -Consistent spacing in the type reference before a function. +When wrapping chained calls `.`, `?.` and `?:` should be placed on the next line === "[:material-heart:](#) Ktlint" ```kotlin - fun String.foo() = "some-result" + val foo = listOf(1, 2, 3) + .filter { it > 2 }!! + .takeIf { it.count() > 100 } + ?.sum() + val foobar = foo() + ?: bar ``` === "[:material-heart-off-outline:](#) Disallowed" ```kotlin - fun String .foo() = "some-result" - fun String - .foo() = "some-result" - fun String? .foo() = "some-result" - fun String? - .foo() = "some-result" + val foo = listOf(1, 2, 3). + filter { it > 2 }!!. + takeIf { it.count() > 100 }?. + sum() + val foobar = foo() ?: + bar ``` -Rule id: `function-type-reference-spacing` (`standard` rule set) +Rule id: `chain-wrapping` (`standard` rule set) -### Fun keyword spacing +### Comment wrapping -Consistent spacing after the fun keyword. +A block comment should start and end on a line that does not contain any other element. === "[:material-heart:](#) Ktlint" ```kotlin - fun foo() = "some-result" + /* Some comment 1 */ + val foo1 = "foo1" + val foo2 = "foo" // Some comment + val foo3 = { /* no-op */ } ``` === "[:material-heart-off-outline:](#) Disallowed" ```kotlin - fun foo() = "some-result" - fun - foo() = "some-result" + /* Some comment 1 */ val foo1 = "foo1" + val foo2 = "foo" /* Block comment instead of end-of-line comment */ + val foo3 = "foo" /* Some comment + * with a newline + */ ``` -Rule id: `fun-keyword-spacing` (`standard` rule set) +Rule id: `comment-wrapping` (`standard` rule set) -### Kdoc wrapping +### Content receiver wrapping -A KDoc comment should start and end on a line that does not contain any other element. +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. === "[:material-heart:](#) Ktlint" ```kotlin - /** Some KDoc comment 1 */ - val foo1 = "foo1" + // ALways wrap regardless of whether max line length is set + context(Foo) + fun fooBar() + + // Wrap each context receiver to a separate line when the + // entire context receiver list does not fit on a single line + context( + Fooooooooooooooooooo1, + Foooooooooooooooooooooooooooooo2 + ) + fun fooBar() + + // Wrap each context receiver to a separate line when the + // entire context receiver list does not fit on a single line. + // Also, wrap each of it projection types in case a context + // receiver does not fit on a single line after it has been + // wrapped. + context( + Foooooooooooooooo< + Foo, + Bar + > + ) + fun fooBar() ``` + === "[:material-heart-off-outline:](#) Disallowed" ```kotlin - /** Some KDoc comment 1 */ val foo1 = "foo1" - val foo2 = "foo2" /** Some KDoc comment - * with a newline - */ + // Should be wrapped regardless of whether max line length is set + context(Foo) fun fooBar() + + // Should be wrapped when the entire context receiver list does not + // fit on a single line + context(Fooooooooooooooooooo1, Foooooooooooooooooooooooooooooo2) + fun fooBar() + + // Should be wrapped when the entire context receiver list does not + // fit on a single line. Also, it should wrap each of it projection + // type in case a context receiver does not fit on a single line + // after it has been wrapped. + context(Foooooooooooooooo) + fun fooBar() ``` -Rule id: `kdoc-wrapping` (`standard` rule set) +Rule id: `context-receiver-wrapping` (`standard` rule set) -### Keyword spacing +### Enum wrapping -Consistent spacing around keywords. +An enum should be a single line, or each enum entry has to be placed on a separate line. In case the enumeration contains enum entries and declarations those are to be separated by a blank line. === "[:material-heart:](#) Ktlint" ```kotlin - fun main() { - if (true) {} + enum class Foo { A, B, C, D } + + enum class Foo { + A, + B, + C, + D, + ; + + fun foo() = "foo" } ``` + === "[:material-heart-off-outline:](#) Disallowed" ```kotlin - fun main() { - if(true){} + enum class Foo { + A, + B, C, + D + } + + enum class Foo { + A; + fun foo() = "foo" } ``` -Rule id: `keyword-spacing` (`standard` rule set) +Rule id: `enum-wrapping` (`standard` rule set) -### Modifier list spacing +### If else wrapping -Consistent spacing between modifiers in and after the last modifier in a modifier list. +A single line if-statement should be kept simple. It may contain no more than one else-branch. The branches may not be wrapped in a block. === "[:material-heart:](#) Ktlint" ```kotlin - abstract class Foo { - protected abstract suspend fun execute() + fun foobar() { + if (true) foo() + if (true) foo() else bar() } ``` + === "[:material-heart-off-outline:](#) Disallowed" ```kotlin - abstract class Foo { - protected abstract suspend fun execute() - } - abstract - class Foo { - protected - abstract - suspend - fun execute() + fun foobar() { + if (true) if (false) foo() else bar() + if (true) bar() else if (false) foo() else bar() + if (true) { foo() } else bar() + if (true) bar() else { if (false) foo() else bar() } } ``` -Rule id: `modifier-list-spacing` (`standard` rule set) +Rule id: `if-else-wrapping` (`standard` rule set) -### Nullable type spacing +!!! Note + This rule is only run when `ktlint_code_style` is set to `ktlint_official` or when the rule is enabled explicitly. -No spaces in a nullable type. +### Multiline expression wrapping + +Multiline expression on the right hand side of an expression are forced to start on a separate line. Expressions in return statement are excluded as that would result in a compilation error. === "[:material-heart:](#) Ktlint" ```kotlin - val foo: String? = null - val foo: List = listOf(null) + val foo = + foo( + parameterName = + "The quick brown fox " + .plus("jumps ") + .plus("over the lazy dog"), + ) ``` + === "[:material-heart-off-outline:](#) Disallowed" ```kotlin - val foo: String ? = null - val foo: List = listOf(null) + val foo = foo( + parameterName = "The quick brown fox " + .plus("jumps ") + .plus("over the lazy dog"), + ) ``` -Rule id: `nullable-type-spacing` (`standard` rule set) +Rule id: `multiline-expression-wrapping` (`standard` rule set) -### Operator spacing +!!! Note + This rule is only run when `ktlint_code_style` is set to `ktlint_official` or when the rule is enabled explicitly. -Consistent spacing around operators. +### Parameter list wrapping + +When class/function signature doesn't fit on a single line, each parameter must be on a separate line === "[:material-heart:](#) Ktlint" ```kotlin - val foo1 = 1 + 2 - val foo2 = 1 - 2 - val foo3 = 1 * 2 - val foo4 = 1 / 2 + class ClassA(paramA: String, paramB: String, paramC: String) + class ClassA( + paramA: String, + paramB: String, + paramC: String + ) + fun f(a: Any, b: Any, c: Any) + fun f( + a: Any, + b: Any, + c: Any + ) + fun foo( + @Bar fooBar: FooBar + ) ``` -=== "[:material-heart-off-outline:](#) Disallowed" +=== "[:material-heart-off-outline:](#) Disallowed (ktlint_official)" ```kotlin - val foo1 = 1+2 - val foo2 = 1- 2 - val foo3 = 1 *2 - val foo4 = 1 / 2 + class ClassA( + paramA: String, paramB: String, + paramC: String + ) + fun f( + a: Any, + b: Any, c: Any + ) + fun foo(@Bar fooBar: FooBar) ``` +=== "[:material-heart-off-outline:](#) Disallowed (non ktlint_official)"" -Rule id: `op-spacing` (`standard` rule set) + ```kotlin + class ClassA( + paramA: String, paramB: String, + paramC: String + ) + fun f( + a: Any, + b: Any, c: Any + ) + ``` -### Parenthesis spacing +Rule id: `parameter-list-wrapping` (`standard` rule set) -Consistent spacing around parenthesis. +### Parameter wrapping -=== "[:material-heart:](#) Ktlint" +When a function or class parameter doesn't fit on a single line, wrap the type or value to a separate line + +=== "[:material-heart:](#) Ktlint (ktlint_official)" ```kotlin - class Foo : Bar { - constructor(string: String) : super() - } - val foo1 = ((1 + 2) / 3) + // Assume that the last allowed character is + // at the X character on the right X + class Bar( + val fooooooooooooooooooooooooTooLong: + Foo, + ) + fun bar( + fooooooooooooooooooooooooTooLong: + Foo, + ) + ``` +=== "[:material-heart:](#) Ktlint (non ktlint_official)" + + ```kotlin + // Assume that the last allowed character is + // at the X character on the right X + class Bar( + val fooooooooooooooooooooooooTooLong: + Foo, + ) + fun bar( + fooooooooooooooooooooooooTooLong: + Foo, + ) ``` === "[:material-heart-off-outline:](#) Disallowed" ```kotlin - class Foo : Bar { - constructor(string: String) : super () - } - val foo1 = ( (1 + 2 ) / 3) + // Assume that the last allowed character is + // at the X character on the right X + class Bar( + val fooooooooooooooooooooooooTooLong: Foo, + ) + fun bar( + fooooooooooooooooooooooooooooTooLong: Foo, + ) ``` -Rule id: `paren-spacing` (`standard` rule set) +Rule id: `parameter-wrapping` (`standard` rule set) -### Range spacing +### Property wrapping -Consistent spacing around range operators. +When a property doesn't fit on a single line, wrap the type or value to a separate line === "[:material-heart:](#) Ktlint" ```kotlin - val foo1 = (1..12 step 2).last - val foo2 = (1..12 step 2).last - val foo3 = (1..12 step 2).last + // Assume that the last allowed character is + // at the X character on the right X + val aVariableWithALooooooooooooongName: + String ``` === "[:material-heart-off-outline:](#) Disallowed" ```kotlin - val foo1 = (1.. 12 step 2).last - val foo2 = (1 .. 12 step 2).last - val foo3 = (1 ..12 step 2).last + // Assume that the last allowed character is + // at the X character on the right X + val aVariableWithALooooooooooooongName: String ``` -Rule id: `range-spacing` (`standard` rule set) +Rule id: `property-wrapping` (`standard` rule set) -### Spacing between function name and opening parenthesis +### Statement wrapping -Consistent spacing between function name and opening parenthesis. +A function, class/object body or other block body statement has to be placed on different line than the braces of the body block. === "[:material-heart:](#) Ktlint" ```kotlin - fun foo() = "foo" + fun foo() { + if (true) { + // do something + } + } + class A { + val a = 0 + val b = 1 + } + enum class FooBar1 { FOO, BAR } + enum class FooBar2 { + FOO, + BAR, + } ``` + === "[:material-heart-off-outline:](#) Disallowed" ```kotlin - fun foo () = "foo" + fun foo() { if (true) { + // do something + } + } + class A { val a = 0 + val b = 1 } ``` -Rule id: `spacing-between-function-name-and-opening-parenthesis` (`standard` rule set) +Rule id: `statement-wrapping` -### Unary operator spacing +### Wrapping -No spaces around unary operators. +Inserts missing newlines (for example between parentheses of a multi-line function call). === "[:material-heart:](#) Ktlint" ```kotlin - fun foo1(i: Int) = i++ - fun foo2(i: Int) = ++i - fun foo3(i: Int) = ++i + val x = f( + a, + b, + c + ) ``` + === "[:material-heart-off-outline:](#) Disallowed" ```kotlin - fun foo1(i: Int) = i ++ - fun foo2(i: Int) = ++ i - fun foo3(i: Int) = ++ - i + val x = f( + a, + b, + c) ``` -Rule id: `unary-op-spacing` (`standard` rule set) +Rule id: `wrapping` (`standard` rule set) diff --git a/ktlint-cli/src/test/kotlin/com/pinterest/ktlint/cli/api/BaselineCLITest.kt b/ktlint-cli/src/test/kotlin/com/pinterest/ktlint/cli/api/BaselineCLITest.kt index 850fdb82cd..a41c208fab 100644 --- a/ktlint-cli/src/test/kotlin/com/pinterest/ktlint/cli/api/BaselineCLITest.kt +++ b/ktlint-cli/src/test/kotlin/com/pinterest/ktlint/cli/api/BaselineCLITest.kt @@ -21,7 +21,7 @@ class BaselineCLITest { projectName, listOf( "TestBaselineFile.kt.test", - "some/path/to/TestBaselineFile2.kt.test", + "some/path/to/TestBaselineFile.kt.test", ), ) { SoftAssertions() @@ -29,11 +29,7 @@ class BaselineCLITest { assertErrorExitCode() assertThat(normalOutput) .containsLineMatching(Regex(".*/$projectName/TestBaselineFile.kt.test:1:24: Unnecessary block.*")) - .containsLineMatching(Regex(".*/$projectName/TestBaselineFile.kt.test:2:1: Unexpected blank line.*")) - .containsLineMatching(Regex(".*/$projectName/some/path/to/TestBaselineFile2.kt.test:1:25: Unnecessary block.*")) - .containsLineMatching( - Regex(".*/$projectName/some/path/to/TestBaselineFile2.kt.test:2:1: Unexpected blank line.*"), - ) + .containsLineMatching(Regex(".*/$projectName/some/path/to/TestBaselineFile.kt.test:1:24: Unnecessary block.*")) }.assertAll() } } @@ -54,7 +50,7 @@ class BaselineCLITest { listOf( "--baseline=$baselinePath", "TestBaselineFile.kt.test", - "some/path/to/TestBaselineFile2.kt.test", + "some/path/to/TestBaselineFile.kt.test", ), ) { SoftAssertions() @@ -62,14 +58,11 @@ class BaselineCLITest { assertNormalExitCode() assertThat(normalOutput) .doesNotContainLineMatching(Regex(".*/$projectName/TestBaselineFile.kt.test:1:24: Unnecessary block.*")) - .doesNotContainLineMatching(Regex(".*/$projectName/TestBaselineFile.kt.test:2:1: Unexpected blank line.*")) .doesNotContainLineMatching( Regex(".*/$projectName/some/path/to/TestBaselineFile.kt.test:1:24: Unnecessary block.*"), - ).doesNotContainLineMatching( - Regex(".*/$projectName/some/path/to/TestBaselineFile.kt.test:2:1: Unexpected blank line.*"), ).containsLineMatching( Regex( - ".*Baseline file '$baselinePath' contains 6 reference\\(s\\) to rule ids without a rule set id. " + + ".*Baseline file '$baselinePath' contains 4 reference\\(s\\) to rule ids without a rule set id. " + "For those references the rule set id 'standard' is assumed. It is advised to regenerate " + "this baseline file.*", ), @@ -92,7 +85,7 @@ class BaselineCLITest { listOf( "--baseline=$baselinePath", "TestBaselineFile.kt.test", - "some/path/to/TestBaselineFile2.kt.test", + "some/path/to/TestBaselineFile.kt.test", ), ) { SoftAssertions() @@ -100,14 +93,11 @@ class BaselineCLITest { assertNormalExitCode() assertThat(normalOutput) .doesNotContainLineMatching(Regex(".*/$projectName/TestBaselineFile.kt.test:1:24: Unnecessary block.*")) - .doesNotContainLineMatching(Regex(".*/$projectName/TestBaselineFile.kt.test:2:1: Unexpected blank line.*")) .doesNotContainLineMatching( Regex(".*/$projectName/some/path/to/TestBaselineFile.kt.test:1:24: Unnecessary block.*"), - ).doesNotContainLineMatching( - Regex(".*/$projectName/some/path/to/TestBaselineFile.kt.test:2:1: Unexpected blank line.*"), ).containsLineMatching( Regex( - ".*Baseline file '$baselinePath' contains 6 reference\\(s\\) to rule ids without a rule set id. " + + ".*Baseline file '$baselinePath' contains 4 reference\\(s\\) to rule ids without a rule set id. " + "For those references the rule set id 'standard' is assumed. It is advised to regenerate " + "this baseline file.*", ), @@ -129,7 +119,7 @@ class BaselineCLITest { listOf( "--baseline=$baselinePath", "TestBaselineFile.kt.test", - "some/path/to/TestBaselineFile2.kt.test", + "some/path/to/TestBaselineFile.kt.test", ), ) { SoftAssertions() @@ -137,13 +127,11 @@ class BaselineCLITest { assertNormalExitCode() assertThat(normalOutput) .doesNotContainLineMatching(Regex("^TestBaselineFile.kt.test:1:24: Unnecessary block.*")) - .doesNotContainLineMatching(Regex("^TestBaselineFile.kt.test:2:1: Unexpected blank line.*")) .doesNotContainLineMatching(Regex("^some/path/to/TestBaselineFile.kt.test:1:24: Unnecessary block.*")) - .doesNotContainLineMatching(Regex("^some/path/to/TestBaselineFile.kt.test:2:1: Unexpected blank line.*")) .containsLineMatching( Regex( // Escape "\" in baseline path for Windows - ".*Baseline file '${baselinePath.replace("\\", "\\\\")}' contains 6 " + + ".*Baseline file '${baselinePath.replace("\\", "\\\\")}' contains 4 " + "reference\\(s\\) to rule ids without a rule set id. For those references the rule set id " + "'standard' is assumed. It is advised to regenerate this baseline file.*", ), @@ -167,19 +155,26 @@ class BaselineCLITest { listOf( "--baseline=$baselinePath", "TestBaselineExtraErrorFile.kt.test", - "some/path/to/TestBaselineExtraErrorFile2.kt.test", + "some/path/to/TestBaselineExtraErrorFile.kt.test", ), ) { SoftAssertions() .apply { assertErrorExitCode() assertThat(normalOutput) - .containsLineMatching(Regex(".*/$projectName/TestBaselineExtraErrorFile.kt.test:2:1: Unexpected blank line.*")) .containsLineMatching( - Regex(".*/$projectName/some/path/to/TestBaselineExtraErrorFile2.kt.test:2:1: Unexpected blank line.*"), + Regex( + ".*/$projectName/TestBaselineExtraErrorFile.kt.test:1:1: Replace the block comment with an " + + "EOL comment.*", + ), + ).containsLineMatching( + Regex( + ".*/$projectName/some/path/to/TestBaselineExtraErrorFile.kt.test:1:1: Replace the block comment with " + + "an EOL comment.*", + ), ).containsLineMatching( Regex( - ".*Baseline file '$baselinePath' contains 6 reference\\(s\\) to rule ids without a rule set id. For " + + ".*Baseline file '$baselinePath' contains 4 reference\\(s\\) to rule ids without a rule set id. For " + "those references the rule set id 'standard' is assumed. It is advised to regenerate this " + "baseline file.*", ), diff --git a/ktlint-cli/src/test/resources/cli/baseline/TestBaselineExtraErrorFile.kt.test b/ktlint-cli/src/test/resources/cli/baseline/TestBaselineExtraErrorFile.kt.test index 0beb3316d4..53e27f36b5 100644 --- a/ktlint-cli/src/test/resources/cli/baseline/TestBaselineExtraErrorFile.kt.test +++ b/ktlint-cli/src/test/resources/cli/baseline/TestBaselineExtraErrorFile.kt.test @@ -1,3 +1,2 @@ -class TestBaselineExtraErrorFile { - -} +/* this should be an EOL comment */ +class TestBaselineExtraErrorFile {} diff --git a/ktlint-cli/src/test/resources/cli/baseline/TestBaselineFile.kt.test b/ktlint-cli/src/test/resources/cli/baseline/TestBaselineFile.kt.test index 9f6b6e33b3..c6e0c762f0 100644 --- a/ktlint-cli/src/test/resources/cli/baseline/TestBaselineFile.kt.test +++ b/ktlint-cli/src/test/resources/cli/baseline/TestBaselineFile.kt.test @@ -1,3 +1 @@ -class TestBaselineFile { - -} +class TestBaselineFile {} diff --git a/ktlint-cli/src/test/resources/cli/baseline/config/test-baseline.xml b/ktlint-cli/src/test/resources/cli/baseline/config/test-baseline.xml index d60da6042b..ec2b8a0304 100644 --- a/ktlint-cli/src/test/resources/cli/baseline/config/test-baseline.xml +++ b/ktlint-cli/src/test/resources/cli/baseline/config/test-baseline.xml @@ -1,17 +1,15 @@ + + + - - - + + - - - - - - + + diff --git a/ktlint-cli/src/test/resources/cli/baseline/readme.md b/ktlint-cli/src/test/resources/cli/baseline/readme.md new file mode 100644 index 0000000000..21a2ecdf42 --- /dev/null +++ b/ktlint-cli/src/test/resources/cli/baseline/readme.md @@ -0,0 +1,5 @@ +Note that following is configured on purpose: +* Files `test-baseline.xml` and `config/test-baseline.xml` are identical. +* The references to the rules do not include the rule set id `standard:`. +* All test files contain an empty function body which is registered in the baseline file. +* The `TextBaselineExtraErrorFile` contains an additional error (a single line block comment). diff --git a/ktlint-cli/src/test/resources/cli/baseline/some/path/to/TestBaselineExtraErrorFile.kt.test b/ktlint-cli/src/test/resources/cli/baseline/some/path/to/TestBaselineExtraErrorFile.kt.test new file mode 100644 index 0000000000..53e27f36b5 --- /dev/null +++ b/ktlint-cli/src/test/resources/cli/baseline/some/path/to/TestBaselineExtraErrorFile.kt.test @@ -0,0 +1,2 @@ +/* this should be an EOL comment */ +class TestBaselineExtraErrorFile {} diff --git a/ktlint-cli/src/test/resources/cli/baseline/some/path/to/TestBaselineExtraErrorFile2.kt.test b/ktlint-cli/src/test/resources/cli/baseline/some/path/to/TestBaselineExtraErrorFile2.kt.test deleted file mode 100644 index 747bc53617..0000000000 --- a/ktlint-cli/src/test/resources/cli/baseline/some/path/to/TestBaselineExtraErrorFile2.kt.test +++ /dev/null @@ -1,3 +0,0 @@ -class TestBaselineExtraErrorFile2 { - -} diff --git a/ktlint-cli/src/test/resources/cli/baseline/some/path/to/TestBaselineFile.kt.test b/ktlint-cli/src/test/resources/cli/baseline/some/path/to/TestBaselineFile.kt.test new file mode 100644 index 0000000000..c6e0c762f0 --- /dev/null +++ b/ktlint-cli/src/test/resources/cli/baseline/some/path/to/TestBaselineFile.kt.test @@ -0,0 +1 @@ +class TestBaselineFile {} diff --git a/ktlint-cli/src/test/resources/cli/baseline/some/path/to/TestBaselineFile2.kt.test b/ktlint-cli/src/test/resources/cli/baseline/some/path/to/TestBaselineFile2.kt.test deleted file mode 100644 index 985fa5ca71..0000000000 --- a/ktlint-cli/src/test/resources/cli/baseline/some/path/to/TestBaselineFile2.kt.test +++ /dev/null @@ -1,3 +0,0 @@ -class TestBaselineFile2 { - -} diff --git a/ktlint-cli/src/test/resources/cli/baseline/test-baseline.xml b/ktlint-cli/src/test/resources/cli/baseline/test-baseline.xml index d60da6042b..ec2b8a0304 100644 --- a/ktlint-cli/src/test/resources/cli/baseline/test-baseline.xml +++ b/ktlint-cli/src/test/resources/cli/baseline/test-baseline.xml @@ -1,17 +1,15 @@ + + + - - - + + - - - - - - + + diff --git a/ktlint-rule-engine-core/api/ktlint-rule-engine-core.api b/ktlint-rule-engine-core/api/ktlint-rule-engine-core.api index 675f0fdd93..db251cea8f 100644 --- a/ktlint-rule-engine-core/api/ktlint-rule-engine-core.api +++ b/ktlint-rule-engine-core/api/ktlint-rule-engine-core.api @@ -475,6 +475,23 @@ public final class com/pinterest/ktlint/rule/engine/core/api/RuleSetId$Companion public final fun isValid (Ljava/lang/String;)Z } +public abstract interface annotation class com/pinterest/ktlint/rule/engine/core/api/SinceKtlint : java/lang/annotation/Annotation { + public abstract fun status ()Lcom/pinterest/ktlint/rule/engine/core/api/SinceKtlint$Status; + public abstract fun version ()Ljava/lang/String; +} + +public abstract interface annotation class com/pinterest/ktlint/rule/engine/core/api/SinceKtlint$Container : java/lang/annotation/Annotation { + public abstract fun value ()[Lcom/pinterest/ktlint/rule/engine/core/api/SinceKtlint; +} + +public final class com/pinterest/ktlint/rule/engine/core/api/SinceKtlint$Status : java/lang/Enum { + public static final field EXPERIMENTAL Lcom/pinterest/ktlint/rule/engine/core/api/SinceKtlint$Status; + public static final field STABLE Lcom/pinterest/ktlint/rule/engine/core/api/SinceKtlint$Status; + public static fun getEntries ()Lkotlin/enums/EnumEntries; + public static fun valueOf (Ljava/lang/String;)Lcom/pinterest/ktlint/rule/engine/core/api/SinceKtlint$Status; + public static fun values ()[Lcom/pinterest/ktlint/rule/engine/core/api/SinceKtlint$Status; +} + public final class com/pinterest/ktlint/rule/engine/core/api/editorconfig/CodeStyleEditorConfigPropertyKt { public static final fun getCODE_STYLE_PROPERTY ()Lcom/pinterest/ktlint/rule/engine/core/api/editorconfig/EditorConfigProperty; public static final fun getCODE_STYLE_PROPERTY_TYPE ()Lorg/ec4j/core/model/PropertyType$LowerCasingPropertyType; diff --git a/ktlint-rule-engine-core/src/main/kotlin/com/pinterest/ktlint/rule/engine/core/api/SinceKtlint.kt b/ktlint-rule-engine-core/src/main/kotlin/com/pinterest/ktlint/rule/engine/core/api/SinceKtlint.kt new file mode 100644 index 0000000000..f568e456e8 --- /dev/null +++ b/ktlint-rule-engine-core/src/main/kotlin/com/pinterest/ktlint/rule/engine/core/api/SinceKtlint.kt @@ -0,0 +1,24 @@ +package com.pinterest.ktlint.rule.engine.core.api + +/** + * The version in which the rule was introduced. + */ +@Repeatable +@Target( + AnnotationTarget.CLASS, + AnnotationTarget.PROPERTY, + AnnotationTarget.FIELD, + AnnotationTarget.CONSTRUCTOR, + AnnotationTarget.FUNCTION, + AnnotationTarget.PROPERTY_GETTER, + AnnotationTarget.PROPERTY_SETTER, + AnnotationTarget.TYPEALIAS, +) +@Retention(AnnotationRetention.BINARY) +@MustBeDocumented +public annotation class SinceKtlint( + val version: String, + val status: Status, +) { + public enum class Status { STABLE, EXPERIMENTAL } +} diff --git a/ktlint-ruleset-standard/api/ktlint-ruleset-standard.api b/ktlint-ruleset-standard/api/ktlint-ruleset-standard.api index 6fcc74658f..2730dbd9ee 100644 --- a/ktlint-ruleset-standard/api/ktlint-ruleset-standard.api +++ b/ktlint-ruleset-standard/api/ktlint-ruleset-standard.api @@ -48,7 +48,7 @@ public final class com/pinterest/ktlint/ruleset/standard/rules/BinaryExpressionW public static final fun getBINARY_EXPRESSION_WRAPPING_RULE_ID ()Lcom/pinterest/ktlint/rule/engine/core/api/RuleId; } -public final class com/pinterest/ktlint/ruleset/standard/rules/BlankLineBeforeDeclarationRule : 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/BlankLineBeforeDeclarationRule : com/pinterest/ktlint/ruleset/standard/StandardRule, com/pinterest/ktlint/rule/engine/core/api/Rule$OfficialCodeStyle { public fun ()V public fun beforeVisitChildNodes (Lorg/jetbrains/kotlin/com/intellij/lang/ASTNode;ZLkotlin/jvm/functions/Function3;)V } @@ -133,7 +133,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/ContextReceiverWrappingRule : com/pinterest/ktlint/ruleset/standard/StandardRule, com/pinterest/ktlint/rule/engine/core/api/Rule$Experimental { +public final class com/pinterest/ktlint/ruleset/standard/rules/ContextReceiverWrappingRule : 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;ZLkotlin/jvm/functions/Function3;)V @@ -143,7 +143,7 @@ public final class com/pinterest/ktlint/ruleset/standard/rules/ContextReceiverWr public static final fun getCONTEXT_RECEIVER_WRAPPING_RULE_ID ()Lcom/pinterest/ktlint/rule/engine/core/api/RuleId; } -public final class com/pinterest/ktlint/ruleset/standard/rules/DiscouragedCommentLocationRule : com/pinterest/ktlint/ruleset/standard/StandardRule, com/pinterest/ktlint/rule/engine/core/api/Rule$Experimental { +public final class com/pinterest/ktlint/ruleset/standard/rules/DiscouragedCommentLocationRule : com/pinterest/ktlint/ruleset/standard/StandardRule { public fun ()V public fun beforeVisitChildNodes (Lorg/jetbrains/kotlin/com/intellij/lang/ASTNode;ZLkotlin/jvm/functions/Function3;)V } @@ -161,7 +161,7 @@ public final class com/pinterest/ktlint/ruleset/standard/rules/EnumEntryNameCase public static final fun getENUM_ENTRY_NAME_CASE_RULE_ID ()Lcom/pinterest/ktlint/rule/engine/core/api/RuleId; } -public final class com/pinterest/ktlint/ruleset/standard/rules/EnumWrappingRule : com/pinterest/ktlint/ruleset/standard/StandardRule, com/pinterest/ktlint/rule/engine/core/api/Rule$Experimental { +public final class com/pinterest/ktlint/ruleset/standard/rules/EnumWrappingRule : 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;ZLkotlin/jvm/functions/Function3;)V @@ -219,7 +219,7 @@ public final class com/pinterest/ktlint/ruleset/standard/rules/FunctionLiteralRu public static final fun getFUNCTION_LITERAL_RULE_ID ()Lcom/pinterest/ktlint/rule/engine/core/api/RuleId; } -public final class com/pinterest/ktlint/ruleset/standard/rules/FunctionNamingRule : com/pinterest/ktlint/ruleset/standard/StandardRule, com/pinterest/ktlint/rule/engine/core/api/Rule$Experimental { +public final class com/pinterest/ktlint/ruleset/standard/rules/FunctionNamingRule : com/pinterest/ktlint/ruleset/standard/StandardRule { public fun ()V public fun beforeVisitChildNodes (Lorg/jetbrains/kotlin/com/intellij/lang/ASTNode;ZLkotlin/jvm/functions/Function3;)V } @@ -238,7 +238,7 @@ public final class com/pinterest/ktlint/ruleset/standard/rules/FunctionReturnTyp public static final fun getFUNCTION_RETURN_TYPE_SPACING_RULE_ID ()Lcom/pinterest/ktlint/rule/engine/core/api/RuleId; } -public final class com/pinterest/ktlint/ruleset/standard/rules/FunctionSignatureRule : com/pinterest/ktlint/ruleset/standard/StandardRule, com/pinterest/ktlint/rule/engine/core/api/Rule$Experimental { +public final class com/pinterest/ktlint/ruleset/standard/rules/FunctionSignatureRule : com/pinterest/ktlint/ruleset/standard/StandardRule { public static final field Companion Lcom/pinterest/ktlint/ruleset/standard/rules/FunctionSignatureRule$Companion; public fun ()V public fun beforeFirstNode (Lcom/pinterest/ktlint/rule/engine/core/api/editorconfig/EditorConfig;)V @@ -290,7 +290,7 @@ public final class com/pinterest/ktlint/ruleset/standard/rules/FunctionTypeRefer public static final fun getFUNCTION_TYPE_REFERENCE_SPACING_RULE_ID ()Lcom/pinterest/ktlint/rule/engine/core/api/RuleId; } -public final class com/pinterest/ktlint/ruleset/standard/rules/IfElseBracingRule : 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/IfElseBracingRule : com/pinterest/ktlint/ruleset/standard/StandardRule, com/pinterest/ktlint/rule/engine/core/api/Rule$OfficialCodeStyle { 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;ZLkotlin/jvm/functions/Function3;)V @@ -300,7 +300,7 @@ public final class com/pinterest/ktlint/ruleset/standard/rules/IfElseBracingRule public static final fun getIF_ELSE_BRACING_RULE_ID ()Lcom/pinterest/ktlint/rule/engine/core/api/RuleId; } -public final class com/pinterest/ktlint/ruleset/standard/rules/IfElseWrappingRule : 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/IfElseWrappingRule : com/pinterest/ktlint/ruleset/standard/StandardRule, com/pinterest/ktlint/rule/engine/core/api/Rule$OfficialCodeStyle { 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;ZLkotlin/jvm/functions/Function3;)V @@ -391,7 +391,7 @@ public final class com/pinterest/ktlint/ruleset/standard/rules/MultiLineIfElseRu public static final fun getMULTI_LINE_IF_ELSE_RULE_ID ()Lcom/pinterest/ktlint/rule/engine/core/api/RuleId; } -public final class com/pinterest/ktlint/ruleset/standard/rules/MultilineExpressionWrappingRule : 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/MultilineExpressionWrappingRule : com/pinterest/ktlint/ruleset/standard/StandardRule, com/pinterest/ktlint/rule/engine/core/api/Rule$OfficialCodeStyle { 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;ZLkotlin/jvm/functions/Function3;)V @@ -410,7 +410,7 @@ public final class com/pinterest/ktlint/ruleset/standard/rules/NoBlankLineBefore public static final fun getNO_BLANK_LINE_BEFORE_RBRACE_RULE_ID ()Lcom/pinterest/ktlint/rule/engine/core/api/RuleId; } -public final class com/pinterest/ktlint/ruleset/standard/rules/NoBlankLineInListRule : 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/NoBlankLineInListRule : com/pinterest/ktlint/ruleset/standard/StandardRule, com/pinterest/ktlint/rule/engine/core/api/Rule$OfficialCodeStyle { public fun ()V public fun beforeVisitChildNodes (Lorg/jetbrains/kotlin/com/intellij/lang/ASTNode;ZLkotlin/jvm/functions/Function3;)V } @@ -437,7 +437,7 @@ public final class com/pinterest/ktlint/ruleset/standard/rules/NoConsecutiveBlan public static final fun getNO_CONSECUTIVE_BLANK_LINES_RULE_ID ()Lcom/pinterest/ktlint/rule/engine/core/api/RuleId; } -public final class com/pinterest/ktlint/ruleset/standard/rules/NoConsecutiveCommentsRule : 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/NoConsecutiveCommentsRule : com/pinterest/ktlint/ruleset/standard/StandardRule, com/pinterest/ktlint/rule/engine/core/api/Rule$OfficialCodeStyle { public fun ()V public fun beforeVisitChildNodes (Lorg/jetbrains/kotlin/com/intellij/lang/ASTNode;ZLkotlin/jvm/functions/Function3;)V } @@ -455,7 +455,7 @@ public final class com/pinterest/ktlint/ruleset/standard/rules/NoEmptyClassBodyR public static final fun getNO_EMPTY_CLASS_BODY_RULE_ID ()Lcom/pinterest/ktlint/rule/engine/core/api/RuleId; } -public final class com/pinterest/ktlint/ruleset/standard/rules/NoEmptyFileRule : com/pinterest/ktlint/ruleset/standard/StandardRule, com/pinterest/ktlint/rule/engine/core/api/Rule$Experimental { +public final class com/pinterest/ktlint/ruleset/standard/rules/NoEmptyFileRule : com/pinterest/ktlint/ruleset/standard/StandardRule { public fun ()V public fun beforeVisitChildNodes (Lorg/jetbrains/kotlin/com/intellij/lang/ASTNode;ZLkotlin/jvm/functions/Function3;)V } @@ -464,7 +464,7 @@ public final class com/pinterest/ktlint/ruleset/standard/rules/NoEmptyFileRuleKt public static final fun getNO_EMPTY_FILE_RULE_ID ()Lcom/pinterest/ktlint/rule/engine/core/api/RuleId; } -public final class com/pinterest/ktlint/ruleset/standard/rules/NoEmptyFirstLineInClassBodyRule : 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/NoEmptyFirstLineInClassBodyRule : com/pinterest/ktlint/ruleset/standard/StandardRule, com/pinterest/ktlint/rule/engine/core/api/Rule$OfficialCodeStyle { 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;ZLkotlin/jvm/functions/Function3;)V @@ -519,7 +519,7 @@ public final class com/pinterest/ktlint/ruleset/standard/rules/NoSemicolonsRuleK public static final fun getNO_SEMICOLONS_RULE_ID ()Lcom/pinterest/ktlint/rule/engine/core/api/RuleId; } -public final class com/pinterest/ktlint/ruleset/standard/rules/NoSingleLineBlockCommentRule : 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/NoSingleLineBlockCommentRule : com/pinterest/ktlint/ruleset/standard/StandardRule, com/pinterest/ktlint/rule/engine/core/api/Rule$OfficialCodeStyle { public fun ()V public fun beforeVisitChildNodes (Lorg/jetbrains/kotlin/com/intellij/lang/ASTNode;ZLkotlin/jvm/functions/Function3;)V } @@ -589,7 +589,7 @@ public final class com/pinterest/ktlint/ruleset/standard/rules/PackageNameRuleKt public static final fun getPACKAGE_NAME_RULE_ID ()Lcom/pinterest/ktlint/rule/engine/core/api/RuleId; } -public final class com/pinterest/ktlint/ruleset/standard/rules/ParameterListSpacingRule : com/pinterest/ktlint/ruleset/standard/StandardRule, com/pinterest/ktlint/rule/engine/core/api/Rule$Experimental { +public final class com/pinterest/ktlint/ruleset/standard/rules/ParameterListSpacingRule : com/pinterest/ktlint/ruleset/standard/StandardRule { public fun ()V public fun beforeVisitChildNodes (Lorg/jetbrains/kotlin/com/intellij/lang/ASTNode;ZLkotlin/jvm/functions/Function3;)V } @@ -618,7 +618,7 @@ public final class com/pinterest/ktlint/ruleset/standard/rules/ParameterWrapping public static final fun getPARAMETER_WRAPPING_RULE_ID ()Lcom/pinterest/ktlint/rule/engine/core/api/RuleId; } -public final class com/pinterest/ktlint/ruleset/standard/rules/PropertyNamingRule : com/pinterest/ktlint/ruleset/standard/StandardRule, com/pinterest/ktlint/rule/engine/core/api/Rule$Experimental { +public final class com/pinterest/ktlint/ruleset/standard/rules/PropertyNamingRule : com/pinterest/ktlint/ruleset/standard/StandardRule { public static final field SERIAL_VERSION_UID_PROPERTY_NAME Ljava/lang/String; public fun ()V public fun beforeVisitChildNodes (Lorg/jetbrains/kotlin/com/intellij/lang/ASTNode;ZLkotlin/jvm/functions/Function3;)V @@ -770,7 +770,7 @@ public final class com/pinterest/ktlint/ruleset/standard/rules/StatementWrapping public fun beforeVisitChildNodes (Lorg/jetbrains/kotlin/com/intellij/lang/ASTNode;ZLkotlin/jvm/functions/Function3;)V } -public final class com/pinterest/ktlint/ruleset/standard/rules/StringTemplateIndentRule : 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/StringTemplateIndentRule : com/pinterest/ktlint/ruleset/standard/StandardRule, com/pinterest/ktlint/rule/engine/core/api/Rule$OfficialCodeStyle { public static final field RAW_STRING_LITERAL_QUOTES Ljava/lang/String; public fun ()V public fun beforeFirstNode (Lcom/pinterest/ktlint/rule/engine/core/api/editorconfig/EditorConfig;)V @@ -820,7 +820,7 @@ public final class com/pinterest/ktlint/ruleset/standard/rules/TrailingCommaOnDe public static final fun getTRAILING_COMMA_ON_DECLARATION_SITE_RULE_ID ()Lcom/pinterest/ktlint/rule/engine/core/api/RuleId; } -public final class com/pinterest/ktlint/ruleset/standard/rules/TryCatchFinallySpacingRule : 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/TryCatchFinallySpacingRule : com/pinterest/ktlint/ruleset/standard/StandardRule, com/pinterest/ktlint/rule/engine/core/api/Rule$OfficialCodeStyle { 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;ZLkotlin/jvm/functions/Function3;)V @@ -830,7 +830,7 @@ public final class com/pinterest/ktlint/ruleset/standard/rules/TryCatchFinallySp public static final fun getTRY_CATCH_RULE_ID ()Lcom/pinterest/ktlint/rule/engine/core/api/RuleId; } -public final class com/pinterest/ktlint/ruleset/standard/rules/TypeArgumentListSpacingRule : com/pinterest/ktlint/ruleset/standard/StandardRule, com/pinterest/ktlint/rule/engine/core/api/Rule$Experimental { +public final class com/pinterest/ktlint/ruleset/standard/rules/TypeArgumentListSpacingRule : 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;ZLkotlin/jvm/functions/Function3;)V @@ -840,7 +840,7 @@ public final class com/pinterest/ktlint/ruleset/standard/rules/TypeArgumentListS public static final fun getTYPE_ARGUMENT_LIST_SPACING_RULE_ID ()Lcom/pinterest/ktlint/rule/engine/core/api/RuleId; } -public final class com/pinterest/ktlint/ruleset/standard/rules/TypeParameterListSpacingRule : com/pinterest/ktlint/ruleset/standard/StandardRule, com/pinterest/ktlint/rule/engine/core/api/Rule$Experimental { +public final class com/pinterest/ktlint/ruleset/standard/rules/TypeParameterListSpacingRule : 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;ZLkotlin/jvm/functions/Function3;)V @@ -850,7 +850,7 @@ public final class com/pinterest/ktlint/ruleset/standard/rules/TypeParameterList public static final fun getTYPE_PARAMETER_LIST_SPACING_RULE_ID ()Lcom/pinterest/ktlint/rule/engine/core/api/RuleId; } -public final class com/pinterest/ktlint/ruleset/standard/rules/UnnecessaryParenthesesBeforeTrailingLambdaRule : com/pinterest/ktlint/ruleset/standard/StandardRule, com/pinterest/ktlint/rule/engine/core/api/Rule$Experimental { +public final class com/pinterest/ktlint/ruleset/standard/rules/UnnecessaryParenthesesBeforeTrailingLambdaRule : com/pinterest/ktlint/ruleset/standard/StandardRule { public fun ()V public fun beforeVisitChildNodes (Lorg/jetbrains/kotlin/com/intellij/lang/ASTNode;ZLkotlin/jvm/functions/Function3;)V } diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/AnnotationRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/AnnotationRule.kt index 4705e22f7e..f1f49ed40a 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/AnnotationRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/AnnotationRule.kt @@ -17,6 +17,8 @@ import com.pinterest.ktlint.rule.engine.core.api.IndentConfig 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.RuleId +import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint +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 @@ -71,6 +73,7 @@ import org.jetbrains.kotlin.utils.addToStdlib.ifTrue * * @see [AnnotationSpacingRule] for white space rules. */ +@SinceKtlint("0.30", STABLE) public class AnnotationRule : StandardRule( id = "annotation", diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/AnnotationSpacingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/AnnotationSpacingRule.kt index aed6ad0251..5e66a2ebe8 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/AnnotationSpacingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/AnnotationSpacingRule.kt @@ -2,6 +2,9 @@ package com.pinterest.ktlint.ruleset.standard.rules import com.pinterest.ktlint.rule.engine.core.api.ElementType 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.isPartOf import com.pinterest.ktlint.rule.engine.core.api.isPartOfComment import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace @@ -25,6 +28,8 @@ import org.jetbrains.kotlin.psi.psiUtil.leaves * * https://kotlinlang.org/docs/reference/coding-conventions.html#annotation-formatting */ +@SinceKtlint("0.39", EXPERIMENTAL) +@SinceKtlint("0.46", STABLE) public class AnnotationSpacingRule : StandardRule("annotation-spacing") { private companion object { const val ERROR_MESSAGE = "Annotations should occur immediately before the annotated construct" diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ArgumentListWrappingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ArgumentListWrappingRule.kt index e0be612d6e..59294c2237 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ArgumentListWrappingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ArgumentListWrappingRule.kt @@ -7,6 +7,8 @@ import com.pinterest.ktlint.rule.engine.core.api.ElementType.VALUE_ARGUMENT_LIST import com.pinterest.ktlint.rule.engine.core.api.IndentConfig 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.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 @@ -39,6 +41,7 @@ import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType * - maxLineLength exceeded (and separating arguments with \n would actually help) * in addition, "(" and ")" must be on separates line if any of the arguments are (otherwise on the same) */ +@SinceKtlint("0.1", STABLE) public class ArgumentListWrappingRule : StandardRule( id = "argument-list-wrapping", 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 119dc62bc6..dfb2c362c6 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 @@ -15,6 +15,8 @@ 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.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.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 @@ -38,6 +40,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) public class BinaryExpressionWrappingRule : StandardRule( id = "binary-expression-wrapping", diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/BlankLineBeforeDeclarationRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/BlankLineBeforeDeclarationRule.kt index d55aebd499..31210429d0 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/BlankLineBeforeDeclarationRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/BlankLineBeforeDeclarationRule.kt @@ -12,6 +12,9 @@ import com.pinterest.ktlint.rule.engine.core.api.ElementType.PROPERTY_ACCESSOR import com.pinterest.ktlint.rule.engine.core.api.ElementType.WHEN 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.indent import com.pinterest.ktlint.rule.engine.core.api.isPartOfComment @@ -30,9 +33,10 @@ import org.jetbrains.kotlin.psi.KtFunctionLiteral * Insert a blank line before declarations. No blank line is inserted before between a class or method signature and the first declaration * in the class or method respectively. Also, no blank lines are inserted between consecutive properties. */ +@SinceKtlint("0.50", EXPERIMENTAL) +@SinceKtlint("1.0", STABLE) public class BlankLineBeforeDeclarationRule : StandardRule("blank-line-before-declaration"), - Rule.Experimental, Rule.OfficialCodeStyle { override fun beforeVisitChildNodes( node: ASTNode, diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/BlockCommentInitialStarAlignmentRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/BlockCommentInitialStarAlignmentRule.kt index 1a0ee15388..9d9242b431 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/BlockCommentInitialStarAlignmentRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/BlockCommentInitialStarAlignmentRule.kt @@ -3,6 +3,8 @@ package com.pinterest.ktlint.ruleset.standard.rules import com.pinterest.ktlint.rule.engine.core.api.ElementType.BLOCK_COMMENT 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.STABLE import com.pinterest.ktlint.rule.engine.core.api.indent import com.pinterest.ktlint.ruleset.standard.StandardRule import org.jetbrains.kotlin.com.intellij.lang.ASTNode @@ -11,6 +13,7 @@ import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.LeafElement /** * When present, align the initial star in a block comment. */ +@SinceKtlint("0.45", STABLE) public class BlockCommentInitialStarAlignmentRule : StandardRule( "block-comment-initial-star-alignment", 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 fc3d6d1916..a5ac358a0c 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 @@ -28,6 +28,8 @@ 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.ONLY_WHEN_RUN_AFTER_RULE_IS_LOADED_AND_ENABLED 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.children import com.pinterest.ktlint.rule.engine.core.api.editorconfig.CODE_STYLE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.editorconfig.EditorConfig @@ -65,6 +67,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) public class ChainMethodContinuationRule : StandardRule( id = "chain-method-continuation", diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ChainWrappingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ChainWrappingRule.kt index 28fcca3cc9..9f71c5ce3e 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ChainWrappingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ChainWrappingRule.kt @@ -19,6 +19,8 @@ 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.RuleId +import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint +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 @@ -40,6 +42,7 @@ import org.jetbrains.kotlin.com.intellij.psi.tree.TokenSet import org.jetbrains.kotlin.lexer.KtTokens import org.jetbrains.kotlin.psi.psiUtil.leaves +@SinceKtlint("0.13", STABLE) public class ChainWrappingRule : StandardRule( id = "chain-wrapping", diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ClassNamingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ClassNamingRule.kt index 118e5bbf56..db40767697 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ClassNamingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ClassNamingRule.kt @@ -6,6 +6,8 @@ import com.pinterest.ktlint.rule.engine.core.api.ElementType.IDENTIFIER import com.pinterest.ktlint.rule.engine.core.api.ElementType.IMPORT_DIRECTIVE import com.pinterest.ktlint.rule.engine.core.api.ElementType.OBJECT_DECLARATION 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.ruleset.standard.StandardRule import com.pinterest.ktlint.ruleset.standard.rules.internal.regExIgnoringDiacriticsAndStrokesOnLetters import org.jetbrains.kotlin.com.intellij.lang.ASTNode @@ -16,6 +18,8 @@ import org.jetbrains.kotlin.com.intellij.lang.ASTNode * The Kotlin convention does not allow explicitly to use backticked class name, but it makes sense to allow this as * well as it is more consistent with name of test functions. */ +@SinceKtlint("0.48", EXPERIMENTAL) +@SinceKtlint("0.49", EXPERIMENTAL) public class ClassNamingRule : StandardRule("class-naming") { private var allowBacktickedClassName = false 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 f5ccac71a2..aee1bb71e1 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 @@ -21,6 +21,8 @@ import com.pinterest.ktlint.rule.engine.core.api.Rule.VisitorModifier.RunAfterRu import com.pinterest.ktlint.rule.engine.core.api.Rule.VisitorModifier.RunAfterRule.Mode.ONLY_WHEN_RUN_AFTER_RULE_IS_LOADED_AND_ENABLED 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.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 @@ -52,6 +54,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) public class ClassSignatureRule : StandardRule( id = "class-signature", diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/CommentSpacingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/CommentSpacingRule.kt index b7549a5b62..04368b85d1 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/CommentSpacingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/CommentSpacingRule.kt @@ -2,6 +2,7 @@ package com.pinterest.ktlint.ruleset.standard.rules import com.pinterest.ktlint.rule.engine.core.api.ElementType.EOL_COMMENT 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.prevLeaf import com.pinterest.ktlint.rule.engine.core.api.upsertWhitespaceBeforeMe import com.pinterest.ktlint.ruleset.standard.StandardRule @@ -9,6 +10,7 @@ import org.jetbrains.kotlin.com.intellij.lang.ASTNode import org.jetbrains.kotlin.com.intellij.psi.PsiWhiteSpace import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.LeafPsiElement +@SinceKtlint("0.23", SinceKtlint.Status.STABLE) public class CommentSpacingRule : StandardRule("comment-spacing") { override fun beforeVisitChildNodes( node: ASTNode, diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/CommentWrappingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/CommentWrappingRule.kt index 24998e9685..8f56f111ea 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/CommentWrappingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/CommentWrappingRule.kt @@ -4,6 +4,9 @@ import com.pinterest.ktlint.rule.engine.core.api.ElementType.BLOCK_COMMENT 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.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.INDENT_SIZE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.editorconfig.INDENT_STYLE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.firstChildLeafOrSelf @@ -22,6 +25,8 @@ import org.jetbrains.kotlin.psi.psiUtil.leaves /** * Checks external wrapping of block comments. Wrapping inside the comment is not altered. */ +@SinceKtlint("0.45", EXPERIMENTAL) +@SinceKtlint("0.49", STABLE) public class CommentWrappingRule : StandardRule( id = "comment-wrapping", diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ContextReceiverWrappingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ContextReceiverWrappingRule.kt index 75da1c4138..9350dbc541 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ContextReceiverWrappingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ContextReceiverWrappingRule.kt @@ -8,8 +8,10 @@ import com.pinterest.ktlint.rule.engine.core.api.ElementType.TYPE_ARGUMENT_LIST import com.pinterest.ktlint.rule.engine.core.api.ElementType.TYPE_PROJECTION 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.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 @@ -33,6 +35,8 @@ import org.jetbrains.kotlin.com.intellij.lang.ASTNode * Wrapping of context receiver to a separate line. Arguments of the context receiver are wrapped to separate line * whenever the max line length is exceeded. */ +@SinceKtlint("0.48", EXPERIMENTAL) +@SinceKtlint("1.0", STABLE) public class ContextReceiverWrappingRule : StandardRule( id = "context-receiver-wrapping", @@ -42,8 +46,7 @@ public class ContextReceiverWrappingRule : INDENT_STYLE_PROPERTY, MAX_LINE_LENGTH_PROPERTY, ), - ), - Rule.Experimental { + ) { 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/DiscouragedCommentLocationRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/DiscouragedCommentLocationRule.kt index 644867e0fa..f837d11b05 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/DiscouragedCommentLocationRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/DiscouragedCommentLocationRule.kt @@ -17,8 +17,10 @@ import com.pinterest.ktlint.rule.engine.core.api.ElementType.VALUE_ARGUMENT import com.pinterest.ktlint.rule.engine.core.api.ElementType.VALUE_ARGUMENT_LIST 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.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.isPartOfComment import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline import com.pinterest.ktlint.rule.engine.core.api.nextCodeSibling @@ -49,9 +51,9 @@ import org.jetbrains.kotlin.com.intellij.psi.tree.IElementType * foo(t: T) = "some-result" * ``` */ -public class DiscouragedCommentLocationRule : - StandardRule("discouraged-comment-location"), - Rule.Experimental { +@SinceKtlint("0.45", EXPERIMENTAL) +@SinceKtlint("1.0", STABLE) +public class DiscouragedCommentLocationRule : StandardRule("discouraged-comment-location") { override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/EnumEntryNameCaseRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/EnumEntryNameCaseRule.kt index c4a8fdad6d..bddce64322 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/EnumEntryNameCaseRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/EnumEntryNameCaseRule.kt @@ -1,6 +1,9 @@ package com.pinterest.ktlint.ruleset.standard.rules 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.ruleset.standard.StandardRule import com.pinterest.ktlint.ruleset.standard.rules.internal.regExIgnoringDiacriticsAndStrokesOnLetters import org.jetbrains.kotlin.com.intellij.lang.ASTNode @@ -10,6 +13,8 @@ import org.jetbrains.kotlin.psi.KtEnumEntry /** * https://kotlinlang.org/docs/coding-conventions.html#property-names */ +@SinceKtlint("0.36", EXPERIMENTAL) +@SinceKtlint("0.46", STABLE) public class EnumEntryNameCaseRule : StandardRule("enum-entry-name-case") { internal companion object { val ENUM_ENTRY_IDENTIFIER_REGEX = "[A-Z]([A-Za-z\\d]*|[A-Z_\\d]*)".regExIgnoringDiacriticsAndStrokesOnLetters() diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/EnumWrappingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/EnumWrappingRule.kt index a1c26a4f72..6bbf36e2c9 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/EnumWrappingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/EnumWrappingRule.kt @@ -7,8 +7,10 @@ import com.pinterest.ktlint.rule.engine.core.api.ElementType.ENUM_ENTRY import com.pinterest.ktlint.rule.engine.core.api.ElementType.MODIFIER_LIST import com.pinterest.ktlint.rule.engine.core.api.ElementType.RBRACE 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 @@ -28,6 +30,8 @@ import org.jetbrains.kotlin.psi.KtClass /** * */ +@SinceKtlint("0.49", EXPERIMENTAL) +@SinceKtlint("1.0", STABLE) public class EnumWrappingRule : StandardRule( id = "enum-wrapping", @@ -36,8 +40,7 @@ public class EnumWrappingRule : 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/FilenameRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FilenameRule.kt index b979590493..c92b0f103d 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FilenameRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FilenameRule.kt @@ -9,6 +9,7 @@ import com.pinterest.ktlint.rule.engine.core.api.ElementType.PROPERTY import com.pinterest.ktlint.rule.engine.core.api.ElementType.TYPEALIAS import com.pinterest.ktlint.rule.engine.core.api.ElementType.TYPE_REFERENCE 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.children import com.pinterest.ktlint.rule.engine.core.api.isRoot import com.pinterest.ktlint.ruleset.standard.StandardRule @@ -41,6 +42,7 @@ import org.jetbrains.kotlin.psi.KtFile * - file without `.kt` extension * - file with name `package.kt` */ +@SinceKtlint("0.23", SinceKtlint.Status.STABLE) public class FilenameRule : StandardRule("filename") { override fun beforeVisitChildNodes( node: ASTNode, diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FinalNewlineRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FinalNewlineRule.kt index 954098b042..a4f839efa7 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FinalNewlineRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FinalNewlineRule.kt @@ -1,6 +1,8 @@ package com.pinterest.ktlint.ruleset.standard.rules 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.STABLE import com.pinterest.ktlint.rule.engine.core.api.editorconfig.EditorConfig import com.pinterest.ktlint.rule.engine.core.api.editorconfig.INSERT_FINAL_NEWLINE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.isRoot @@ -9,6 +11,7 @@ import org.jetbrains.kotlin.com.intellij.lang.ASTNode import org.jetbrains.kotlin.com.intellij.psi.PsiWhiteSpace import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.PsiWhiteSpaceImpl +@SinceKtlint("0.9", STABLE) public class FinalNewlineRule : StandardRule( id = "final-newline", diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FunKeywordSpacingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FunKeywordSpacingRule.kt index d5ac0df2e9..57b280d40b 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FunKeywordSpacingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FunKeywordSpacingRule.kt @@ -3,6 +3,9 @@ package com.pinterest.ktlint.ruleset.standard.rules import com.pinterest.ktlint.rule.engine.core.api.ElementType import com.pinterest.ktlint.rule.engine.core.api.ElementType.FUN_KEYWORD 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.nextLeaf import com.pinterest.ktlint.ruleset.standard.StandardRule import org.jetbrains.kotlin.com.intellij.lang.ASTNode @@ -11,6 +14,8 @@ import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.LeafPsiElement /** * Lints and formats the spacing after the fun keyword */ +@SinceKtlint("0.45", EXPERIMENTAL) +@SinceKtlint("0.49", STABLE) public class FunKeywordSpacingRule : StandardRule("fun-keyword-spacing") { override fun beforeVisitChildNodes( node: ASTNode, 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 bbb46468b5..d9a7ef01b9 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 @@ -13,6 +13,8 @@ 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.children import com.pinterest.ktlint.rule.engine.core.api.editorconfig.CODE_STYLE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.editorconfig.EditorConfig @@ -59,6 +61,7 @@ import org.jetbrains.kotlin.psi.psiUtil.getChildOfType * } * ``` */ +@SinceKtlint("1.0", EXPERIMENTAL) public class FunctionExpressionBodyRule : StandardRule( id = "function-expression-body", 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 551cbb6c96..4ef5f5fbbd 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 @@ -14,6 +14,8 @@ 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.children import com.pinterest.ktlint.rule.engine.core.api.editorconfig.CODE_STYLE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.editorconfig.EditorConfig @@ -66,6 +68,7 @@ private val LOGGER = KotlinLogging.logger {}.initKtLintKLogger() * } * ``` */ +@SinceKtlint("1.0", EXPERIMENTAL) public class FunctionLiteralRule : StandardRule( id = "function-literal", diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FunctionNamingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FunctionNamingRule.kt index 162b2713b9..d98d244d74 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FunctionNamingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FunctionNamingRule.kt @@ -3,8 +3,10 @@ package com.pinterest.ktlint.ruleset.standard.rules import com.pinterest.ktlint.rule.engine.core.api.ElementType.FUN import com.pinterest.ktlint.rule.engine.core.api.ElementType.IDENTIFIER import com.pinterest.ktlint.rule.engine.core.api.ElementType.IMPORT_DIRECTIVE -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.ruleset.standard.StandardRule import com.pinterest.ktlint.ruleset.standard.rules.internal.regExIgnoringDiacriticsAndStrokesOnLetters import org.jetbrains.kotlin.com.intellij.lang.ASTNode @@ -14,9 +16,9 @@ import org.jetbrains.kotlin.psi.KtImportDirective /** * https://kotlinlang.org/docs/coding-conventions.html#function-names */ -public class FunctionNamingRule : - StandardRule("function-naming"), - Rule.Experimental { +@SinceKtlint("0.48", EXPERIMENTAL) +@SinceKtlint("1.0", STABLE) +public class FunctionNamingRule : StandardRule("function-naming") { private var isTestClass = false override fun beforeVisitChildNodes( diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FunctionReturnTypeSpacingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FunctionReturnTypeSpacingRule.kt index 5564c7087e..ef91c6a5c0 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FunctionReturnTypeSpacingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FunctionReturnTypeSpacingRule.kt @@ -4,6 +4,9 @@ import com.pinterest.ktlint.rule.engine.core.api.ElementType.COLON import com.pinterest.ktlint.rule.engine.core.api.ElementType.FUN import com.pinterest.ktlint.rule.engine.core.api.ElementType.WHITE_SPACE 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.MAX_LINE_LENGTH_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline @@ -14,6 +17,8 @@ import com.pinterest.ktlint.ruleset.standard.StandardRule import org.jetbrains.kotlin.com.intellij.lang.ASTNode import org.jetbrains.kotlin.psi.psiUtil.leaves +@SinceKtlint("0.46", EXPERIMENTAL) +@SinceKtlint("0.49", STABLE) public class FunctionReturnTypeSpacingRule : StandardRule( id = "function-return-type-spacing", diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FunctionSignatureRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FunctionSignatureRule.kt index fdf331fefb..85fe956cb1 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FunctionSignatureRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FunctionSignatureRule.kt @@ -18,8 +18,10 @@ 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.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 @@ -51,6 +53,8 @@ import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.LeafElement import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.LeafPsiElement import org.jetbrains.kotlin.utils.addToStdlib.ifTrue +@SinceKtlint("0.46", EXPERIMENTAL) +@SinceKtlint("1.0", STABLE) public class FunctionSignatureRule : StandardRule( id = "function-signature", @@ -67,8 +71,7 @@ public class FunctionSignatureRule : FORCE_MULTILINE_WHEN_PARAMETER_COUNT_GREATER_OR_EQUAL_THAN_PROPERTY, FUNCTION_BODY_EXPRESSION_WRAPPING_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/FunctionStartOfBodySpacingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FunctionStartOfBodySpacingRule.kt index 4e845c8a82..e703cacb7c 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FunctionStartOfBodySpacingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FunctionStartOfBodySpacingRule.kt @@ -3,6 +3,9 @@ package com.pinterest.ktlint.ruleset.standard.rules import com.pinterest.ktlint.rule.engine.core.api.ElementType import com.pinterest.ktlint.rule.engine.core.api.ElementType.FUN 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.nextLeaf import com.pinterest.ktlint.rule.engine.core.api.prevLeaf import com.pinterest.ktlint.rule.engine.core.api.upsertWhitespaceAfterMe @@ -13,6 +16,8 @@ import org.jetbrains.kotlin.com.intellij.lang.ASTNode /** * Lints and formats the spacing after the fun keyword */ +@SinceKtlint("0.46", EXPERIMENTAL) +@SinceKtlint("0.49", STABLE) public class FunctionStartOfBodySpacingRule : StandardRule("function-start-of-body-spacing") { override fun beforeVisitChildNodes( node: ASTNode, 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 7b0c8e57d5..c14f798fc1 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 @@ -5,6 +5,8 @@ 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.nextCodeSibling import com.pinterest.ktlint.rule.engine.core.api.prevSibling import com.pinterest.ktlint.rule.engine.core.api.upsertWhitespaceBeforeMe @@ -14,6 +16,7 @@ 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 { diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FunctionTypeReferenceSpacingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FunctionTypeReferenceSpacingRule.kt index b01a694aa2..5f83c99f3a 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FunctionTypeReferenceSpacingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FunctionTypeReferenceSpacingRule.kt @@ -6,10 +6,14 @@ import com.pinterest.ktlint.rule.engine.core.api.ElementType.TYPE_REFERENCE import com.pinterest.ktlint.rule.engine.core.api.ElementType.VALUE_PARAMETER_LIST import com.pinterest.ktlint.rule.engine.core.api.ElementType.WHITE_SPACE 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.nextSibling import com.pinterest.ktlint.ruleset.standard.StandardRule import org.jetbrains.kotlin.com.intellij.lang.ASTNode +@SinceKtlint("0.45", EXPERIMENTAL) +@SinceKtlint("0.49", EXPERIMENTAL) public class FunctionTypeReferenceSpacingRule : StandardRule("function-type-reference-spacing") { override fun beforeVisitChildNodes( node: ASTNode, diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/IfElseBracingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/IfElseBracingRule.kt index 1cfda745e1..f84024c13a 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/IfElseBracingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/IfElseBracingRule.kt @@ -11,6 +11,9 @@ import com.pinterest.ktlint.rule.engine.core.api.ElementType.THEN 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 @@ -31,6 +34,8 @@ import org.jetbrains.kotlin.psi.psiUtil.leaves * All branches of the if-statement should be wrapped between braces if at least one branch is wrapped between braces. Consistent bracing * makes statements easier to read. */ +@SinceKtlint("0.49", EXPERIMENTAL) +@SinceKtlint("1.0", STABLE) public class IfElseBracingRule : StandardRule( id = "if-else-bracing", @@ -40,7 +45,6 @@ public class IfElseBracingRule : INDENT_STYLE_PROPERTY, ), ), - Rule.Experimental, Rule.OfficialCodeStyle { private var indentConfig = IndentConfig.DEFAULT_INDENT_CONFIG diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/IfElseWrappingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/IfElseWrappingRule.kt index 13c02ccd3e..39d9092b5d 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/IfElseWrappingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/IfElseWrappingRule.kt @@ -13,6 +13,9 @@ 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.ONLY_WHEN_RUN_AFTER_RULE_IS_LOADED_AND_ENABLED 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 @@ -36,6 +39,8 @@ import org.jetbrains.kotlin.utils.addToStdlib.applyIf * Enforce that single line if statements are kept simple. A single line if statement is allowed only when it has at most one else branch. * Also, the branches of such an if statement may not be wrapped in a block. */ +@SinceKtlint("0.49", EXPERIMENTAL) +@SinceKtlint("1.0", STABLE) public class IfElseWrappingRule : StandardRule( id = "if-else-wrapping", @@ -46,7 +51,6 @@ public class IfElseWrappingRule : INDENT_STYLE_PROPERTY, ), ), - Rule.Experimental, Rule.OfficialCodeStyle { private var indentConfig = IndentConfig.DEFAULT_INDENT_CONFIG diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ImportOrderingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ImportOrderingRule.kt index 0d86ebe121..65d46e2f6f 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ImportOrderingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ImportOrderingRule.kt @@ -3,6 +3,8 @@ package com.pinterest.ktlint.ruleset.standard.rules import com.pinterest.ktlint.logger.api.initKtLintKLogger import com.pinterest.ktlint.rule.engine.core.api.ElementType 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.STABLE import com.pinterest.ktlint.rule.engine.core.api.editorconfig.EditorConfig import com.pinterest.ktlint.rule.engine.core.api.editorconfig.EditorConfigProperty import com.pinterest.ktlint.ruleset.standard.StandardRule @@ -37,6 +39,7 @@ private val LOGGER = KotlinLogging.logger {}.initKtLintKLogger() * * In case the custom property is not provided, the rule defaults to alphabetical order in case of "android" flag supplied, or to idea otherwise. */ +@SinceKtlint("0.10", STABLE) public class ImportOrderingRule : StandardRule( id = "import-ordering", diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/IndentationRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/IndentationRule.kt index 23ce722a38..415cab2ff8 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/IndentationRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/IndentationRule.kt @@ -87,6 +87,8 @@ import com.pinterest.ktlint.rule.engine.core.api.IndentConfig.IndentStyle.SPACE import com.pinterest.ktlint.rule.engine.core.api.IndentConfig.IndentStyle.TAB 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.STABLE import com.pinterest.ktlint.rule.engine.core.api.children import com.pinterest.ktlint.rule.engine.core.api.column import com.pinterest.ktlint.rule.engine.core.api.editorconfig.CODE_STYLE_PROPERTY @@ -126,6 +128,7 @@ import java.util.LinkedList private val LOGGER = KotlinLogging.logger {}.initKtLintKLogger() +@SinceKtlint("0.1", STABLE) public class IndentationRule : StandardRule( id = "indent", diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/KdocWrappingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/KdocWrappingRule.kt index 73da2517d0..29f4a35572 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/KdocWrappingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/KdocWrappingRule.kt @@ -5,6 +5,9 @@ import com.pinterest.ktlint.rule.engine.core.api.ElementType.KDOC_END import com.pinterest.ktlint.rule.engine.core.api.ElementType.KDOC_START import com.pinterest.ktlint.rule.engine.core.api.ElementType.WHITE_SPACE 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.INDENT_SIZE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.editorconfig.INDENT_STYLE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.indent @@ -18,6 +21,8 @@ import org.jetbrains.kotlin.com.intellij.lang.ASTNode /** * Checks external wrapping of KDoc comment. Wrapping inside the KDoc comment is not altered. */ +@SinceKtlint("0.45", EXPERIMENTAL) +@SinceKtlint("0.49", STABLE) public class KdocWrappingRule : StandardRule( id = "kdoc-wrapping", diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/MaxLineLengthRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/MaxLineLengthRule.kt index 4ec0b52dad..4421b1ded3 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/MaxLineLengthRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/MaxLineLengthRule.kt @@ -3,6 +3,8 @@ package com.pinterest.ktlint.ruleset.standard.rules import com.pinterest.ktlint.rule.engine.core.api.ElementType 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.STABLE import com.pinterest.ktlint.rule.engine.core.api.editorconfig.EditorConfig import com.pinterest.ktlint.rule.engine.core.api.editorconfig.EditorConfigProperty import com.pinterest.ktlint.rule.engine.core.api.editorconfig.MAX_LINE_LENGTH_PROPERTY @@ -22,6 +24,7 @@ import org.jetbrains.kotlin.kdoc.psi.api.KDoc import org.jetbrains.kotlin.psi.KtImportDirective import org.jetbrains.kotlin.psi.KtPackageDirective +@SinceKtlint("0.9", STABLE) public class MaxLineLengthRule : StandardRule( id = "max-line-length", diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ModifierListSpacingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ModifierListSpacingRule.kt index d8a2e12961..c0bb471380 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ModifierListSpacingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ModifierListSpacingRule.kt @@ -5,6 +5,9 @@ import com.pinterest.ktlint.rule.engine.core.api.ElementType.ANNOTATION_ENTRY 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.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.indent import com.pinterest.ktlint.rule.engine.core.api.isPartOfComment @@ -18,6 +21,8 @@ import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.LeafPsiElement /** * Lint and format the spacing between the modifiers in and after the last modifier in a modifier list. */ +@SinceKtlint("0.45", EXPERIMENTAL) +@SinceKtlint("0.49", STABLE) public class ModifierListSpacingRule : StandardRule("modifier-list-spacing") { override fun beforeVisitChildNodes( node: ASTNode, diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ModifierOrderRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ModifierOrderRule.kt index 4dcb9b8411..0b4adfec80 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ModifierOrderRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ModifierOrderRule.kt @@ -27,6 +27,8 @@ import com.pinterest.ktlint.rule.engine.core.api.ElementType.SUSPEND_KEYWORD import com.pinterest.ktlint.rule.engine.core.api.ElementType.TAILREC_KEYWORD import com.pinterest.ktlint.rule.engine.core.api.ElementType.VARARG_KEYWORD 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.STABLE import com.pinterest.ktlint.ruleset.standard.StandardRule import org.jetbrains.kotlin.com.intellij.lang.ASTNode import org.jetbrains.kotlin.com.intellij.psi.tree.TokenSet @@ -34,6 +36,7 @@ import org.jetbrains.kotlin.psi.KtAnnotationEntry import org.jetbrains.kotlin.psi.KtDeclarationModifierList import java.util.Arrays +@SinceKtlint("0.7", STABLE) public class ModifierOrderRule : StandardRule("modifier-order") { // subset of ElementType.MODIFIER_KEYWORDS_ARRAY (+ annotations entries) private val order = diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/MultiLineIfElseRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/MultiLineIfElseRule.kt index 08f81d548a..47eefde2a6 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/MultiLineIfElseRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/MultiLineIfElseRule.kt @@ -12,6 +12,8 @@ import com.pinterest.ktlint.rule.engine.core.api.ElementType.RPAR import com.pinterest.ktlint.rule.engine.core.api.ElementType.THEN import com.pinterest.ktlint.rule.engine.core.api.IndentConfig 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.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 @@ -31,6 +33,7 @@ import org.jetbrains.kotlin.psi.psiUtil.leaves /** * https://kotlinlang.org/docs/reference/coding-conventions.html#formatting-control-flow-statements */ +@SinceKtlint("0.25", STABLE) public class MultiLineIfElseRule : StandardRule( id = "multiline-if-else", diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/MultilineExpressionWrappingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/MultilineExpressionWrappingRule.kt index c2a95fdf68..e5b79bdca6 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/MultilineExpressionWrappingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/MultilineExpressionWrappingRule.kt @@ -28,6 +28,9 @@ 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.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 @@ -48,6 +51,8 @@ import org.jetbrains.kotlin.com.intellij.lang.ASTNode /** * This rule wraps each multiline expression to a newline. */ +@SinceKtlint("0.49", EXPERIMENTAL) +@SinceKtlint("1.0", STABLE) public class MultilineExpressionWrappingRule : StandardRule( id = "multiline-expression-wrapping", @@ -57,7 +62,6 @@ public class MultilineExpressionWrappingRule : INDENT_STYLE_PROPERTY, ), ), - Rule.Experimental, Rule.OfficialCodeStyle { private var indentConfig = DEFAULT_INDENT_CONFIG diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoBlankLineBeforeRbraceRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoBlankLineBeforeRbraceRule.kt index 6c16e269f7..15405905fe 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoBlankLineBeforeRbraceRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoBlankLineBeforeRbraceRule.kt @@ -2,12 +2,15 @@ package com.pinterest.ktlint.ruleset.standard.rules import com.pinterest.ktlint.rule.engine.core.api.ElementType.RBRACE 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.STABLE import com.pinterest.ktlint.rule.engine.core.api.nextLeaf import com.pinterest.ktlint.ruleset.standard.StandardRule import org.jetbrains.kotlin.com.intellij.lang.ASTNode import org.jetbrains.kotlin.com.intellij.psi.PsiWhiteSpace import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.LeafPsiElement +@SinceKtlint("0.10.2", STABLE) public class NoBlankLineBeforeRbraceRule : StandardRule("no-blank-line-before-rbrace") { override fun beforeVisitChildNodes( node: ASTNode, diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoBlankLineInListRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoBlankLineInListRule.kt index e164722709..9adfc0aa3b 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoBlankLineInListRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoBlankLineInListRule.kt @@ -10,6 +10,9 @@ 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.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.nextSibling import com.pinterest.ktlint.rule.engine.core.api.prevSibling import com.pinterest.ktlint.ruleset.standard.StandardRule @@ -17,9 +20,10 @@ import org.jetbrains.kotlin.com.intellij.lang.ASTNode import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.LeafPsiElement import org.jetbrains.kotlin.com.intellij.psi.tree.IElementType +@SinceKtlint("0.49", EXPERIMENTAL) +@SinceKtlint("1.0", STABLE) public class NoBlankLineInListRule : StandardRule("no-blank-line-in-list"), - Rule.Experimental, Rule.OfficialCodeStyle { override fun beforeVisitChildNodes( node: ASTNode, diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoBlankLinesInChainedMethodCallsRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoBlankLinesInChainedMethodCallsRule.kt index 1a5ab3472a..3b8cc863b7 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoBlankLinesInChainedMethodCallsRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoBlankLinesInChainedMethodCallsRule.kt @@ -2,11 +2,13 @@ package com.pinterest.ktlint.ruleset.standard.rules import com.pinterest.ktlint.rule.engine.core.api.ElementType.DOT_QUALIFIED_EXPRESSION import com.pinterest.ktlint.rule.engine.core.api.RuleId +import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint import com.pinterest.ktlint.ruleset.standard.StandardRule import org.jetbrains.kotlin.com.intellij.lang.ASTNode import org.jetbrains.kotlin.com.intellij.psi.PsiWhiteSpace import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.LeafPsiElement +@SinceKtlint("0.46", SinceKtlint.Status.STABLE) public class NoBlankLinesInChainedMethodCallsRule : StandardRule("no-blank-lines-in-chained-method-calls") { override fun beforeVisitChildNodes( node: ASTNode, diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoConsecutiveBlankLinesRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoConsecutiveBlankLinesRule.kt index fc871a22c2..1b31726008 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoConsecutiveBlankLinesRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoConsecutiveBlankLinesRule.kt @@ -4,6 +4,8 @@ import com.pinterest.ktlint.rule.engine.core.api.ElementType.CLASS import com.pinterest.ktlint.rule.engine.core.api.ElementType.IDENTIFIER import com.pinterest.ktlint.rule.engine.core.api.ElementType.PRIMARY_CONSTRUCTOR 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.STABLE import com.pinterest.ktlint.rule.engine.core.api.nextLeaf import com.pinterest.ktlint.rule.engine.core.api.prevCodeLeaf import com.pinterest.ktlint.ruleset.standard.StandardRule @@ -11,6 +13,7 @@ import org.jetbrains.kotlin.com.intellij.lang.ASTNode import org.jetbrains.kotlin.com.intellij.psi.PsiWhiteSpace import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.LeafPsiElement +@SinceKtlint("0.1", STABLE) public class NoConsecutiveBlankLinesRule : StandardRule("no-consecutive-blank-lines") { override fun beforeVisitChildNodes( node: ASTNode, diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoConsecutiveCommentsRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoConsecutiveCommentsRule.kt index 7f14a4ff9f..0d1b1a04b4 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoConsecutiveCommentsRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoConsecutiveCommentsRule.kt @@ -6,6 +6,9 @@ import com.pinterest.ktlint.rule.engine.core.api.ElementType.KDOC_END import com.pinterest.ktlint.rule.engine.core.api.ElementType.KDOC_START 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.isWhiteSpace import com.pinterest.ktlint.rule.engine.core.api.prevLeaf import com.pinterest.ktlint.ruleset.standard.StandardRule @@ -19,9 +22,10 @@ import org.jetbrains.kotlin.com.intellij.lang.ASTNode * * Consecutive EOL comments are always allowed as they are often used instead of a block comment. */ +@SinceKtlint("0.49", EXPERIMENTAL) +@SinceKtlint("1.0", STABLE) public class NoConsecutiveCommentsRule : StandardRule("no-consecutive-comments"), - Rule.Experimental, Rule.OfficialCodeStyle { override fun beforeVisitChildNodes( node: ASTNode, diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoEmptyClassBodyRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoEmptyClassBodyRule.kt index 00be584ec9..fe43aca326 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoEmptyClassBodyRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoEmptyClassBodyRule.kt @@ -5,6 +5,8 @@ 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.WHITE_SPACE 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.STABLE import com.pinterest.ktlint.rule.engine.core.api.children import com.pinterest.ktlint.rule.engine.core.api.isPartOf import com.pinterest.ktlint.rule.engine.core.api.nextLeaf @@ -12,6 +14,7 @@ import com.pinterest.ktlint.ruleset.standard.StandardRule import org.jetbrains.kotlin.com.intellij.lang.ASTNode import org.jetbrains.kotlin.psi.KtObjectLiteralExpression +@SinceKtlint("0.9", STABLE) public class NoEmptyClassBodyRule : StandardRule("no-empty-class-body") { override fun beforeVisitChildNodes( node: ASTNode, diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoEmptyFileRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoEmptyFileRule.kt index 9661f7a760..4da4869c08 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoEmptyFileRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoEmptyFileRule.kt @@ -1,8 +1,10 @@ package com.pinterest.ktlint.ruleset.standard.rules import com.pinterest.ktlint.rule.engine.core.api.ElementType -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.isPartOfComment import com.pinterest.ktlint.rule.engine.core.api.isRoot @@ -10,9 +12,9 @@ import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace import com.pinterest.ktlint.ruleset.standard.StandardRule import org.jetbrains.kotlin.com.intellij.lang.ASTNode -public class NoEmptyFileRule : - StandardRule(id = "no-empty-file"), - Rule.Experimental { +@SinceKtlint("0.50", EXPERIMENTAL) +@SinceKtlint("1.0", STABLE) +public class NoEmptyFileRule : StandardRule(id = "no-empty-file") { override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoEmptyFirstLineInClassBodyRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoEmptyFirstLineInClassBodyRule.kt index 00a3e5e992..9a280e1e79 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoEmptyFirstLineInClassBodyRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoEmptyFirstLineInClassBodyRule.kt @@ -4,6 +4,9 @@ import com.pinterest.ktlint.rule.engine.core.api.ElementType.CLASS_BODY 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 @@ -13,6 +16,8 @@ import com.pinterest.ktlint.ruleset.standard.StandardRule import org.jetbrains.kotlin.com.intellij.lang.ASTNode import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.LeafPsiElement +@SinceKtlint("0.49", EXPERIMENTAL) +@SinceKtlint("1.0", STABLE) public class NoEmptyFirstLineInClassBodyRule : StandardRule( id = "no-empty-first-line-in-class-body", @@ -22,7 +27,6 @@ public class NoEmptyFirstLineInClassBodyRule : INDENT_STYLE_PROPERTY, ), ), - Rule.Experimental, Rule.OfficialCodeStyle { private var indentConfig = IndentConfig.DEFAULT_INDENT_CONFIG diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoEmptyFirstLineInMethodBlockRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoEmptyFirstLineInMethodBlockRule.kt index e27c35f374..e55ea2c08b 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoEmptyFirstLineInMethodBlockRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoEmptyFirstLineInMethodBlockRule.kt @@ -4,6 +4,9 @@ import com.pinterest.ktlint.rule.engine.core.api.ElementType import com.pinterest.ktlint.rule.engine.core.api.ElementType.CLASS_BODY import com.pinterest.ktlint.rule.engine.core.api.ElementType.FUN 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.isPartOf import com.pinterest.ktlint.rule.engine.core.api.prevLeaf import com.pinterest.ktlint.ruleset.standard.StandardRule @@ -11,6 +14,8 @@ import org.jetbrains.kotlin.com.intellij.lang.ASTNode import org.jetbrains.kotlin.com.intellij.psi.PsiWhiteSpace import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.LeafPsiElement +@SinceKtlint("0.34", EXPERIMENTAL) +@SinceKtlint("0.46", STABLE) public class NoEmptyFirstLineInMethodBlockRule : StandardRule("no-empty-first-line-in-method-block") { override fun beforeVisitChildNodes( node: ASTNode, diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoLineBreakAfterElseRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoLineBreakAfterElseRule.kt index 2699e724a7..ea83c56504 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoLineBreakAfterElseRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoLineBreakAfterElseRule.kt @@ -4,6 +4,8 @@ import com.pinterest.ktlint.rule.engine.core.api.ElementType.ELSE_KEYWORD import com.pinterest.ktlint.rule.engine.core.api.ElementType.IF_KEYWORD import com.pinterest.ktlint.rule.engine.core.api.ElementType.LBRACE 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.STABLE import com.pinterest.ktlint.rule.engine.core.api.nextLeaf import com.pinterest.ktlint.rule.engine.core.api.prevLeaf import com.pinterest.ktlint.ruleset.standard.StandardRule @@ -11,6 +13,7 @@ import org.jetbrains.kotlin.com.intellij.lang.ASTNode import org.jetbrains.kotlin.com.intellij.psi.PsiWhiteSpace import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.LeafPsiElement +@SinceKtlint("0.15", STABLE) public class NoLineBreakAfterElseRule : StandardRule("no-line-break-after-else") { override fun beforeVisitChildNodes( node: ASTNode, diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoLineBreakBeforeAssignmentRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoLineBreakBeforeAssignmentRule.kt index fe34da7e58..4503603aaf 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoLineBreakBeforeAssignmentRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoLineBreakBeforeAssignmentRule.kt @@ -2,6 +2,8 @@ package com.pinterest.ktlint.ruleset.standard.rules import com.pinterest.ktlint.rule.engine.core.api.ElementType.EQ 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.STABLE import com.pinterest.ktlint.rule.engine.core.api.isPartOfComment import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline @@ -13,6 +15,7 @@ import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.LeafPsiElement import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.PsiWhiteSpaceImpl import org.jetbrains.kotlin.psi.psiUtil.siblings +@SinceKtlint("0.13", STABLE) public class NoLineBreakBeforeAssignmentRule : StandardRule("no-line-break-before-assignment") { override fun beforeVisitChildNodes( node: ASTNode, diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoMultipleSpacesRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoMultipleSpacesRule.kt index 1b5c6c0922..a6ceb95499 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoMultipleSpacesRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoMultipleSpacesRule.kt @@ -3,11 +3,14 @@ package com.pinterest.ktlint.ruleset.standard.rules import com.pinterest.ktlint.rule.engine.core.api.ElementType.KDOC_MARKDOWN_LINK import com.pinterest.ktlint.rule.engine.core.api.ElementType.KDOC_TAG 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.STABLE import com.pinterest.ktlint.ruleset.standard.StandardRule import org.jetbrains.kotlin.com.intellij.lang.ASTNode import org.jetbrains.kotlin.com.intellij.psi.PsiWhiteSpace import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.LeafPsiElement +@SinceKtlint("0.2", STABLE) public class NoMultipleSpacesRule : StandardRule("no-multi-spaces") { override fun beforeVisitChildNodes( node: ASTNode, diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoSemicolonsRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoSemicolonsRule.kt index b651dee99f..c80ab10159 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoSemicolonsRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoSemicolonsRule.kt @@ -6,6 +6,8 @@ import com.pinterest.ktlint.rule.engine.core.api.ElementType.OBJECT_KEYWORD import com.pinterest.ktlint.rule.engine.core.api.ElementType.SEMICOLON import com.pinterest.ktlint.rule.engine.core.api.Rule.VisitorModifier.RunAfterRule 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.STABLE import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace import com.pinterest.ktlint.rule.engine.core.api.lastChildLeafOrSelf import com.pinterest.ktlint.rule.engine.core.api.nextLeaf @@ -25,6 +27,7 @@ import org.jetbrains.kotlin.psi.KtIfExpression import org.jetbrains.kotlin.psi.KtLoopExpression import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType +@SinceKtlint("0.1", STABLE) public class NoSemicolonsRule : StandardRule( id = "no-semi", diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoSingleLineBlockCommentRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoSingleLineBlockCommentRule.kt index e51babdebf..6095a27386 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoSingleLineBlockCommentRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoSingleLineBlockCommentRule.kt @@ -6,6 +6,9 @@ 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.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.INDENT_SIZE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.editorconfig.INDENT_STYLE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace @@ -21,6 +24,8 @@ import org.jetbrains.kotlin.psi.psiUtil.leaves /** * A block comment following another element on the same line is replaced with an EOL comment, if possible. */ +@SinceKtlint("0.49.1", EXPERIMENTAL) +@SinceKtlint("1.0", STABLE) public class NoSingleLineBlockCommentRule : StandardRule( id = "no-single-line-block-comment", @@ -31,7 +36,6 @@ public class NoSingleLineBlockCommentRule : ), visitorModifiers = setOf(RunAfterRule(COMMENT_WRAPPING_RULE_ID, REGARDLESS_WHETHER_RUN_AFTER_RULE_IS_LOADED_OR_DISABLED)), ), - Rule.Experimental, Rule.OfficialCodeStyle { override fun beforeVisitChildNodes( node: ASTNode, diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoTrailingSpacesRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoTrailingSpacesRule.kt index e1a44b7518..4dc21993e6 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoTrailingSpacesRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoTrailingSpacesRule.kt @@ -3,6 +3,8 @@ package com.pinterest.ktlint.ruleset.standard.rules import com.pinterest.ktlint.rule.engine.core.api.ElementType.EOL_COMMENT import com.pinterest.ktlint.rule.engine.core.api.ElementType.WHITE_SPACE 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.STABLE import com.pinterest.ktlint.rule.engine.core.api.isPartOfComment import com.pinterest.ktlint.rule.engine.core.api.nextLeaf import com.pinterest.ktlint.rule.engine.core.api.parent @@ -11,6 +13,7 @@ import org.jetbrains.kotlin.com.intellij.lang.ASTNode import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.LeafPsiElement import org.jetbrains.kotlin.kdoc.psi.api.KDoc +@SinceKtlint("0.1", STABLE) public class NoTrailingSpacesRule : StandardRule("no-trailing-spaces") { override fun beforeVisitChildNodes( node: ASTNode, diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoUnitReturnRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoUnitReturnRule.kt index 7473933b4e..d059ad119f 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoUnitReturnRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoUnitReturnRule.kt @@ -5,10 +5,13 @@ import com.pinterest.ktlint.rule.engine.core.api.ElementType.LBRACE import com.pinterest.ktlint.rule.engine.core.api.ElementType.TYPE_REFERENCE 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.STABLE import com.pinterest.ktlint.rule.engine.core.api.nextCodeLeaf import com.pinterest.ktlint.ruleset.standard.StandardRule import org.jetbrains.kotlin.com.intellij.lang.ASTNode +@SinceKtlint("0.7", STABLE) public class NoUnitReturnRule : StandardRule("no-unit-return") { override fun beforeVisitChildNodes( node: ASTNode, diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoUnusedImportsRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoUnusedImportsRule.kt index 72998ef1c8..cddcd04067 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoUnusedImportsRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoUnusedImportsRule.kt @@ -9,6 +9,8 @@ import com.pinterest.ktlint.rule.engine.core.api.ElementType.OPERATION_REFERENCE import com.pinterest.ktlint.rule.engine.core.api.ElementType.PACKAGE_DIRECTIVE import com.pinterest.ktlint.rule.engine.core.api.ElementType.REFERENCE_EXPRESSION 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.STABLE import com.pinterest.ktlint.rule.engine.core.api.isPartOf import com.pinterest.ktlint.rule.engine.core.api.isRoot import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline @@ -31,6 +33,7 @@ import org.jetbrains.kotlin.psi.KtImportDirective import org.jetbrains.kotlin.psi.KtPackageDirective import org.jetbrains.kotlin.resolve.ImportPath +@SinceKtlint("0.2", STABLE) public class NoUnusedImportsRule : StandardRule("no-unused-imports") { private val ref = mutableSetOf( diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoWildcardImportsRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoWildcardImportsRule.kt index bd497dec92..153df4f75f 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoWildcardImportsRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoWildcardImportsRule.kt @@ -2,6 +2,8 @@ package com.pinterest.ktlint.ruleset.standard.rules import com.pinterest.ktlint.rule.engine.core.api.ElementType.IMPORT_DIRECTIVE 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.STABLE import com.pinterest.ktlint.rule.engine.core.api.editorconfig.EditorConfig import com.pinterest.ktlint.rule.engine.core.api.editorconfig.EditorConfigProperty import com.pinterest.ktlint.ruleset.standard.StandardRule @@ -10,6 +12,7 @@ import org.ec4j.core.model.PropertyType import org.jetbrains.kotlin.com.intellij.lang.ASTNode import org.jetbrains.kotlin.psi.KtImportDirective +@SinceKtlint("0.2", STABLE) public class NoWildcardImportsRule : StandardRule( id = "no-wildcard-imports", diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NullableTypeSpacingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NullableTypeSpacingRule.kt index b10e9f8d0e..c93222ec61 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NullableTypeSpacingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NullableTypeSpacingRule.kt @@ -3,11 +3,16 @@ package com.pinterest.ktlint.ruleset.standard.rules import com.pinterest.ktlint.rule.engine.core.api.ElementType.QUEST import com.pinterest.ktlint.rule.engine.core.api.ElementType.WHITE_SPACE 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.prevLeaf import com.pinterest.ktlint.ruleset.standard.StandardRule import org.jetbrains.kotlin.com.intellij.lang.ASTNode import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.LeafPsiElement +@SinceKtlint("0.46", EXPERIMENTAL) +@SinceKtlint("0.49", STABLE) public class NullableTypeSpacingRule : StandardRule("nullable-type-spacing") { override fun beforeVisitChildNodes( node: ASTNode, diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/PackageNameRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/PackageNameRule.kt index 48747b2936..49b9033226 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/PackageNameRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/PackageNameRule.kt @@ -3,6 +3,8 @@ package com.pinterest.ktlint.ruleset.standard.rules import com.pinterest.ktlint.rule.engine.core.api.ElementType import com.pinterest.ktlint.rule.engine.core.api.ElementType.PACKAGE_DIRECTIVE 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.STABLE import com.pinterest.ktlint.rule.engine.core.api.nextCodeSibling import com.pinterest.ktlint.ruleset.standard.StandardRule import com.pinterest.ktlint.ruleset.standard.rules.internal.regExIgnoringDiacriticsAndStrokesOnLetters @@ -11,6 +13,7 @@ import org.jetbrains.kotlin.com.intellij.lang.ASTNode /** * https://kotlinlang.org/docs/coding-conventions.html#naming-rules */ +@SinceKtlint("0.25", STABLE) public class PackageNameRule : StandardRule("package-name") { override fun beforeVisitChildNodes( node: ASTNode, diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ParameterListSpacingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ParameterListSpacingRule.kt index af8fd15019..40817d11de 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ParameterListSpacingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ParameterListSpacingRule.kt @@ -8,8 +8,10 @@ import com.pinterest.ktlint.rule.engine.core.api.ElementType.TYPE_REFERENCE 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.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.children import com.pinterest.ktlint.rule.engine.core.api.isPartOfComment import com.pinterest.ktlint.rule.engine.core.api.nextCodeSibling @@ -28,9 +30,9 @@ import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.LeafPsiElement * commas and colons. However, it does have a more complete view on the higher concept of the parameter-list without * interfering of the parameter-list-wrapping rule. */ -public class ParameterListSpacingRule : - StandardRule("parameter-list-spacing"), - Rule.Experimental { +@SinceKtlint("0.46", EXPERIMENTAL) +@SinceKtlint("1.0", STABLE) +public class ParameterListSpacingRule : StandardRule("parameter-list-spacing") { override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ParameterListWrappingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ParameterListWrappingRule.kt index f428e3745f..d227508952 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ParameterListWrappingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ParameterListWrappingRule.kt @@ -12,6 +12,8 @@ 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.RuleId +import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint +import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE import com.pinterest.ktlint.rule.engine.core.api.column import com.pinterest.ktlint.rule.engine.core.api.editorconfig.CODE_STYLE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.editorconfig.CodeStyleValue.ktlint_official @@ -36,6 +38,7 @@ import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.PsiWhiteSpaceImpl import org.jetbrains.kotlin.psi.psiUtil.children import org.jetbrains.kotlin.psi.psiUtil.leaves +@SinceKtlint("0.16", STABLE) public class ParameterListWrappingRule : StandardRule( id = "parameter-list-wrapping", diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ParameterWrappingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ParameterWrappingRule.kt index 4dd2fb664a..35f2dfa9be 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ParameterWrappingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ParameterWrappingRule.kt @@ -11,6 +11,8 @@ import com.pinterest.ktlint.rule.engine.core.api.ElementType.VALUE_PARAMETER 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.RuleId +import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint +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 @@ -39,6 +41,7 @@ private val LOGGER = KotlinLogging.logger {}.initKtLintKLogger() * * This rule has many similarities with the [PropertyWrappingRule] but some subtle differences. */ +@SinceKtlint("0.49", STABLE) public class ParameterWrappingRule : StandardRule( id = "parameter-wrapping", diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/PropertyNamingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/PropertyNamingRule.kt index 0e5d2f7120..b604267bb4 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/PropertyNamingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/PropertyNamingRule.kt @@ -12,8 +12,10 @@ import com.pinterest.ktlint.rule.engine.core.api.ElementType.PRIVATE_KEYWORD import com.pinterest.ktlint.rule.engine.core.api.ElementType.PROPERTY import com.pinterest.ktlint.rule.engine.core.api.ElementType.PROPERTY_ACCESSOR import com.pinterest.ktlint.rule.engine.core.api.ElementType.VAL_KEYWORD -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.ruleset.standard.StandardRule import com.pinterest.ktlint.ruleset.standard.rules.internal.regExIgnoringDiacriticsAndStrokesOnLetters @@ -24,9 +26,9 @@ import org.jetbrains.kotlin.com.intellij.psi.tree.IElementType * https://kotlinlang.org/docs/coding-conventions.html#function-names * https://kotlinlang.org/docs/coding-conventions.html#property-names */ -public class PropertyNamingRule : - StandardRule("property-naming"), - Rule.Experimental { +@SinceKtlint("0.48", EXPERIMENTAL) +@SinceKtlint("1.0", STABLE) +public class PropertyNamingRule : StandardRule("property-naming") { override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/PropertyWrappingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/PropertyWrappingRule.kt index 1a5cb283e9..6e6764c768 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/PropertyWrappingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/PropertyWrappingRule.kt @@ -10,6 +10,7 @@ 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.IndentConfig.Companion.DEFAULT_INDENT_CONFIG 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.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 @@ -37,6 +38,7 @@ private val LOGGER = KotlinLogging.logger {}.initKtLintKLogger() * * This rule has many similarities with the [ParameterWrappingRule] but some subtle differences. */ +@SinceKtlint("0.49", SinceKtlint.Status.STABLE) public class PropertyWrappingRule : StandardRule( id = "property-wrapping", diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundAngleBracketsRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundAngleBracketsRule.kt index 809a68c4e0..d016ea680d 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundAngleBracketsRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundAngleBracketsRule.kt @@ -7,6 +7,8 @@ import com.pinterest.ktlint.rule.engine.core.api.ElementType.VAL_KEYWORD import com.pinterest.ktlint.rule.engine.core.api.ElementType.VAR_KEYWORD import com.pinterest.ktlint.rule.engine.core.api.ElementType.WHITE_SPACE 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.STABLE import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithoutNewline import com.pinterest.ktlint.rule.engine.core.api.nextLeaf import com.pinterest.ktlint.rule.engine.core.api.prevLeaf @@ -14,6 +16,7 @@ import com.pinterest.ktlint.ruleset.standard.StandardRule import org.jetbrains.kotlin.com.intellij.lang.ASTNode import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.LeafElement +@SinceKtlint("0.30", STABLE) public class SpacingAroundAngleBracketsRule : StandardRule("spacing-around-angle-brackets") { override fun beforeVisitChildNodes( node: ASTNode, diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundColonRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundColonRule.kt index 4105a3c79e..5dd34b8650 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundColonRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundColonRule.kt @@ -3,6 +3,8 @@ package com.pinterest.ktlint.ruleset.standard.rules import com.pinterest.ktlint.rule.engine.core.api.ElementType.COLON import com.pinterest.ktlint.rule.engine.core.api.ElementType.EQ 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.STABLE import com.pinterest.ktlint.rule.engine.core.api.isPartOfComment import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline @@ -28,6 +30,7 @@ import org.jetbrains.kotlin.psi.KtTypeParameterList import org.jetbrains.kotlin.psi.psiUtil.siblings import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull +@SinceKtlint("0.1", STABLE) public class SpacingAroundColonRule : StandardRule("colon-spacing") { override fun beforeVisitChildNodes( node: ASTNode, diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundCommaRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundCommaRule.kt index a908db7b97..efd6a89cc1 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundCommaRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundCommaRule.kt @@ -4,6 +4,8 @@ import com.pinterest.ktlint.rule.engine.core.api.ElementType.GT import com.pinterest.ktlint.rule.engine.core.api.ElementType.RBRACKET import com.pinterest.ktlint.rule.engine.core.api.ElementType.RPAR 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.STABLE import com.pinterest.ktlint.rule.engine.core.api.isPartOfString import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline import com.pinterest.ktlint.rule.engine.core.api.nextLeaf @@ -18,6 +20,7 @@ import org.jetbrains.kotlin.com.intellij.psi.PsiWhiteSpace import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.LeafPsiElement import org.jetbrains.kotlin.com.intellij.psi.tree.TokenSet +@SinceKtlint("0.1", STABLE) public class SpacingAroundCommaRule : StandardRule("comma-spacing") { private val rTokenSet = TokenSet.create(RPAR, RBRACKET, GT) diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundCurlyRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundCurlyRule.kt index fa68f7a06f..3d01f1c888 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundCurlyRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundCurlyRule.kt @@ -18,6 +18,8 @@ import com.pinterest.ktlint.rule.engine.core.api.ElementType.RPAR import com.pinterest.ktlint.rule.engine.core.api.ElementType.SAFE_ACCESS import com.pinterest.ktlint.rule.engine.core.api.ElementType.SEMICOLON 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.STABLE import com.pinterest.ktlint.rule.engine.core.api.isLeaf import com.pinterest.ktlint.rule.engine.core.api.isPartOfString import com.pinterest.ktlint.rule.engine.core.api.nextLeaf @@ -33,6 +35,7 @@ import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.TreeElement import org.jetbrains.kotlin.lexer.KtTokens import org.jetbrains.kotlin.psi.KtLambdaExpression +@SinceKtlint("0.1", STABLE) public class SpacingAroundCurlyRule : StandardRule("curly-spacing") { override fun beforeVisitChildNodes( node: ASTNode, diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundDotRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundDotRule.kt index f5d3eee497..ac2d3f15b3 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundDotRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundDotRule.kt @@ -1,6 +1,8 @@ package com.pinterest.ktlint.ruleset.standard.rules 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.STABLE import com.pinterest.ktlint.rule.engine.core.api.isPartOfComment import com.pinterest.ktlint.rule.engine.core.api.isPartOfString import com.pinterest.ktlint.rule.engine.core.api.nextLeaf @@ -10,6 +12,7 @@ import org.jetbrains.kotlin.com.intellij.lang.ASTNode import org.jetbrains.kotlin.com.intellij.psi.PsiWhiteSpace import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.LeafPsiElement +@SinceKtlint("0.30", STABLE) public class SpacingAroundDotRule : StandardRule("dot-spacing") { override fun beforeVisitChildNodes( node: ASTNode, diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundDoubleColonRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundDoubleColonRule.kt index cea0b21d42..0c339c11e4 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundDoubleColonRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundDoubleColonRule.kt @@ -4,6 +4,8 @@ import com.pinterest.ktlint.rule.engine.core.api.ElementType.CALLABLE_REFERENCE_ import com.pinterest.ktlint.rule.engine.core.api.ElementType.CLASS_LITERAL_EXPRESSION import com.pinterest.ktlint.rule.engine.core.api.ElementType.COLONCOLON 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.STABLE import com.pinterest.ktlint.rule.engine.core.api.isPartOf import com.pinterest.ktlint.rule.engine.core.api.nextLeaf import com.pinterest.ktlint.rule.engine.core.api.prevLeaf @@ -12,6 +14,7 @@ import org.jetbrains.kotlin.com.intellij.lang.ASTNode import org.jetbrains.kotlin.com.intellij.psi.PsiWhiteSpace import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.LeafPsiElement +@SinceKtlint("0.37", STABLE) public class SpacingAroundDoubleColonRule : StandardRule("double-colon-spacing") { override fun beforeVisitChildNodes( node: ASTNode, diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundKeywordRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundKeywordRule.kt index fe4eace2bd..a0672889cf 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundKeywordRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundKeywordRule.kt @@ -14,6 +14,8 @@ import com.pinterest.ktlint.rule.engine.core.api.ElementType.WHEN_KEYWORD import com.pinterest.ktlint.rule.engine.core.api.ElementType.WHILE_KEYWORD import com.pinterest.ktlint.rule.engine.core.api.ElementType.WHITE_SPACE 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.STABLE import com.pinterest.ktlint.rule.engine.core.api.nextLeaf import com.pinterest.ktlint.rule.engine.core.api.prevLeaf import com.pinterest.ktlint.rule.engine.core.api.upsertWhitespaceAfterMe @@ -28,6 +30,7 @@ import org.jetbrains.kotlin.psi.KtBlockExpression import org.jetbrains.kotlin.psi.KtPropertyAccessor import org.jetbrains.kotlin.psi.KtWhenEntry +@SinceKtlint("0.1", STABLE) public class SpacingAroundKeywordRule : StandardRule("keyword-spacing") { private val noLFBeforeSet = create(ELSE_KEYWORD, CATCH_KEYWORD, FINALLY_KEYWORD) private val tokenSet = diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundOperatorsRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundOperatorsRule.kt index 539b40b7ed..5dc088adfc 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundOperatorsRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundOperatorsRule.kt @@ -26,6 +26,8 @@ import com.pinterest.ktlint.rule.engine.core.api.ElementType.PLUS import com.pinterest.ktlint.rule.engine.core.api.ElementType.PLUSEQ import com.pinterest.ktlint.rule.engine.core.api.ElementType.VALUE_ARGUMENT 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.STABLE import com.pinterest.ktlint.rule.engine.core.api.isPartOf import com.pinterest.ktlint.rule.engine.core.api.nextLeaf import com.pinterest.ktlint.rule.engine.core.api.prevLeaf @@ -38,6 +40,7 @@ import org.jetbrains.kotlin.com.intellij.psi.tree.TokenSet import org.jetbrains.kotlin.psi.KtImportDirective import org.jetbrains.kotlin.psi.KtPrefixExpression +@SinceKtlint("0.1", STABLE) public class SpacingAroundOperatorsRule : StandardRule("op-spacing") { private val tokenSet = TokenSet.create( diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundParensRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundParensRule.kt index 10158fcd15..1b4878df0b 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundParensRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundParensRule.kt @@ -12,6 +12,8 @@ import com.pinterest.ktlint.rule.engine.core.api.ElementType.SUPER_KEYWORD import com.pinterest.ktlint.rule.engine.core.api.ElementType.VALUE_ARGUMENT_LIST 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.STABLE import com.pinterest.ktlint.rule.engine.core.api.nextLeaf import com.pinterest.ktlint.rule.engine.core.api.prevLeaf import com.pinterest.ktlint.ruleset.standard.StandardRule @@ -23,6 +25,7 @@ import org.jetbrains.kotlin.com.intellij.psi.PsiWhiteSpace * * See https://kotlinlang.org/docs/reference/coding-conventions.html#horizontal-whitespace */ +@SinceKtlint("0.24", STABLE) public class SpacingAroundParensRule : StandardRule("paren-spacing") { override fun beforeVisitChildNodes( node: ASTNode, diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundRangeOperatorRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundRangeOperatorRule.kt index 303e6088b9..bcd25ee1e4 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundRangeOperatorRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundRangeOperatorRule.kt @@ -3,6 +3,8 @@ package com.pinterest.ktlint.ruleset.standard.rules import com.pinterest.ktlint.rule.engine.core.api.ElementType.RANGE import com.pinterest.ktlint.rule.engine.core.api.ElementType.RANGE_UNTIL 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.STABLE import com.pinterest.ktlint.rule.engine.core.api.nextLeaf import com.pinterest.ktlint.rule.engine.core.api.prevLeaf import com.pinterest.ktlint.ruleset.standard.StandardRule @@ -10,6 +12,7 @@ import org.jetbrains.kotlin.com.intellij.lang.ASTNode import org.jetbrains.kotlin.com.intellij.psi.PsiWhiteSpace import org.jetbrains.kotlin.lexer.KtSingleValueToken +@SinceKtlint("0.13", STABLE) public class SpacingAroundRangeOperatorRule : StandardRule("range-spacing") { override fun beforeVisitChildNodes( node: ASTNode, diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundUnaryOperatorRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundUnaryOperatorRule.kt index b3095378d0..a8fa5f048d 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundUnaryOperatorRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundUnaryOperatorRule.kt @@ -2,6 +2,9 @@ package com.pinterest.ktlint.ruleset.standard.rules import com.pinterest.ktlint.rule.engine.core.api.ElementType 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.isPartOfComment import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace @@ -13,6 +16,8 @@ import org.jetbrains.kotlin.com.intellij.lang.ASTNode * * @see [Kotlin Style Guide](https://kotlinlang.org/docs/reference/coding-conventions.html#horizontal-whitespace) */ +@SinceKtlint("0.38", EXPERIMENTAL) +@SinceKtlint("0.46", STABLE) public class SpacingAroundUnaryOperatorRule : StandardRule("unary-op-spacing") { override fun beforeVisitChildNodes( node: ASTNode, diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingBetweenDeclarationsWithAnnotationsRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingBetweenDeclarationsWithAnnotationsRule.kt index 5d52cd19b2..31e58179b7 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingBetweenDeclarationsWithAnnotationsRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingBetweenDeclarationsWithAnnotationsRule.kt @@ -2,6 +2,9 @@ package com.pinterest.ktlint.ruleset.standard.rules import com.pinterest.ktlint.rule.engine.core.api.ElementType.MODIFIER_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.indent import com.pinterest.ktlint.rule.engine.core.api.isPartOfComment @@ -19,6 +22,8 @@ import org.jetbrains.kotlin.psi.psiUtil.leaves /** * @see https://youtrack.jetbrains.com/issue/KT-35106 */ +@SinceKtlint("0.37", EXPERIMENTAL) +@SinceKtlint("0.46", STABLE) public class SpacingBetweenDeclarationsWithAnnotationsRule : StandardRule("spacing-between-declarations-with-annotations") { override fun beforeVisitChildNodes( node: ASTNode, diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingBetweenDeclarationsWithCommentsRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingBetweenDeclarationsWithCommentsRule.kt index fed6c14dab..960c21c7b3 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingBetweenDeclarationsWithCommentsRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingBetweenDeclarationsWithCommentsRule.kt @@ -3,6 +3,9 @@ package com.pinterest.ktlint.ruleset.standard.rules import com.pinterest.ktlint.rule.engine.core.api.ElementType.FILE import com.pinterest.ktlint.rule.engine.core.api.ElementType.WHITE_SPACE 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.prevLeaf import com.pinterest.ktlint.rule.engine.core.api.prevSibling import com.pinterest.ktlint.ruleset.standard.StandardRule @@ -17,6 +20,8 @@ import org.jetbrains.kotlin.psi.psiUtil.startOffset /** * @see https://youtrack.jetbrains.com/issue/KT-35088 */ +@SinceKtlint("0.37", EXPERIMENTAL) +@SinceKtlint("0.46", STABLE) public class SpacingBetweenDeclarationsWithCommentsRule : StandardRule("spacing-between-declarations-with-comments") { override fun beforeVisitChildNodes( node: ASTNode, diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingBetweenFunctionNameAndOpeningParenthesisRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingBetweenFunctionNameAndOpeningParenthesisRule.kt index b61ffad9c4..cd038ba79f 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingBetweenFunctionNameAndOpeningParenthesisRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingBetweenFunctionNameAndOpeningParenthesisRule.kt @@ -3,10 +3,15 @@ package com.pinterest.ktlint.ruleset.standard.rules import com.pinterest.ktlint.rule.engine.core.api.ElementType import com.pinterest.ktlint.rule.engine.core.api.ElementType.WHITE_SPACE 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.nextSibling import com.pinterest.ktlint.ruleset.standard.StandardRule import org.jetbrains.kotlin.com.intellij.lang.ASTNode +@SinceKtlint("0.46", EXPERIMENTAL) +@SinceKtlint("0.49", STABLE) public class SpacingBetweenFunctionNameAndOpeningParenthesisRule : StandardRule("spacing-between-function-name-and-opening-parenthesis") { override fun beforeVisitChildNodes( node: ASTNode, diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/StatementWrappingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/StatementWrappingRule.kt index 14d78c9a49..6c9126a7ae 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/StatementWrappingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/StatementWrappingRule.kt @@ -10,6 +10,8 @@ import com.pinterest.ktlint.rule.engine.core.api.ElementType.VALUE_PARAMETER_LIS import com.pinterest.ktlint.rule.engine.core.api.ElementType.WHEN 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.SinceKtlint +import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.EXPERIMENTAL 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 @@ -26,6 +28,7 @@ import org.jetbrains.kotlin.com.intellij.psi.PsiElement import org.jetbrains.kotlin.psi.KtClass import org.jetbrains.kotlin.utils.addToStdlib.applyIf +@SinceKtlint("1.0", EXPERIMENTAL) public class StatementWrappingRule : StandardRule( "statement-wrapping", diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/StringTemplateIndentRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/StringTemplateIndentRule.kt index e79b5bb1d5..687d0a920a 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/StringTemplateIndentRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/StringTemplateIndentRule.kt @@ -12,6 +12,9 @@ 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.ONLY_WHEN_RUN_AFTER_RULE_IS_LOADED_AND_ENABLED 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 @@ -27,6 +30,8 @@ import org.jetbrains.kotlin.com.intellij.lang.ASTNode import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.LeafPsiElement import org.jetbrains.kotlin.psi.KtStringTemplateExpression +@SinceKtlint("0.49", EXPERIMENTAL) +@SinceKtlint("1.0", STABLE) public class StringTemplateIndentRule : StandardRule( id = "string-template-indent", @@ -45,7 +50,6 @@ public class StringTemplateIndentRule : INDENT_STYLE_PROPERTY, ), ), - Rule.Experimental, Rule.OfficialCodeStyle { private lateinit var nextIndent: String private lateinit var wrongIndentChar: String diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/StringTemplateRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/StringTemplateRule.kt index 14b0c5a371..faf9b35e60 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/StringTemplateRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/StringTemplateRule.kt @@ -8,6 +8,8 @@ import com.pinterest.ktlint.rule.engine.core.api.ElementType.LONG_TEMPLATE_ENTRY import com.pinterest.ktlint.rule.engine.core.api.ElementType.LONG_TEMPLATE_ENTRY_START import com.pinterest.ktlint.rule.engine.core.api.ElementType.REGULAR_STRING_PART 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.STABLE import com.pinterest.ktlint.ruleset.standard.StandardRule import org.jetbrains.kotlin.com.intellij.lang.ASTNode import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.LeafPsiElement @@ -17,6 +19,7 @@ import org.jetbrains.kotlin.psi.KtNameReferenceExpression import org.jetbrains.kotlin.psi.KtSuperExpression import org.jetbrains.kotlin.psi.KtThisExpression +@SinceKtlint("0.9", STABLE) public class StringTemplateRule : StandardRule("string-template") { override fun beforeVisitChildNodes( node: ASTNode, diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/TrailingCommaOnCallSiteRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/TrailingCommaOnCallSiteRule.kt index d31fb28a69..1a91d539e6 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/TrailingCommaOnCallSiteRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/TrailingCommaOnCallSiteRule.kt @@ -9,6 +9,9 @@ import com.pinterest.ktlint.rule.engine.core.api.ElementType.VALUE_ARGUMENT import com.pinterest.ktlint.rule.engine.core.api.ElementType.VALUE_ARGUMENT_LIST import com.pinterest.ktlint.rule.engine.core.api.Rule.VisitorModifier.RunAfterRule.Mode.ONLY_WHEN_RUN_AFTER_RULE_IS_LOADED_AND_ENABLED 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.EditorConfigProperty @@ -30,6 +33,8 @@ import org.jetbrains.kotlin.com.intellij.psi.tree.TokenSet * * @see [Kotlin Style Guide](https://kotlinlang.org/docs/coding-conventions.html#trailing-commas) */ +@SinceKtlint("0.43", EXPERIMENTAL) +@SinceKtlint("0.47", STABLE) public class TrailingCommaOnCallSiteRule : StandardRule( id = "trailing-comma-on-call-site", diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/TrailingCommaOnDeclarationSiteRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/TrailingCommaOnDeclarationSiteRule.kt index 0b6677350c..59106a484d 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/TrailingCommaOnDeclarationSiteRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/TrailingCommaOnDeclarationSiteRule.kt @@ -15,6 +15,9 @@ import com.pinterest.ktlint.rule.engine.core.api.ElementType.WHEN_ENTRY import com.pinterest.ktlint.rule.engine.core.api.ElementType.WHITE_SPACE import com.pinterest.ktlint.rule.engine.core.api.Rule.VisitorModifier.RunAfterRule.Mode.ONLY_WHEN_RUN_AFTER_RULE_IS_LOADED_AND_ENABLED 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.EditorConfigProperty @@ -54,6 +57,8 @@ import org.jetbrains.kotlin.psi.psiUtil.prevLeaf * * @see [Kotlin Style Guide](https://kotlinlang.org/docs/coding-conventions.html#trailing-commas) */ +@SinceKtlint("0.43", EXPERIMENTAL) +@SinceKtlint("0.46", STABLE) public class TrailingCommaOnDeclarationSiteRule : StandardRule( id = "trailing-comma-on-declaration-site", diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/TryCatchFinallySpacingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/TryCatchFinallySpacingRule.kt index 1d6dbbae3d..8adf9d23bd 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/TryCatchFinallySpacingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/TryCatchFinallySpacingRule.kt @@ -10,6 +10,9 @@ 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.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 @@ -25,6 +28,8 @@ import org.jetbrains.kotlin.com.intellij.lang.ASTNode /** * Checks spacing and wrapping of try-catch-finally. */ +@SinceKtlint("0.49", EXPERIMENTAL) +@SinceKtlint("1.0", STABLE) public class TryCatchFinallySpacingRule : StandardRule( id = "try-catch-finally-spacing", @@ -34,7 +39,6 @@ public class TryCatchFinallySpacingRule : INDENT_STYLE_PROPERTY, ), ), - Rule.Experimental, Rule.OfficialCodeStyle { private var indentConfig = DEFAULT_INDENT_CONFIG diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/TypeArgumentListSpacingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/TypeArgumentListSpacingRule.kt index b673ecd9c2..5de1063e14 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/TypeArgumentListSpacingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/TypeArgumentListSpacingRule.kt @@ -2,8 +2,10 @@ package com.pinterest.ktlint.ruleset.standard.rules import com.pinterest.ktlint.rule.engine.core.api.ElementType 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 @@ -22,6 +24,8 @@ import org.jetbrains.kotlin.com.intellij.lang.ASTNode /** * Lints and formats the spacing before and after the angle brackets of a type argument list. */ +@SinceKtlint("0.45", EXPERIMENTAL) +@SinceKtlint("1.0", STABLE) public class TypeArgumentListSpacingRule : StandardRule( id = "type-argument-list-spacing", @@ -30,8 +34,7 @@ public class TypeArgumentListSpacingRule : 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/TypeParameterListSpacingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/TypeParameterListSpacingRule.kt index 289a089043..42d7968329 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/TypeParameterListSpacingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/TypeParameterListSpacingRule.kt @@ -12,8 +12,10 @@ import com.pinterest.ktlint.rule.engine.core.api.ElementType.TYPEALIAS import com.pinterest.ktlint.rule.engine.core.api.ElementType.TYPE_PARAMETER_LIST 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.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 @@ -30,6 +32,8 @@ import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.LeafPsiElement /** * Lints and formats the spacing before and after the angle brackets of a type parameter list. */ +@SinceKtlint("0.45", EXPERIMENTAL) +@SinceKtlint("1.0", STABLE) public class TypeParameterListSpacingRule : StandardRule( id = "type-parameter-list-spacing", @@ -38,8 +42,7 @@ public class TypeParameterListSpacingRule : 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/UnnecessaryParenthesesBeforeTrailingLambdaRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/UnnecessaryParenthesesBeforeTrailingLambdaRule.kt index 5439635f92..2b6c9092a5 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/UnnecessaryParenthesesBeforeTrailingLambdaRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/UnnecessaryParenthesesBeforeTrailingLambdaRule.kt @@ -5,8 +5,10 @@ import com.pinterest.ktlint.rule.engine.core.api.ElementType.LAMBDA_ARGUMENT import com.pinterest.ktlint.rule.engine.core.api.ElementType.LPAR import com.pinterest.ktlint.rule.engine.core.api.ElementType.RPAR import com.pinterest.ktlint.rule.engine.core.api.ElementType.VALUE_ARGUMENT_LIST -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.isPartOf import com.pinterest.ktlint.rule.engine.core.api.nextCodeSibling @@ -16,9 +18,9 @@ import org.jetbrains.kotlin.com.intellij.lang.ASTNode /** * Ensures there are no unnecessary parentheses before a trailing lambda. */ -public class UnnecessaryParenthesesBeforeTrailingLambdaRule : - StandardRule("unnecessary-parentheses-before-trailing-lambda"), - Rule.Experimental { +@SinceKtlint("0.44", EXPERIMENTAL) +@SinceKtlint("1.0", STABLE) +public class UnnecessaryParenthesesBeforeTrailingLambdaRule : StandardRule("unnecessary-parentheses-before-trailing-lambda") { override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/WrappingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/WrappingRule.kt index 1d4fdaa190..0ed2f2133e 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/WrappingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/WrappingRule.kt @@ -47,6 +47,8 @@ import com.pinterest.ktlint.rule.engine.core.api.IndentConfig.Companion.DEFAULT_ 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.RuleId +import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint +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 @@ -95,6 +97,7 @@ private val LOGGER = KotlinLogging.logger {}.initKtLintKLogger() * is fixed with respect to indentation of the parent. This is just a simple best effort for the case that the * indentation rule is not run. */ +@SinceKtlint("0.45", STABLE) public class WrappingRule : StandardRule( id = "wrapping",