A range clause names a blank variable that can be left out

tx0/go:blank-range-variablestrictwarningstyle

What it finds

for i, _ := range xs says the same as for i := range xs, and for _ = range xs the same as for range xs. The blank identifier there only adds noise.

Reported are range clauses whose last variable is _, with := or =. The fix removes the blank variable, and with it the assignment when nothing is left, and is safe.

From the rule's source, blank_range_variable.rs.

Example from the rule's tests
package p func f(xs []int) int {	n := 0	for i, _ := range xs {tx0 reports: the blank variable of this range can be left out		n += i	}	for _ = range xs {tx0 reports: the blank variable of this range can be left out		n++	}	for _, x := range xs {		n += x	}	return n}
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/go:blank-range-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/go:blank-range-variable] reason="..."

tx0 explain tx0/go:blank-range-variable shows the same in the terminal. Found a false positive? Report it.