golangci-lint: Linter Aggregator for Go
\n\n1. What It Is and Why You Need It
\n\ngolangci-lint is a powerful linter aggregator for the Go language that combines dozens of popular static code analysis tools into a single, fast, and configurable interface. Instead of installing and running each linter separately (e.g., vet, staticcheck, errcheck, gocyclo, and dozens of others), the developer gets one command that runs them all in parallel, caches results, and produces a unified report. This saves hours of CI/CD setup and local development time.
Why is it needed? In large Go projects (microservices, CLI utilities, web servers), maintaining code quality manually is impossible. Errors like unhandled errors, unused variables, incorrect formatting, or potential deadlocks can lead to bugs in production. golangci-lint automatically finds such issues during code review or pre-commit. It also helps maintain a consistent code style within the team, which is critical for readability and maintainability.
\n\nKey advantages over running linters individually: speed (linters run in parallel, results are cached), flexibility (you can enable/disable any linter, configure its rules via YAML config), integration (works with IDEs, CI/CD systems, supports go vet out of the box), and unified output format (JSON, SARIF, colored text — for any tool).
2. Installation
\n\nInstalling golangci-lint can be done in several ways. The recommended method is via go install (requires Go 1.18+):
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest\n\nAfter installation, the binary will be available in $GOPATH/bin (usually ~/go/bin). Verify the installation:
golangci-lint --version\n\nAlternative methods (for CI/CD or if Go is not available):
\n- \n
- Linux/macOS (curl):
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.55.2\n - macOS (Homebrew):
brew install golangci-lint\n - Docker:
docker run --rm -v $(pwd):/app -w /app golangci/golangci-lint:v1.55.2 golangci-lint run -v\n
3. Quick Start — Minimal Working Example
\n\nCreate a simple Go module and a file with an intentional error:
\n\nmkdir myproject && cd myproject\ngo mod init myproject\n\nCreate a file main.go:
package main\n\nimport "fmt"\n\nfunc main() {\n x := 10\n fmt.Println("Hello")\n // Error: unused variable x\n}\n\nRun the linter:
\n\ngolangci-lint run\n\nThe output will be something like:
\n\nmain.go:6:2: `x` is unused (deadcode)\n x := 10\n ^\n\nThe linter found an unused variable. Fix the code (remove the line x := 10) and run it again — there will be no errors.
For a stricter check, use the -v (verbose) flag and --fast (only fast linters):
golangci-lint run -v --fast\n\n4. Main Methods/Functions/Commands
\n\nUnlike a library, golangci-lint is a CLI tool. Its "methods" are commands and flags. Let's look at 8 key commands and options.
\n\n4.1. run — Main linter execution
\nSignature: golangc
Also in library
Working with Excel in Kotlin: Apache POI and Apache POI for Kotlin Libraries
Node.js Task Scheduler (node-cron, node-schedule, Bull)
Reactive Programming in Rust: Libraries, Frameworks, and Practical Examples
Working with Excel in Kotlin: Apache POI Libraries and Kotlin Wrappers
GraphQL Java — server library for implementing GraphQL API in Java