From d8179bb3c6ece370d0ce3bb800524b2720061c27 Mon Sep 17 00:00:00 2001 From: Paul Dingemans Date: Mon, 13 Dec 2021 20:14:41 +0100 Subject: [PATCH] Remove support of continuation index in secondary constructor This aligns the formatting with the default IntelliJ formatting of secondary constructors. Closes #1222 --- .../ktlint/ruleset/standard/IndentationRule.kt | 6 +++--- .../ruleset/standard/IndentationRuleTest.kt | 16 +++++++--------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/IndentationRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/IndentationRule.kt index 95b157f3dd..8c184fa7d8 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/IndentationRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/IndentationRule.kt @@ -774,10 +774,10 @@ class IndentationRule : Rule("indent"), Rule.Modifier.RestrictToRootLast { ctx.exitAdjBy(returnType!!, -1) } n.treeParent.isPartOf(SECONDARY_CONSTRUCTOR) -> { - expectedIndent += 2 + expectedIndent++ debug { "++after(COLON IN CONSTRUCTOR) -> $expectedIndent" } - val returnType = n.nextCodeSibling() - ctx.exitAdjBy(returnType!!, -2) + val nextCodeSibling = n.nextCodeSibling() + ctx.exitAdjBy(nextCodeSibling!!, -1) } else -> { expectedIndent++ diff --git a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/IndentationRuleTest.kt b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/IndentationRuleTest.kt index 8717a392f0..b2e78cb6e0 100644 --- a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/IndentationRuleTest.kt +++ b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/IndentationRuleTest.kt @@ -1349,7 +1349,7 @@ internal class IndentationRuleTest { """ class Issue1222 { constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int, defStyleRes: Int) : - super(context, attrs, defStyleAttr, defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes) { init(attrs, defStyleAttr, defStyleRes) } } @@ -1358,14 +1358,14 @@ internal class IndentationRuleTest { """ class Issue1222 { constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int, defStyleRes: Int) : - super(context, attrs, defStyleAttr, defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes) { init(attrs, defStyleAttr, defStyleRes) } } """.trimIndent() assertThat(IndentationRule().lint(code)) .containsExactly( - LintError(3, 1, "indent", "Unexpected indentation (8) (should be 12)"), + LintError(3, 1, "indent", "Unexpected indentation (12) (should be 8)"), ) assertThat(IndentationRule().format(code)).isEqualTo(formattedCode) } @@ -1387,18 +1387,16 @@ internal class IndentationRuleTest { """ class Issue1222 { constructor(string1: String, string2: String2) : - super( - string1, string2 - ) { + super( + string1, string2 + ) { // do something } } """.trimIndent() assertThat(IndentationRule().lint(code)) .containsExactly( - LintError(3, 1, "indent", "Unexpected indentation (8) (should be 12)"), - LintError(4, 1, "indent", "Unexpected indentation (8) (should be 16)"), - LintError(5, 1, "indent", "Unexpected indentation (8) (should be 12)"), + LintError(4, 1, "indent", "Unexpected indentation (8) (should be 12)"), ) assertThat(IndentationRule().format(code)).isEqualTo(formattedCode) }