Recommended Go linters and golangci-lint configuration. Use when setting up linting for a Go project or configuring CI/CD.
Install
npx skillscat add cxuu/golang-skills/go-linting Install via the SkillsCat registry.
We need to produce a 2-3 sentence plain-text summary, objective, factual, no marketing language, no superlatives, no calls to action. Must be at most 60 words. No markdown formatting, no bullet points, no headings. Just plain text. Should explain what the skill does, what problem it solves, when to use it. Must be 2-3 sentences. Let's craft about 3 sentences maybe. Count words. Possible summary: "This skill provides a recommended set of Go linters and a golangci-lint configuration to enforce consistent code quality.
Go Linting
Source: Uber Go Style Guide
Core Principle
More important than any "blessed" set of linters: lint consistently across a codebase.
Consistent linting helps catch common issues and establishes a high bar for code quality without being unnecessarily prescriptive.
Minimum Recommended Linters
Source: Uber Go Style Guide
These linters catch the most common issues while maintaining a high quality bar:
| Linter | Purpose |
|---|---|
| errcheck | Ensure errors are handled |
| goimports | Format code and manage imports |
| revive | Common style mistakes (modern replacement for golint) |
| govet | Analyze code for common mistakes |
| staticcheck | Various static analysis checks |
Note:
reviveis the modern, faster successor to the now-deprecatedgolint.
Lint Runner: golangci-lint
Source: Uber Go Style Guide
Use golangci-lint as your lint runner:
- Performance: Optimized for large codebases
- Unified config: Configure many linters at once
- Extensible: Add linters as needed for your project
See the example .golangci.yml from uber-go/guide.
Example Configuration
Create .golangci.yml in your project root:
linters:
enable:
- errcheck
- goimports
- revive
- govet
- staticcheck
linters-settings:
goimports:
local-prefixes: github.com/your-org/your-repo
revive:
rules:
- name: blank-imports
- name: context-as-argument
- name: error-return
- name: error-strings
- name: exported
run:
timeout: 5mRunning
# Install
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
# Run all linters
golangci-lint run
# Run on specific paths
golangci-lint run ./pkg/...Quick Reference
| Task | Command/Action |
|---|---|
| Install golangci-lint | go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest |
| Run linters | golangci-lint run |
| Run on path | golangci-lint run ./pkg/... |
| Config file | .golangci.yml in project root |
| CI integration | Run golangci-lint run in pipeline |
Linter Selection Guidelines
| When you need... | Use |
|---|---|
| Error handling coverage | errcheck |
| Import formatting | goimports |
| Style consistency | revive |
| Bug detection | govet, staticcheck |
| All of the above | golangci-lint with config |
See Also
- For core style principles:
go-style-core - For testing best practices:
go-testing