-
Notifications
You must be signed in to change notification settings - Fork 2
/
.golangci.yml
250 lines (207 loc) · 10.5 KB
/
.golangci.yml
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
# This file contains all available configuration options with their default values.
# https://github.com/golangci/golangci-lint#configuration
# options for analysis running
run:
# default concurrency is a available CPU number
#concurrency: 4
# timeout for analysis, e.g. 30s, 5m, default is 1m
#deadline: 1m
# exit code when at least one issue was found, default is 1
issues-exit-code: 1
# include test files or not, default is true
tests: true
# all available settings of specific linters
linters-settings:
# errcheck 检查 "unchecked errors", 如: 类型断言没有接收err, 没有接收函数返回的err, 用匿名变量接收err ......
errcheck:
# report about not checking of errors in type assetions: `a := b.(MyStruct)`;
# default is false: such cases aren't reported by default.
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.
check-blank: true
# path to a file containing a list of functions to exclude from checking
# see https://github.com/kisielk/errcheck#excluding-functions for details
#exclude: /path/to/file.txt
govet:
enable:
- shadow
settings: # settings per analyzer
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
# gofmt 格式检查 format check
gofmt:
simplify: true # simplify code: gofmt with `-s` option, true by default
# goimports gofmt检查 + import检查
goimports:
# put imports beginning with prefix after 3rd-party packages;
# it's a comma-separated list of prefixes
local-prefixes: code.byted.org/bytertc/schedule
revive:
rules:
- name: var-naming
arguments:
- [] # AllowList
- ['SDN'] # DenyList
# gosimple #提供信息,帮助了解哪些代码可以简化
#gosimple:
# staticcheck #提供了巨多的静态检查, detect bugs, suggest code simplifications, point out dead code, and much more.
#staticcheck:
# ineffassign 检查只赋值而未被使用的变量
# https://github.com/gordonklaus/ineffassign
#ineffassign:
# typecheck #Like the front-end of a Go compiler, parses and type-checks Go code
#typecheck:
#bodyclose: # 检查是否关闭http response body
#stylecheck: # replacement for golint
#gosec: 检查安全问题, https://github.com/securego/gosec
#unconvert: # 检测不必要的类型转换
#gochecknoinits: 检查是否有使用init()
#gochecknoglobals: 检查是否有使用全局变量
# gocyclo 检查函数的复杂度 https://github.com/alecthomas/gocyclo
gocyclo:
min-complexity: 10 # minimal code complexity to report, 30 by default (but we recommend 10-20)
# dupl 检测可疑的代码复制
dupl:
threshold: 100 # tokens count to trigger issue, 150 by default
# 查找重复的字符串,可以抽取成常量
goconst:
min-len: 3 # minimal length of string constant, 3 by default
min-occurrences: 3 # minimal occurrences count to trigger, 3 by default
# misspell 拼写检查
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'.
locale: US
#ignore-words:
# - someword
# lll 检测函数行数, 文件行数
lll:
line-length: 140 # max line length, lines longer will be reported. Default is 120.
#tab-width: 1 # tab width in spaces. Default to 1.
# unparam 检查未被使用的函数参数
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.
check-exported: false
# nakedret 检查当函数行数操作一定数量时的 naked return, 用以降低风险
nakedret:
# make an issue if func has more lines of code than this setting and it has naked returns; default is 30
max-func-lines: 30
# prealloc 检测可以提前分配缓存的slice
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.
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
# https://github.com/go-critic/go-critic
# https://go-critic.github.io/overview
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.
#enabled-checks:
# - rangeValCopy
# Which checks should be disabled; can't be combined with 'enabled-checks'; default is empty
disabled-checks:
- 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".
enabled-tags:
- performance
- style
- experimental
#settings: # settings passed to gocritic
# captLocal: # must be valid enabled check name
# paramsOnly: true
# rangeValCopy:
# sizeThreshold: 32
linters:
enable-all: false # true: 启用除了disable部分的其他所有linters. 不能与disable_all字段同时设置为true
# 0, 可以通过命令golangci-lint help linters查看默认enable和disable的lingters
# 1, 带有[default enable]标记的linter是全部的默认enable的linter, 在这里重复列出是为了方便直观查看
# 2, golangci-lint默认enable的linters全部都已经在此列出
# 3, 并且额外enable了bodyclose, unconvert, nakedret, unparam这几个原本默认disable的linters
# 4, 不在enable列表中的linters都会被disable( 这些原本就属于默认的disable linters)
enable:
- errcheck # [default enable] 检查 "unchecked errors", 如: 类型断言没有接收err, 没有接收函数返回的err, 用匿名变量接收err ......
- gosimple # [default enable] 提供信息,帮助了解哪些代码可以简化
- govet # [default enable] 检查作用域内变量相互覆盖等风险
- ineffassign # [default enable] 检查只赋值而未被使用的变量
- staticcheck # [default enable] 提供了巨多的静态检查, detect bugs, suggest code simplifications, point out dead code, and much more.
- typecheck # [default enable] Like the front-end of a Go compiler, parses and type-checks Go code
- unused # [default enable] 检查未被使用的常量, 变量, 函数, 和类型
- bodyclose # [default disable] 检查是否关闭http response body
- unconvert # [default disable] 检测不必要的类型转换
- nakedret # [default disable] 检查当函数行数操作一定数量时的 naked return, 用以降低风险
- unparam # [default disable] 检查未被使用的函数参数
- gofmt # [default disable] 格式检查 format check
- goimports # [default disable] gofmt检查 + import检查
- exportloopref
- revive
disable-all: false # true: 关闭除了enbale列表中之外的所有linters. 不能与enable_all字段同时为true
disable:
- gochecknoglobals # [default disable] 检查是否有使用全局变量
- gochecknoinits # [default disable] 检查是否有使用init()
- depguard # [default disable] 用来检查是否使用了"允许/禁止list"上的package
- dupl # [default disable] 检测可疑的代码复制
- goconst # [default disable] 查找重复的字符串,可以抽取成常量
- gocritic # [default disable]
- gocyclo # [default disable] 检查函数的复杂度
- gosec # [default disable] 检查安全问题
- lll # [default disable] 检测函数行数, 文件行数
- misspell # [default disable] 拼写检查
- prealloc # [default disable] 检测可以提前分配缓存的slice
- stylecheck # [default disable] replacement for golint
#presets:
# - bugs
# - unused
issues:
# Which dirs to exclude: issues from them won't be reported.
# Can use regexp here: `generated.*`, regexp is applied on full path,
# including the path prefix if one is set.
# Default dirs are skipped independently of this option's value (see exclude-dirs-use-default).
# "/" will be replaced by current OS file path separator to properly work on Windows.
# Default: []
exclude-dirs:
- api/kitex_gen/
- api/proto_gen/
- api/hertz_gen/
- test/mocks/
# Which files to exclude: they will be analyzed, but issues from them won't be reported.
# 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.
# Default: []
exclude-files:
- internal/pkg/dsrpc/media_server.autogen.go
- internal/pkg/dsrpc/schedule_client.autogen.go
- internal/pkg/dsrpc/media_client.autogen.go
- internal/pkg/dsrpc/schedule_server.autogen.go
# Maximum issues count per one linter.
# Set to 0 to disable.
# Default: 50
max-issues-per-linter: 0
# Maximum count of issues with the same text.
# Set to 0 to disable.
# Default: 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.
new: false