diff --git a/formatter/src/main/kotlin/org/kotlin/formatter/scanning/IfExpressionScanner.kt b/formatter/src/main/kotlin/org/kotlin/formatter/scanning/IfExpressionScanner.kt index 8f87fea..e1cd83c 100644 --- a/formatter/src/main/kotlin/org/kotlin/formatter/scanning/IfExpressionScanner.kt +++ b/formatter/src/main/kotlin/org/kotlin/formatter/scanning/IfExpressionScanner.kt @@ -119,7 +119,7 @@ internal class IfExpressionScanner(private val kotlinScanner: KotlinScanner) : N } } or { oneOrMore { anyNode() } thenMapToTokens { nodes -> - listOf(SynchronizedBreakToken(whitespaceLength = 1)) + listOf(SynchronizedBreakToken(whitespaceLength = 0)) .plus(kotlinScanner.scanNodes(nodes, ScannerState.STATEMENT)) } } diff --git a/formatter/src/test/kotlin/org/kotlin/formatter/KotlinFormatterTest.kt b/formatter/src/test/kotlin/org/kotlin/formatter/KotlinFormatterTest.kt index e79e829..b5a87e8 100644 --- a/formatter/src/test/kotlin/org/kotlin/formatter/KotlinFormatterTest.kt +++ b/formatter/src/test/kotlin/org/kotlin/formatter/KotlinFormatterTest.kt @@ -1856,6 +1856,15 @@ class KotlinFormatterTest { ) } + @Test + fun `does not break a short if-else block`() { + val result = + KotlinFormatter(maxLineLength = 100) + .format("""if (aCondition) "Some value" else "Some other value"""") + + assertThat(result).isEqualTo("""if (aCondition) "Some value" else "Some other value"""") + } + @Test fun `does not break a before else if`() { val result =