介绍

要查看支持的Linter列表以及启用/禁用的Linter:

1
golangci-lint help linters

默认情况下启用Linter:

  • govet -Vet检查Go源代码并报告可疑构造,例如,其参数与格式字符串不一致的Printf调用
  • errcheck -Errcheck是用于检查go程序中未经检查的错误的程序。在某些情况下,这些未经检查的错误可能是关键错误
  • staticcheck -staticcheck是对类固醇的研究,应用了大量的静态分析检查
  • unused -检查Go代码中未使用的常量,变量,函数和类型
  • gosimple -Linter for Go源代码,专门用于简化代码
  • structcheck-查找未使用的struct字段
  • varcheck-查找未使用的全局变量和常量
  • ineffassign-检测何时不使用对现有变量的分配
  • deadcode-查找未使用的代码
  • typecheck-像Go编译器的前端一样,对Go代码进行解析和类型检查

默认情况下禁用Linters(-E/–enable):

  • bodyclose-检查HTTP响应主体是否成功关闭
  • noctx -noctx查找发送没有上下文的http请求
  • golint -Golint与gofmt不同。Gofmt重新格式化Go源代码,而golint打印出样式错误
  • rowserrcheck-检查是否成功检查了行的Err
  • stylecheck -Stylecheck可以代替棉绒
  • gosec-检查源代码是否存在安全问题
  • interfacer -建议较窄接口类型的Linter
  • unconvert -删除不必要的类型转换
  • dupl-代码克隆检测工具
  • goconst-查找可以被常量替换的重复字符串
  • gocyclo-计算并检查函数的圈复杂度
  • gocognit-计算并检查功能的认知复杂性
  • asciicheck-简单的linter检查您的代码是否不包含非ASCII标识符
  • gofmt -Gofmt检查代码是否为gofmt版本。默认情况下,此工具与-s选项一起运行,以检查代码是否简化
  • gofumpt -Gofumpt检查代码是否经过gofumpt编辑。
  • goimports -Goimports可以执行gofmt所做的一切。此外,它还会检查未使用的导入
  • goheader-检查文件头是否与模式匹配
  • GCI - Gci的控制golang包进口秩序,并使其始终确定性。
  • maligned-检测Go结构的工具,如果对它们进行字段排序,这些结构将占用更少的内存
  • depguard -Go linter,检查软件包导入是否在可接受的软件包列表中
  • misspell-查找注释中通常拼写错误的英语单词
  • lll-报告长行
  • unparam-报告未使用的功能参数
  • dogsled -太多空白标识符检查分配(例如,x, ,,_,:= F())
  • nuderet-查找大于指定函数长度的函数中的裸返回
  • prealloc-查找可能预先分配的切片声明
  • scopelint -Scopelint检查go程序中的未固定变量
  • gocritic-最自以为是的Go源代码linter
  • gochecknoinits-检查Go代码中是否没有init函数
  • gochecknoglobals-检查Go代码中是否没有全局变量
  • godox-用于检测FIXME,TODO和其他注释关键字的工具
  • funlen-长功能检测工具
  • whitespace -用于检测前导和尾随空白的工具
  • wsl-空白Linter-强制您使用空行!
  • goprintffuncname-检查类似printf的函数是否以f末尾命名
  • gomnd-分析器,用于检测幻数。
  • goerr113 -Golang linter检查错误处理表达式
  • gomodguard-允许和阻止列表linter用于直接访问Go模块。这不同于depguard,后者的块类型不同,例如版本约束和模块建议。
  • godot-检查评论是否在一段时间内结束
  • testpackage-使您使用单独的_test包的linter
  • nestif-报告深层嵌套的if语句
  • exportloopref-检查指向封闭循环变量的指针
  • exhaustive -检查枚举开关语句的详尽无遗
  • sqlclosecheck-检查sql.Rows和sql.Stmt是否关闭。
  • nlreturn -nlreturn在return和branch语句之前检查换行,以提高代码清晰度
  • nolintlint-报告格式错误或拒绝指令不足

配置文件

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
# This file contains all available configuration options
# with their default values.

# 此文件包含所有可用的配置选项及其默认值。

# 分析运行选项
run:
  # default concurrency is a available CPU number
  # 默认并发是可用的CPU数
  concurrency: 8

  # timeout for analysis, e.g. 30s, 5m, default is 1m
  # 分析超时,例如30s,5m,默认为1m
  timeout: 1m

  # exit code when at least one issue was found, default is 1
  # 至少发现一个问题时退出代码,默认为1
  issues-exit-code: 1

  # include test files or not, default is true
  # 是否包含测试文件,默认为true
  tests: true

  # list of build tags, all linters use it. Default is empty list.
  # 构建标记列表,所有linter都使用它。默认为空列表。
  build-tags:
    # - mytag

  # which dirs to skip: issues from them won't be reported;
  # can use regexp here: generated.*, regexp is applied on full path;
  # default value is empty list, but default dirs are skipped independently
  # from this option's value (see skip-dirs-use-default).
  # "/" will be replaced by current OS file path separator to properly work
  # on Windows.

  # 跳过哪些目录:不会报告它们的问题;
  # 可以在此处使用regexp:generate。*,regexp应用于完整路径;
  # 默认值为空列表,但默认目录将独立跳过
  # 从此选项的值开始(请参阅skip-dirs-use-default)。
  # “ /”将被当前的操作系统文件路径分隔符替换以正常工作
  # 在Windows上。

  skip-dirs:
    # - src/external_libs
    # - autogenerated_by_my_lib

  # 默认为true。启用目录跳过:
  # vendor $,third_party $,testdata $,examples $,Godeps $,builtin $
  skip-dirs-use-default: true

  # which files to skip: they will be analyzed, but issues from them
  # won't be reported. Default value is empty list, but there is
  # no need to include all autogenerated files, we confidently recognize
  # autogenerated files. If it's not please let us know.
  # "/" will be replaced by current OS file path separator to properly work
  # on Windows.

  # 跳过哪些文件:将对其进行分析,但会产生问题
  # 将不会被报告。默认值为空列表,但是有
  # 无需包含所有自动生成的文件,我们可以放心地认识到
  # 自动生成的文件。如果不是,请告诉我们。
  # “ /”将被当前的操作系统文件路径分隔符替换以正常工作
  # 在Windows上。

  skip-files:
    # - ".*\\.my\\.go$"
    # - lib/bad.go

  # by default isn't set. If set we pass it to "go list -mod={option}". From "go help modules":
  # If invoked with -mod=readonly, the go command is disallowed from the implicit
  # automatic updating of go.mod described above. Instead, it fails when any changes
  # to go.mod are needed. This setting is most useful to check that go.mod does
  # not need updates, such as in a continuous integration and testing system.
  # If invoked with -mod=vendor, the go command assumes that the vendor
  # directory holds the correct copies of dependencies and ignores
  # the dependency descriptions in go.mod.

  # 默认情况下未设置。如果设置,我们将其传递到"go list -mod={option}"。从"go help modules":
  # 如果使用-mod=readonly调用,则不允许从的隐式自动更新中使用go命令转到.mod如上所述。
  # 相反,当转到.mod是需要的。此设置最有助于检查转到.mod不需要更新,例如在持续集成和测试系统中。
  # 如果使用-mod=vendor调用,go命令假定vendor目录保存了正确的依赖项副本,并忽略了中的依赖项描述转到.mod.
#   modules-download-mode: readonly|release|vendor

  # Allow multiple parallel golangci-lint instances running.
  # If false (default) - golangci-lint acquires file lock on start.

  # 允许运行多个并行的golangci-lint实例。
  # 如果为false(默认值)-golangci-lint在启动时获取文件锁定。
  allow-parallel-runners: false


# output configuration options
# 输出配置选项
output:
  # colored-line-number|line-number|json|tab|checkstyle|code-climate, default is "colored-line-number"
  # 彩色线号|线号| json | tab | checkstyle |代码气候,默认为“彩色线号”
  format: colored-line-number

  # print lines of code with issue, default is true
  #打印有问题的代码行,默认为true
  print-issued-lines: true

  # print linter name in the end of issue text, default is true
  # 在问题文本的末尾打印linter名称,默认为true
  print-linter-name: true

  # make issues output unique by line, default is true
  # 使问题按行唯一输出,默认为true
  uniq-by-line: true

  # add a prefix to the output file references; default is no prefix
  # 在输出文件引用中添加前缀;默认是没有前缀
  path-prefix: ""


# all available settings of specific linters
linters-settings:
  dogsled:
    # checks assignments with too many blank identifiers; default is 2
    # 检查带有太多空白标识符的分配;默认是2
    max-blank-identifiers: 2
  dupl:

    # tokens count to trigger issue, 150 by default
    # 令牌数可触发问题,默认为150
    threshold: 100
  errcheck:
    # report about not checking of errors in type assertions: `a := b.(MyStruct)`;
    # default is false: such cases aren't reported by default.
    # 报告有关不检查类型断言中的错误的信息:`a := b.(MyStruct)`;
    # default为false:默认情况下不会报告此类情况。
    check-type-assertions: true

    # report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`;
    # default is false: such cases aren't reported by default.
    # 报告有关将错误分配给空白标识符的信息:`num, _ := strconv.Atoi(numStr)`;
    # default为false:默认情况下不会报告此类情况。
    check-blank: true

    # [deprecated] comma-separated list of pairs of the form pkg:regex
    # the regex is used to ignore names within pkg. (default "fmt:.*").
    # see https://github.com/kisielk/errcheck#the-deprecated-method for details
    # [不建议使用]以逗号分隔的形式为pkg:regex的对列表
    # 正则表达式用于忽略pkg中的名称。 (默认为“ fmt:。*”)。
    # 有关详细信息,请参见https://github.com/kisielk/errcheck#the-deprecated-method
    # ignore: fmt:.*,io/ioutil:^Read.*

    # path to a file containing a list of functions to exclude from checking
    # see https://github.com/kisielk/errcheck#excluding-functions for details
    # 包含要从检查中排除的功能列表的文件的路径
    # 有关详细信息,请参见https://github.com/kisielk/errcheck#exception-functions
    # exclude: /path/to/file.txt
  exhaustive:
    # indicates that switch statements are to be considered exhaustive if a
    # 'default' case is present, even if all enum members aren't listed in the
    # switch

    # 表示在以下情况下将switch语句视为exhaustive
    # 存在“default”情况,甚至没有在switch列表中列出所有枚举成员,
    default-signifies-exhaustive: false
  funlen:
    lines: 100
    statements: 50
  gci:
    # put imports beginning with prefix after 3rd-party packages;
    # only support one prefix
    # if not set, use goimports.local-prefixes
    # 将导入内容以前缀开头的第三方包放在后面;
    # 仅支持一个前缀
    # 如果未设置,请使用goimports.local-prefixes
    # local-prefixes: github.com/org/project
  gocognit:
    # minimal code complexity to report, 30 by default (but we recommend 10-20)
    # 报告的最小代码复杂度,默认为30(但我们建议10-20)
    min-complexity: 10
  nestif:
    # minimal complexity of if statements to report, 5 by default
    # 要报告的if语句的最小复杂度,默认为5
    min-complexity: 4
  goconst:
    # minimal length of string constant, 3 by default
    # 字符串常量的最小长度,默认为3
    min-len: 2
    # minimal occurrences count to trigger, 3 by default
    # 触发最少事件的次数,默认为3
    min-occurrences: 2
  gocritic:
    # Which checks should be enabled; can't be combined with 'disabled-checks';
    # See https://go-critic.github.io/overview#checks-overview
    # To check which checks are enabled run `GL_DEBUG=gocritic golangci-lint run`
    # By default list of stable checks is used.
    # 应该启用哪些检查;不能与“禁用检查”结合使用;
    # 参见https://go-critic.github.io/overview#checks-overview
    # 要检查启用了哪些检查,请运行`GL_DEBUG = gocritic golangci-lint run`。
    # 默认情况下使用稳定检查列表。
    # enabled-checks:
    #   - rangeValCopy

    # Which checks should be disabled; can't be combined with 'enabled-checks'; default is empty
    # 应该禁用哪些检查;不能与“启用检查”结合使用;默认为空
    disabled-checks:
      - dupImport # https://github.com/go-critic/go-critic/issues/845
      - ifElseChain
      - octalLiteral
      - whyNoLint
      - wrapperFunc

    # Enable multiple checks by tags, run `GL_DEBUG=gocritic golangci-lint run` to see all tags and checks.
    # Empty list by default. See https://github.com/go-critic/go-critic#usage -> section "Tags".

    #按标签启用多项检查,运行GL_DEBUG = gocritic golangci-lint run查看所有标签和检查。
    #默认为空列表。请参阅https://github.com/go-critic/go-critic#usage->“标签”部分。

    enabled-tags:
      - diagnostic
      - experimental
      - opinionated
      - performance
      - style
    # disabled-tags:
    #   - experimental

    # settings: # settings passed to gocritic
    #   captLocal: # must be valid enabled check name
    #     paramsOnly: true
    #   rangeValCopy:
    #     sizeThreshold: 32
  gocyclo:
    # minimal code complexity to report, 30 by default (but we recommend 10-20)
    # 报告的最小代码复杂度,默认为30(但我们建议10-20)
    min-complexity: 15
  godot:
    # 检查所有顶级注释,不仅是声明
    # check all top-level comments, not only declarations
    check-all: false
  godox:
    # report any comments starting with keywords, this is useful for TODO or FIXME comments that
    # might be left in the code accidentally and should be resolved before merging
    # 报告以关键字开头的所有评论,这对于TODO或FIXME评论非常有用,
    # 可能会意外地留在代码中,应该在合并之前解决
    keywords: # default keywords are TODO, BUG, and FIXME, these can be overwritten by this setting
    # 默认关键字是TODO,BUG和FIXME,这些关键字可以被此设置覆盖
      - NOTE
      - OPTIMIZE # marks code that should be optimized before merging
      - HACK # marks hack-arounds that should be removed before merging
  gofmt:
    # simplify code: gofmt with `-s` option, true by default
    # 简化代码:带有`-s`选项的gofmt,默认为true
    simplify: true
  goheader:
    values:
      const:
        # define here const type values in format k:v, for example:
        # YEAR: 2020
        # COMPANY: MY COMPANY
        # 在此处以k:v格式定义const类型值,例如:
        # 年:2020
        # 公司:我的公司
      regexp:
        # define here regexp type values, for example
        # AUTHOR: .*@mycompany\.com
        # 例如在这里定义regexp类型值
        # 作者:。* @ mycompany \ .com
    template:
      # put here copyright header template for source code files, for example:
      #    {{ AUTHOR }} {{ COMPANY }} {{ YEAR }}
      #    SPDX-License-Identifier: Apache-2.0
      #
      #    Licensed under the Apache License, Version 2.0 (the "License");
      #    you may not use this file except in compliance with the License.
      #    You may obtain a copy of the License at:
      #
      #      http://www.apache.org/licenses/LICENSE-2.0
      #
      #    Unless required by applicable law or agreed to in writing, software
      #    distributed under the License is distributed on an "AS IS" BASIS,
      #    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      #    See the License for the specific language governing permissions and
      #    limitations under the License.

      #将源代码文件的版权标题模板放在此处,例如:
      #{{AUTHOR}} {{COMPANY}} {{YEAR}}
      #SPDX-License-Identifier:Apache-2.0
      #
      #根据Apache许可证2.0版(“许可证”)获得许可;
      #除非符合许可,否则您不得使用此文件。
      #您可以在以下位置获得许可的副本:
      #
      #http://www.apache.org/licenses/LICENSE-2.0
      #
      #除非适用法律要求或书面同意,否则软件根据许可协议分发的#是按“原样”分发的,
      #没有任何明示或暗示的保证或条件。
      #有关特定语言的管理权限,请参阅许可证。
      #许可中的限制。
      template-path:
      # also as alternative of directive 'template' you may put the path to file with the template source
      # 也可以作为指令'template'的替代方法,您可以使用模板源放置
  goimports:
    # put imports beginning with prefix after 3rd-party packages;
    # it's a comma-separated list of prefixes
    # 将导入内容以前缀开头的3rd-party包放在后面;
    # 这是一个用逗号分隔的前缀列表
    # local-prefixes: github.com/org/project
  golint:
    # minimal confidence for issues, default is 0.8
    # 问题的最低置信度,默认值为0.8
    min-confidence: 0
  gomnd:
    settings:
      mnd:
        # the list of enabled checks, see https://github.com/tommy-muehle/go-mnd/#checks for description.
        # 启用检查的列表,请参阅https://github.com/tommy-muehle/go-mnd/#checks了解说明。
        checks: argument,case,condition,return
  gomodguard:
    allowed:
      modules:                                                        # List of allowed modules
        # - gopkg.in/yaml.v2
      domains:                                                        # List of allowed module domains
        # - golang.org
    blocked:
      modules:                                                        # List of blocked modules
        # - github.com/uudashr/go-module:                             # Blocked module
        #     recommendations:                                        # Recommended modules that should be used instead (Optional)
        #       - golang.org/x/mod
        #     reason: "`mod` is the official go.mod parser library."  # Reason why the recommended module should be used (Optional)
      versions:                                                       # List of blocked module version constraints
        # - github.com/mitchellh/go-homedir:                          # Blocked module with version constraint
        #     version: "< 1.1.0"                                      # Version constraint, see https://github.com/Masterminds/semver#basic-comparisons
        #     reason: "testing if blocked version constraint works."  # Reason why the version constraint exists. (Optional)
  govet:
    # report about shadowed variables
    check-shadowing: true

    # settings per analyzer
    settings:
      printf: # analyzer name, run `go tool vet help` to see all analyzers
        funcs: # run `go tool vet help printf` to see available settings for `printf` analyzer
          - (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
          - (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
          - (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
          - (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf

    # enable or disable analyzers by name
    enable:
      - atomicalign
    enable-all: false
    disable:
      - shadow
    disable-all: false
  depguard:
    list-type: blacklist
    include-go-root: false
    packages:
      - github.com/sirupsen/logrus
    packages-with-error-message:
      # specify an error message to output when a blacklisted package is used
      - github.com/sirupsen/logrus: "logging is allowed only by logutils.Log"
  lll:
    # max line length, lines longer will be reported. Default is 120.
    # '\t' is counted as 1 character by default, and can be changed with the tab-width option
    # 最大行长,将报告更长的行。默认值为120。
    # '\ t'默认为1个字符,可使用tab-width选项更改
    line-length: 140
    # tab width in spaces. Default to 1.
    tab-width: 1
  maligned:
    # print struct with more effective memory layout or not, false by default
    # 打印结构是否具有更有效的内存布局,默认为false
    suggest-new: true
  misspell:
    # Correct spellings using locale preferences for US or UK.
    # Default is to use a neutral variety of English.
    # Setting locale to US will correct the British spelling of 'colour' to 'color'.
    # 使用美国或英国的语言环境首选项更正拼写。
    # 默认为使用中性英语。
    # 将语言环境设置为美国将把“colour”的英文拼写更正为“ color”。
    locale: US
    ignore-words:
      # - someword
  nakedret:
    # make an issue if func has more lines of code than this setting and it has naked returns; default is 30
    #如果func的代码行数超过此设置并且有裸露的返回值,则会引起问题;默认是30
    max-func-lines: 30
  prealloc:
    # XXX: we don't recommend using this linter before doing performance profiling.
    # For most programs usage of prealloc will be a premature optimization.

    # Report preallocation suggestions only on simple loops that have no returns/breaks/continues/gotos in them.
    # True by default.

    # XXX:我们不建议在进行性能分析之前使用此Linter。
    # 对于大多数程序,使用prealloc将是过早的优化。

    # 仅在其中没有返回/中断/继续/失败的简单循环上报告预分配建议。
    # 默认为True。
    simple: true
    range-loops: true # Report preallocation suggestions on range loops, true by default
    for-loops: false # Report preallocation suggestions on for loops, false by default
  nolintlint:
    # Enable to ensure that nolint directives are all used. Default is true.
    # 启用以确保全部使用nolint伪指令。默认为true。
    allow-unused: false
    # Disable to ensure that nolint directives don't have a leading space. Default is true.
    #禁用以确保nolint指令没有前导空格。默认为true。
    allow-leading-space: true
    # Exclude following linters from requiring an explanation.  Default is [].
    allow-no-explanation: []
    # Enable to require an explanation of nonzero length after each nolint directive. Default is false.
    #允许在每个nolint指令后要求对非零长度进行解释。默认值为false。
    require-explanation: false
    # Enable to require nolint directives to mention the specific linter being suppressed. Default is false.
    #启用以要求nolint指令提及要抑制的特定linter。默认值为false。
    require-specific: false
  rowserrcheck:
    packages:
      - github.com/jmoiron/sqlx
  testpackage:
    # regexp pattern to skip files
    # skip-regexp: (export|internal)_test\.go
  unparam:
    # Inspect exported functions, default is false. Set to true if no external program/library imports your code.
    # XXX: if you enable this setting, unparam will report a lot of false-positives in text editors:
    # if it's called for subdir of a project it can't find external interfaces. All text editor integrations
    # with golangci-lint call it on a directory with the changed file.
    # 检查导出的函数,默认为false。如果没有外部程序/库导入您的代码,则设置为true。
    # XXX:如果启用此设置,则unparam将在文本编辑器中报告很多错误肯定的信息:
    # 如果调用项目的子目录,则找不到外部接口。所有文本编辑器集成
    # 使用golangci-lint在带有更改文件的目录中调用它。
    check-exported: false
  unused:
    # treat code as a program (not a library) and report unused exported identifiers; default is false.
    # XXX: if you enable this setting, unused will report a lot of false-positives in text editors:
    # if it's called for subdir of a project it can't find funcs usages. All text editor integrations
    # with golangci-lint call it on a directory with the changed file.
    # 将代码视为程序(不是库),并报告未使用的导出标识符;默认为false。
    # XXX:如果启用此设置,则未使用的将在文本编辑器中报告很多误报:
    # 如果调用项目的子目录,则找不到函数用法。所有文本编辑器集成
    # 使用golangci-lint在带有更改文件的目录中调用它。
    check-exported: false
  whitespace:
    # 在每个多行if语句后强制换行(或注释)
    multi-if: false   # Enforces newlines (or comments) after every multi-line if statement
    # 在每个多行函数签名之后强制换行(或注释)
    multi-func: false # Enforces newlines (or comments) after every multi-line function signature
  wsl:
    # If true append is only allowed to be cuddled if appending value is
    # matching variables, fields or types on line above. Default is true.
    # 如果为true,则仅当添加值为
    # 匹配上面的行中的变量,字段或类型。默认为true。
    strict-append: true
    # Allow calls and assignments to be cuddled as long as the lines have any
    # matching variables, fields or types. Default is true.
    #只要这些行有任何匹配变量,字段或类型。就允许拥抱调用和分配
    #默认为true。
    allow-assign-and-call: true
    # Allow multiline assignments to be cuddled. Default is true.
    #允许多行分配。默认为true。
    allow-multiline-assign: true
    # Allow declarations (var) to be cuddled.
    # 允许声明(var)。
    allow-cuddle-declarations: true
    # Allow trailing comments in ending of blocks
    #允许在块末尾添加尾随注释
    allow-trailing-comment: true
    # Force newlines in end of case at this limit (0 = never).
    #在大小写结尾处以此限制强制换行符(0=never)。
    force-case-trailing-whitespace: 0
    # Force cuddling of err checks with err var assignment
    #使用err var分配强制拥抱err检查
    force-err-cuddling: false
    # Allow leading comments to be separated with empty liens
    #允许用空的留置权分隔开头的评论
    allow-separated-leading-comment: true
  gofumpt:
    # Choose whether or not to use the extra rules that are disabled
    # by default
    # 选择是否使用已禁用的其他规则
    # 默认
    extra-rules: false

  # custom部分可用于定义要在运行时加载的linter插件。请参阅自述文件
  # 了解更多信息。
  # custom:
  #   # Each custom linter should have a unique name.
  #    example:
  #     # The path to the plugin *.so. Can be absolute or local. Required for each custom linter
  #     path: /path/to/example.so
  #     # The description of the linter. Optional, just for documentation purposes.
  #     description: This is an example usage of a plugin linter.
  #     # Intended to point to the repo location of the linter. Optional, just for documentation purposes.
  #     original-url: github.com/golangci/example-linter

linters:
  # please, do not use `enable-all`: it's deprecated and will be removed soon.
  # inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
  disable-all: true
  enable:
    - bodyclose
    - deadcode
    - depguard
    - dogsled
    - dupl
    - errcheck
    - exhaustive
    - funlen
    - gochecknoinits
    - goconst
    - gocritic
    - gocyclo
    - gofmt
    - goimports
    - golint
    - gomnd
    - goprintffuncname
    - gosec
    - gosimple
    - govet
    - ineffassign
    - interfacer
    - lll
    - misspell
    - nakedret
    - noctx
    - nolintlint
    - rowserrcheck
    - scopelint
    - staticcheck
    - structcheck
    - stylecheck
    - typecheck
    - unconvert
    - unparam
    - unused
    - varcheck
    - whitespace
    - asciicheck
    - gochecknoglobals
    - gocognit
    - godot
    - godox
    - goerr113
    - maligned
    - nestif
    - prealloc
    - testpackage
    - wsl
    - exportloopref
    - gci
    # - gofumpt
    - goheader
    - gomodguard
    - nlreturn
    - sqlclosecheck


issues:
  # List of regexps of issue texts to exclude, empty list by default.
  # But independently from this option we use default exclude patterns,
  # it can be disabled by `exclude-use-default: false`. To list all
  # excluded by default patterns execute `golangci-lint run --help`
  # 要排除的问题文本的正则表达式列表,默认为空列表。
  # 但是独立于此选项,我们使用默认的排除模式,
  # 它可以被`exclude-use-default:false`禁用。全部列出
  # 默认模式排除的代码执行`golangci-lint run --help`
  # exclude:
  #   - abcdef

  # Excluding configuration per-path, per-linter, per-text and per-source
  exclude-rules:
    # Exclude some linters from running on tests files.
    - path: _test\.go
      linters:
        - gomnd

    # # Exclude known linters from partially hard-vendored code,
    # # which is impossible to exclude via "nolint" comments.
    # - path: internal/hmac/
    #   text: "weak cryptographic primitive"
    #   linters:
    #     - gosec

    # # Exclude some staticcheck messages
    # - linters:
    #     - staticcheck
    #   text: "SA9003:"

    # # Exclude lll issues for long lines with go:generate
    # - linters:
    #     - lll
    #   source: "^//go:generate "
    # https://github.com/go-critic/go-critic/issues/926
    - linters:
        - gocritic
      text: "unnecessaryDefer:"

  # Independently from option `exclude` we use default exclude patterns,
  # it can be disabled by this option. To list all
  # excluded by default patterns execute `golangci-lint run --help`.
  # Default value for this option is true.
  # 与选项`exclude`无关,我们使用默认的排除模式,
  # 可以通过此选项禁用它。全部列出
  # 默认情况下排除的模式执行`golangci-lint run --help`。
  # 此选项的默认值为true。
  exclude-use-default: false

  # The default value is false. If set to true exclude and exclude-rules
  # regular expressions become case sensitive.
  # 默认值为false。如果设置为true,则排除和排除规则
  # 正则表达式区分大小写。
  exclude-case-sensitive: false

  # The list of ids of default excludes to include or disable. By default it's empty.
  include:
    # - EXC0002 # disable excluding of issues about comments from golint

  # Maximum issues count per one linter. Set to 0 to disable. Default is 50.
  max-issues-per-linter: 0

  # Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
  max-same-issues: 0

  # Show only new issues: if there are unstaged changes or untracked files,
  # only those changes are analyzed, else only changes in HEAD~ are analyzed.
  # It's a super-useful option for integration of golangci-lint into existing
  # large codebase. It's not practical to fix all existing issues at the moment
  # of integration: much better don't allow issues in new code.
  # Default is false.
  # 仅显示新问题:如果有未进行的更改或未跟踪的文件,
  # 仅分析那些更改,否则仅分析HEAD〜中的更改。
  # 这是将golangci-lint集成到现有的超级有用的选项
  # 大型代码库。目前解决所有现有问题不切实际
  new: false

  # Show only new issues created after git revision `REV`
  new-from-rev: REV

  # Show only new issues created in git patch with set file path.
  new-from-patch: path/to/patch/file

severity:
  # Default value is empty string.
  # Set the default severity for issues. If severity rules are defined and the issues
  # do not match or no severity is provided to the rule this will be the default
  # severity applied. Severities should match the supported severity names of the
  # selected out format.
  # - Code climate: https://docs.codeclimate.com/docs/issues#issue-severity
  # -   Checkstyle: https://checkstyle.sourceforge.io/property_types.html#severity
  # -       Github: https://help.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-error-message
  #默认值为空字符串。
  #设置问题的默认严重性。如果定义了严重性规则和问题
  #不匹配或没有为该规则提供严重性,这将是默认值
  #应用的严重性。严重性应与支持的严重性名称相匹配
  #选择了格式。
  #-代码环境:https://docs.codeclimate.com/docs/issues#issue-severity
  #-Checkstyle:https://checkstyle.sourceforge.io/property_types.html#severity
  #-Github:https://help.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-error-message
  # default-severity: ""

  # The default value is false.
  # If set to true severity-rules regular expressions become case sensitive.
  case-sensitive: false

  # Default value is empty list.
  # When a list of severity rules are provided, severity information will be added to lint
  # issues. Severity rules have the same filtering capability as exclude rules except you
  # are allowed to specify one matcher per severity rule.
  # Only affects out formats that support setting severity information.

  # 默认值为空列表。
  # 当提供严重性规则列表时,严重性信息将添加到lint
  # 个问题。严重性规则与排除规则具有相同的过滤功能,但您可以
  # 允许为每个严重性规则指定一个匹配器。
  # 仅影响支持设置严重性信息的输出格式。
  # rules:
  #   - linters:
  #     - dupl
  #     severity: info
  # golangci.com configuration
# https://github.com/golangci/golangci/wiki/Configuration
service:
  golangci-lint-version: 1.30.x # use the fixed version to not introduce new linters unexpectedly
  prepare:
    - echo "here I can run custom commands, but no preparation needed for this repo"