This document explains how the .golangci.yml configuration enforces the Tiger Style principles from tigerstyle.dev.
- Function Length: Limited to 70 lines (
funlen: lines: 70) - Cyclomatic Complexity: Max 10 per function (
cyclop: max-complexity: 10) - Package Functions: Max 15 functions per package (
cyclop: max-functions: 15)
- Explicit Types: Enforced by
staticcheckandgosimple - Variable Scope: Minimized through
varcheckandunused - Memory Safety: Checked by
gosecandgovet
- All Errors Must Be Handled: Enforced by
errcheck - No Unused Variables: Enforced by
unusedandvarcheck - Proper Error Wrapping: Enforced by
wrapcheck
- Resource Optimization: Enforced by
prealloc,unparam,wastedassign - Predictable Code: Enforced by
staticcheckandgosimple - Efficient Patterns: Enforced by
gocritic
- Memory Allocation: Checked by
prealloc - Unused Parameters: Detected by
unparam - Wasted Assignments: Caught by
wastedassign
- Clear Naming: Enforced by
revivewith custom rules - Consistent Style: Enforced by
gofmtandgoimports - No Abbreviations: Enforced by
revivenaming rules - Units in Names: Encouraged through documentation
- Logical Structure: Enforced by
reviveandstaticcheck - Simple Interfaces: Enforced by
unparamandgocritic - Consistent Formatting: Enforced by
gofmt,goimports,whitespace
- No Duplicates: Enforced by
dupl - Consistent Indentation: Enforced by
gofmtandwhitespace - Line Length: Limited to 100 characters (
lll: line-length: 100) - Standardized Tooling: Enforced through consistent linting rules
cyclop: Control flow complexityfunlen: Function length limitserrcheck: Error handlinggovet: Go vet checksgosimple: Code simplificationstaticcheck: Static analysisgocritic: Code quality checksgosec: Security checks
prealloc: Pre-allocate slicesunparam: Unused parameterswastedassign: Wasted assignmentsunconvert: Unnecessary conversions
revive: Code style and naminggofmt: Code formattinggoimports: Import organizationlll: Line length limitsmisspell: Spelling checkswhitespace: Whitespace consistencydupl: Duplicate code detection
- Function length limits relaxed for test files
- Complexity limits relaxed for test files
- All linters disabled for test data directories
- All linters disabled for generated code
- Mock files excluded from most checks
- Function length limits relaxed for main command files
- Migration files have relaxed constraints
# Install golangci-lint
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
# Run linting
golangci-lint run
# Run with specific linters
golangci-lint run --enable=revive,staticcheck
# Fix auto-fixable issues
golangci-lint run --fixThe configuration is already integrated into the GitHub Actions workflow at .github/workflows/linter.yml.
Most Go IDEs support golangci-lint integration. Configure your IDE to use the .golangci.yml file for consistent linting across all environments.
- Function Length: Strict 70-line limit for production code
- Complexity: Maximum cyclomatic complexity of 10
- Error Handling: All errors must be explicitly handled
- Naming: Descriptive names with units/qualifiers when appropriate
- Consistency: Uniform formatting and style across the codebase
- Resource Optimization: Pre-allocate slices, avoid wasted assignments
- Predictable Code: Use explicit types, avoid magic numbers
- Efficient Patterns: Follow Go best practices for performance
- Readability: Clear, consistent code formatting
- Maintainability: Logical organization and structure
- Collaboration: Standardized tooling and practices
This configuration enforces Tiger Style principles by:
- Treating all warnings as errors
- Setting strict limits on function complexity and length
- Enforcing comprehensive error handling
- Maintaining a consistent code style and formatting
- Promoting performance-conscious coding practices
The goal is to create code that is safe, performant, and enjoyable to work with, following the core principles outlined in the Tiger Style guide.