|
| 1 | +## Golden config for golangci-lint v1.47.3 |
| 2 | +# |
| 3 | +# This is the best config for golangci-lint based on my experience and opinion. |
| 4 | +# It is very strict, but not extremely strict. |
| 5 | +# Feel free to adopt and change it for your needs. |
| 6 | + |
| 7 | +run: |
| 8 | + # Timeout for analysis, e.g. 30s, 5m. |
| 9 | + # Default: 1m |
| 10 | + timeout: 3m |
| 11 | + |
| 12 | + |
| 13 | +# This file contains only configs which differ from defaults. |
| 14 | +# All possible options can be found here https://github.com/golangci/golangci-lint/blob/master/.golangci.reference.yml |
| 15 | +linters-settings: |
| 16 | + cyclop: |
| 17 | + # The maximal code complexity to report. |
| 18 | + # Default: 10 |
| 19 | + max-complexity: 30 |
| 20 | + # The maximal average package complexity. |
| 21 | + # If it's higher than 0.0 (float) the check is enabled |
| 22 | + # Default: 0.0 |
| 23 | + package-average: 10.0 |
| 24 | + |
| 25 | + errcheck: |
| 26 | + # Report about not checking of errors in type assertions: `a := b.(MyStruct)`. |
| 27 | + # Such cases aren't reported by default. |
| 28 | + # Default: false |
| 29 | + check-type-assertions: true |
| 30 | + |
| 31 | + funlen: |
| 32 | + # Checks the number of lines in a function. |
| 33 | + # If lower than 0, disable the check. |
| 34 | + # Default: 60 |
| 35 | + lines: 100 |
| 36 | + # Checks the number of statements in a function. |
| 37 | + # If lower than 0, disable the check. |
| 38 | + # Default: 40 |
| 39 | + statements: 50 |
| 40 | + |
| 41 | + gocognit: |
| 42 | + # Minimal code complexity to report |
| 43 | + # Default: 30 (but we recommend 10-20) |
| 44 | + min-complexity: 20 |
| 45 | + |
| 46 | + gocritic: |
| 47 | + # Settings passed to gocritic. |
| 48 | + # The settings key is the name of a supported gocritic checker. |
| 49 | + # The list of supported checkers can be find in https://go-critic.github.io/overview. |
| 50 | + settings: |
| 51 | + captLocal: |
| 52 | + # Whether to restrict checker to params only. |
| 53 | + # Default: true |
| 54 | + paramsOnly: false |
| 55 | + underef: |
| 56 | + # Whether to skip (*x).method() calls where x is a pointer receiver. |
| 57 | + # Default: true |
| 58 | + skipRecvDeref: false |
| 59 | + |
| 60 | + mnd: |
| 61 | + # List of function patterns to exclude from analysis. |
| 62 | + # Values always ignored: `time.Date` |
| 63 | + # Default: [] |
| 64 | + ignored-functions: |
| 65 | + - os.Chmod |
| 66 | + - os.Mkdir |
| 67 | + - os.MkdirAll |
| 68 | + - os.OpenFile |
| 69 | + - os.WriteFile |
| 70 | + - prometheus.ExponentialBuckets |
| 71 | + - prometheus.ExponentialBucketsRange |
| 72 | + - prometheus.LinearBuckets |
| 73 | + - strconv.FormatFloat |
| 74 | + - strconv.FormatInt |
| 75 | + - strconv.FormatUint |
| 76 | + - strconv.ParseFloat |
| 77 | + - strconv.ParseInt |
| 78 | + - strconv.ParseUint |
| 79 | + |
| 80 | + gomodguard: |
| 81 | + blocked: |
| 82 | + # List of blocked modules. |
| 83 | + # Default: [] |
| 84 | + modules: |
| 85 | + - github.com/golang/protobuf: |
| 86 | + recommendations: |
| 87 | + - google.golang.org/protobuf |
| 88 | + reason: "see https://developers.google.com/protocol-buffers/docs/reference/go/faq#modules" |
| 89 | + - github.com/satori/go.uuid: |
| 90 | + recommendations: |
| 91 | + - github.com/google/uuid |
| 92 | + reason: "satori's package is not maintained" |
| 93 | + - github.com/gofrs/uuid: |
| 94 | + recommendations: |
| 95 | + - github.com/google/uuid |
| 96 | + reason: "see recommendation from dev-infra team: https://confluence.gtforge.com/x/gQI6Aw" |
| 97 | + |
| 98 | + govet: |
| 99 | + # Enable all analyzers. |
| 100 | + # Default: false |
| 101 | + enable-all: true |
| 102 | + # Disable analyzers by name. |
| 103 | + # Run `go tool vet help` to see all analyzers. |
| 104 | + # Default: [] |
| 105 | + disable: |
| 106 | + - fieldalignment # too strict |
| 107 | + # Settings per analyzer. |
| 108 | + settings: |
| 109 | + shadow: |
| 110 | + # Whether to be strict about shadowing; can be noisy. |
| 111 | + # Default: false |
| 112 | + strict: true |
| 113 | + |
| 114 | + nakedret: |
| 115 | + # Make an issue if func has more lines of code than this setting, and it has naked returns. |
| 116 | + # Default: 30 |
| 117 | + max-func-lines: 0 |
| 118 | + |
| 119 | + nolintlint: |
| 120 | + # Exclude following linters from requiring an explanation. |
| 121 | + # Default: [] |
| 122 | + allow-no-explanation: [ funlen, gocognit, lll ] |
| 123 | + # Enable to require an explanation of nonzero length after each nolint directive. |
| 124 | + # Default: false |
| 125 | + require-explanation: true |
| 126 | + # Enable to require nolint directives to mention the specific linter being suppressed. |
| 127 | + # Default: false |
| 128 | + require-specific: true |
| 129 | + |
| 130 | + rowserrcheck: |
| 131 | + # database/sql is always checked |
| 132 | + # Default: [] |
| 133 | + packages: |
| 134 | + - github.com/jmoiron/sqlx |
| 135 | + |
| 136 | + tenv: |
| 137 | + # The option `all` will run against whole test files (`_test.go`) regardless of method/function signatures. |
| 138 | + # Otherwise, only methods that take `*testing.T`, `*testing.B`, and `testing.TB` as arguments are checked. |
| 139 | + # Default: false |
| 140 | + all: true |
| 141 | + |
| 142 | + |
| 143 | +linters: |
| 144 | + disable-all: true |
| 145 | + enable: |
| 146 | + ## enabled by default |
| 147 | + - errcheck # Errcheck is a program for checking for unchecked errors in go programs. These unchecked errors can be critical bugs in some cases |
| 148 | + - gosimple # Linter for Go source code that specializes in simplifying a code |
| 149 | + - govet # Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string |
| 150 | + - ineffassign # Detects when assignments to existing variables are not used |
| 151 | + - staticcheck # Staticcheck is a go vet on steroids, applying a ton of static analysis checks |
| 152 | + - unused # Checks Go code for unused constants, variables, functions and types |
| 153 | + ## disabled by default |
| 154 | + # - asasalint # Check for pass []any as any in variadic func(...any) |
| 155 | + - asciicheck # Simple linter to check that your code does not contain non-ASCII identifiers |
| 156 | + - bidichk # Checks for dangerous unicode character sequences |
| 157 | + - bodyclose # checks whether HTTP response body is closed successfully |
| 158 | + - contextcheck # check the function whether use a non-inherited context |
| 159 | + - cyclop # checks function and package cyclomatic complexity |
| 160 | + - dupl # Tool for code clone detection |
| 161 | + - durationcheck # check for two durations multiplied together |
| 162 | + - errname # Checks that sentinel errors are prefixed with the Err and error types are suffixed with the Error. |
| 163 | + - errorlint # errorlint is a linter for that can be used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13. |
| 164 | + - exhaustive # check exhaustiveness of enum switch statements |
| 165 | + - forbidigo # Forbids identifiers |
| 166 | + - funlen # Tool for detection of long functions |
| 167 | + # - gochecknoglobals # check that no global variables exist |
| 168 | + - gochecknoinits # Checks that no init functions are present in Go code |
| 169 | + - gocognit # Computes and checks the cognitive complexity of functions |
| 170 | + - goconst # Finds repeated strings that could be replaced by a constant |
| 171 | + - gocritic # Provides diagnostics that check for bugs, performance and style issues. |
| 172 | + - gocyclo # Computes and checks the cyclomatic complexity of functions |
| 173 | + - godot # Check if comments end in a period |
| 174 | + - goimports # In addition to fixing imports, goimports also formats your code in the same style as gofmt. |
| 175 | + - gomoddirectives # Manage the use of 'replace', 'retract', and 'excludes' directives in go.mod. |
| 176 | + - gomodguard # Allow and block list linter for direct Go module dependencies. This is different from depguard where there are different block types for example version constraints and module recommendations. |
| 177 | + - goprintffuncname # Checks that printf-like functions are named with f at the end |
| 178 | + - gosec # Inspects source code for security problems |
| 179 | + - lll # Reports long lines |
| 180 | + - makezero # Finds slice declarations with non-zero initial length |
| 181 | + # - nakedret # Finds naked returns in functions greater than a specified function length |
| 182 | + - mnd # An analyzer to detect magic numbers. |
| 183 | + - nestif # Reports deeply nested if statements |
| 184 | + - nilerr # Finds the code that returns nil even if it checks that the error is not nil. |
| 185 | + - nilnil # Checks that there is no simultaneous return of nil error and an invalid value. |
| 186 | + # - noctx # noctx finds sending http request without context.Context |
| 187 | + - nolintlint # Reports ill-formed or insufficient nolint directives |
| 188 | + # - nonamedreturns # Reports all named returns |
| 189 | + - nosprintfhostport # Checks for misuse of Sprintf to construct a host with port in a URL. |
| 190 | + - predeclared # find code that shadows one of Go's predeclared identifiers |
| 191 | + - promlinter # Check Prometheus metrics naming via promlint |
| 192 | + - revive # Fast, configurable, extensible, flexible, and beautiful linter for Go. Drop-in replacement of golint. |
| 193 | + - rowserrcheck # checks whether Err of rows is checked successfully |
| 194 | + - sqlclosecheck # Checks that sql.Rows and sql.Stmt are closed. |
| 195 | + - stylecheck # Stylecheck is a replacement for golint |
| 196 | + - testpackage # linter that makes you use a separate _test package |
| 197 | + - tparallel # tparallel detects inappropriate usage of t.Parallel() method in your Go test codes |
| 198 | + - unconvert # Remove unnecessary type conversions |
| 199 | + - unparam # Reports unused function parameters |
| 200 | + - usetesting # Reports uses of functions with replacement inside the testing package |
| 201 | + - wastedassign # wastedassign finds wasted assignment statements. |
| 202 | + - whitespace # Tool for detection of leading and trailing whitespace |
| 203 | + ## you may want to enable |
| 204 | + #- decorder # check declaration order and count of types, constants, variables and functions |
| 205 | + #- exhaustruct # Checks if all structure fields are initialized |
| 206 | + #- goheader # Checks is file header matches to pattern |
| 207 | + #- ireturn # Accept Interfaces, Return Concrete Types |
| 208 | + #- prealloc # [premature optimization, but can be used in some cases] Finds slice declarations that could potentially be preallocated |
| 209 | + #- varnamelen # [great idea, but too many false positives] checks that the length of a variable's name matches its scope |
| 210 | + #- wrapcheck # Checks that errors returned from external packages are wrapped |
| 211 | + ## disabled |
| 212 | + #- containedctx # containedctx is a linter that detects struct contained context.Context field |
| 213 | + #- depguard # [replaced by gomodguard] Go linter that checks if package imports are in a list of acceptable packages |
| 214 | + #- dogsled # Checks assignments with too many blank identifiers (e.g. x, _, _, _, := f()) |
| 215 | + #- errchkjson # [don't see profit + I'm against of omitting errors like in the first example https://github.com/breml/errchkjson] Checks types passed to the json encoding functions. Reports unsupported types and optionally reports occasions, where the check for the returned error can be omitted. |
| 216 | + #- forcetypeassert # [replaced by errcheck] finds forced type assertions |
| 217 | + #- gci # Gci controls golang package import order and makes it always deterministic. |
| 218 | + #- godox # Tool for detection of FIXME, TODO and other comment keywords |
| 219 | + #- goerr113 # [too strict] Golang linter to check the errors handling expressions |
| 220 | + #- gofmt # [replaced by goimports] Gofmt checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification |
| 221 | + #- gofumpt # [replaced by goimports, gofumports is not available yet] Gofumpt checks whether code was gofumpt-ed. |
| 222 | + #- grouper # An analyzer to analyze expression groups. |
| 223 | + #- ifshort # Checks that your code uses short syntax for if-statements whenever possible |
| 224 | + #- importas # Enforces consistent import aliases |
| 225 | + #- maintidx # maintidx measures the maintainability index of each function. |
| 226 | + #- misspell # [useless] Finds commonly misspelled English words in comments |
| 227 | + #- nlreturn # [too strict and mostly code is not more readable] nlreturn checks for a new line before return and branch statements to increase code clarity |
| 228 | + #- nosnakecase # Detects snake case of variable naming and function name. # TODO: maybe enable after https://github.com/sivchari/nosnakecase/issues/14 |
| 229 | + #- paralleltest # [too many false positives] paralleltest detects missing usage of t.Parallel() method in your Go test |
| 230 | + #- tagliatelle # Checks the struct tags. |
| 231 | + #- thelper # thelper detects golang test helpers without t.Helper() call and checks the consistency of test helpers |
| 232 | + #- wsl # [too strict and mostly code is not more readable] Whitespace Linter - Forces you to use empty lines! |
| 233 | + |
| 234 | + |
| 235 | +issues: |
| 236 | + # Maximum count of issues with the same text. |
| 237 | + # Set to 0 to disable. |
| 238 | + # Default: 3 |
| 239 | + max-same-issues: 50 |
| 240 | + |
| 241 | + exclude-rules: |
| 242 | + - source: "^//\\s*go:generate\\s" |
| 243 | + linters: [ lll ] |
| 244 | + - source: "(noinspection|TODO)" |
| 245 | + linters: [ godot ] |
| 246 | + - source: "//noinspection" |
| 247 | + linters: [ gocritic ] |
| 248 | + - source: "^\\s+if _, ok := err\\.\\([^.]+\\.InternalError\\); ok {" |
| 249 | + linters: [ errorlint ] |
| 250 | + - path: "_test\\.go" |
| 251 | + linters: |
| 252 | + - bodyclose |
| 253 | + - dupl |
| 254 | + - funlen |
| 255 | + - goconst |
| 256 | + - gosec |
| 257 | + - noctx |
| 258 | + - wrapcheck |
0 commit comments