.golangci.yml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. # This code is licensed under the terms of the MIT license.
  2. run:
  3. # Timeout for analysis, e.g. 30s, 5m.
  4. # Default: 1m
  5. timeout: 3m
  6. # This file contains only configs which differ from defaults.
  7. # All possible options can be found here https://github.com/golangci/golangci-lint/blob/master/.golangci.reference.yml
  8. linters-settings:
  9. cyclop:
  10. # The maximal code complexity to report.
  11. # Default: 10
  12. max-complexity: 30
  13. # The maximal average package complexity.
  14. # If it's higher than 0.0 (float) the check is enabled
  15. # Default: 0.0
  16. package-average: 10.0
  17. errcheck:
  18. # Report about not checking of errors in type assertions: `a := b.(MyStruct)`.
  19. # Such cases aren't reported by default.
  20. # Default: false
  21. check-type-assertions: true
  22. funlen:
  23. # Checks the number of lines in a function.
  24. # If lower than 0, disable the check.
  25. # Default: 60
  26. lines: 100
  27. # Checks the number of statements in a function.
  28. # If lower than 0, disable the check.
  29. # Default: 40
  30. statements: 50
  31. gocognit:
  32. # Minimal code complexity to report
  33. # Default: 30 (but we recommend 10-20)
  34. min-complexity: 20
  35. gomnd:
  36. # List of function patterns to exclude from analysis.
  37. # Values always ignored: `time.Date`
  38. # Default: []
  39. ignored-functions:
  40. - os.Chmod
  41. - os.Mkdir
  42. - os.MkdirAll
  43. - os.OpenFile
  44. - os.WriteFile
  45. - strconv.FormatFloat
  46. - strconv.FormatInt
  47. - strconv.FormatUint
  48. - strconv.ParseFloat
  49. - strconv.ParseInt
  50. - strconv.ParseUint
  51. govet:
  52. # Enable all analyzers.
  53. # Default: false
  54. enable-all: true
  55. # Disable analyzers by name.
  56. # Run `go tool vet help` to see all analyzers.
  57. # Default: []
  58. disable:
  59. - fieldalignment # too strict
  60. - shadow # too many false positives
  61. nakedret:
  62. # Make an issue if func has more lines of code than this setting, and it has naked returns.
  63. # Default: 30
  64. max-func-lines: 10
  65. nolintlint:
  66. # Exclude following linters from requiring an explanation.
  67. # Default: []
  68. allow-no-explanation: [ funlen, gocognit, lll ]
  69. # Enable to require an explanation of nonzero length after each nolint directive.
  70. # Default: false
  71. require-explanation: true
  72. # Enable to require nolint directives to mention the specific linter being suppressed.
  73. # Default: false
  74. require-specific: true
  75. tenv:
  76. # The option `all` will run against whole test files (`_test.go`) regardless of method/function signatures.
  77. # Otherwise, only methods that take `*testing.T`, `*testing.B`, and `testing.TB` as arguments are checked.
  78. # Default: false
  79. all: true
  80. gosec:
  81. excludes:
  82. - G107 # variables in URLs
  83. - G404 # use of weak random generator
  84. linters:
  85. disable-all: true
  86. enable:
  87. ## enabled by default
  88. - errcheck # checking for unchecked errors, these unchecked errors can be critical bugs in some cases
  89. - gosimple # specializes in simplifying a code
  90. - govet # reports suspicious constructs, such as Printf calls whose arguments do not align with the format string
  91. - ineffassign # detects when assignments to existing variables are not used
  92. - staticcheck # is a go vet on steroids, applying a ton of static analysis checks
  93. - typecheck # like the front-end of a Go compiler, parses and type-checks Go code
  94. - unused # checks for unused constants, variables, functions and types
  95. ## disabled by default
  96. - asasalint # checks for pass []any as any in variadic func(...any)
  97. - asciicheck # checks that your code does not contain non-ASCII identifiers
  98. - bidichk # checks for dangerous unicode character sequences
  99. - bodyclose # checks whether HTTP response body is closed successfully
  100. #- contextcheck # checks the function whether use a non-inherited context # TODO: enable after golangci-lint uses https://github.com/sylvia7788/contextcheck/releases/tag/v1.0.7
  101. - cyclop # checks function and package cyclomatic complexity
  102. - dupl # tool for code clone detection
  103. - durationcheck # checks for two durations multiplied together
  104. - errname # checks that sentinel errors are prefixed with the Err and error types are suffixed with the Error
  105. - errorlint # finds code that will cause problems with the error wrapping scheme introduced in Go 1.13
  106. - execinquery # checks query string in Query function which reads your Go src files and warning it finds
  107. - exhaustive # checks exhaustiveness of enum switch statements
  108. - exportloopref # checks for pointers to enclosing loop variables
  109. - forbidigo # forbids identifiers
  110. - funlen # tool for detection of long functions
  111. #- gochecknoglobals # checks that no global variables exist
  112. #- gochecknoinits # checks that no init functions are present in Go code
  113. - gocognit # computes and checks the cognitive complexity of functions
  114. - goconst # finds repeated strings that could be replaced by a constant
  115. - gocritic # provides diagnostics that check for bugs, performance and style issues
  116. - gocyclo # computes and checks the cyclomatic complexity of functions
  117. #- godot # checks if comments end in a period
  118. #- goimports # in addition to fixing imports, goimports also formats your code in the same style as gofmt
  119. #- gomnd # detects magic numbers - ENABLE LATER
  120. - gomoddirectives # manages the use of 'replace', 'retract', and 'excludes' directives in go.mod
  121. - gomodguard # allow and block lists linter for direct Go module dependencies. This is different from depguard where there are different block types for example version constraints and module recommendations
  122. - goprintffuncname # checks that printf-like functions are named with f at the end
  123. - gosec # inspects source code for security problems
  124. - lll # reports long lines
  125. #- makezero # finds slice declarations with non-zero initial length
  126. - nakedret # finds naked returns in functions greater than a specified function length
  127. - nestif # reports deeply nested if statements
  128. - nilerr # finds the code that returns nil even if it checks that the error is not nil
  129. - nilnil # checks that there is no simultaneous return of nil error and an invalid value
  130. #- noctx # finds sending http request without context.Context
  131. - nolintlint # reports ill-formed or insufficient nolint directives
  132. #- nonamedreturns # reports all named returns
  133. - nosprintfhostport # checks for misuse of Sprintf to construct a host with port in a URL
  134. - predeclared # finds code that shadows one of Go's predeclared identifiers
  135. #- promlinter # checks Prometheus metrics naming via promlint
  136. - reassign # checks that package variables are not reassigned
  137. - revive # fast, configurable, extensible, flexible, and beautiful linter for Go, drop-in replacement of golint
  138. #- rowserrcheck # checks whether Err of rows is checked successfully
  139. #- sqlclosecheck # checks that sql.Rows and sql.Stmt are closed
  140. - stylecheck # is a replacement for golint
  141. - tenv # detects using os.Setenv instead of t.Setenv since Go1.17
  142. #- testpackage # makes you use a separate _test package
  143. - tparallel # detects inappropriate usage of t.Parallel() method in your Go test codes
  144. #- unconvert # removes unnecessary type conversions
  145. - unparam # reports unused function parameters
  146. - usestdlibvars # detects the possibility to use variables/constants from the Go standard library
  147. #- wastedassign # finds wasted assignment statements
  148. #- whitespace # detects leading and trailing whitespace
  149. ## you may want to enable
  150. #- decorder # checks declaration order and count of types, constants, variables and functions
  151. #- exhaustruct # checks if all structure fields are initialized
  152. #- gci # controls golang package import order and makes it always deterministic
  153. - godox # detects FIXME, TODO and other comment keywords
  154. #- goheader # checks is file header matches to pattern
  155. - interfacebloat # checks the number of methods inside an interface
  156. #- ireturn # accept interfaces, return concrete types
  157. #- prealloc # [premature optimization, but can be used in some cases] finds slice declarations that could potentially be preallocated
  158. #- varnamelen # [great idea, but too many false positives] checks that the length of a variable's name matches its scope
  159. #- wrapcheck # checks that errors returned from external packages are wrapped
  160. ## disabled
  161. #- containedctx # detects struct contained context.Context field
  162. #- depguard # [replaced by gomodguard] checks if package imports are in a list of acceptable packages
  163. #- dogsled # checks assignments with too many blank identifiers (e.g. x, _, _, _, := f())
  164. #- 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
  165. #- forcetypeassert # [replaced by errcheck] finds forced type assertions
  166. #- goerr113 # [too strict] checks the errors handling expressions
  167. #- gofmt # [replaced by goimports] checks whether code was gofmt-ed
  168. #- gofumpt # [replaced by goimports, gofumports is not available yet] checks whether code was gofumpt-ed
  169. #- grouper # analyzes expression groups
  170. #- importas # enforces consistent import aliases
  171. #- logrlint # [owner archived repository] checks logr arguments
  172. #- maintidx # measures the maintainability index of each function
  173. #- misspell # [useless] finds commonly misspelled English words in comments
  174. #- nlreturn # [too strict and mostly code is not more readable] checks for a new line before return and branch statements to increase code clarity
  175. #- paralleltest # [too many false positives] detects missing usage of t.Parallel() method in your Go test
  176. #- tagliatelle # checks the struct tags
  177. #- thelper # detects golang test helpers without t.Helper() call and checks the consistency of test helpers
  178. #- wsl # [too strict and mostly code is not more readable] whitespace linter forces you to use empty lines
  179. ## deprecated
  180. #- deadcode # [deprecated, replaced by unused] finds unused code
  181. #- exhaustivestruct # [deprecated, replaced by exhaustruct] checks if all struct's fields are initialized
  182. #- golint # [deprecated, replaced by revive] golint differs from gofmt. Gofmt reformats Go source code, whereas golint prints out style mistakes
  183. #- ifshort # [deprecated] checks that your code uses short syntax for if-statements whenever possible
  184. #- interfacer # [deprecated] suggests narrower interface types
  185. #- maligned # [deprecated, replaced by govet fieldalignment] detects Go structs that would take less memory if their fields were sorted
  186. #- nosnakecase # [deprecated, replaced by revive var-naming] detects snake case of variable naming and function name
  187. #- scopelint # [deprecated, replaced by exportloopref] checks for unpinned variables in go programs
  188. #- structcheck # [deprecated, replaced by unused] finds unused struct fields
  189. #- varcheck # [deprecated, replaced by unused] finds unused global variables and constants
  190. issues:
  191. # Maximum count of issues with the same text.
  192. # Set to 0 to disable.
  193. # Default: 3
  194. max-same-issues: 50
  195. exclude-rules:
  196. - source: "^//\\s*go:generate\\s"
  197. linters: [ lll ]
  198. - source: "(noinspection|TODO)"
  199. linters: [ godot ]
  200. - source: "//noinspection"
  201. linters: [ gocritic ]
  202. - source: "^\\s+if _, ok := err\\.\\([^.]+\\.InternalError\\); ok {"
  203. linters: [ errorlint ]
  204. - path: ".skeleton"
  205. linters:
  206. - unused
  207. - unparam
  208. - path: ".*_test.go"
  209. linters:
  210. - bodyclose
  211. - dupl
  212. - errcheck
  213. - funlen
  214. - gochecknoglobals
  215. - gocognit
  216. - goconst
  217. - gosec
  218. - lll
  219. - noctx
  220. - unparam
  221. - wrapcheck
  222. - linters:
  223. - gocritic
  224. text: "appendAssign:"
  225. - linters:
  226. - revive
  227. text: "unexported-return:"
  228. - linters:
  229. - govet
  230. text: "shadow: declaration of \"err\" shadows declaration"