.golangci.yml 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. run:
  2. # timeout for analysis
  3. deadline: 10m
  4. # Skip autogenerated files for mobile and gRPC as well as copied code for
  5. # internal use.
  6. skip-files:
  7. - "mobile\\/.*generated\\.go"
  8. - "\\.pb\\.go$"
  9. - "\\.pb\\.gw\\.go$"
  10. - "internal\\/musig2v040"
  11. skip-dirs:
  12. - channeldb/migration_01_to_11
  13. - channeldb/migration/lnwire21
  14. build-tags:
  15. - autopilotrpc
  16. - chainrpc
  17. - dev
  18. - invoicesrpc
  19. - neutrinorpc
  20. - peersrpc
  21. - signrpc
  22. - walletrpc
  23. - watchtowerrpc
  24. - kvdb_etcd
  25. - kvdb_postgres
  26. - kvdb_sqlite
  27. - integration
  28. linters-settings:
  29. errorlint:
  30. # Check for incorrect fmt.Errorf error wrapping.
  31. errorf: true
  32. govet:
  33. # Don't report about shadowed variables
  34. check-shadowing: false
  35. gofmt:
  36. # simplify code: gofmt with `-s` option, true by default
  37. simplify: true
  38. tagliatelle:
  39. case:
  40. rules:
  41. json: snake
  42. whitespace:
  43. multi-func: true
  44. multi-if: true
  45. gosec:
  46. excludes:
  47. - G402 # Look for bad TLS connection settings.
  48. - G306 # Poor file permissions used when writing to a new file.
  49. staticcheck:
  50. go: "1.21"
  51. checks: ["-SA1019"]
  52. lll:
  53. # Max line length, lines longer will be reported.
  54. line-length: 80
  55. # Tab width in spaces.
  56. tab-width: 8
  57. funlen:
  58. # Checks the number of lines in a function.
  59. # If lower than 0, disable the check.
  60. lines: 200
  61. # Checks the number of statements in a function.
  62. statements: 80
  63. dupl:
  64. # Tokens count to trigger issue.
  65. threshold: 200
  66. nestif:
  67. # Minimal complexity of if statements to report.
  68. min-complexity: 10
  69. nlreturn:
  70. # Size of the block (including return statement that is still "OK")
  71. # so no return split required.
  72. block-size: 3
  73. gomnd:
  74. # List of numbers to exclude from analysis.
  75. # The numbers should be written as string.
  76. # Values always ignored: "1", "1.0", "0" and "0.0"
  77. # Default: []
  78. ignored-numbers:
  79. - '0666'
  80. - '0755'
  81. # List of function patterns to exclude from analysis.
  82. # Values always ignored: `time.Date`
  83. # Default: []
  84. ignored-functions:
  85. - 'math.*'
  86. - 'strconv.ParseInt'
  87. - 'errors.Wrap'
  88. gomoddirectives:
  89. replace-allow-list:
  90. # See go.mod for the explanation why these are needed.
  91. - github.com/ulikunitz/xz
  92. - github.com/gogo/protobuf
  93. - google.golang.org/protobuf
  94. linters:
  95. enable-all: true
  96. disable:
  97. # Global variables are used in many places throughout the code base.
  98. - gochecknoglobals
  99. # We want to allow short variable names.
  100. - varnamelen
  101. # We want to allow TODOs.
  102. - godox
  103. # Instances of table driven tests that don't pre-allocate shouldn't trigger
  104. # the linter.
  105. - prealloc
  106. # Init functions are used by loggers throughout the codebase.
  107. - gochecknoinits
  108. # Deprecated linters. See https://golangci-lint.run/usage/linters/.
  109. - interfacer
  110. - golint
  111. - maligned
  112. - scopelint
  113. - exhaustivestruct
  114. - bodyclose
  115. - contextcheck
  116. - nilerr
  117. - noctx
  118. - rowserrcheck
  119. - sqlclosecheck
  120. - structcheck
  121. - tparallel
  122. - unparam
  123. - wastedassign
  124. - ifshort
  125. - varcheck
  126. - deadcode
  127. - nosnakecase
  128. # Disable gofumpt as it has weird behavior regarding formatting multiple
  129. # lines for a function which is in conflict with our contribution
  130. # guidelines. See https://github.com/mvdan/gofumpt/issues/235.
  131. - gofumpt
  132. # Disable whitespace linter as it has conflict rules against our
  133. # contribution guidelines. See https://github.com/bombsimon/wsl/issues/109.
  134. #
  135. # TODO(yy): bring it back when the above issue is fixed.
  136. - wsl
  137. # Allow using default empty values.
  138. - exhaustruct
  139. # Allow exiting case select faster by putting everything in default.
  140. - exhaustive
  141. # Allow tests to be put in the same package.
  142. - testpackage
  143. # Don't run the cognitive related linters.
  144. - gocognit
  145. - gocyclo
  146. - maintidx
  147. - cyclop
  148. # Allow customized interfaces to be returned from functions.
  149. - ireturn
  150. # Disable too many blank identifiers check. We won't be able to run this
  151. # unless a large refactor has been applied to old code.
  152. - dogsled
  153. # We don't wrap errors.
  154. - wrapcheck
  155. # Allow dynamic errors.
  156. - goerr113
  157. # We use ErrXXX instead.
  158. - errname
  159. # Disable nil check to allow returning multiple nil values.
  160. - nilnil
  161. # We often split tests into separate test functions. If we are forced to
  162. # call t.Helper() within those functions, we lose the information where
  163. # exactly a test failed in the generated failure stack trace.
  164. - thelper
  165. # The linter is too aggressive and doesn't add much value since reviewers
  166. # will also catch magic numbers that make sense to extract.
  167. - gomnd
  168. # Some of the tests cannot be parallelized. On the other hand, we don't
  169. # gain much performance with this check so we disable it for now until
  170. # unit tests become our CI bottleneck.
  171. - paralleltest
  172. issues:
  173. # Only show newly introduced problems.
  174. new-from-rev: 8c66353e4c02329abdacb5a8df29998035ec2e24
  175. exclude-rules:
  176. # Exclude gosec from running for tests so that tests with weak randomness
  177. # (math/rand) will pass the linter.
  178. - path: _test\.go
  179. linters:
  180. - gosec
  181. - funlen
  182. - revive
  183. # Allow duplications in tests so it's easier to follow a single unit
  184. # test.
  185. - dupl
  186. - path: mock*
  187. linters:
  188. - revive
  189. # forcetypeassert is skipped for the mock because the test would fail
  190. # if the returned value doesn't match the type, so there's no need to
  191. # check the convert.
  192. - forcetypeassert
  193. - path: test*
  194. linters:
  195. - gosec
  196. - funlen
  197. # Allow duplicated code and fmt.Printf() in DB migrations.
  198. - path: channeldb/migration*
  199. linters:
  200. - dupl
  201. - forbidigo
  202. - godot
  203. # Allow duplicated code and fmt.Printf() in DB migration tests.
  204. - path: channeldb/migtest
  205. linters:
  206. - dupl
  207. - forbidigo
  208. - godot
  209. # Allow fmt.Printf() in lncli.
  210. - path: cmd/lncli/*
  211. linters:
  212. - forbidigo
  213. # Allow fmt.Printf() in config parsing.
  214. - path: config\.go
  215. linters:
  216. - forbidigo
  217. - path: lnd\.go
  218. linters:
  219. - forbidigo
  220. - path: lnmock/*
  221. linters:
  222. # forcetypeassert is skipped for the mock because the test would fail
  223. # if the returned value doesn't match the type, so there's no need to
  224. # check the convert.
  225. - forcetypeassert
  226. - path: mock*
  227. linters:
  228. # forcetypeassert is skipped for the mock because the test would fail
  229. # if the returned value doesn't match the type, so there's no need to
  230. # check the convert.
  231. - forcetypeassert