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