.golangci.yml 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. ## This file contains all available configuration options
  2. ## with their default values.
  3. # See https://github.com/golangci/golangci-lint#config-file
  4. # See https://golangci-lint.run/usage/configuration/
  5. # Options for analysis running.
  6. run:
  7. # Exit code when at least one issue was found.
  8. # Default: 1
  9. issues-exit-code: 2
  10. # Include test files or not.
  11. # Default: true
  12. tests: false
  13. # Which dirs to skip: issues from them won't be reported.
  14. # Can use regexp here: `generated.*`, regexp is applied on full path.
  15. # Default value is empty list,
  16. # but default dirs are skipped independently of this option's value (see skip-dirs-use-default).
  17. # "/" will be replaced by current OS file path separator to properly work on Windows.
  18. skip-dirs: []
  19. # Which files to skip: they will be analyzed, but issues from them won't be reported.
  20. # Default value is empty list,
  21. # but there is no need to include all autogenerated files,
  22. # we confidently recognize autogenerated files.
  23. # If it's not please let us know.
  24. # "/" will be replaced by current OS file path separator to properly work on Windows.
  25. skip-files: []
  26. # Main linters configurations.
  27. # See https://golangci-lint.run/usage/linters
  28. linters:
  29. # Disable all default enabled linters.
  30. disable-all: true
  31. # Custom enable linters we want to use.
  32. enable:
  33. - errcheck # Errcheck is a program for checking for unchecked errors in go programs.
  34. - 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.
  35. - funlen # Tool for detection of long functions
  36. - goconst # Finds repeated strings that could be replaced by a constant
  37. - gocritic # Provides diagnostics that check for bugs, performance and style issues.
  38. - gofmt # Gofmt checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification
  39. - gosimple # Linter for Go source code that specializes in simplifying code
  40. - govet # Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string
  41. - misspell # Finds commonly misspelled English words in comments
  42. - nolintlint # Reports ill-formed or insufficient nolint directives
  43. - revive # Fast, configurable, extensible, flexible, and beautiful linter for Go. Drop-in replacement of golint.
  44. - staticcheck # It's a set of rules from staticcheck. It's not the same thing as the staticcheck binary.
  45. - typecheck # Like the front-end of a Go compiler, parses and type-checks Go code
  46. - usestdlibvars # A linter that detect the possibility to use variables/constants from the Go standard library.
  47. - whitespace # Tool for detection of leading and trailing whitespace
  48. issues:
  49. exclude-rules:
  50. # helpers in tests often (rightfully) pass a *testing.T as their first argument
  51. - path: _test\.go
  52. text: "context.Context should be the first parameter of a function"
  53. linters:
  54. - revive
  55. # Yes, they are, but it's okay in a test
  56. - path: _test\.go
  57. text: "exported func.*returns unexported type.*which can be annoying to use"
  58. linters:
  59. - revive
  60. # https://github.com/go-critic/go-critic/issues/926
  61. - linters:
  62. - gocritic
  63. text: "unnecessaryDefer:"
  64. # https://golangci-lint.run/usage/linters
  65. linters-settings:
  66. # https://golangci-lint.run/usage/linters/#misspell
  67. misspell:
  68. locale: US
  69. ignore-words:
  70. - cancelled
  71. # https://golangci-lint.run/usage/linters/#revive
  72. # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md
  73. revive:
  74. ignore-generated-header: true
  75. severity: error
  76. rules:
  77. - name: atomic
  78. - name: line-length-limit
  79. severity: error
  80. arguments: [ 380 ]
  81. - name: unhandled-error
  82. severity: warning
  83. disabled: true
  84. arguments: []
  85. - name: var-naming
  86. severity: warning
  87. disabled: true
  88. arguments:
  89. # AllowList
  90. - [ "ID","URL","IP","HTTP","JSON","API","UID","Id","Api","Uid","Http","Json","Ip","Url" ]
  91. # DenyList
  92. - [ "VM" ]
  93. - name: string-format
  94. severity: warning
  95. disabled: false
  96. arguments:
  97. - - 'core.WriteError[1].Message'
  98. - '/^([^A-Z]|$)/'
  99. - must not start with a capital letter
  100. - - 'fmt.Errorf[0]'
  101. - '/(^|[^\.!?])$/'
  102. - must not end in punctuation
  103. - - panic
  104. - '/^[^\n]*$/'
  105. - must not contain line breaks
  106. - name: function-result-limit
  107. severity: warning
  108. disabled: false
  109. arguments: [ 4 ]
  110. # https://golangci-lint.run/usage/linters/#funlen
  111. funlen:
  112. # Checks the number of lines in a function.
  113. # If lower than 0, disable the check.
  114. # Default: 60
  115. lines: 330
  116. # Checks the number of statements in a function.
  117. # If lower than 0, disable the check.
  118. # Default: 40
  119. statements: -1
  120. # https://golangci-lint.run/usage/linters/#goconst
  121. goconst:
  122. # Minimal length of string constant.
  123. # Default: 3
  124. min-len: 4
  125. # Minimum occurrences of constant string count to trigger issue.
  126. # Default: 3
  127. # For subsequent optimization, the value is reduced.
  128. min-occurrences: 30
  129. # Ignore test files.
  130. # Default: false
  131. ignore-tests: true
  132. # Look for existing constants matching the values.
  133. # Default: true
  134. match-constant: false
  135. # Search also for duplicated numbers.
  136. # Default: false
  137. numbers: true
  138. # Minimum value, only works with goconst.numbers
  139. # Default: 3
  140. min: 5
  141. # Maximum value, only works with goconst.numbers
  142. # Default: 3
  143. max: 20
  144. # Ignore when constant is not used as function argument.
  145. # Default: true
  146. ignore-calls: false
  147. # https://golangci-lint.run/usage/linters/#gocritic
  148. gocritic:
  149. disabled-checks:
  150. - ifElseChain
  151. - assignOp
  152. - appendAssign
  153. - singleCaseSwitch
  154. - regexpMust
  155. - typeSwitchVar
  156. - elseif
  157. # https://golangci-lint.run/usage/linters/#gosimple
  158. gosimple:
  159. # Select the Go version to target.
  160. # Default: 1.13
  161. # Deprecated: use the global `run.go` instead.
  162. go: "1.15"
  163. # Sxxxx checks in https://staticcheck.io/docs/configuration/options/#checks
  164. # Default: ["*"]
  165. checks: [
  166. "all", "-S1000", "-S1001", "-S1002", "-S1008", "-S1009", "-S1016", "-S1023", "-S1025", "-S1029", "-S1034", "-S1040"
  167. ]
  168. # https://golangci-lint.run/usage/linters/#govet
  169. govet:
  170. # Report about shadowed variables.
  171. # Default: false
  172. check-shadowing: true
  173. # Settings per analyzer.
  174. settings:
  175. # Analyzer name, run `go tool vet help` to see all analyzers.
  176. printf:
  177. # Comma-separated list of print function names to check (in addition to default, see `go tool vet help printf`).
  178. # Default: []
  179. funcs:
  180. - (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
  181. - (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
  182. - (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
  183. - (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
  184. # shadow:
  185. # Whether to be strict about shadowing; can be noisy.
  186. # Default: false
  187. # strict: false
  188. unusedresult:
  189. # Comma-separated list of functions whose results must be used
  190. # (in addition to defaults context.WithCancel,context.WithDeadline,context.WithTimeout,context.WithValue,
  191. # errors.New,fmt.Errorf,fmt.Sprint,fmt.Sprintf,sort.Reverse)
  192. # Default []
  193. funcs:
  194. - pkg.MyFunc
  195. - context.WithCancel
  196. # Comma-separated list of names of methods of type func() string whose results must be used
  197. # (in addition to default Error,String)
  198. # Default []
  199. stringmethods:
  200. - MyMethod
  201. # Enable all analyzers.
  202. # Default: false
  203. enable-all: true
  204. # Disable analyzers by name.
  205. # Run `go tool vet help` to see all analyzers.
  206. # Default: []
  207. disable:
  208. - asmdecl
  209. - assign
  210. - atomic
  211. - atomicalign
  212. - bools
  213. - buildtag
  214. - cgocall
  215. - composites
  216. - copylocks
  217. - deepequalerrors
  218. - errorsas
  219. - fieldalignment
  220. - findcall
  221. - framepointer
  222. - httpresponse
  223. - ifaceassert
  224. - loopclosure
  225. - lostcancel
  226. - nilfunc
  227. - nilness
  228. - reflectvaluecompare
  229. - shift
  230. - shadow
  231. - sigchanyzer
  232. - sortslice
  233. - stdmethods
  234. - stringintconv
  235. - structtag
  236. - testinggoroutine
  237. - tests
  238. - unmarshal
  239. - unreachable
  240. - unsafeptr
  241. - unusedwrite
  242. # https://golangci-lint.run/usage/linters/#staticcheck
  243. staticcheck:
  244. # Select the Go version to target.
  245. # Default: "1.13"
  246. # Deprecated: use the global `run.go` instead.
  247. go: "1.15"
  248. # SAxxxx checks in https://staticcheck.io/docs/configuration/options/#checks
  249. # Default: ["*"]
  250. checks: [ "all","-SA1019","-SA4015","-SA1029","-SA1016","-SA9003","-SA4006","-SA6003" ]
  251. # https://golangci-lint.run/usage/linters/#gofmt
  252. gofmt:
  253. # Simplify code: gofmt with `-s` option.
  254. # Default: true
  255. simplify: true
  256. # Apply the rewrite rules to the source before reformatting.
  257. # https://pkg.go.dev/cmd/gofmt
  258. # Default: []
  259. rewrite-rules: [ ]
  260. # - pattern: 'interface{}'
  261. # replacement: 'any'
  262. # - pattern: 'a[b:len(a)]'
  263. # replacement: 'a[b:]'