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$