Skip to content

statement-wrapping

Kotlinstyleno fixdefault: offkotlin/ktlint

Reports a block whose line breaks the formatter would change, such as several statements on one line ({ a(); b() }).

One statement to a line is the layout every Kotlin reader expects, and a second statement after a ; is easily missed. It also makes a diff show a change to the statement and not to its neighbour.

To fix, run the formatter.

Reported
fun f(x: Int) {
val a = if (x > 0)
...
val b = when (x) {
1 -> { println(1) }
...
}
foo(); bar()
val c = someVeryLongReceiverName.firstFunctionCall(argumentNumberOne).secondFunctionCall(argumentNumberTwo).thirdFunctionCall(argumentNumberThree)
callTheFunction(argumentNumberOne, argumentNumberTwo, argumentNumberThree, argumentNumberFour, argumentNumberFive, argumentNumberSix, argumentNumberSeven)
}
kotlin:
lint:
rules:
statement-wrapping: warn # off (default), warn, error

Enabled by the presets: kotlin/ktlint.

Suppress one line with sudsy-disable-next-line statement-wrapping 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 statement-wrapping full