golangci-lint
Golangci-lint is a fast, comprehensive linters runner for Go that provides a unified interface to over 100 different Go linters. It's designed to be the ultimate Go code quality tool, combining multiple linters into a single, efficient, and highly configurable solution.
Key features:
- ⚡ Extremely Fast: Runs linters in parallel, reuses Go build cache, and caches analysis results for optimal performance
- 📦 100+ Linters Included: Comprehensive collection of linters covering all aspects of Go code quality - no need to install them separately
- ⚙️ YAML Configuration: Flexible configuration system with sensible defaults and extensive customization options
- 🥇 Minimal False Positives: Carefully tuned default settings to reduce noise and focus on real issues
- 🔥 Rich Output Formats: Multiple output formats including text with colors, JSON, SARIF, HTML, JUnit-XML, and more
Comprehensive linting coverage:
- Code Quality: Detects bugs, performance issues, and maintainability problems
- Style Enforcement: Ensures consistent formatting and coding conventions
- Security Analysis: Identifies potential security vulnerabilities and unsafe patterns
- Performance Optimization: Finds inefficient code patterns and suggests improvements
- Complexity Analysis: Measures and controls code complexity and cognitive load
- Error Handling: Validates proper error handling patterns in Go
Popular included linters:
- staticcheck: Advanced static analysis for Go
- govet: Official Go static analyzer
- errcheck: Checks for unchecked errors
- gosimple: Suggests code simplifications
- ineffassign: Detects ineffectual assignments
- misspell: Finds commonly misspelled words
- gocyclo: Cyclomatic complexity analysis
- gosec: Security-focused static analysis
Advanced capabilities:
- Smart Caching: Dramatically speeds up repeated runs by caching results
- Incremental Analysis: Can analyze only changed files for faster analysis
- Custom Rules: Support for custom linters and configuration
- Issue Filtering: Sophisticated filtering and suppression of false positives
- Parallel Execution: Concurrent linter execution for maximum speed
Golangci-lint is the industry standard for Go code quality and is used by thousands of Go projects for maintaining high code standards and catching issues early in the development process.
golangci-lint documentation
- Version in MegaLinter: 2.11.4
- Visit Official Web Site
- See How to configure golangci-lint rules
- If custom
.golangci.ymlconfig file isn't found, .golangci.yml will be used
- If custom
- See How to disable golangci-lint rules in files
- See Index of problems detected by golangci-lint
Configuration in MegaLinter
- Enable golangci-lint by adding
GO_GOLANGCI_LINTin ENABLE_LINTERS variable - Disable golangci-lint by adding
GO_GOLANGCI_LINTin DISABLE_LINTERS variable
- Enable autofixes by adding
GO_GOLANGCI_LINTin APPLY_FIXES variable
| Variable | Description | Default value |
|---|---|---|
| GO_GOLANGCI_LINT_ARGUMENTS | User custom arguments to add in linter CLI call Ex: -s --foo "bar" |
|
| GO_GOLANGCI_LINT_COMMAND_REMOVE_ARGUMENTS | User custom arguments to remove from command line before calling the linter Ex: -s --foo "bar" |
|
| GO_GOLANGCI_LINT_CLI_LINT_MODE | Override default CLI lint mode ⚠️ As default value is project, overriding might not work - file: Calls the linter for each file- list_of_files: Call the linter with the list of files as argument- project: Call the linter from the root of the project |
project |
| GO_GOLANGCI_LINT_FILE_EXTENSIONS | Allowed file extensions. "*" matches any extension, "" matches empty extension. Empty list excludes all filesEx: [".py", ""] |
[".go"] |
| GO_GOLANGCI_LINT_FILE_NAMES_REGEX | File name regex filters. Regular expression list for filtering files by their base names using regex full match. Empty list includes all files Ex: ["Dockerfile(-.+)?", "Jenkinsfile"] |
Include every file |
| GO_GOLANGCI_LINT_PRE_COMMANDS | List of bash commands to run before the linter | None |
| GO_GOLANGCI_LINT_POST_COMMANDS | List of bash commands to run after the linter | None |
| GO_GOLANGCI_LINT_UNSECURED_ENV_VARIABLES | List of env variables explicitly not filtered before calling GO_GOLANGCI_LINT and its pre/post commands | None |
| GO_GOLANGCI_LINT_CONFIG_FILE | golangci-lint configuration file name Use LINTER_DEFAULT to let the linter find it |
.golangci.yml |
| GO_GOLANGCI_LINT_RULES_PATH | Path where to find linter configuration file | Workspace folder, then MegaLinter default rules |
| GO_GOLANGCI_LINT_DISABLE_ERRORS | Run linter but consider errors as warnings | false |
| GO_GOLANGCI_LINT_DISABLE_ERRORS_IF_LESS_THAN | Maximum number of errors allowed | 0 |
| GO_GOLANGCI_LINT_CLI_EXECUTABLE | Override CLI executable | ['golangci-lint'] |
IDE Integration
Use golangci-lint in your favorite IDE to catch errors before MegaLinter !
MegaLinter Flavors
This linter is available in the following flavors
| Flavor | Description | Embedded linters | Info | |
|---|---|---|---|---|
![]() |
all | Default MegaLinter Flavor | 136 | |
| cupcake | MegaLinter for the most commonly used languages | 92 | ||
| go | Optimized for GO based projects | 54 |
Behind the scenes
How are identified applicable files
- File extensions:
.go
How the linting is performed
golangci-lint is called once on the whole project directory (project CLI lint mode)
- filtering can not be done using MegaLinter configuration variables,it must be done using golangci-lint configuration or ignore file (if existing)
VALIDATE_ALL_CODEBASE: falsedoesn't make golangci-lint analyze only updated files
Example calls
golangci-lint run myfile.go
golangci-lint run -c .golangci.yml myfile.go
Help content
Smart, fast linters runner.
Usage:
golangci-lint [flags]
golangci-lint [command]
Available Commands:
cache Cache control and information.
completion Generate the autocompletion script for the specified shell
config Configuration file information and verification.
custom Build a version of golangci-lint with custom linters.
fmt Format Go source files.
formatters List current formatters configuration.
help Display extra help
linters List current linters configuration.
migrate Migrate configuration file from v1 to v2.
run Lint the code.
version Display the golangci-lint version.
Flags:
--color string Use color when printing; can be 'always', 'auto', or 'never' (default "auto")
-h, --help Help for a command
-v, --verbose Verbose output
--version Print version
Use "golangci-lint [command] --help" for more information about a command.
Installation on mega-linter Docker image
- Dockerfile commands :
# Parent descriptor install
# renovate: datasource=repology depName=alpine_edge/go versioning=loose
ARG GO_ALPINE_VERSION=1.26.3-r0
RUN apk add --no-cache \
--repository=https://dl-cdn.alpinelinux.org/alpine/edge/main \
--repository=https://dl-cdn.alpinelinux.org/alpine/edge/community \
go=${GO_ALPINE_VERSION}
# Linter install
# renovate: datasource=github-tags depName=golangci/golangci-lint
ARG GO_GOLANGCI_LINT_VERSION=2.11.4
RUN wget -O- -nv https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s "v${GO_GOLANGCI_LINT_VERSION}" \
&& golangci-lint --version
Known errors and resolutions
When this linter fails for a known non-lint reason (remote service unavailable, malformed config, missing credentials, etc.), MegaLinter detects the pattern below in the linter output and surfaces the matching guidance.
GO_GOLANGCI_LINT_ERROR_MODULE_DOWNLOAD
Detection pattern (regex):
(go: .*: (reading|module .*: Get) .*: (dial tcp|TLS handshake|connection refused)|module lookup disabled by GOPROXY=off|verifying .*: checksum mismatch)
Resolution guidance:
golangci-lint could not download Go module dependencies before typechecking.
This is a network/proxy issue, not a lint finding.
Resolutions:
- Retry the run; module proxy outages are usually transient.
- If your project uses a private Go module proxy, set `GOPROXY` / `GOPRIVATE` and whitelist them for this linter in your .mega-linter.yml:
GO_GOLANGCI_LINT_UNSECURED_ENV_VARIABLES:
- GOPROXY
- GOPRIVATE
- GOSUMDB
- GONOSUMCHECK
- Pre-populate `$GOPATH/pkg/mod` in CI cache to avoid downloads on each run.
GO_GOLANGCI_LINT_ERROR_CONFIG_INVALID
Detection pattern (regex):
(can't load config:|failed to load config|unsupported version of the configuration|is not a linter, it cannot be enabled or disabled|is a formatter)
Resolution guidance:
golangci-lint could not load the `.golangci.yml` configuration file.
Resolutions:
- Validate the YAML syntax and indentation of `.golangci.yml`.
- Ensure all linter names referenced under `enable:` / `disable:` exist in the installed golangci-lint version (some linters were renamed/removed across major versions).
- Run `golangci-lint config verify` locally to reproduce.
GO_GOLANGCI_LINT_ERROR_TYPECHECK
Detection pattern (regex):
(typecheck.*could not (import|load)|level=error.*build (failed|error)|# .*\n.*: undefined:)
Resolution guidance:
golangci-lint's typecheck stage failed to build the Go program. golangci-lint requires the code to compile in order to run most analyzers.
Resolutions:
- Run `go build ./...` locally; fix the underlying compilation errors first.
- Ensure all required packages are in `go.mod` and the module cache is reachable.
GO_GOLANGCI_LINT_ERROR_OUT_OF_MEMORY
Detection pattern (regex):
(runtime: out of memory|fatal error: runtime: out of memory|signal: killed)
Resolution guidance:
golangci-lint was killed (OOM) while analyzing a large Go project.
Resolutions:
- Increase the memory available to the MegaLinter container/runner.
- Reduce scope by setting `GO_GOLANGCI_LINT_FILTER_REGEX_INCLUDE` / `..._EXCLUDE` or by enabling fewer linters in `.golangci.yml`.
- Temporarily mark the linter as non-blocking by adding to your .mega-linter.yml:
DISABLE_ERRORS_LINTERS:
- GO_GOLANGCI_LINT

