A local var is never assigned after its declaration

tx0/kotlin:var-could-be-valrecommendedwarningmaintainability/designdepth fastsmell

What it finds

A var that keeps its initial value is a val that tells readers to look for changes that never come. Declaring it val documents that it does not change, and the compiler then enforces it.

From the rule's source, var_could_be_val.rs.

Example from the rule's tests
fun build(): String {    var prefix = "a"tx0 reports: prefix is never assigned again and can be a val    var count = 0    count++    var label = "x"    listOf(1).forEach { label = "y" }    var later: String    later = "z"    return prefix + count + label + later}
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 recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/kotlin:var-could-be-val" = "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:var-could-be-val] reason="..."

tx0 explain tx0/kotlin:var-could-be-val shows the same in the terminal. Found a false positive? Report it.