.golangci.yml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. # This file contains all available configuration options
  2. # with their default values.
  3. # options for analysis running
  4. run:
  5. # default concurrency is a available CPU number
  6. concurrency: 4
  7. # timeout for analysis, e.g. 30s, 5m, default is 1m
  8. timeout: 1m
  9. # exit code when at least one issue was found, default is 1
  10. issues-exit-code: 1
  11. # include test files or not, default is true
  12. tests: true
  13. # list of build tags, all linters use it. Default is empty list.
  14. build-tags:
  15. - mytag
  16. # which dirs to skip: issues from them won't be reported;
  17. # can use regexp here: generated.*, regexp is applied on full path;
  18. # default value is empty list, but default dirs are skipped independently
  19. # from this option's value (see skip-dirs-use-default).
  20. skip-dirs:
  21. - src/external_libs
  22. - autogenerated_by_my_lib
  23. # default is true. Enables skipping of directories:
  24. # vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
  25. skip-dirs-use-default: true
  26. # which files to skip: they will be analyzed, but issues from them
  27. # won't be reported. Default value is empty list, but there is
  28. # no need to include all autogenerated files, we confidently recognize
  29. # autogenerated files. If it's not please let us know.
  30. skip-files:
  31. - ".*\\.my\\.go$"
  32. - lib/bad.go
  33. # by default isn't set. If set we pass it to "go list -mod={option}". From "go help modules":
  34. # If invoked with -mod=readonly, the go command is disallowed from the implicit
  35. # automatic updating of go.mod described above. Instead, it fails when any changes
  36. # to go.mod are needed. This setting is most useful to check that go.mod does
  37. # not need updates, such as in a continuous integration and testing system.
  38. # If invoked with -mod=vendor, the go command assumes that the vendor
  39. # directory holds the correct copies of dependencies and ignores
  40. # the dependency descriptions in go.mod.
  41. #! modules-download-mode: readonly|release|vendor
  42. # output configuration options
  43. output:
  44. # colored-line-number|line-number|json|tab|checkstyle|code-climate, default is "colored-line-number"
  45. format: colored-line-number
  46. # print lines of code with issue, default is true
  47. print-issued-lines: true
  48. # print linter name in the end of issue text, default is true
  49. print-linter-name: true
  50. # make issues output unique by line, default is true
  51. uniq-by-line: true
  52. # all available settings of specific linters
  53. linters-settings:
  54. dogsled:
  55. # checks assignments with too many blank identifiers; default is 2
  56. max-blank-identifiers: 2
  57. dupl:
  58. # tokens count to trigger issue, 150 by default
  59. threshold: 100
  60. errcheck:
  61. # report about not checking of errors in type assetions: `a := b.(MyStruct)`;
  62. # default is false: such cases aren't reported by default.
  63. check-type-assertions: false
  64. # report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`;
  65. # default is false: such cases aren't reported by default.
  66. check-blank: false
  67. # [deprecated] comma-separated list of pairs of the form pkg:regex
  68. # the regex is used to ignore names within pkg. (default "fmt:.*").
  69. # see https://github.com/kisielk/errcheck#the-deprecated-method for details
  70. ignore: fmt:.*,io/ioutil:^Read.*
  71. # path to a file containing a list of functions to exclude from checking
  72. # see https://github.com/kisielk/errcheck#excluding-functions for details
  73. #!exclude: /path/to/file.txt
  74. funlen:
  75. lines: 60
  76. statements: 40
  77. gocognit:
  78. # minimal code complexity to report, 30 by default (but we recommend 10-20)
  79. min-complexity: 10
  80. goconst:
  81. # minimal length of string constant, 3 by default
  82. min-len: 3
  83. # minimal occurrences count to trigger, 3 by default
  84. min-occurrences: 3
  85. gocritic:
  86. # Which checks should be enabled; can't be combined with 'disabled-checks';
  87. # See https://go-critic.github.io/overview#checks-overview
  88. # To check which checks are enabled run `GL_DEBUG=gocritic golangci-lint run`
  89. # By default list of stable checks is used.
  90. enabled-checks:
  91. #!- rangeValCopy
  92. # Which checks should be disabled; can't be combined with 'enabled-checks'; default is empty
  93. disabled-checks:
  94. - regexpMust
  95. # Enable multiple checks by tags, run `GL_DEBUG=gocritic golangci-lint run` to see all tags and checks.
  96. # Empty list by default. See https://github.com/go-critic/go-critic#usage -> section "Tags".
  97. enabled-tags:
  98. - performance
  99. settings: # settings passed to gocritic
  100. captLocal: # must be valid enabled check name
  101. paramsOnly: true
  102. rangeValCopy:
  103. sizeThreshold: 32
  104. gocyclo:
  105. # minimal code complexity to report, 30 by default (but we recommend 10-20)
  106. min-complexity: 10
  107. godox:
  108. # report any comments starting with keywords, this is useful for TODO or FIXME comments that
  109. # might be left in the code accidentally and should be resolved before merging
  110. keywords: # default keywords are TODO, BUG, and FIXME, these can be overwritten by this setting
  111. - NOTE
  112. - OPTIMIZE # marks code that should be optimized before merging
  113. - HACK # marks hack-arounds that should be removed before merging
  114. gofmt:
  115. # simplify code: gofmt with `-s` option, true by default
  116. simplify: true
  117. goimports:
  118. # put imports beginning with prefix after 3rd-party packages;
  119. # it's a comma-separated list of prefixes
  120. local-prefixes: github.com/org/project
  121. golint:
  122. # minimal confidence for issues, default is 0.8
  123. min-confidence: 0.8
  124. gomnd:
  125. settings:
  126. mnd:
  127. # the list of enabled checks, see https://github.com/tommy-muehle/go-mnd/#checks for description.
  128. checks: argument,case,condition,operation,return,assign
  129. govet:
  130. # report about shadowed variables
  131. check-shadowing: true
  132. # settings per analyzer
  133. settings:
  134. printf: # analyzer name, run `go tool vet help` to see all analyzers
  135. funcs: # run `go tool vet help printf` to see available settings for `printf` analyzer
  136. - (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
  137. - (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
  138. - (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
  139. - (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
  140. # enable or disable analyzers by name
  141. enable:
  142. - atomicalign
  143. enable-all: false
  144. disable:
  145. - shadow
  146. disable-all: false
  147. depguard:
  148. list-type: blacklist
  149. include-go-root: false
  150. packages:
  151. - github.com/sirupsen/logrus
  152. packages-with-error-message:
  153. # specify an error message to output when a blacklisted package is used
  154. - github.com/sirupsen/logrus: "logging is allowed only by logutils.Log"
  155. lll:
  156. # max line length, lines longer will be reported. Default is 120.
  157. # '\t' is counted as 1 character by default, and can be changed with the tab-width option
  158. line-length: 120
  159. # tab width in spaces. Default to 1.
  160. tab-width: 1
  161. maligned:
  162. # print struct with more effective memory layout or not, false by default
  163. suggest-new: true
  164. misspell:
  165. # Correct spellings using locale preferences for US or UK.
  166. # Default is to use a neutral variety of English.
  167. # Setting locale to US will correct the British spelling of 'colour' to 'color'.
  168. locale: US
  169. ignore-words:
  170. - someword
  171. nakedret:
  172. # make an issue if func has more lines of code than this setting and it has naked returns; default is 30
  173. max-func-lines: 30
  174. prealloc:
  175. # XXX: we don't recommend using this linter before doing performance profiling.
  176. # For most programs usage of prealloc will be a premature optimization.
  177. # Report preallocation suggestions only on simple loops that have no returns/breaks/continues/gotos in them.
  178. # True by default.
  179. simple: true
  180. range-loops: true # Report preallocation suggestions on range loops, true by default
  181. for-loops: false # Report preallocation suggestions on for loops, false by default
  182. rowserrcheck:
  183. packages:
  184. - github.com/jmoiron/sqlx
  185. unparam:
  186. # Inspect exported functions, default is false. Set to true if no external program/library imports your code.
  187. # XXX: if you enable this setting, unparam will report a lot of false-positives in text editors:
  188. # if it's called for subdir of a project it can't find external interfaces. All text editor integrations
  189. # with golangci-lint call it on a directory with the changed file.
  190. check-exported: false
  191. unused:
  192. # treat code as a program (not a library) and report unused exported identifiers; default is false.
  193. # XXX: if you enable this setting, unused will report a lot of false-positives in text editors:
  194. # if it's called for subdir of a project it can't find funcs usages. All text editor integrations
  195. # with golangci-lint call it on a directory with the changed file.
  196. check-exported: false
  197. whitespace:
  198. multi-if: false # Enforces newlines (or comments) after every multi-line if statement
  199. multi-func: false # Enforces newlines (or comments) after every multi-line function signature
  200. wsl:
  201. # If true append is only allowed to be cuddled if appending value is
  202. # matching variables, fields or types on line above. Default is true.
  203. strict-append: true
  204. # Allow calls and assignments to be cuddled as long as the lines have any
  205. # matching variables, fields or types. Default is true.
  206. allow-assign-and-call: true
  207. # Allow multiline assignments to be cuddled. Default is true.
  208. allow-multiline-assign: true
  209. # Allow declarations (var) to be cuddled.
  210. allow-cuddle-declarations: false
  211. # Allow trailing comments in ending of blocks
  212. allow-trailing-comment: false
  213. # Force newlines in end of case at this limit (0 = never).
  214. force-case-trailing-whitespace: 0
  215. # The custom section can be used to define linter plugins to be loaded at runtime. See README doc
  216. # for more info.
  217. custom:
  218. # Each custom linter should have a unique name.
  219. #! example:
  220. #! # The path to the plugin *.so. Can be absolute or local. Required for each custom linter
  221. #! path: /path/to/example.so
  222. #! # The description of the linter. Optional, just for documentation purposes.
  223. #! description: This is an example usage of a plugin linter.
  224. #! # Intended to point to the repo location of the linter. Optional, just for documentation purposes.
  225. #! original-url: github.com/golangci/example-linter
  226. linters:
  227. enable:
  228. - megacheck
  229. - govet
  230. disable:
  231. - maligned
  232. - prealloc
  233. disable-all: false
  234. presets:
  235. - bugs
  236. - unused
  237. fast: false
  238. issues:
  239. # List of regexps of issue texts to exclude, empty list by default.
  240. # But independently from this option we use default exclude patterns,
  241. # it can be disabled by `exclude-use-default: false`. To list all
  242. # excluded by default patterns execute `golangci-lint run --help`
  243. exclude:
  244. - abcdef
  245. # Excluding configuration per-path, per-linter, per-text and per-source
  246. exclude-rules:
  247. # Exclude some linters from running on tests files.
  248. - path: _test\.go
  249. linters:
  250. - gocyclo
  251. - errcheck
  252. - dupl
  253. - gosec
  254. # Exclude known linters from partially hard-vendored code,
  255. # which is impossible to exclude via "nolint" comments.
  256. - path: internal/hmac/
  257. text: "weak cryptographic primitive"
  258. linters:
  259. - gosec
  260. # Exclude some staticcheck messages
  261. - linters:
  262. - staticcheck
  263. text: "SA9003:"
  264. # Exclude lll issues for long lines with go:generate
  265. - linters:
  266. - lll
  267. source: "^//go:generate "
  268. # Independently from option `exclude` we use default exclude patterns,
  269. # it can be disabled by this option. To list all
  270. # excluded by default patterns execute `golangci-lint run --help`.
  271. # Default value for this option is true.
  272. exclude-use-default: false
  273. # Maximum issues count per one linter. Set to 0 to disable. Default is 50.
  274. max-issues-per-linter: 0
  275. # Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
  276. max-same-issues: 0
  277. # Show only new issues: if there are unstaged changes or untracked files,
  278. # only those changes are analyzed, else only changes in HEAD~ are analyzed.
  279. # It's a super-useful option for integration of golangci-lint into existing
  280. # large codebase. It's not practical to fix all existing issues at the moment
  281. # of integration: much better don't allow issues in new code.
  282. # Default is false.
  283. new: false
  284. # Show only new issues created after git revision `REV`
  285. #!new-from-rev: REV
  286. #new-from-rev: HEAD^
  287. # Show only new issues created in git patch with set file path.
  288. #!new-from-patch: path/to/patch/file