Gometalinter
DEPRECATED: Use https://github.com/golangci/golangci-lint
Install / Use
/learn @alecthomas/GometalinterREADME
Go Meta Linter
gometalinter is DEPRECATED and the project will be archived on 2019-04-07. See #590 for discussion.
Switch to golangci-lint.
<!-- MarkdownTOC -->
- Installing
- Editor integration
- Supported linters
- Configuration file
- Comment directives
- Quickstart
- FAQ
- Checkstyle XML format
The number of tools for statically checking Go source for errors and warnings is impressive.
This is a tool that concurrently runs a whole bunch of those linters and normalises their output to a standard format:
<file>:<line>:[<column>]: <message> (<linter>)
eg.
stutter.go:9::warning: unused global variable unusedGlobal (varcheck)
stutter.go:12:6:warning: exported type MyStruct should have comment or be unexported (golint)
It is intended for use with editor/IDE integration.
Installing
Binary Releases
To install the latest stable release:
curl -L https://git.io/vp6lP | sh
Alternatively you can install a specific version from the releases list.
Homebrew
brew tap alecthomas/homebrew-tap
brew install gometalinter
Editor integration
- SublimeLinter plugin.
- Atom go-plus package.
- Emacs Flycheck checker.
- Go for Visual Studio Code.
- GoLand File Watcher.
- Vim/Neovim
Supported linters
- go vet - Reports potential errors that otherwise compile.
- go tool vet --shadow - Reports variables that may have been unintentionally shadowed.
- gotype - Syntactic and semantic analysis similar to the Go compiler.
- gotype -x - Syntactic and semantic analysis in external test packages (similar to the Go compiler).
- deadcode - Finds unused code.
- gocyclo - Computes the cyclomatic complexity of functions.
- golint - Google's (mostly stylistic) linter.
- varcheck - Find unused global variables and constants.
- structcheck - Find unused struct fields.
- maligned - Detect structs that would take less memory if their fields were sorted.
- errcheck - Check that error return values are used.
- staticcheck - Statically detect bugs, both obvious and subtle ones.
- dupl - Reports potentially duplicated code.
- ineffassign - Detect when assignments to existing variables are not used.
- interfacer - Suggest narrower interfaces that can be used.
- unconvert - Detect redundant type conversions.
- goconst - Finds repeated strings that could be replaced by a constant.
- gosec - Inspects source code for security problems by scanning the Go AST.
Disabled by default (enable with --enable=<linter>):
- testify - Show location of failed testify assertions.
- test - Show location of test failures from the stdlib testing module.
- gofmt -s - Checks if the code is properly formatted and could not be further simplified.
- goimports - Checks missing or unreferenced package imports.
- gochecknoinits - Report init functions, to reduce side effects in code.
- gochecknoglobals - Report global vars, to reduce side effects in code.
- lll - Report long lines (see
--line-length=N). - misspell - Finds commonly misspelled English words.
- nakedret - Finds naked returns.
- unparam - Find unused function parameters.
- safesql - Finds potential SQL injection vulnerabilities.
Additional linters can be added through the command line with --linter=NAME:COMMAND:PATTERN (see below).
Configuration file
gometalinter now supports a JSON configuration file called .gometalinter.json that can
be placed at the root of your project. The configuration file will be automatically loaded
from the working directory or any parent directory and can be overridden by passing
--config=<file> or ignored with --no-config. The format of this file is determined by
the Config struct in config.go.
The configuration file mostly corresponds to command-line flags, with the following exceptions:
- Linters defined in the configuration file will overlay existing definitions, not replace them.
- "Enable" defines the exact set of linters that will be enabled (default
linters are disabled).
--helpdisplays the list of default linters with the exact names you must use.
Here is an example configuration file:
{
"Enable": ["deadcode", "unconvert"]
}
If a .gometalinter.json file is loaded, individual options can still be overridden by
passing command-line flags. All flags are parsed in order, meaning configuration passed
with the --config flag will override any command-line flags passed before and be
overridden by flags passed after.
Format key
The default Format key places the different fields of an Issue into a template. this
corresponds to the --format option command-line flag.
Default Format:
Format: "{{.Path}}:{{.Line}}:{{if .Col}}{{.Col}}{{end}}:{{.Severity}}: {{.Message}} ({{.Linter}})"
Format Methods
{{.Path.Relative}}- equivalent to{{.Path}}which outputs a relative path to the file{{.Path.Abs}}- outputs an absolute path to the file
Adding Custom linters
Linters can be added and customized from the config file using the Linters field.
Linters supports the following fields:
Command- the path to the linter binary and any default argumentsPattern- a regular expression used to parse the linter outputIsFast- if the linter should be run when the--fastflag is usedPartitionStrategy- how paths args should be passed to the linter command:directories- call the linter once with a list of all the directoriesfiles- call the linter once with a list of all the filespackages- call the linter once with a list of all the package pathsfiles-by-package- call the linter once per package with a list of the files in the package.single-directory- call the linter once per directory
The config for default linters can be overridden by using the name of the linter.
Additional linters can be configured via the command line using the format
NAME:COMMAND:PATTERN.
Example:
$ gometalinter --linter='vet:go tool vet -printfuncs=Infof,Debugf,Warningf,Errorf:PATH:LINE:MESSAGE' .
Comment directives
gometalinter supports suppression of linter messages via comment directives. The form of the directive is:
// nolint[: <linter>[, <linter>, ...]]
Suppression works in the following way:
-
Line-level suppression
A comment directive suppresses any linter messages on that line.
eg. In this example any messages for
a := 10will be suppressed and errchec
Related Skills
node-connect
333.7kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
82.0kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
333.7kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
commit-push-pr
82.0kCommit, push, and open a PR
