TIL: standalone linters for Go

Tom Deneire
2 min readJul 7, 2023
Photo by Nong on Unsplash

Standalone linting

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.

go vet

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.

staticcheck

Next, I looked at staticcheck:

This has considerably more checks (see staticcheck -list-checks ) and therefore gave me more results (28 lines).

staticcheck can also emit JSON.

golangci-lint

The most comprehensive option is golangci-lint :

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:

--

--