go-critic
go-critic copied to clipboard
lint: add zero value re-assignment checker
Detect unnecessary zero value assignments.
Should not give a warning for constants that happen to have zero value.
Before:
type foo struct {a int; b string}
var f foo
f.a = 0
f.b = ""
After:
type foo struct {a int; b string}
var f foo
There is a problem: I don't know how to implement this one using our current framework. We should figure out good solution.
Would be nice to have such a linter as expressed in the uber-go guidelines here. Have there been any enhancements added to the framework which would allow implementing such a linter? One issue is that it would likely need to ignore unit test files, since it's probably quite common to have something like the following in test code (copied from the linked guideline):
tests := []struct{
give string
want int
}{
{give: "0", want: 0},
// ...
}