A range clause names a blank variable that can be left out
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.
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} 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:
[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.