đź“ť Edit page
âž• Add page
Lint
golint
The golint
tool is marked as deprecated on GitHub.
Tools
The golint docs recommend the following:
Static check
- StaticCheck.io
- dominikh/go-tools repo
Staticcheck - The advanced Go linter
- Run in docs
- Checks
Install globally:
$ go install honnef.co/go/tools/cmd/staticcheck@latest
Or in a project:
$ go go honnef.co/go/tools/cmd/staticcheck@latest
The downside for the second approach is that you’ll get a warning in go.mod
from your IDE that the package is unused. And running go mod tidy
remove it. I don’t know how to add it to dev dependencies or stop it getting removed. Maybe just have it as a global dependency in a project. See my Makefile of go-project-template.
Check current package.
$ staticcheck .
Check all packages.
$ staticcheck ./...
Explain:
$ staticcheck -explain <check>
e.g. after seeing foo.go:1248:4: unnecessary use of fmt.Sprintf (S1039)
, you would run:
$ staticcheck -explain S1039
Go vet
This works with no arguments. Or supply packages.
$ go vet
$ go vet .
$ go vet ./...
Help:
$ go help vet
$ go doc cmd/vet