Skip to content

golangci-lint

golangci-lint documentation

golangci-lint - GitHub

Configuration in Mega-Linter

Variable Description Default value
GO_GOLANGCI_LINT_ARGUMENTS User custom arguments to add in linter CLI call
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_FILE_EXTENSIONS Allowed file extensions. "*" matches any extension, "" matches empty extension. Empty list excludes all files
Ex: [".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_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 Mega-Linter default rules
GO_GOLANGCI_LINT_DISABLE_ERRORS Run linter but consider errors as warnings false

IDE Integration

Use golangci-lint in your favorite IDE to catch errors before Mega-Linter !

IDE Extension Name Install
Atom go-plus Visit Web Site
Emacs flycheck-golandci-lint Visit Web Site
Emacs SpaceMacs Visit Web Site
goland goland Visit Web Site
Sublime Text SublimeLinter-contrib-golang-cilint Visit Web Site
vim vim-go Visit Web Site
Visual Studio Code vscode.Go Install in VsCode

Mega-Linter Flavours

This linter is available in the following flavours

Flavor Description Embedded linters Info
all Default Mega-Linter Flavor 83 Docker Image Size (tag) Docker Pulls
go Optimized for GO based projects 38 Docker Image Size (tag) Docker Pulls

Behind the scenes

How are identified applicable files

  • File extensions: .go

Example calls

golangci-lint run myfile.go
golangci-lint run -c .golangci.yml myfile.go

Help content

Smart, fast linters runner. Run it in cloud for every GitHub pull request on https://golangci.com

Usage:
  golangci-lint [flags]
  golangci-lint [command]

Available Commands:
  cache       Cache control and information
  completion  Output completion script
  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 2)
      --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

Example success log

Results of golangci-lint linter (version 1.33.0)
See documentation on https://nvuillam.github.io/mega-linter/descriptors/go_golangci_lint/
-----------------------------------------------

[SUCCESS] .automation/test/golang/golang_good_01.go


Example error log

Results of golangci-lint linter (version 1.33.0)
See documentation on https://nvuillam.github.io/mega-linter/descriptors/go_golangci_lint/
-----------------------------------------------

[ERROR] .automation/test/golang/golang_bad_01.go
    level=error msg="[linters context] typechecking error: .automation/test/golang/golang_bad_01.go:1:1: expected 'package', found 'if'"
    level=warning msg="[runner] Can't run linter goanalysis_metalinter: S1020: failed prerequisites: [(inspect@command-line-arguments, isgenerated@command-line-arguments): analysis skipped: errors in package: [-: .automation/test/golang/golang_bad_01.go:1:1: expected 'package', found 'if']]"
    level=warning msg="[runner] Can't run linter unused: buildir: analysis skipped: errors in package: [-: .automation/test/golang/golang_bad_01.go:1:1: expected 'package', found 'if']"
    level=error msg="Running error: buildir: analysis skipped: errors in package: [-: .automation/test/golang/golang_bad_01.go:1:1: expected 'package', found 'if']"