golangci-lint Configuration¶
The default .golangci.yml configuration used by Go Gamma Actions.
Overview¶
This configuration enables 50+ linters organized by category, with sensible defaults for most Go projects.
Full Configuration¶
version: "2"
run:
timeout: 5m
modules-download-mode: readonly
linters:
default: none
enable:
# Default linters
- errcheck # Unchecked errors
- gosimple # Simplify code
- govet # go vet
- ineffassign # Ineffectual assignments
- staticcheck # Comprehensive analysis
- unused # Unused code
# Bug detection
- bodyclose # HTTP body closure
- copyloopvar # Loop variable capture
- durationcheck # Duration multiplication
- errchkjson # JSON encoding errors
- exhaustive # Exhaustive switches
- makezero # Slice initialization
- nilerr # Nil error returns
- nilnil # (nil, nil) returns
- rowserrcheck # sql.Rows.Err()
- sqlclosecheck # SQL resource cleanup
# Complexity
- cyclop # Cyclomatic complexity
- funlen # Function length
- gocognit # Cognitive complexity
- gocyclo # Cyclomatic complexity
- maintidx # Maintainability index
- nestif # Nested if depth
# Code style
- decorder # Declaration order
- gci # Import ordering
- gofmt # Formatting
- gofumpt # Strict formatting
- goimports # Import management
- goconst # Repeated strings
- gocritic # Comprehensive checks
- godot # Comment periods
- misspell # Spelling
- nakedret # Naked returns
- nolintlint # nolint usage
- prealloc # Slice preallocation
- predeclared # Shadowing builtins
- revive # Style enforcement
- stylecheck # Style checks
- unconvert # Unnecessary conversions
- unparam # Unused parameters
- whitespace # Whitespace issues
# Error handling
- errorlint # Error wrapping
- wrapcheck # Error wrapping
# Security
- gosec # Security issues
# Testing
- testifylint # testify practices
- tenv # os.Setenv in tests
- tparallel # t.Parallel()
linters-settings:
cyclop:
max-complexity: 15
package-average: 10.0
skip-tests: true
errcheck:
check-type-assertions: true
check-blank: true
funlen:
lines: 100
statements: 50
ignore-comments: true
gocognit:
min-complexity: 20
gocyclo:
min-complexity: 15
gocritic:
enabled-tags:
- diagnostic
- style
- performance
- experimental
- opinionated
disabled-checks:
- hugeParam
- rangeValCopy
gofumpt:
extra-rules: true
goimports:
local-prefixes: github.com/go-gamma
govet:
enable-all: true
disable:
- fieldalignment
maintidx:
under: 20
misspell:
locale: US
nakedret:
max-func-lines: 30
nestif:
min-complexity: 5
prealloc:
simple: true
range-loops: true
for-loops: true
revive:
rules:
- name: blank-imports
- name: context-as-argument
- name: context-keys-type
- name: dot-imports
- name: error-return
- name: error-strings
- name: error-naming
- name: exported
- name: if-return
- name: increment-decrement
- name: var-naming
- name: var-declaration
- name: package-comments
- name: range
- name: receiver-naming
- name: time-naming
- name: unexported-return
- name: indent-error-flow
- name: errorf
- name: empty-block
- name: superfluous-else
- name: unused-parameter
- name: unreachable-code
- name: redefines-builtin-id
staticcheck:
checks: [all]
stylecheck:
checks:
- all
- -ST1000
- -ST1003
unparam:
check-exported: false
wrapcheck:
ignore-sigs:
- .Errorf(
- errors.New(
- errors.Unwrap(
- errors.Join(
- .Wrap(
- .Wrapf(
- .WithMessage(
- .WithStack(
issues:
exclude-rules:
- path: _test\.go
linters:
- errcheck
- funlen
- gocognit
- gocyclo
- gosec
- wrapcheck
- dupl
- path: \.pb\.go$
linters: [all]
- path: cmd/
linters:
- gochecknoglobals
- gochecknoinits
exclude-dirs:
- vendor
- third_party
- testdata
- examples
max-issues-per-linter: 50
max-same-issues: 10
Customization¶
Override in Your Project¶
Create .golangci.yml in your project root:
version: "2"
linters-settings:
gocyclo:
min-complexity: 20 # More lenient
issues:
exclude-rules:
- path: legacy/
linters: [all] # Skip legacy code