Today I looked at some option for standalone linting of Go code. What I mean by that is linting that is not done in an editor or IDE like Goland. Not that there’s anything wrong with that — Goland has really good linting, so I’ve seen — but I like to use linting independently, as part of the build process, and also capture the output.
The first option I looked at was the built-in command
go vet (run
go vet ./... in the root folder of your project).
Although it has more than 20 analyzers enabled by default (you can check with
go tool vet help), this was still the option that got me the least results (9 lines) for the code-base I’m testing this on, which is about 50,000 lines. By the way, try
find . -name ‘.go’ | xargs wc -lfor counting.
go vet also has an option to get the command output in JSON, which is interesting for further use.
Next, I looked at
Staticcheck is a state of the art linter for the Go programming language. Using static analysis, it finds bugs and…
This has considerably more checks (see
staticcheck -list-checks ) and therefore gave me more results (28 lines).
staticcheck can also emit JSON.
The most comprehensive option is
GitHub - golangci/golangci-lint: Fast linters Runner for Go
Fast linters Runner for Go. Contribute to golangci/golangci-lint development by creating an account on GitHub.
It is especially detailed when you run it with the parameter
--enable-all=true . This gave me a whopping 4,455 lines of output.
You can check the linters with
golangci-lint help linters . The project documentation can be found at: