|
| 1 | +# =================================== |
| 2 | +# golangci-lint configuration |
| 3 | +# =================================== |
| 4 | +# This file ensures reproducible linting across local development and CI. |
| 5 | +# Docs: https://golangci-lint.run/usage/configuration/ |
| 6 | + |
| 7 | +run: |
| 8 | + timeout: 5m |
| 9 | + issues-exit-code: 1 |
| 10 | + tests: true |
| 11 | + modules-download-mode: readonly |
| 12 | + |
| 13 | +output: |
| 14 | + formats: |
| 15 | + - format: colored-line-number |
| 16 | + print-issued-lines: true |
| 17 | + print-linter-name: true |
| 18 | + |
| 19 | +linters: |
| 20 | + enable: |
| 21 | + # Default linters |
| 22 | + - errcheck # Check for unchecked errors |
| 23 | + - gosimple # Simplify code |
| 24 | + - govet # Suspicious constructs |
| 25 | + - ineffassign # Detect ineffectual assignments |
| 26 | + - staticcheck # Static analysis |
| 27 | + - unused # Unused code |
| 28 | + |
| 29 | + # Additional recommended |
| 30 | + - bodyclose # HTTP response body close |
| 31 | + - dogsled # Too many blank identifiers |
| 32 | + - dupl # Code duplication (threshold below) |
| 33 | + - errorlint # Error wrapping issues |
| 34 | + - exhaustive # Enum switch completeness |
| 35 | + - gochecknoinits # No init functions |
| 36 | + - goconst # Repeated strings → const |
| 37 | + - gocritic # Opinionated linter |
| 38 | + - gofmt # Formatting check |
| 39 | + - goimports # Import formatting |
| 40 | + - gosec # Security issues |
| 41 | + - misspell # Spelling mistakes |
| 42 | + - nakedret # Naked returns in long functions |
| 43 | + - nilerr # Return nil after error check |
| 44 | + - noctx # HTTP requests without context |
| 45 | + - prealloc # Slice preallocation |
| 46 | + - predeclared # Shadowing predeclared identifiers |
| 47 | + - revive # Replacement for golint |
| 48 | + - unconvert # Unnecessary conversions |
| 49 | + - unparam # Unused function parameters |
| 50 | + - whitespace # Unnecessary whitespace |
| 51 | + |
| 52 | + disable: |
| 53 | + - depguard # Requires configuration for allowed packages |
| 54 | + - funlen # Often too restrictive for table-driven tests |
| 55 | + - gocognit # Cognitive complexity - use judiciously |
| 56 | + - gocyclo # Cyclomatic complexity - use judiciously |
| 57 | + - lll # Line length - gofmt handles wrapping |
| 58 | + |
| 59 | +linters-settings: |
| 60 | + dupl: |
| 61 | + threshold: 150 # Tokens before flagging duplication |
| 62 | + |
| 63 | + errcheck: |
| 64 | + check-type-assertions: true |
| 65 | + check-blank: true |
| 66 | + exclude-functions: |
| 67 | + - io.Copy |
| 68 | + - io.ReadAll |
| 69 | + - (io.ReadCloser).Close |
| 70 | + |
| 71 | + errorlint: |
| 72 | + errorf: true |
| 73 | + asserts: true |
| 74 | + comparison: true |
| 75 | + |
| 76 | + exhaustive: |
| 77 | + default-signifies-exhaustive: true |
| 78 | + |
| 79 | + goconst: |
| 80 | + min-len: 3 |
| 81 | + min-occurrences: 3 |
| 82 | + |
| 83 | + gocritic: |
| 84 | + enabled-tags: |
| 85 | + - diagnostic |
| 86 | + - style |
| 87 | + - performance |
| 88 | + disabled-checks: |
| 89 | + - whyNoLint # Sometimes we need nolint without explanation |
| 90 | + |
| 91 | + goimports: |
| 92 | + local-prefixes: gitlab.bluewillows.net |
| 93 | + |
| 94 | + gosec: |
| 95 | + excludes: |
| 96 | + - G104 # Errors unhandled - errcheck covers this |
| 97 | + - G304 # File path from variable - often intentional |
| 98 | + |
| 99 | + govet: |
| 100 | + enable-all: true |
| 101 | + disable: |
| 102 | + - fieldalignment # Too noisy, minor optimization |
| 103 | + |
| 104 | + misspell: |
| 105 | + locale: US |
| 106 | + |
| 107 | + nakedret: |
| 108 | + max-func-lines: 30 |
| 109 | + |
| 110 | + prealloc: |
| 111 | + simple: true |
| 112 | + for-loops: true |
| 113 | + |
| 114 | + revive: |
| 115 | + rules: |
| 116 | + - name: blank-imports |
| 117 | + - name: context-as-argument |
| 118 | + - name: context-keys-type |
| 119 | + - name: dot-imports |
| 120 | + - name: error-return |
| 121 | + - name: error-strings |
| 122 | + - name: error-naming |
| 123 | + - name: exported |
| 124 | + - name: increment-decrement |
| 125 | + - name: indent-error-flow |
| 126 | + - name: package-comments |
| 127 | + - name: range |
| 128 | + - name: receiver-naming |
| 129 | + - name: time-naming |
| 130 | + - name: unexported-return |
| 131 | + - name: var-declaration |
| 132 | + - name: var-naming |
| 133 | + |
| 134 | + unparam: |
| 135 | + check-exported: false # Can cause issues with interfaces |
| 136 | + |
| 137 | +issues: |
| 138 | + exclude-use-default: false |
| 139 | + max-issues-per-linter: 0 |
| 140 | + max-same-issues: 0 |
| 141 | + |
| 142 | + exclude-rules: |
| 143 | + # Test files can have longer functions and more complexity |
| 144 | + - path: _test\.go |
| 145 | + linters: |
| 146 | + - dupl |
| 147 | + - gosec |
| 148 | + - goconst |
| 149 | + |
| 150 | + # Allow fmt.Print in main for CLI output |
| 151 | + - path: cmd/ |
| 152 | + linters: |
| 153 | + - forbidigo |
| 154 | + |
| 155 | + # Generated code should be excluded |
| 156 | + - path: ".*\\.gen\\.go$" |
| 157 | + linters: |
| 158 | + - dupl |
| 159 | + - goconst |
| 160 | + - gocritic |
| 161 | + |
| 162 | + # Mock files often have unused parameters by design |
| 163 | + - path: mock |
| 164 | + linters: |
| 165 | + - unparam |
| 166 | + |
| 167 | + # Provider implementations may have similar patterns |
| 168 | + - path: providers/ |
| 169 | + linters: |
| 170 | + - dupl |
| 171 | + text: "duplicate of" |
| 172 | + |
| 173 | +severity: |
| 174 | + default-severity: warning |
| 175 | + rules: |
| 176 | + - linters: [gosec, errcheck] |
| 177 | + severity: error |
0 commit comments