ci: add linter

This commit is contained in:
2026-01-03 17:57:11 +08:00
parent a6a83f8d9f
commit a8b3a34db7
5 changed files with 65 additions and 8 deletions

44
.golangci.yaml Normal file
View File

@@ -0,0 +1,44 @@
version: "2"
linters:
enable:
# --- 风格与规范 ---
- revive # 替代 golint检查代码风格
- misspell # 检查拼写错误
- goconst # 建议将重复的字符串提取为常量
- loggercheck # 检查日志使用规范
# --- 复杂度与质量 ---
- gocognit # 认知复杂度 (推荐)
- gocyclo # 圈复杂度
- nestif # 检查 if 嵌套深度
- funlen # 检查函数长度
# --- 性能与 Bug 预防 ---
- bodyclose # 检查 HTTP body 是否关闭 (非常重要)
- noctx # 检查是否忘记传 Context
- prealloc # 建议预分配 slice (性能优化)
- unconvert # 移除不必要的类型转换
- unparam # 检查未使用的函数参数
- gocritic # 综合性检查,包含多种检查器
- makezero # 检查 make 的零值参数
settings:
nestif:
min-complexity: 4 # 最多三层嵌套
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
paths:
- third_party$
- builtin$
- examples$
formatters:
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$