| name | golangci-lint |
| description | Configure and run golangci-lint |
golangci-lint
Meta-linter that runs multiple linters in parallel.
Install
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
Usage
golangci-lint run
golangci-lint run ./...
golangci-lint run --fix
Basic Configuration
run:
timeout: 5m
tests: true
linters:
enable:
- gofmt
- govet
- staticcheck
- errcheck
- gosimple
- ineffassign
- unused
linters-settings:
errcheck:
check-blank: true
govet:
check-shadowing: true
Recommended Linters
linters:
enable:
- gofmt
- govet
- staticcheck
- errcheck
- gosimple
- ineffassign
- unused
- revive
- gocyclo
- misspell
Exclude Patterns
issues:
exclude-rules:
- path: _test\.go
linters:
- errcheck
- gosec
- text: "should have comment"
linters:
- revive
CI Integration
golangci-lint run --out-format=github-actions
golangci-lint run --out-format=code-climate > gl-code-quality-report.json
Common Fixes
errcheck: Unchecked Error
file.Close()
defer file.Close()
gosimple: Redundant Code
for i, _ := range items
for i := range items
ineffassign: Ineffective Assignment
result := compute()
result = other()
result := other()
Performance Tuning
run:
concurrency: 4
deadline: 5m
skip-dirs:
- vendor
- third_party