.golangci.yml 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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. - forbidigo
  21. - forcetypeassert
  22. - gocritic
  23. - gosec
  24. - govet
  25. - ineffassign
  26. - iotamixing
  27. - loggercheck
  28. # Check for simple misspellings of words.
  29. - misspell
  30. - nilerr
  31. - nilnesserr
  32. - noctx
  33. # Require explanations for nolint comments
  34. - nolintlint
  35. - prealloc
  36. # Overwriting predeclared Golang names such as 'len' and 'min'.
  37. - predeclared
  38. # Validate common mistakes in Golang, such as invalid time.Parse format, invalid regular expression, etc.
  39. - staticcheck
  40. - unparam
  41. # Unused constants, variables, functions and types
  42. - unused
  43. settings:
  44. depguard:
  45. # Rules to apply.
  46. #
  47. # Variables:
  48. # - File Variables
  49. # Use an exclamation mark `!` to negate a variable.
  50. # Example: `!$test` matches any file that is not a go test file.
  51. #
  52. # `$all` - matches all go files
  53. # `$test` - matches all go test files
  54. #
  55. # - Package Variables
  56. #
  57. # `$gostd` - matches all of go's standard library (Pulled from `GOROOT`)
  58. #
  59. # Default (applies if no custom rules are defined): Only allow $gostd in all files.
  60. rules:
  61. # Name of a rule.
  62. main:
  63. # Defines package matching behavior. Available modes:
  64. # - `original`: allowed if it doesn't match the deny list and either matches the allow list or the allow list is empty.
  65. # - `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.
  66. # - `lax`: allowed if it doesn't match the deny list or the allow rule is more specific (longer) than the deny rule.
  67. # Default: "original"
  68. list-mode: lax
  69. # List of file globs that will match this list of settings to compare against.
  70. # By default, if a path is relative, it is relative to the directory where the golangci-lint command is executed.
  71. # The placeholder '${base-path}' is substituted with a path relative to the mode defined with `run.relative-path-mode`.
  72. # The placeholder '${config-path}' is substituted with a path relative to the configuration file.
  73. # Default: $all
  74. # files:
  75. # - "!**/*_a _file.go"
  76. # List of allowed packages.
  77. # Entries can be a variable (starting with $), a string prefix, or an exact match (if ending with $).
  78. # Default: []
  79. # allow:
  80. # List of packages that are not allowed.
  81. # Entries can be a variable (starting with $), a string prefix, or an exact match (if ending with $).
  82. # Default: []
  83. deny:
  84. # Debugging can be done without an external dependency.
  85. - pkg: "github.com/davecgh/go-spew/spew"
  86. desc: Use a custom formatter e.g. JSON
  87. # Unmaintained.
  88. - pkg: "github.com/benbjohnson/clock"
  89. desc: deprecated
  90. # Unnecessary for most use cases.
  91. - pkg: "github.com/mitchellh/go-homedir"
  92. desc: Use os.UserHomeDir()
  93. # Unmaintained.
  94. - pkg: "gopkg.in/godo.v2/watcher/fswatch"
  95. desc: Use package fsnotify/fsnotify
  96. - pkg: "github.com/pkg/errors"
  97. desc: Should be replaced by standard lib errors package
  98. errorlint:
  99. errorf: false
  100. exhaustive:
  101. # Program elements to check for exhaustiveness.
  102. # Default: [ switch ]
  103. check:
  104. - switch
  105. - map
  106. ignore-enum-types: "vaa.ChainID" # This type is used all over and doesn't need to be exhaustive
  107. #default-signifies-exhaustive: true
  108. exhaustruct:
  109. include:
  110. # List of regular expressions to match struct packages and their names.
  111. # Regular expressions must match complete canonical struct package/name/structname.
  112. # If this list is empty, all structs are tested.
  113. # Default: []
  114. - ./+governor.tokenConfigEntry$
  115. # TODO: MessagePublications _should_ be exhaustive but this will require many changes.
  116. - ./_common.MessagePublication$
  117. exclude:
  118. - .+/cobra\.Command$
  119. - .+/http\.Client$
  120. - .+/prometheus.+
  121. forbidigo:
  122. forbid:
  123. - pattern: 'io\.ReadAll'
  124. msg: "method can cause DoS for large user-controlled inputs. Use common.SafeRead instead."
  125. exclude-godoc-examples: true
  126. analyze-types: true
  127. gocritic:
  128. disabled-checks:
  129. - assignOp
  130. - appendAssign
  131. - captLocal # We should probably enable this one
  132. - commentFormatting # We should probably enable this one
  133. - elseif
  134. - exitAfterDefer
  135. - ifElseChain
  136. - sloppyLen
  137. - underef
  138. - unslice
  139. govet:
  140. # The following list includes all the linters that are disabled by default.
  141. # Uncomment any of these to enable them:
  142. enable:
  143. # - atomicalign # Check for non-64-bits-aligned arguments to sync/atomic functions
  144. # - deepequalerrors # Check for calls of reflect.DeepEqual on error values
  145. # - fieldalignment # Find structs that would use less memory if their fields were sorted
  146. # - findcall # Find calls to a particular function
  147. - nilness # Check for redundant or impossible nil comparisons
  148. # - reflectvaluecompare # Check for comparing reflect.Value values with == or reflect.DeepEqual
  149. # - shadow # Check for possible unintended shadowing of variables
  150. # - sortslice # Check the argument type of sort.Slice
  151. # - timeformat # Check for calls of (time.Time).Format or time.Parse with 2006-02-01
  152. # - unusedwrite # Check for unused writes
  153. nolintlint:
  154. # Disable to ensure that all nolint directives actually have an effect.
  155. # Default: false
  156. allow-unused: false
  157. # Exclude following linters from requiring an explanation.
  158. # Default: []
  159. allow-no-explanation: [dupWord]
  160. # Enable to require an explanation of nonzero length after each nolint directive.
  161. # Default: false
  162. require-explanation: true
  163. # Enable to require nolint directives to mention the specific linter being suppressed.
  164. # Default: false
  165. require-specific: true
  166. staticcheck:
  167. checks:
  168. # All of these lints should eventually be added.
  169. # They occurred during the migration to v2 and were disabled to make the upgrade easier.
  170. # https://golangci-lint.run/usage/linters/#staticcheck
  171. ["all", "-ST1000", "-ST1003", "-ST1016", "-ST1020", "-ST1021", "-ST1022", "-QF1003", "-QF1006", "-QF1008", "-QF1011", "-S1009", "-ST1017", "-ST1018", "-ST1019", "-ST1023"]
  172. unparam:
  173. # Inspect exported functions.
  174. #
  175. # Set to true if no external program/library imports your code.
  176. # XXX: if you enable this setting, unparam will report a lot of false-positives in text editors:
  177. # if it's called for subdir of a project it can't find external interfaces. All text editor integrations
  178. # with golangci-lint call it on a directory with the changed file.
  179. #
  180. # Default: false
  181. check-exported: true
  182. exclusions:
  183. generated: lax
  184. presets:
  185. - comments
  186. - common-false-positives
  187. - legacy
  188. - std-error-handling
  189. rules:
  190. # This file contains hard-coded Sui core contract addresses that are marked as hardcoded credentials.
  191. - path: pkg/txverifier/sui_test.go
  192. text: 'G101: Potential hardcoded credentials'
  193. - linters:
  194. - dupword
  195. - misspell
  196. path: .*generated_mainnet_tokens\.go$
  197. text: ".*" # This matches any text in the file
  198. - linters:
  199. - godox
  200. path: node/hack/
  201. # Ignore test files for these tools.
  202. - linters:
  203. - contextcheck
  204. - dupWord
  205. - exhaustruct
  206. - nolintlint
  207. path: _test\.go
  208. - linters:
  209. - exhaustruct
  210. path: (?i).*mock.*
  211. paths:
  212. - third_party$
  213. - builtin$
  214. - examples$
  215. issues:
  216. max-issues-per-linter: 0
  217. # Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
  218. max-same-issues: 0
  219. formatters:
  220. exclusions:
  221. generated: lax
  222. paths:
  223. - third_party$
  224. - builtin$
  225. - examples$