Custom Linting¶
Configure golangci-lint for your project's specific needs.
Using Custom Configuration¶
Step 1: Create Configuration¶
Create .golangci.yml in your project root:
version: "2"
linters-settings:
gocyclo:
min-complexity: 20 # Override default
issues:
exclude-dirs:
- generated
Step 2: Reference in Workflow¶
Common Customizations¶
Increase Complexity Limits¶
For legacy or complex codebases:
Exclude Directories¶
Exclude Specific Files¶
issues:
exclude-rules:
- path: _mock\.go$
linters: [all]
- path: internal/legacy/
linters:
- gocyclo
- funlen
Disable Linters¶
Enable Additional Linters¶
Per-File Configuration¶
Suppress in Code¶
Suppress with Reason¶
Suppress Specific Line¶
Team Guidelines¶
Recommended Exclusions¶
issues:
exclude-rules:
# Test files are more lenient
- path: _test\.go
linters:
- errcheck
- funlen
- gocyclo
# Generated code
- path: \.pb\.go$
linters: [all]
# Main packages
- path: cmd/
linters:
- gochecknoglobals
Recommended Limits¶
| Metric | Default | Recommended |
|---|---|---|
| Cyclomatic complexity | 15 | 10-20 |
| Cognitive complexity | 20 | 15-30 |
| Function length | 100 | 80-150 |
| Max issues | 50 | 20-100 |