The standard Go code quality toolchain is gofmt for formatting, go vet for suspicious constructs, Staticcheck for deeper analysis, and golangci-lint to run many linters together in CI. golint is deprecated and frozen, so do not use it in new projects.
Add govulncheck for dependency and standard library vulnerabilities, and the race detector (go test -race) for concurrency bugs. Together they catch most problems before code review.
gofmt is the canonical Go formatter, and all Go code is expected to be formatted with it. go fmt ./... runs it on every package, and gofmt -l . lists files that differ without changing them, which is useful in CI.
goimports does the same and also adds or removes import lines. gofumpt is a stricter superset of gofmt used by some teams. Editors usually run one of these on save through gopls.
go vet is part of the Go toolchain and finds mistakes the compiler accepts, such as wrong Printf format verbs, copied locks, unreachable code and misuse of struct tags. go test already runs a small subset of vet checks automatically.
Staticcheck (honnef.co/go/tools) finds bugs, deprecated API use, simplifications and performance problems with a low rate of false positives. Install and run it like this:
Its checks are grouped by prefix: SA for correctness bugs, S for simplifications, ST for style and QF for quick fixes. Recent Go versions also let you pin tools in go.mod with the tool directive and run them with go tool, which keeps versions consistent across the team.
golangci-lint runs dozens of linters in parallel with caching and a single configuration file. Version 2 changed the configuration format, so new files start with version: "2":
Commonly enabled linters include errcheck (unchecked errors), govet, staticcheck, revive (the successor to golint), gosec (security issues), bodyclose (unclosed HTTP bodies) and gocritic. Enable a few that matter to your team instead of every available linter, or the output becomes noise. Check the project's migration guide if you have a version 1 configuration.
golint was deprecated and frozen by the Go team in 2020 and its repository was later archived. It reported style issues with many false positives and is not maintained. Use revive or the staticcheck style checks instead; both are available inside golangci-lint.
govulncheck ./... reports known vulnerabilities in your dependencies and the standard library, and only flags those your code can actually reach.go test -race ./... runs tests with the race detector, which finds unsynchronised access to shared memory at runtime.go test -cover ./... shows coverage, and go test -fuzz fuzzes functions with generated inputs.Run the same commands locally and in CI so results match:
For a local hook, a pre-commit script that runs gofmt -l and golangci-lint run --new-from-rev=HEAD~1 checks only the code you changed. The --new-from-rev flag helps when you introduce linting to an old code base, because only new issues fail the build.
No. It is deprecated and frozen. Use staticcheck and revive, usually through golangci-lint.
go vet ships with Go and checks a focused set of likely mistakes. Staticcheck has many more checks, including deprecated API use and code simplifications, and is installed separately.
Not strictly, but golangci-lint runs Staticcheck alongside other linters in one fast command with one configuration, which is easier to manage in CI.
Use a //nolint:lintername // reason comment for golangci-lint, and always add a reason so reviewers know why it is justified.
Format with gofmt, run go vet and Staticcheck, and aggregate linters with golangci-lint in CI. Replace golint with revive, add govulncheck and go test -race, and keep the same checks in local hooks and in the pipeline.