Skip to content

no-unit-return

Kotlincleanupno fixdefault: warnkotlin/ktlint

Reports a function with a block body that declares : Unit as its return type.

Unit is what a function returns by default, so writing it repeats the language and distracts a reader who looks for a type that matters.

To fix, delete : Unit.

Reported
fun a(): Unit {}
fun b(x: Int = 1): Unit { return }
fun c(): Int { return 1 }
fun d(): Unit = Unit
fun Unit.e() {}
fun f() {
fun g(): Unit {}
}
kotlin:
lint:
rules:
no-unit-return: warn # off, warn (default), error

Enabled by the presets: kotlin/ktlint.

Suppress one line with sudsy-disable-next-line no-unit-return 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 no-unit-return full