Thanks to visit codestin.com
Credit goes to github.com

Skip to content

proposal: cmd/go: fix: include selected staticcheck analyzers #76918

@adonovan

Description

@adonovan

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    ProposalToolProposalIssues describing a requested change to a Go tool or command-line program.

    Type

    No type

    Projects

    Status

    Incoming

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions