golangci-lint
golangci-lint documentation
- Version in MegaLinter: 1.55.2
- Visit Official Web Site
- See How to configure golangci-lint rules
- If custom
.golangci.yml
config 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_LINT
in ENABLE_LINTERS variable - Disable golangci-lint by adding
GO_GOLANGCI_LINT
in DISABLE_LINTERS variable
- Enable autofixes by adding
GO_GOLANGCI_LINT
in 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_FILTER_REGEX_INCLUDE | Custom regex including filter Ex: (src\|lib) |
Include every file |
GO_GOLANGCI_LINT_FILTER_REGEX_EXCLUDE | Custom regex excluding filter Ex: (test\|examples) |
Exclude no file |
GO_GOLANGCI_LINT_CLI_LINT_MODE | Override default CLI lint mode - 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 |
list_of_files |
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 nameUse 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 Flavours
This linter is available in the following flavours
Flavor | Description | Embedded linters | Info | |
---|---|---|---|---|
![]() |
all | Default MegaLinter Flavor | 118 | |
cupcake | MegaLinter for the most commonly used languages | 85 | ||
go | Optimized for GO based projects | 53 |
Behind the scenes
How are identified applicable files
- File extensions:
.go
How the linting is performed
- golangci-lint is called once with the list of files as arguments (
list_of_files
CLI lint mode)
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 Config
help Help
linters List current linters configuration
run Run the linters
version Version
Flags:
--color string Use color when printing; can be 'always', 'auto', or 'never' (default "auto")
-j, --concurrency int Concurrency (default NumCPU) (default 4)
--cpu-profile-path string Path to CPU profile output file
-h, --help help for golangci-lint
--mem-profile-path string Path to memory profile output file
--trace-path string Path to trace output file
-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 :
RUN wget -O- -nv https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh \
&& golangci-lint --version
- APK packages (Linux):