.golangci.yml 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. version: "2"
  2. linters:
  3. default: none
  4. enable:
  5. # Malicious unicode characters that change the meaning are not in the source code.
  6. - bidichk
  7. # Ensure that the body is closed on HTTP and websocket conns
  8. - bodyclose
  9. - contextcheck
  10. - depguard
  11. # Duplicate word usage, such as 'and and' in a comment.
  12. - dupword
  13. - durationcheck
  14. - errcheck
  15. # Type assertion and comparison validation on errors. https://github.com/polyfloyd/go-errorlint
  16. - errorlint
  17. # Enum and maps used on switch statements are exhaustive
  18. - exhaustive
  19. - exhaustruct
  20. - forcetypeassert
  21. - gocritic
  22. - gosec
  23. - govet
  24. - ineffassign
  25. - loggercheck
  26. # Check for simple misspellings of words.
  27. - misspell
  28. - noctx
  29. # Require explanations for nolint comments
  30. - nolintlint
  31. - prealloc
  32. # Overwriting predeclared Golang names such as 'len' and 'min'.
  33. - predeclared
  34. # Validate common mistakes in Golang, such as invalid time.Parse format, invalid regular expression, etc.
  35. - staticcheck
  36. - unparam
  37. # Unused constants, variables, functions and types
  38. - unused
  39. settings:
  40. depguard:
  41. # Rules to apply.
  42. #
  43. # Variables:
  44. # - File Variables
  45. # Use an exclamation mark `!` to negate a variable.
  46. # Example: `!$test` matches any file that is not a go test file.
  47. #
  48. # `$all` - matches all go files
  49. # `$test` - matches all go test files
  50. #
  51. # - Package Variables
  52. #
  53. # `$gostd` - matches all of go's standard library (Pulled from `GOROOT`)
  54. #
  55. # Default (applies if no custom rules are defined): Only allow $gostd in all files.
  56. rules:
  57. # Name of a rule.
  58. main:
  59. # Defines package matching behavior. Available modes:
  60. # - `original`: allowed if it doesn't match the deny list and either matches the allow list or the allow list is empty.
  61. # - `strict`: allowed only if it matches the allow list and either doesn't match the deny list or the allow rule is more specific (longer) than the deny rule.
  62. # - `lax`: allowed if it doesn't match the deny list or the allow rule is more specific (longer) than the deny rule.
  63. # Default: "original"
  64. list-mode: lax
  65. # List of file globs that will match this list of settings to compare against.
  66. # By default, if a path is relative, it is relative to the directory where the golangci-lint command is executed.
  67. # The placeholder '${base-path}' is substituted with a path relative to the mode defined with `run.relative-path-mode`.
  68. # The placeholder '${config-path}' is substituted with a path relative to the configuration file.
  69. # Default: $all
  70. # files:
  71. # - "!**/*_a _file.go"
  72. # List of allowed packages.
  73. # Entries can be a variable (starting with $), a string prefix, or an exact match (if ending with $).
  74. # Default: []
  75. # allow:
  76. # List of packages that are not allowed.
  77. # Entries can be a variable (starting with $), a string prefix, or an exact match (if ending with $).
  78. # Default: []
  79. deny:
  80. # Debugging can be done without an external dependency.
  81. - pkg: "github.com/davecgh/go-spew/spew"
  82. desc: Use a custom formatter e.g. JSON
  83. # Unmaintained.
  84. - pkg: "github.com/benbjohnson/clock"
  85. desc: deprecated
  86. # Unnecessary for most use cases.
  87. - pkg: "github.com/mitchellh/go-homedir"
  88. desc: Use os.UserHomeDir()
  89. # Unmaintained.
  90. - pkg: "gopkg.in/godo.v2/watcher/fswatch"
  91. desc: Use package fsnotify/fsnotify
  92. - pkg: "github.com/pkg/errors"
  93. desc: Should be replaced by standard lib errors package
  94. errorlint:
  95. errorf: false
  96. exhaustive:
  97. # Program elements to check for exhaustiveness.
  98. # Default: [ switch ]
  99. check:
  100. - switch
  101. - map
  102. ignore-enum-types: "vaa.ChainID" # This type is used all over and doesn't need to be exhaustive
  103. #default-signifies-exhaustive: true
  104. exhaustruct:
  105. include:
  106. # List of regular expressions to match struct packages and their names.
  107. # Regular expressions must match complete canonical struct package/name/structname.
  108. # If this list is empty, all structs are tested.
  109. # Default: []
  110. - ./+governor.tokenConfigEntry$
  111. # TODO: MessagePublications _should_ be exhaustive but this will require many changes.
  112. - ./_common.MessagePublication$
  113. exclude:
  114. - .+/cobra\.Command$
  115. - .+/http\.Client$
  116. - .+/prometheus.+
  117. gocritic:
  118. disable-all: true
  119. # disabled-checks:
  120. # - exitAfterDefer
  121. # - assignOp
  122. # - ifElseChain
  123. # - elseif
  124. enabled-checks:
  125. - argOrder
  126. - badCall
  127. - badCond
  128. - badLock
  129. - badRegexp
  130. - badSorting
  131. - builtinShadow
  132. - builtinShadowDecl
  133. - caseOrder
  134. - dupArg
  135. - dupBranchBody
  136. - dupCase
  137. - dupSubExpr
  138. - externalErrorReassign
  139. - importShadow
  140. - mapKey
  141. - newDeref
  142. - offBy1
  143. - regexpPattern
  144. - sloppyReassign
  145. - truncateCmp
  146. - uncheckedInlineErr
  147. - weakCond
  148. # performance lints
  149. - indexAlloc
  150. nolintlint:
  151. # Disable to ensure that all nolint directives actually have an effect.
  152. # Default: false
  153. allow-unused: false
  154. # Exclude following linters from requiring an explanation.
  155. # Default: []
  156. allow-no-explanation: [dupWord]
  157. # Enable to require an explanation of nonzero length after each nolint directive.
  158. # Default: false
  159. require-explanation: true
  160. # Enable to require nolint directives to mention the specific linter being suppressed.
  161. # Default: false
  162. require-specific: true
  163. staticcheck:
  164. checks:
  165. # All of these lints should eventually be added.
  166. # They occurred during the migration to v2 and were disabled to make the upgrade easier.
  167. # https://golangci-lint.run/usage/linters/#staticcheck
  168. ["all", "-ST1000", "-ST1003", "-ST1016", "-ST1020", "-ST1021", "-ST1022", "-SA9003", "-QF1003", "-QF1006", "-QF1008", "-QF1011", "-S1009", "-ST1017", "-ST1018", "-ST1019", "-ST1023"]
  169. unparam:
  170. # Inspect exported functions.
  171. #
  172. # Set to true if no external program/library imports your code.
  173. # XXX: if you enable this setting, unparam will report a lot of false-positives in text editors:
  174. # if it's called for subdir of a project it can't find external interfaces. All text editor integrations
  175. # with golangci-lint call it on a directory with the changed file.
  176. #
  177. # Default: false
  178. check-exported: true
  179. exclusions:
  180. generated: lax
  181. presets:
  182. - comments
  183. - common-false-positives
  184. - legacy
  185. - std-error-handling
  186. rules:
  187. # This file contains hard-coded Sui core contract addresses that are marked as hardcoded credentials.
  188. - path: pkg/txverifier/sui_test.go
  189. text: 'G101: Potential hardcoded credentials'
  190. - linters:
  191. - dupword
  192. - misspell
  193. path: .*generated_mainnet_tokens\.go$
  194. text: ".*" # This matches any text in the file
  195. - linters:
  196. - godox
  197. path: node/hack/
  198. # Ignore test files for these tools.
  199. - linters:
  200. - contextcheck
  201. - dupWord
  202. - exhaustruct
  203. - nolintlint
  204. path: _test\.go
  205. - linters:
  206. - exhaustruct
  207. path: (?i).*mock.*
  208. paths:
  209. - third_party$
  210. - builtin$
  211. - examples$
  212. issues:
  213. max-issues-per-linter: 0
  214. # Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
  215. max-same-issues: 0
  216. formatters:
  217. exclusions:
  218. generated: lax
  219. paths:
  220. - third_party$
  221. - builtin$
  222. - examples$