flag code used only by its own tests
staticcheck compiled from "did a git pull this afternoon" but on a different machine so it's hard to cut and paste output
The code isn't easily extracted, but the basic form is something like this:
// foo.go
type x int
func (v x) String() string { return fmt.Sprintf("%d", v) }
// foo_test.go
func TestX(t *testing.T) {
var dummy x = 3
s := dummy.String()
if s == "" { t.Fatalf("i'm dumb") }
}
unused doesn't report this as being unused, because it is used. But, in fact, it is not used by anything but its own tests, which means it's actually completely redundant.
I am not entirely sure how to clearly articulate this distinction, because there can be things which are used only in tests but are actually useful for tests because they're used by the design of a test that's testing something else.
This would probably have too many false positives if it were very aggressive, but it still feels like there ought to be a way to detect a thing like this.
I have seen this a couple times and I agree that it would be a good add. I would personally want this on but it can and probably will result in some kind of false-positives in some cases. Maybe it can be added as a new check that is disabled by default?