mirror of
https://github.com/shadow1ng/fscan.git
synced 2025-11-04 18:19:19 +00:00
移除复杂度阈值的TODO注释,承认当前配置为项目标准: - gocyclo: 35 - gocognit: 80 这些阈值经过实践验证,适合当前项目规模和安全扫描工具的特性。 工程化配置已稳定,可专注功能开发。
177 lines
4.0 KiB
YAML
177 lines
4.0 KiB
YAML
# golangci-lint 配置
|
||
# 文档: https://golangci-lint.run/usage/configuration/
|
||
|
||
run:
|
||
# 超时时间
|
||
timeout: 5m
|
||
|
||
# 测试文件也检查
|
||
tests: true
|
||
|
||
# 输出配置
|
||
output:
|
||
# 输出格式
|
||
formats:
|
||
- format: colored-line-number
|
||
|
||
# 显示问题详情
|
||
print-issued-lines: true
|
||
print-linter-name: true
|
||
|
||
# 按严重程度排序
|
||
sort-results: true
|
||
|
||
# Linter 配置
|
||
linters:
|
||
# 禁用所有默认linters
|
||
disable-all: true
|
||
|
||
# 启用指定的linters
|
||
enable:
|
||
# Go 官方工具
|
||
- govet # Go官方检查工具(会特殊处理printf)
|
||
- gofmt # 代码格式化检查
|
||
# - goimports # import排序检查(需要goimports工具,临时禁用)
|
||
|
||
# 错误检查
|
||
- errcheck # 检查未处理的错误
|
||
- errorlint # 错误包装检查
|
||
|
||
# 代码质量
|
||
- staticcheck # 静态分析
|
||
- unused # 未使用的代码
|
||
- gosimple # 简化建议
|
||
- ineffassign # 无效赋值
|
||
- typecheck # 类型检查
|
||
|
||
# 代码复杂度
|
||
- gocyclo # 圈复杂度
|
||
- gocognit # 认知复杂度
|
||
|
||
# 安全检查(安全工具必备)
|
||
- gosec # 安全检查
|
||
|
||
# 代码风格
|
||
- misspell # 拼写检查
|
||
- whitespace # 空白符检查
|
||
# - revive # 代码风格检查(暂时禁用,避免阻塞CI)
|
||
|
||
# Linter 特定配置
|
||
linters-settings:
|
||
# govet 配置
|
||
govet:
|
||
# 启用所有检查
|
||
enable-all: true
|
||
|
||
# 禁用 printf 检查
|
||
# 原因: i18n.GetTextF 使用键名查找格式化字符串,静态分析无法识别
|
||
disable:
|
||
- printf
|
||
|
||
# errcheck 配置
|
||
errcheck:
|
||
# 检查类型断言
|
||
check-type-assertions: true
|
||
# 检查空白标识符
|
||
check-blank: false
|
||
|
||
# gocyclo 配置
|
||
gocyclo:
|
||
# 圈复杂度阈值
|
||
min-complexity: 35
|
||
|
||
# gocognit 配置
|
||
gocognit:
|
||
# 认知复杂度阈值
|
||
min-complexity: 80
|
||
|
||
# gosec 配置
|
||
gosec:
|
||
# 严重级别: low, medium, high
|
||
severity: medium
|
||
confidence: medium
|
||
|
||
# 排除特定规则
|
||
excludes:
|
||
- G104 # 未处理的错误(由errcheck处理)
|
||
- G115 # 整型转换溢出(在特定场景下是安全的)
|
||
- G204 # 子进程使用用户输入(扫描工具特性,需要执行外部命令)
|
||
- G301 # 目录权限0755(标准权限)
|
||
- G302 # 文件权限0644(标准权限)
|
||
- G304 # 文件路径由用户输入(扫描工具特性)
|
||
- G306 # 文件权限(标准权限)
|
||
- G402 # TLS InsecureSkipVerify(扫描工具需要测试各种TLS配置)
|
||
- G601 # for循环内存别名(Go 1.22+已修复)
|
||
|
||
# revive 配置
|
||
revive:
|
||
confidence: 0.8
|
||
rules:
|
||
# 启用基础规则
|
||
- name: blank-imports
|
||
- name: context-as-argument
|
||
- name: dot-imports
|
||
- name: error-return
|
||
- name: error-strings
|
||
- name: error-naming
|
||
- name: exported
|
||
- name: increment-decrement
|
||
- name: var-naming
|
||
- name: package-comments
|
||
- name: range
|
||
- name: receiver-naming
|
||
- name: indent-error-flow
|
||
- name: superfluous-else
|
||
- name: unreachable-code
|
||
- name: redefines-builtin-id
|
||
|
||
# misspell 配置
|
||
misspell:
|
||
locale: US
|
||
|
||
# 问题配置
|
||
issues:
|
||
# 限制问题输出(避免刷屏)
|
||
max-issues-per-linter: 50
|
||
max-same-issues: 3
|
||
|
||
# 新代码检查
|
||
new: false
|
||
|
||
# 排除目录
|
||
exclude-dirs:
|
||
- vendor
|
||
- testdocker
|
||
- image
|
||
|
||
# 排除文件
|
||
exclude-files:
|
||
- ".*\\.pb\\.go$"
|
||
|
||
# 排除规则
|
||
exclude-rules:
|
||
# 排除测试文件的某些检查
|
||
- path: _test\.go
|
||
linters:
|
||
- gocyclo
|
||
- gocognit
|
||
- errcheck
|
||
|
||
# 排除长行(某些场景下合理)
|
||
- linters:
|
||
- lll
|
||
source: "^//go:generate "
|
||
|
||
# 排除 fieldalignment(结构体对齐优化,影响可读性)
|
||
- linters:
|
||
- govet
|
||
text: "fieldalignment:"
|
||
|
||
# 排除 revive 的包注释要求(太严格)
|
||
- linters:
|
||
- revive
|
||
text: "package-comments:"
|
||
|
||
# 不排除默认的问题
|
||
exclude-use-default: false
|