|
| 1 | +## Golden config for golangci-lint - strict, but within the realm of what Go authors might use. |
| 2 | +# |
| 3 | +# This is tied to the version of golangci-lint listed in the Makefile, usage with other |
| 4 | +# versions of golangci-lint will yield errors and/or false positives. |
| 5 | +# |
| 6 | +# Docs: https://github.com/golangci/golangci-lint/blob/HEAD/.golangci.reference.yml |
| 7 | +# Based heavily on https://gist.github.com/maratori/47a4d00457a92aa426dbd48a18776322 |
| 8 | + |
| 9 | +version: "2" |
| 10 | + |
| 11 | +issues: |
| 12 | + # Maximum issues count per one linter. Set to 0 to disable. Default is 50. |
| 13 | + max-issues-per-linter: 0 |
| 14 | + # Maximum count of issues with the same text. Set to 0 to disable. Default is 3. |
| 15 | + max-same-issues: 0 |
| 16 | + |
| 17 | +formatters: |
| 18 | + enable: |
| 19 | + # - gci |
| 20 | + # - gofmt |
| 21 | + - gofumpt |
| 22 | + # - goimports |
| 23 | + # - golines |
| 24 | + - swaggo |
| 25 | + |
| 26 | + settings: |
| 27 | + golines: |
| 28 | + # Default: 100 |
| 29 | + max-len: 120 |
| 30 | + |
| 31 | +linters: |
| 32 | + default: all |
| 33 | + disable: |
| 34 | + # linters that give advice contrary to what the Go authors advise |
| 35 | + - decorder # checks declaration order and count of types, constants, variables and functions |
| 36 | + - dupword # [useless without config] checks for duplicate words in the source code |
| 37 | + - exhaustruct # [highly recommend to enable] checks if all structure fields are initialized |
| 38 | + - forcetypeassert # [replaced by errcheck] finds forced type assertions |
| 39 | + - ginkgolinter # [if you use ginkgo/gomega] enforces standards of using ginkgo and gomega |
| 40 | + - gochecknoglobals # checks that no global variables exist |
| 41 | + - cyclop # replaced by revive |
| 42 | + - gocyclo # replaced by revive |
| 43 | + - forbidigo # needs configuration to be useful |
| 44 | + - funlen # replaced by revive |
| 45 | + - godox # TODO's are OK |
| 46 | + - ireturn # It's OK |
| 47 | + - musttag |
| 48 | + - nonamedreturns |
| 49 | + - goconst # finds repeated strings that could be replaced by a constant |
| 50 | + - goheader # checks is file header matches to pattern |
| 51 | + - gomodguard # [use more powerful depguard] allow and block lists linter for direct Go module dependencies |
| 52 | + - gomoddirectives |
| 53 | + - err113 # bad advice about dynamic errors |
| 54 | + - lll # [replaced by golines] reports long lines |
| 55 | + - mnd # detects magic numbers, duplicated by revive |
| 56 | + - nlreturn # [too strict and mostly code is not more readable] checks for a new line before return and branch statements to increase code clarity |
| 57 | + - noinlineerr # disallows inline error handling `if err := ...; err != nil {` |
| 58 | + - prealloc # [premature optimization, but can be used in some cases] finds slice declarations that could potentially be preallocated |
| 59 | + - tagliatelle # needs configuration |
| 60 | + - testableexamples # checks if examples are testable (have an expected output) |
| 61 | + - testpackage # makes you use a separate _test package |
| 62 | + - paralleltest # not every test should be in parallel |
| 63 | + - wrapcheck # not required |
| 64 | + - wsl # [too strict and mostly code is not more readable] whitespace linter forces you to use empty lines |
| 65 | + - wsl_v5 # [too strict and mostly code is not more readable] add or remove empty lines |
| 66 | + - zerologlint # detects the wrong usage of zerolog that a user forgets to dispatch zerolog.Event |
| 67 | + |
| 68 | + # All settings can be found here https://github.com/golangci/golangci-lint/blob/HEAD/.golangci.reference.yml |
| 69 | + settings: |
| 70 | + depguard: |
| 71 | + rules: |
| 72 | + "deprecated": |
| 73 | + files: |
| 74 | + - "$all" |
| 75 | + deny: |
| 76 | + - pkg: github.com/golang/protobuf |
| 77 | + desc: Use google.golang.org/protobuf instead, see https://developers.google.com/protocol-buffers/docs/reference/go/faq#modules |
| 78 | + - pkg: github.com/satori/go.uuid |
| 79 | + desc: Use github.com/google/uuid instead, satori's package is not maintained |
| 80 | + - pkg: github.com/gofrs/uuid$ |
| 81 | + desc: Use github.com/gofrs/uuid/v5 or later, it was not a go module before v5 |
| 82 | + "non-test files": |
| 83 | + files: |
| 84 | + - "!$test" |
| 85 | + deny: |
| 86 | + - pkg: math/rand$ |
| 87 | + desc: Use math/rand/v2 instead, see https://go.dev/blog/randv2 |
| 88 | + - pkg: "github.com/sirupsen/logrus" |
| 89 | + desc: not allowed |
| 90 | + - pkg: "github.com/pkg/errors" |
| 91 | + desc: Should be replaced by standard lib errors package |
| 92 | + |
| 93 | + dupl: |
| 94 | + # token count (default: 150) |
| 95 | + threshold: 300 |
| 96 | + |
| 97 | + embeddedstructfieldcheck: |
| 98 | + # Checks that sync.Mutex and sync.RWMutex are not used as embedded fields. |
| 99 | + forbid-mutex: true |
| 100 | + |
| 101 | + errcheck: |
| 102 | + # Report about not checking of errors in type assertions: `a := b.(MyStruct)`. |
| 103 | + check-type-assertions: true |
| 104 | + check-blank: true |
| 105 | + |
| 106 | + exhaustive: |
| 107 | + # Program elements to check for exhaustiveness. |
| 108 | + # Default: [ switch ] |
| 109 | + check: |
| 110 | + - switch |
| 111 | + - map |
| 112 | + default-signifies-exhaustive: true |
| 113 | + |
| 114 | + fatcontext: |
| 115 | + # Check for potential fat contexts in struct pointers. |
| 116 | + # May generate false positives. |
| 117 | + # Default: false |
| 118 | + check-struct-pointers: true |
| 119 | + |
| 120 | + funcorder: |
| 121 | + # Checks if the exported methods of a structure are placed before the non-exported ones. |
| 122 | + struct-method: false |
| 123 | + |
| 124 | + gocognit: |
| 125 | + min-complexity: 55 |
| 126 | + |
| 127 | + gocritic: |
| 128 | + enable-all: true |
| 129 | + disabled-checks: |
| 130 | + - paramTypeCombine |
| 131 | + # The list of supported checkers can be found at https://go-critic.com/overview. |
| 132 | + settings: |
| 133 | + captLocal: |
| 134 | + # Whether to restrict checker to params only. |
| 135 | + paramsOnly: false |
| 136 | + underef: |
| 137 | + # Whether to skip (*x).method() calls where x is a pointer receiver. |
| 138 | + skipRecvDeref: false |
| 139 | + hugeParam: |
| 140 | + # Default: 80 |
| 141 | + sizeThreshold: 200 |
| 142 | + |
| 143 | + govet: |
| 144 | + enable-all: true |
| 145 | + |
| 146 | + godot: |
| 147 | + scope: toplevel |
| 148 | + |
| 149 | + inamedparam: |
| 150 | + # Skips check for interface methods with only a single parameter. |
| 151 | + skip-single-param: true |
| 152 | + |
| 153 | + nakedret: |
| 154 | + # Default: 30 |
| 155 | + max-func-lines: 4 |
| 156 | + |
| 157 | + nestif: |
| 158 | + min-complexity: 12 |
| 159 | + |
| 160 | + nolintlint: |
| 161 | + # Exclude following linters from requiring an explanation. |
| 162 | + # Default: [] |
| 163 | + allow-no-explanation: [funlen, gocognit, golines] |
| 164 | + # Enable to require an explanation of nonzero length after each nolint directive. |
| 165 | + require-explanation: true |
| 166 | + # Enable to require nolint directives to mention the specific linter being suppressed. |
| 167 | + require-specific: true |
| 168 | + |
| 169 | + revive: |
| 170 | + enable-all-rules: true |
| 171 | + rules: |
| 172 | + - name: add-constant |
| 173 | + severity: warning |
| 174 | + disabled: false |
| 175 | + exclude: [""] |
| 176 | + arguments: |
| 177 | + - max-lit-count: "5" |
| 178 | + allow-strs: '"","\n"' |
| 179 | + allow-ints: "0,1,2,3,24,30,60,100,365,0o600,0o700,0o750,0o755" |
| 180 | + allow-floats: "0.0,0.,1.0,1.,2.0,2." |
| 181 | + - name: cognitive-complexity |
| 182 | + arguments: [55] |
| 183 | + - name: cyclomatic |
| 184 | + arguments: [60] |
| 185 | + - name: function-length |
| 186 | + arguments: [150, 225] |
| 187 | + - name: line-length-limit |
| 188 | + arguments: [150] |
| 189 | + - name: nested-structs |
| 190 | + disabled: true |
| 191 | + - name: max-public-structs |
| 192 | + arguments: [10] |
| 193 | + - name: flag-parameter # fixes are difficult |
| 194 | + disabled: true |
| 195 | + |
| 196 | + rowserrcheck: |
| 197 | + # database/sql is always checked. |
| 198 | + # Default: [] |
| 199 | + packages: |
| 200 | + - github.com/jmoiron/sqlx |
| 201 | + |
| 202 | + perfsprint: |
| 203 | + # optimize fmt.Sprintf("x: %s", y) into "x: " + y |
| 204 | + strconcat: false |
| 205 | + |
| 206 | + staticcheck: |
| 207 | + checks: |
| 208 | + - all |
| 209 | + |
| 210 | + usetesting: |
| 211 | + # Enable/disable `os.TempDir()` detections. |
| 212 | + # Default: false |
| 213 | + os-temp-dir: true |
| 214 | + |
| 215 | + varnamelen: |
| 216 | + max-distance: 40 |
| 217 | + min-name-length: 2 |
| 218 | + |
| 219 | + exclusions: |
| 220 | + # Default: [] |
| 221 | + presets: |
| 222 | + - common-false-positives |
| 223 | + rules: |
| 224 | + # Allow "err" and "ok" vars to shadow existing declarations, otherwise we get too many false positives. |
| 225 | + - text: '^shadow: declaration of "(err|ok)" shadows declaration' |
| 226 | + linters: |
| 227 | + - govet |
| 228 | + - text: "parameter 'ctx' seems to be unused, consider removing or renaming it as _" |
| 229 | + linters: |
| 230 | + - revive |
| 231 | + - path: _test\.go |
| 232 | + linters: |
| 233 | + - dupl |
| 234 | + - gosec |
| 235 | + - godot |
| 236 | + - govet # alignment |
| 237 | + - noctx |
| 238 | + - perfsprint |
| 239 | + - revive |
| 240 | + - varnamelen |
0 commit comments