function-expression-body
What it does
Section titled “What it does”Reports a function with a block body that is only a return, which the formatter would write as an expression body (fun f(): Int { return 1 } is fun f(): Int = 1).
Why it matters
Section titled “Why it matters”A function with a single return as its body is clearer as an expression: the type is inferred and a line of braces goes away. One style makes functions of that kind look the same.
To fix, run the formatter, or write the expression body.
Example
Section titled “Example”... fun foo(a: Int, b: String, c: Long, d: Double, e: Float, f: Short, g: Byte, h: Char, i: Boolean, j: Unit): Int { return 1 }
... 1...
fun ok(a: Int) = a
fun sum(): Int { return 1 }}Configuration
Section titled “Configuration”kotlin: lint: rules: function-expression-body: warn # off (default), warn, errorEnabled by the presets: kotlin/ktlint.
Suppress one line with sudsy-disable-next-line function-expression-body in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools; Sudsy reports what each upstream rule reports.
| Tool | Rule | Match |
|---|---|---|
| ktlint | function-expression-body |
full |