Skip to content

multiline-if-else

Kotlinstyleno fixdefault: offkotlin/ktlint

Reports an if whose line breaks the formatter would change.

An if and else that are split over lines in an arbitrary way are hard to read, and a line added to a branch that has no braces is not part of it. One layout for every if avoids both.

To fix, run the formatter.

Reported
fun f(x: Int) {
val a = if (x > 0)
1
else 2
...
kotlin:
lint:
rules:
multiline-if-else: warn # off (default), warn, error

Enabled by the presets: kotlin/ktlint.

Suppress one line with sudsy-disable-next-line multiline-if-else in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
ktlint if-else-wrapping full
ktlint multiline-if-else full