Expected Rule behavior
The Kotlin Coding Conventions state:
Do not use a labeled return for the last statement in a lambda.
It would be nice to have a rule to check this. In addition, if possible, it would be nice to have a check for the opposite behaviour for multiline bodies specifically - this is the preferred style in our team but I have seen this in more places. Neither of these conflicts with IntelliJ formatting, since that does not touch labelled returns.
Concretely, I would expect the following behaviour:
// Accepted
fun foo() {
val x = lambda {
"value"
}
}
// Rejected
fun foo() {
val x = lambda {
return@lambda "value"
}
}
// Accepted when multiline bodies do not require a labelled return (default)
fun foo() {
val x = lambda {
doSomething()
"value"
}
}
// Accepted when multiline bodies do require a labelled return (configurable)
fun foo() {
val x = lambda {
doSomething()
return@lambda "value"
}
}