go-chatgpt
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

273 lines
13 KiB

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