From aa3282afde1333ad2c53fbc9e4b39f625433d8f9 Mon Sep 17 00:00:00 2001 From: Paul Dingemans Date: Thu, 29 Feb 2024 18:02:00 +0100 Subject: [PATCH 1/2] Mark new rules as experimental Closes #2575 --- .../ruleset/standard/rules/BlankLineBetweenWhenConditions.kt | 4 +++- .../com/pinterest/ktlint/ruleset/standard/rules/KdocRule.kt | 4 +++- .../standard/rules/SpacingAroundSquareBracketsRule.kt | 5 ++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/BlankLineBetweenWhenConditions.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/BlankLineBetweenWhenConditions.kt index 5298463306..34a79aba34 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/BlankLineBetweenWhenConditions.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/BlankLineBetweenWhenConditions.kt @@ -3,6 +3,7 @@ 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.WHEN_ENTRY 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 @@ -34,7 +35,8 @@ public class BlankLineBetweenWhenConditions : StandardRule( id = "blank-line-between-when-conditions", usesEditorConfigProperties = setOf(LINE_BREAK_AFTER_WHEN_CONDITION_PROPERTY), - ) { + ), + Rule.Experimental { private var lineBreakAfterWhenCondition = LINE_BREAK_AFTER_WHEN_CONDITION_PROPERTY.defaultValue override fun beforeFirstNode(editorConfig: EditorConfig) { diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/KdocRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/KdocRule.kt index 2760efc3cd..1c52ff8445 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/KdocRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/KdocRule.kt @@ -10,6 +10,7 @@ import com.pinterest.ktlint.rule.engine.core.api.ElementType.PROPERTY import com.pinterest.ktlint.rule.engine.core.api.ElementType.SECONDARY_CONSTRUCTOR import com.pinterest.ktlint.rule.engine.core.api.ElementType.TYPEALIAS import com.pinterest.ktlint.rule.engine.core.api.ElementType.VALUE_PARAMETER +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 @@ -31,7 +32,8 @@ public class KdocRule : INDENT_SIZE_PROPERTY, INDENT_STYLE_PROPERTY, ), - ) { + ), + Rule.Experimental { override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundSquareBracketsRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundSquareBracketsRule.kt index 81bc8f8fb2..c7d0dea9f7 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundSquareBracketsRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundSquareBracketsRule.kt @@ -4,6 +4,7 @@ import com.pinterest.ktlint.rule.engine.core.api.ElementType.COLLECTION_LITERAL_ import com.pinterest.ktlint.rule.engine.core.api.ElementType.KDOC_MARKDOWN_LINK import com.pinterest.ktlint.rule.engine.core.api.ElementType.LBRACKET import com.pinterest.ktlint.rule.engine.core.api.ElementType.RBRACKET +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 @@ -19,7 +20,9 @@ import org.jetbrains.kotlin.com.intellij.lang.ASTNode * See https://kotlinlang.org/docs/reference/coding-conventions.html#horizontal-whitespace */ @SinceKtlint("1.2", EXPERIMENTAL) -public class SpacingAroundSquareBracketsRule : StandardRule("square-brackets-spacing") { +public class SpacingAroundSquareBracketsRule : + StandardRule("square-brackets-spacing"), + Rule.Experimental { override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, From 1e1340bc93e2c774c9204045f3f632da9a7abdb2 Mon Sep 17 00:00:00 2001 From: Paul Dingemans Date: Thu, 29 Feb 2024 19:57:13 +0100 Subject: [PATCH 2/2] Fix API contract --- ktlint-ruleset-standard/api/ktlint-ruleset-standard.api | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ktlint-ruleset-standard/api/ktlint-ruleset-standard.api b/ktlint-ruleset-standard/api/ktlint-ruleset-standard.api index 5c7c9c1356..a3455bf324 100644 --- a/ktlint-ruleset-standard/api/ktlint-ruleset-standard.api +++ b/ktlint-ruleset-standard/api/ktlint-ruleset-standard.api @@ -72,7 +72,7 @@ public final class com/pinterest/ktlint/ruleset/standard/rules/BlankLineBeforeDe public static final fun getBLANK_LINE_BEFORE_DECLARATION_RULE_ID ()Lcom/pinterest/ktlint/rule/engine/core/api/RuleId; } -public final class com/pinterest/ktlint/ruleset/standard/rules/BlankLineBetweenWhenConditions : com/pinterest/ktlint/ruleset/standard/StandardRule { +public final class com/pinterest/ktlint/ruleset/standard/rules/BlankLineBetweenWhenConditions : com/pinterest/ktlint/ruleset/standard/StandardRule, com/pinterest/ktlint/rule/engine/core/api/Rule$Experimental { public static final field Companion Lcom/pinterest/ktlint/ruleset/standard/rules/BlankLineBetweenWhenConditions$Companion; public fun ()V public fun beforeFirstNode (Lcom/pinterest/ktlint/rule/engine/core/api/editorconfig/EditorConfig;)V @@ -385,7 +385,7 @@ public final class com/pinterest/ktlint/ruleset/standard/rules/IndentationRuleKt public static final fun getINDENTATION_RULE_ID ()Lcom/pinterest/ktlint/rule/engine/core/api/RuleId; } -public final class com/pinterest/ktlint/ruleset/standard/rules/KdocRule : com/pinterest/ktlint/ruleset/standard/StandardRule { +public final class com/pinterest/ktlint/ruleset/standard/rules/KdocRule : com/pinterest/ktlint/ruleset/standard/StandardRule, com/pinterest/ktlint/rule/engine/core/api/Rule$Experimental { public fun ()V public fun beforeVisitChildNodes (Lorg/jetbrains/kotlin/com/intellij/lang/ASTNode;ZLkotlin/jvm/functions/Function3;)V } @@ -804,7 +804,7 @@ public final class com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundRang public static final fun getSPACING_AROUND_RANGE_OPERATOR_RULE_ID ()Lcom/pinterest/ktlint/rule/engine/core/api/RuleId; } -public final class com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundSquareBracketsRule : com/pinterest/ktlint/ruleset/standard/StandardRule { +public final class com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundSquareBracketsRule : com/pinterest/ktlint/ruleset/standard/StandardRule, com/pinterest/ktlint/rule/engine/core/api/Rule$Experimental { public fun ()V public fun beforeVisitChildNodes (Lorg/jetbrains/kotlin/com/intellij/lang/ASTNode;ZLkotlin/jvm/functions/Function3;)V }