Control structures are nested deeper than the configured maximum

tx0/kotlin:deep-nestingstrictwarningmaintainability/complexitydepth fastmaintainability

What it finds

Counts how deeply if, when, loops and try nest inside a function, lambdas and local functions included. Each level is a condition to keep in mind while reading the innermost code. Only the first place in a function that goes deeper than the maximum is reported. The maximum is the parameter max, 4 by default.

From the rule's source, nesting_depth.rs.

Example from the rule's tests
fun deep(items: List<List<Int>>) {    for (row in items) {        for (x in row) {            if (x > 0) {                while (x > 10) {                    if (x == 11) {tx0 reports: this is nested 5 levels deep, more than 4                        println(x)                    }                }            }        }    }} fun chain(x: Int) {    if (x == 1) {    } else if (x == 2) {    } else if (x == 3) {    } else if (x == 4) {    } else if (x == 5) {    }}
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:deep-nesting" = "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:deep-nesting] reason="..."

tx0 explain tx0/kotlin:deep-nesting shows the same in the terminal. Found a false positive? Report it.