-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path.golangci.yaml
More file actions
139 lines (131 loc) · 4.2 KB
/
.golangci.yaml
File metadata and controls
139 lines (131 loc) · 4.2 KB
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
version: "2"
output:
formats:
text:
print-issued-lines: true
print-linter-name: true
show-stats: true
formatters:
enable:
- gofmt
- goimports
- gofumpt
settings:
gofmt:
simplify: true
rewrite-rules:
- pattern: 'interface{}'
replacement: 'any'
- pattern: 'a[b:len(a)]'
replacement: 'a[b:]'
goimports:
local-prefixes:
- github.com/m4n5ter/another-me
gofumpt:
module-path: github.com/m4n5ter/another-me
extra-rules: true
linters:
default: none
enable:
# --- 格式化与基础检查 ---
- govet # 分析 Go 源码并报告可疑的构造
- revive # 强大的风格检查器,可配置性高,替代 golint
- staticcheck # 大量静态分析检查 (SA*)
- unused # 检查未使用的代码
- ineffassign # 检查无效的赋值操作
- copyloopvar # 检查循环变量是否被正确捕获 (替代已移除的 exportloopref)
# --- 编码规范相关 (sentinel.mdc) ---
- sloglint # 检查 slog 日志库的正确使用 (符合 sentinel.mdc 日志规范)
- errorlint # 检查 fmt.Errorf 格式化字符串中是否正确使用了 %w
- errcheck # 检查未处理的错误
- bodyclose # 检查 HTTP 响应体是否关闭
- durationcheck # 检查不当的持续时间(duration)使用方式
- goconst # 查找重复的字符串,建议提取为常量
- unconvert # 移除不必要的类型转换
- depguard # 检查并限制包的导入
# --- 潜在问题与改进 ---
- asciicheck # 检查非 ASCII 字符
- dogsled # 检查空白标识符的不当使用
- dupl # 检查重复代码
- gocritic # 提供额外的代码检查,很有用
- gocyclo # 检查函数复杂度
- nolintlint # 检查 //nolint 指令的有效性和格式
- prealloc # 查找可能需要预分配切片的地方以提高性能
- rowserrcheck # 检查 sql.Rows/sql.Row 的 Err() 是否被检查
- sqlclosecheck # 检查 sql.Rows/sql.Stmt 是否关闭
- wrapcheck # 检查错误包装
- tparallel # 检查测试是否正确使用了 t.Parallel()
- nestif # 报告深度嵌套的 if 语句
settings:
errcheck:
check-blank: true
exclude-functions:
- io/ioutil.ReadFile
- io.Copy(*bytes.Buffer)
- io.Copy(os.Stdout)
- (io.Closer).Close
- (*github.com/qdrant/go-client/qdrant.Client).Close
- (net/http.ResponseWriter).Write
- (net.Conn).Close
- github.com/json-iterator/go.Marshal
- (*github.com/json-iterator/go.Encoder).Encode
sloglint:
static-msg: true
gocyclo:
min-complexity: 40
misspell:
locale: "US"
revive:
rules:
- name: comment-spacings
- name: dot-imports
severity: warning
disabled: false
exclude: [""]
arguments:
- allowed-packages: ["github.com/m4n5ter/another-me/pkg/option"]
- name: blank-imports
- name: error-naming
- name: error-return
- name: error-strings
- name: var-naming
- name: function-result-limit
arguments: [3]
staticcheck:
dot-import-whitelist:
- "github.com/m4n5ter/another-me/pkg/option"
wrapcheck:
ignore-sig-regexps:
- \\.Errorf$
- \\errors\\.New$
- \\errors\\.Unwrap$
- \\errors\\.Is$
- \\errors\\.As$
nolintlint:
allow-unused: false
require-explanation: true
require-specific: true
depguard:
rules:
deny-log:
deny:
- pkg: "log$"
desc: "禁止使用标准库 log,请使用 log/slog,如果需要 Fatal,请使用 slog.Error 并调用 os.Exit 或 return/panic"
- pkg: "encoding/json"
desc: '禁止使用标准库 encoding/json,请使用 json "github.com/json-iterator/go"'
nestif:
min-complexity: 20
exclusions:
rules:
- path: _test\.go
linters:
- gocyclo
- errcheck
- dupl
- gosec
- unused
- wrapcheck
- gocritic
issues:
max-issues-per-linter: 0 # 0 表示禁用
max-same-issues: 0 # 0 表示禁用