Background: The staticcheck suite includes hundreds of high-quality analyzers, many appropriate for either go vet (which diagnoses mistakes) or go fix (which applies safe fixes to mistakes or benign style issues), or both. Many of staticcheck's analyzers, a hand-curated subset of slightly more than half, have been enabled in gopls for a while.
Some of them are synergistic with analyzers already in go fix: for example, go fix's stringsbuilder replaces a loop around s += fmt.Sprintf(...) by use of a stringsbuilder, such as s.WriteString(fmt.Sprintf(...)). Staticcheck's QF1012 analyzer then simplifies this to fmt.Fprintf(&s, ...), which is both better style and more efficient. Running just the go fix analyzers without the staticcheck analyzers may result in fixes that feel incomplete.
Proposal: We propose to incorporate a subset of staticcheck's analyzers in go vet and/or go fix. Rather than list hundreds of specific analyzers, we should decide based on policy criteria: those added to go vet should report mistakes with high precision, and those added to go fix should suggest fixes that are safe to apply. (These are the same criteria used in gopls.) The new packages would be vendored into GOROOT/src/cmd/vendor/honnef.co/go/tools.
@dominikh
Background: The staticcheck suite includes hundreds of high-quality analyzers, many appropriate for either
go vet(which diagnoses mistakes) orgo fix(which applies safe fixes to mistakes or benign style issues), or both. Many of staticcheck's analyzers, a hand-curated subset of slightly more than half, have been enabled in gopls for a while.Some of them are synergistic with analyzers already in go fix: for example, go fix's
stringsbuilderreplaces a loop arounds += fmt.Sprintf(...)by use of a stringsbuilder, such ass.WriteString(fmt.Sprintf(...)). Staticcheck's QF1012 analyzer then simplifies this tofmt.Fprintf(&s, ...), which is both better style and more efficient. Running just the go fix analyzers without the staticcheck analyzers may result in fixes that feel incomplete.Proposal: We propose to incorporate a subset of staticcheck's analyzers in go vet and/or go fix. Rather than list hundreds of specific analyzers, we should decide based on policy criteria: those added to go vet should report mistakes with high precision, and those added to go fix should suggest fixes that are safe to apply. (These are the same criteria used in gopls.) The new packages would be vendored into GOROOT/src/cmd/vendor/honnef.co/go/tools.
@dominikh