A local variable is declared and never read
What it finds
A local val or var that nothing reads is dead code, or a sign that the value was meant to be used and was not. The compiler warns about it too. Names that start with _ or ignored, and variables whose initializer is a lambda or object passed nowhere, are reported too, while _ itself is left alone.
From the rule's source, unused_variable.rs.
fun compute(items: List<Int>): Int { val total = items.sum() val unused = items.sizetx0 reports: unused is never read var written = 0tx0 reports: written is never read written = 3 val (first, second) = items.first() to items.last()tx0 reports: second is never read val _ignored = 1 items.forEach { val inner = it }tx0 reports: inner is never read return total + first} 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:
[rules]
"tx0/kotlin:unused-variable" = "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:unused-variable] reason="..."tx0 explain tx0/kotlin:unused-variable shows the same in the terminal. Found a false positive? Report it.