ktfmt icon indicating copy to clipboard operation
ktfmt copied to clipboard

Trailing comma on `when`-case should be followed by newline.

Open plobsing opened this issue 3 years ago • 0 comments

To be consistent with the handling of other constructs that support trailing commas. In particular the case of a trailing-comma followed by -> is also seen with lambdas where it does prompt the insertion of a newline.

val whenWithTrailingComma =
    when (someEnum) {
        A,
        B, -> caseBody() // Trailing comma does not prevent the elision of any newlines.
        else -> TODO("unhandled")
    }

val lambdaWithTrailingComma =
    { a, b, // Trailing comma leads to newline insertion.
        ->
        body()
    }

plobsing avatar Jan 09 '23 00:01 plobsing