golangci-lint
Lint and analyze Go source code
TLDR
Run linters in the current folder
List enabled and disabled linters (Note: Disabled linters are shown last, do not mistake them for enabled ones)
Enable a specific linter for this run
SYNOPSIS
golangci-lint [run] [flags] [pkg|file|dir...] | version | help
PARAMETERS
--version
Print version and exit
--help, -h
Show help
--config=PATH
Path to config file (.golangci.yml)
--no-config
Don't load config file
--out-format=FORMAT
Output format: colored-line-number, line-number, json, etc.
--print-issued-lines
Print lines with issues
--print-linter-name
Print linter name before issues
--timeout=DURATION
Timeout for lint (default 1m0s)
--max-issues-per-linter=NUM
Max issues per linter (default 50)
--max-same-issues=NUM
Max same issues printed (default 3)
--issues-exit-code=NUM
Exit code for issues (0,1=default,2)
--path-prefix=PREFIX
Prepend path prefix to output paths
--build-tags=TAGS
Build tags for vetting
--skip-dirs-use-default
Use default skipped dirs
--verbose, -v
Verbose mode
DESCRIPTION
golangci-lint is a high-performance linter for Go code that aggregates over 50 popular linters into a single, fast tool. It runs linters in parallel, employs intelligent caching to skip unchanged files, and supports customizable configurations via YAML files. Ideal for CI/CD pipelines, it detects issues like unused variables, code style violations, potential bugs, and performance problems.
Key features include:
- Speed: Up to 10x faster than running linters separately.
- Configurability: Fine-tune linters, severity levels, and exclusions in .golangci.yml.
- Output formats: Supports plain text, JSON, code-climate, and more.
- Integrations: Works with editors like VS Code and Vim via plugins.
It's the de facto standard for Go projects on GitHub, used by major companies. Developers use it to enforce code quality without slowing down workflows. Install via go install and run on packages or directories.
CAVEATS
Requires Go 1.21+; high memory usage with many linters enabled; caching may miss changes if not invalidated properly; config validation needed for custom setups.
INSTALLATION
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
Or via package managers like brew, apt.
CONFIG EXAMPLE
Use .golangci.yml:
linters:
enable:
- gofmt
- govet
issues:
exclude-use-default: false
SUBCOMMANDS
run: Lint code (default).
completion: Shell completion.
lint: Alias for run.
HISTORY
Created in 2017 by Dmitry Timoshkov (@maratori) to solve slow, fragmented Go linting. Evolved from golint integration, now maintained by a team with 30k+ stars on GitHub. Replaced deprecated tools like golint; v1.0 in 2019 marked stability.


