If you are using VS Code for Go development, you have probably installed
Go for Visual Studio Code
extension. It allows configuring a linter of choice by going to settings
(CTRL+,), typing
go.lintTool and selecting a desired linter:
golint
golint
is a default linter. To run it across all files in the project, execute this
from the project's root directory:
$ golint ./...
For each issue detected, golint's output contains source code file name, line
and column numbers and the linter message.
When I run golint on one of my projects that I used for benchmark, it found 9
issues.
Staticcheck
Staticcheck
is an advanced linter. VS Code Go extension can install it automatically if we
select
staticcheck as
go.lintTool
value and opt to install it in the popup notification that will apper upon
selection:
Installation log can be verified in the output window:
To run it across all files in the project, execute this from the project's
root directory:
$ staticcheck ./...
Similar to golinit, for each issue detected the output contains source code
file name, line and column numbers and the linter message.
When I run Staticcheck on my benchmark project, it found 57 issues.
revive
revive is another Go linting tool which is listed among other linters in the
default linters list in go.lintTools:
Installation output log:
To run it across all files in the project, execute this from the project's
root directory:
$ revive ./...
Similar to golinit, for each issue detected the output contains source code
file name, line and column numbers and the linter message.
When I run revive on my benchmark project, it found 11 issues.
golangci-lint
golangci-lint
is a Go linters aggregator which currently includes 48 linters. Some are
enabled by default (e.g. staticcheck) and some are not. There is no need to
install all linters, this tool does it all, just select
golangci-lint as
go.lintTool value:
Installation log output:
To run it across all files in the project, execute this from the project's
root directory:
$ golangci-lint run
The output is more verbose, in addition to source code file name, line
and column numbers, for each issue detected golangci-lint also prints that
code line with a caret that shows exact character in line for which the linter
message is issued. All messages are coloured.
When I run golangci-lint on my benchmark project, it found the same
number of issues as Staticcheck. When compared the output, I found that
issues reported were mostly the same as those from Staticcheck but were
reported as the catch of some other enabled linters (e.g. gosimple, govet,
deadcheck, unused etc...).
Conclusion
Given the more complete and verbose output and larger community around the
project, I would opt for using golangci-lint as the preferred Go
linting tool.