.golangci.yml 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. linters:
  2. enable:
  3. - bodyclose
  4. - copyloopvar # Detects places where loop variables are copied.
  5. - depguard
  6. - dogsled
  7. - dupword # Detects duplicate words.
  8. - durationcheck
  9. - errchkjson
  10. - forbidigo
  11. - gocritic # Metalinter; detects bugs, performance, and styling issues.
  12. - gocyclo
  13. - gofumpt # Detects whether code was gofumpt-ed.
  14. - goimports
  15. - gosec # Detects security problems.
  16. - gosimple
  17. - govet
  18. - ineffassign
  19. - misspell # Detects commonly misspelled English words in comments.
  20. - nakedret # Detects uses of naked returns.
  21. - nilerr # Detects code that returns nil even if it checks that the error is not nil.
  22. - nolintlint # Detects ill-formed or insufficient nolint directives.
  23. - perfsprint # Detects fmt.Sprintf uses that can be replaced with a faster alternative.
  24. - prealloc # Detects slice declarations that could potentially be pre-allocated.
  25. - predeclared # Detects code that shadows one of Go's predeclared identifiers
  26. - reassign
  27. - revive # Metalinter; drop-in replacement for golint.
  28. - staticcheck
  29. - stylecheck # Replacement for golint
  30. - thelper # Detects test helpers without t.Helper().
  31. - tparallel # Detects inappropriate usage of t.Parallel().
  32. - typecheck
  33. - unconvert # Detects unnecessary type conversions.
  34. - unparam
  35. - unused
  36. - usestdlibvars
  37. - usetesting # Reports uses of functions with replacement inside the testing package.
  38. - wastedassign
  39. disable:
  40. - errcheck
  41. run:
  42. # prevent golangci-lint from deducting the go version to lint for through go.mod,
  43. # which causes it to fallback to go1.17 semantics.
  44. #
  45. # TODO(thaJeztah): update "usetesting" settings to enable go1.24 features once our minimum version is go1.24
  46. go: "1.23.8"
  47. timeout: 5m
  48. linters-settings:
  49. depguard:
  50. rules:
  51. main:
  52. deny:
  53. - pkg: "github.com/containerd/containerd/errdefs"
  54. desc: The containerd errdefs package was migrated to a separate module. Use github.com/containerd/errdefs instead.
  55. - pkg: "github.com/containerd/containerd/log"
  56. desc: The containerd log package was migrated to a separate module. Use github.com/containerd/log instead.
  57. - pkg: "github.com/containerd/containerd/pkg/userns"
  58. desc: Use github.com/moby/sys/userns instead.
  59. - pkg: "github.com/containerd/containerd/platforms"
  60. desc: The containerd platforms package was migrated to a separate module. Use github.com/containerd/platforms instead.
  61. - pkg: "github.com/docker/docker/pkg/system"
  62. desc: This package should not be used unless strictly necessary.
  63. - pkg: "github.com/docker/distribution/uuid"
  64. desc: Use github.com/google/uuid instead.
  65. - pkg: "io/ioutil"
  66. desc: The io/ioutil package has been deprecated, see https://go.dev/doc/go1.16#ioutil
  67. forbidigo:
  68. forbid:
  69. - pkg: ^regexp$
  70. p: ^regexp\.MustCompile
  71. msg: Use internal/lazyregexp.New instead.
  72. gocyclo:
  73. min-complexity: 16
  74. gosec:
  75. excludes:
  76. - G104 # G104: Errors unhandled; (TODO: reduce unhandled errors, or explicitly ignore)
  77. - G113 # G113: Potential uncontrolled memory consumption in Rat.SetString (CVE-2022-23772); (only affects go < 1.16.14. and go < 1.17.7)
  78. - G115 # G115: integer overflow conversion; (TODO: verify these: https://github.com/docker/cli/issues/5584)
  79. - G306 # G306: Expect WriteFile permissions to be 0600 or less (too restrictive; also flags "0o644" permissions)
  80. - G307 # G307: Deferring unsafe method "*os.File" on type "Close" (also EXC0008); (TODO: evaluate these and fix where needed: G307: Deferring unsafe method "*os.File" on type "Close")
  81. govet:
  82. enable:
  83. - shadow
  84. settings:
  85. shadow:
  86. strict: true
  87. lll:
  88. line-length: 200
  89. nakedret:
  90. # Disallow naked returns if func has more lines of code than this setting.
  91. # Default: 30
  92. max-func-lines: 0
  93. revive:
  94. rules:
  95. # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#empty-block
  96. - name: empty-block
  97. severity: warning
  98. disabled: false
  99. # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#empty-lines
  100. - name: empty-lines
  101. severity: warning
  102. disabled: false
  103. # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#import-shadowing
  104. - name: import-shadowing
  105. severity: warning
  106. disabled: false
  107. # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#line-length-limit
  108. - name: line-length-limit
  109. severity: warning
  110. disabled: false
  111. arguments: [200]
  112. # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unused-receiver
  113. - name: unused-receiver
  114. severity: warning
  115. disabled: false
  116. # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#use-any
  117. - name: use-any
  118. severity: warning
  119. disabled: false
  120. usetesting:
  121. # FIXME(thaJeztah): Disable `os.Chdir()` detections; should be automatically disabled on Go < 1.24; see https://github.com/docker/cli/pull/5835#issuecomment-2665302478
  122. os-chdir: false
  123. # FIXME(thaJeztah): Disable `context.Background()` detections; should be automatically disabled on Go < 1.24; see https://github.com/docker/cli/pull/5835#issuecomment-2665302478
  124. context-background: false
  125. # FIXME(thaJeztah): Disable `context.TODO()` detections; should be automatically disabled on Go < 1.24; see https://github.com/docker/cli/pull/5835#issuecomment-2665302478
  126. context-todo: false
  127. issues:
  128. # The default exclusion rules are a bit too permissive, so copying the relevant ones below
  129. exclude-use-default: false
  130. # This option has been defined when Go modules was not existed and when the
  131. # golangci-lint core was different, this is not something we still recommend.
  132. exclude-dirs-use-default: false
  133. exclude:
  134. - parameter .* always receives
  135. exclude-files:
  136. - cli/compose/schema/bindata.go
  137. - .*generated.*
  138. exclude-rules:
  139. # We prefer to use an "exclude-list" so that new "default" exclusions are not
  140. # automatically inherited. We can decide whether or not to follow upstream
  141. # defaults when updating golang-ci-lint versions.
  142. # Unfortunately, this means we have to copy the whole exclusion pattern, as
  143. # (unlike the "include" option), the "exclude" option does not take exclusion
  144. # ID's.
  145. #
  146. # These exclusion patterns are copied from the default excluses at:
  147. # https://github.com/golangci/golangci-lint/blob/v1.44.0/pkg/config/issues.go#L10-L104
  148. #
  149. # The default list of exclusions can be found at:
  150. # https://golangci-lint.run/usage/false-positives/#default-exclusions
  151. # EXC0001
  152. - text: "Error return value of .((os\\.)?std(out|err)\\..*|.*Close|.*Flush|os\\.Remove(All)?|.*print(f|ln)?|os\\.(Un)?Setenv). is not checked"
  153. linters:
  154. - errcheck
  155. # EXC0003
  156. - text: "func name will be used as test\\.Test.* by other packages, and that stutters; consider calling this"
  157. linters:
  158. - revive
  159. # EXC0006
  160. - text: "Use of unsafe calls should be audited"
  161. linters:
  162. - gosec
  163. # EXC0007
  164. - text: "Subprocess launch(ed with variable|ing should be audited)"
  165. linters:
  166. - gosec
  167. # EXC0009
  168. - text: "(Expect directory permissions to be 0750 or less|Expect file permissions to be 0600 or less)"
  169. linters:
  170. - gosec
  171. # EXC0010
  172. - text: "Potential file inclusion via variable"
  173. linters:
  174. - gosec
  175. # TODO: make sure all packages have a description. Currently, there's 67 packages without.
  176. - text: "package-comments: should have a package comment"
  177. linters:
  178. - revive
  179. # Exclude some linters from running on tests files.
  180. - path: _test\.go
  181. linters:
  182. - errcheck
  183. - gosec
  184. - text: "ST1000: at least one file in a package should have a package comment"
  185. linters:
  186. - stylecheck
  187. # Allow "err" and "ok" vars to shadow existing declarations, otherwise we get too many false positives.
  188. - text: '^shadow: declaration of "(err|ok)" shadows declaration'
  189. linters:
  190. - govet
  191. # Maximum issues count per one linter. Set to 0 to disable. Default is 50.
  192. max-issues-per-linter: 0
  193. # Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
  194. max-same-issues: 0