A function has more return statements than the configured maximum

tx0/kotlin:too-many-returnsstrictwarningmaintainability/complexitydepth fastmaintainability

What it finds

Many exits make it hard to see what a function returns in which case. Returns from lambdas, with a label, and from nested functions are not counted. The maximum is the parameter max, 5 by default.

From the rule's source, return_count.rs.

Example from the rule's tests
fun exits(x: Int): Int {tx0 reports: exits has 6 return statements, more than 5    if (x == 1) return 1    if (x == 2) return 2    if (x == 3) return 3    if (x == 4) return 4    if (x == 5) return 5    listOf(1).forEach { return@forEach }    return 0} fun few(x: Int): Int {    if (x == 1) return 1    return 0}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/kotlin:too-many-returns" = "warning"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/kotlin:too-many-returns] reason="..."

tx0 explain tx0/kotlin:too-many-returns shows the same in the terminal. Found a false positive? Report it.