.golangci.yml 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. # See https://github.com/golangci/golangci-lint#config-file
  2. run:
  3. issues-exit-code: 1 #Default
  4. tests: true #Default
  5. linters:
  6. # Disable everything by default so upgrades to not include new "default
  7. # enabled" linters.
  8. disable-all: true
  9. # Specifically enable linters we want to use.
  10. enable:
  11. - asasalint
  12. - bodyclose
  13. - depguard
  14. - errcheck
  15. - errorlint
  16. - godot
  17. - gofumpt
  18. - goimports
  19. - gosec
  20. - gosimple
  21. - govet
  22. - ineffassign
  23. - misspell
  24. - perfsprint
  25. - revive
  26. - staticcheck
  27. - testifylint
  28. - typecheck
  29. - unconvert
  30. - unused
  31. - unparam
  32. - usestdlibvars
  33. - usetesting
  34. issues:
  35. # Maximum issues count per one linter.
  36. # Set to 0 to disable.
  37. # Default: 50
  38. # Setting to unlimited so the linter only is run once to debug all issues.
  39. max-issues-per-linter: 0
  40. # Maximum count of issues with the same text.
  41. # Set to 0 to disable.
  42. # Default: 3
  43. # Setting to unlimited so the linter only is run once to debug all issues.
  44. max-same-issues: 0
  45. # Excluding configuration per-path, per-linter, per-text and per-source.
  46. exclude-rules:
  47. # TODO: Having appropriate comments for exported objects helps development,
  48. # even for objects in internal packages. Appropriate comments for all
  49. # exported objects should be added and this exclusion removed.
  50. - path: '.*internal/.*'
  51. text: "exported (method|function|type|const) (.+) should have comment or be unexported"
  52. linters:
  53. - revive
  54. # Yes, they are, but it's okay in a test.
  55. - path: _test\.go
  56. text: "exported func.*returns unexported type.*which can be annoying to use"
  57. linters:
  58. - revive
  59. # Example test functions should be treated like main.
  60. - path: example.*_test\.go
  61. text: "calls to (.+) only in main[(][)] or init[(][)] functions"
  62. linters:
  63. - revive
  64. # It's okay to not run gosec and perfsprint in a test.
  65. - path: _test\.go
  66. linters:
  67. - gosec
  68. - perfsprint
  69. # Ignoring gosec G404: Use of weak random number generator (math/rand instead of crypto/rand)
  70. # as we commonly use it in tests and examples.
  71. - text: "G404:"
  72. linters:
  73. - gosec
  74. # Ignoring gosec G402: TLS MinVersion too low
  75. # as the https://pkg.go.dev/crypto/tls#Config handles MinVersion default well.
  76. - text: "G402: TLS MinVersion too low."
  77. linters:
  78. - gosec
  79. include:
  80. # revive exported should have comment or be unexported.
  81. - EXC0012
  82. # revive package comment should be of the form ...
  83. - EXC0013
  84. linters-settings:
  85. depguard:
  86. rules:
  87. non-tests:
  88. files:
  89. - "!$test"
  90. - "!**/*test/*.go"
  91. - "!**/internal/matchers/*.go"
  92. deny:
  93. - pkg: "testing"
  94. - pkg: "github.com/stretchr/testify"
  95. - pkg: "crypto/md5"
  96. - pkg: "crypto/sha1"
  97. - pkg: "crypto/**/pkix"
  98. auto/sdk:
  99. files:
  100. - "!internal/global/trace.go"
  101. - "~internal/global/trace_test.go"
  102. deny:
  103. - pkg: "go.opentelemetry.io/auto/sdk"
  104. desc: Do not use SDK from automatic instrumentation.
  105. otlp-internal:
  106. files:
  107. - "!**/exporters/otlp/internal/**/*.go"
  108. deny:
  109. - pkg: "go.opentelemetry.io/otel/exporters/otlp/internal"
  110. desc: Do not use cross-module internal packages.
  111. otlptrace-internal:
  112. files:
  113. - "!**/exporters/otlp/otlptrace/*.go"
  114. - "!**/exporters/otlp/otlptrace/internal/**.go"
  115. deny:
  116. - pkg: "go.opentelemetry.io/otel/exporters/otlp/otlptrace/internal"
  117. desc: Do not use cross-module internal packages.
  118. otlpmetric-internal:
  119. files:
  120. - "!**/exporters/otlp/otlpmetric/internal/*.go"
  121. - "!**/exporters/otlp/otlpmetric/internal/**/*.go"
  122. deny:
  123. - pkg: "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/internal"
  124. desc: Do not use cross-module internal packages.
  125. otel-internal:
  126. files:
  127. - "**/sdk/*.go"
  128. - "**/sdk/**/*.go"
  129. - "**/exporters/*.go"
  130. - "**/exporters/**/*.go"
  131. - "**/schema/*.go"
  132. - "**/schema/**/*.go"
  133. - "**/metric/*.go"
  134. - "**/metric/**/*.go"
  135. - "**/bridge/*.go"
  136. - "**/bridge/**/*.go"
  137. - "**/trace/*.go"
  138. - "**/trace/**/*.go"
  139. - "**/log/*.go"
  140. - "**/log/**/*.go"
  141. deny:
  142. - pkg: "go.opentelemetry.io/otel/internal$"
  143. desc: Do not use cross-module internal packages.
  144. - pkg: "go.opentelemetry.io/otel/internal/attribute"
  145. desc: Do not use cross-module internal packages.
  146. - pkg: "go.opentelemetry.io/otel/internal/internaltest"
  147. desc: Do not use cross-module internal packages.
  148. - pkg: "go.opentelemetry.io/otel/internal/matchers"
  149. desc: Do not use cross-module internal packages.
  150. godot:
  151. exclude:
  152. # Exclude links.
  153. - '^ *\[[^]]+\]:'
  154. # Exclude sentence fragments for lists.
  155. - '^[ ]*[-•]'
  156. # Exclude sentences prefixing a list.
  157. - ':$'
  158. goimports:
  159. local-prefixes: go.opentelemetry.io
  160. misspell:
  161. locale: US
  162. ignore-words:
  163. - cancelled
  164. perfsprint:
  165. err-error: true
  166. errorf: true
  167. int-conversion: true
  168. sprintf1: true
  169. strconcat: true
  170. revive:
  171. # Sets the default failure confidence.
  172. # This means that linting errors with less than 0.8 confidence will be ignored.
  173. # Default: 0.8
  174. confidence: 0.01
  175. # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md
  176. rules:
  177. - name: blank-imports
  178. - name: bool-literal-in-expr
  179. - name: constant-logical-expr
  180. - name: context-as-argument
  181. disabled: true
  182. arguments:
  183. - allowTypesBefore: "*testing.T"
  184. - name: context-keys-type
  185. - name: deep-exit
  186. - name: defer
  187. arguments:
  188. - ["call-chain", "loop"]
  189. - name: dot-imports
  190. - name: duplicated-imports
  191. - name: early-return
  192. arguments:
  193. - "preserveScope"
  194. - name: empty-block
  195. - name: empty-lines
  196. - name: error-naming
  197. - name: error-return
  198. - name: error-strings
  199. - name: errorf
  200. - name: exported
  201. arguments:
  202. - "sayRepetitiveInsteadOfStutters"
  203. - name: flag-parameter
  204. - name: identical-branches
  205. - name: if-return
  206. - name: import-shadowing
  207. - name: increment-decrement
  208. - name: indent-error-flow
  209. arguments:
  210. - "preserveScope"
  211. - name: package-comments
  212. - name: range
  213. - name: range-val-in-closure
  214. - name: range-val-address
  215. - name: redefines-builtin-id
  216. - name: string-format
  217. arguments:
  218. - - panic
  219. - '/^[^\n]*$/'
  220. - must not contain line breaks
  221. - name: struct-tag
  222. - name: superfluous-else
  223. arguments:
  224. - "preserveScope"
  225. - name: time-equal
  226. - name: unconditional-recursion
  227. - name: unexported-return
  228. - name: unhandled-error
  229. arguments:
  230. - "fmt.Fprint"
  231. - "fmt.Fprintf"
  232. - "fmt.Fprintln"
  233. - "fmt.Print"
  234. - "fmt.Printf"
  235. - "fmt.Println"
  236. - name: unnecessary-stmt
  237. - name: useless-break
  238. - name: var-declaration
  239. - name: var-naming
  240. arguments:
  241. - ["ID"] # AllowList
  242. - ["Otel", "Aws", "Gcp"] # DenyList
  243. - name: waitgroup-by-value
  244. testifylint:
  245. enable-all: true
  246. disable:
  247. - float-compare
  248. - go-require
  249. - require-error