Skip to content
This repository has been archived by the owner on Jun 4, 2024. It is now read-only.

Commit

Permalink
Fix formatting of single-line if-else expressions.
Browse files Browse the repository at this point in the history
The previous change inadvertently introduced an extra space in the formatting of single-line if-else expressions:

    if (condition) aValue else  anotherValue

This fix removes the extraneous space.
  • Loading branch information
hovinen committed Oct 7, 2021
1 parent 98c9d89 commit bce950c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down

0 comments on commit bce950c

Please sign in to comment.