diff --git a/ktlint-ruleset-experimental/src/test/kotlin/com/pinterest/ktlint/ruleset/experimental/MultiLineIfElseRuleTest.kt b/ktlint-ruleset-experimental/src/test/kotlin/com/pinterest/ktlint/ruleset/experimental/MultiLineIfElseRuleTest.kt index c205827919..ed1d0324da 100644 --- a/ktlint-ruleset-experimental/src/test/kotlin/com/pinterest/ktlint/ruleset/experimental/MultiLineIfElseRuleTest.kt +++ b/ktlint-ruleset-experimental/src/test/kotlin/com/pinterest/ktlint/ruleset/experimental/MultiLineIfElseRuleTest.kt @@ -89,6 +89,41 @@ class MultiLineIfElseRuleTest { ) } + @Test + fun testMultilineCondition() { + val ifElseWithoutCurlyBrace = + """ + fun main() { + if (i2 > 0 && + i3 < 0 + ) + return 2 + else + return 3 + } + """.trimIndent() + + assertThat(lint(ifElseWithoutCurlyBrace)).isEqualTo( + listOf( + LintError(5, 9, "multiline-if-else", "Missing { ... }"), + LintError(7, 9, "multiline-if-else", "Missing { ... }") + ) + ) + assertThat(format(ifElseWithoutCurlyBrace)).isEqualTo( + """ + fun main() { + if (i2 > 0 && + i3 < 0 + ) { + return 2 + } else { + return 3 + } + } + """.trimIndent() + ) + } + private fun assertOK(kotlinScript: String) { Assertions.assertThat(format(kotlinScript)).isEqualTo(kotlinScript) Assertions.assertThat(lint(kotlinScript)).isEqualTo(emptyList())