diff --git a/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/IndentationRule.kt b/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/IndentationRule.kt index 2fc6d11d6e..848c09a367 100644 --- a/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/IndentationRule.kt +++ b/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/IndentationRule.kt @@ -207,7 +207,12 @@ class IndentationRule : Rule("indent"), Rule.Modifier.RestrictToRootLast { ) { return } - if (!node.nextCodeLeaf()?.prevLeaf().isWhiteSpaceWithNewline() && + if (!node.nextCodeLeaf()?.prevLeaf { + // Skip comments, whitespace, and empty nodes + !it.isPartOfComment() && + !it.isWhiteSpaceWithoutNewline() && + it.textLength > 0 + }.isWhiteSpaceWithNewline() && // IDEA quirk: // if (true && // true diff --git a/ktlint-ruleset-experimental/src/test/kotlin/com/pinterest/ktlint/ruleset/experimental/IndentationRuleTest.kt b/ktlint-ruleset-experimental/src/test/kotlin/com/pinterest/ktlint/ruleset/experimental/IndentationRuleTest.kt index fd605acd24..29a1275c8a 100644 --- a/ktlint-ruleset-experimental/src/test/kotlin/com/pinterest/ktlint/ruleset/experimental/IndentationRuleTest.kt +++ b/ktlint-ruleset-experimental/src/test/kotlin/com/pinterest/ktlint/ruleset/experimental/IndentationRuleTest.kt @@ -254,6 +254,27 @@ class IndentationRuleTest { ).isEmpty() } + @Test(description = "https://github.com/pinterest/ktlint/issues/433") + fun testLintParameterListWithComments() { + assertThat( + IndentationRule().lint( + """ + fun main() { + foo( + /*param1=*/param1, + /*param2=*/param2 + ) + + foo( + /*param1=*/ param1, + /*param2=*/ param2 + ) + } + """.trimIndent() + ) + ).isEmpty() + } + @Test fun testUnexpectedTabCharacter() { val ktScript = "fun main() {\n\t\treturn 0\n\t}"