Skip to content

Commit

Permalink
Always break between when conditions, even if they fit in line
Browse files Browse the repository at this point in the history
Summary: This request from Aloha makes prefect sense. I scanned through the changes in our codebase, and they all look better to me.

Reviewed By: hick209

Differential Revision: D35802846

fbshipit-source-id: 3c6906ab70e200bb9ae31e155f36bf8a8b788051
  • Loading branch information
strulovich authored and facebook-github-bot committed Apr 22, 2022
1 parent 4dc2273 commit bfc9bed
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1699,8 +1699,14 @@ class KotlinInputAstVisitor(
builder.token("else")
} else {
builder.block(ZERO) {
forEachCommaSeparated(whenEntry.conditions.asIterable()) { visit(it) }
builder.guessToken(",")
val conditions = whenEntry.conditions
for ((index, condition) in conditions.withIndex()) {
visit(condition)
builder.guessToken(",")
if (index != conditions.lastIndex) {
builder.forcedBreak()
}
}
}
}
val whenExpression = whenEntry.expression
Expand Down
6 changes: 4 additions & 2 deletions core/src/test/java/com/facebook/ktfmt/format/FormatterTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1244,7 +1244,8 @@ class FormatterTest {
"""
|fun f(x: Int) {
| when {
| 0, 1 -> print(1)
| 0,
| 1 -> print(1)
| else -> print(0)
| }
|}
Expand Down Expand Up @@ -4641,7 +4642,8 @@ class FormatterTest {
|
| when (foo) {
| 'x', -> 43
| 'x', 'y', -> 43
| 'x',
| 'y', -> 43
| 'x',
| 'y',
| 'z',
Expand Down

0 comments on commit bfc9bed

Please sign in to comment.