-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
151 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
name: Lint | ||
|
||
# 定义触发条件 | ||
on: | ||
push: | ||
pull_request: | ||
|
||
jobs: | ||
lint: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version: stable | ||
|
||
- name: Run golangci-lint | ||
uses: golangci/golangci-lint-action@v6 | ||
with: | ||
version: v1.62.2 | ||
args: '--config .golangci.yml' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
# golangci-lint 配置文件 | ||
|
||
run: | ||
concurrency: 4 # 并行执行的 linter 数量,默认为可用 CPU 数量 | ||
deadline: 5m # 分析的最大超时时间,默认为 5 分钟 | ||
timeout: 10m # 超时时间 | ||
issues-exit-code: 1 # 如果发现至少一个问题,退出码为 1 | ||
tests: true # 包含测试文件进行分析 | ||
modules-download-mode: readonly # 防止分析过程中修改 go.mod 文件 | ||
|
||
output: | ||
formats: # 设置多个输出格式 | ||
- format: colored-line-number # 使用颜色化的行号格式 | ||
sort-results: true # 按文件名和行号排序结果 | ||
print-issued-lines: true # 输出包含问题的代码行 | ||
print-linter-name: true # 输出 linter 名称 | ||
|
||
linters-settings: | ||
errcheck: | ||
check-type-assertions: true # 检查类型断言的错误处理 | ||
check-blank: false # 检查将错误分配给空标识符的情况 | ||
exclude-functions: # 不检查这些函数 | ||
- fmt:.* | ||
- io/ioutil:^Read.* | ||
revive: | ||
# 是否启用所有可用的规则 | ||
enable-all-rules: true | ||
# 默认失败置信度 | ||
confidence: 0.1 | ||
rules: | ||
- name: var-naming # 变量命名规则 | ||
severity: warning | ||
disabled: true | ||
- name: line-length-limit # 行长度限制 | ||
severity: warning | ||
disabled: false | ||
exclude: [ "" ] | ||
arguments: [ 120 ] | ||
- name: add-constant # 使用命名常量而非魔法数字 | ||
severity: warning | ||
disabled: true | ||
- name: package-comments # 包注释 | ||
severity: warning | ||
disabled: true | ||
- name: import-alias-naming # 导入别名命名规则 | ||
severity: warning | ||
disabled: true | ||
- name: get-return # 使用get必须有返回值 | ||
severity: warning | ||
disabled: true | ||
- name: max-public-structs # 最大公共结构体数目 | ||
severity: warning | ||
disabled: true | ||
- name: argument-limit # 函数参数限制 | ||
severity: warning | ||
disabled: true | ||
- name: function-length # 函数长度限制 | ||
severity: warning | ||
disabled: true | ||
- name: cyclomatic # 圈复杂度 | ||
severity: warning | ||
disabled: true | ||
- name: cognitive-complexity # 认知复杂度 | ||
severity: warning | ||
disabled: false | ||
arguments: [ 10 ] | ||
gofmt: | ||
simplify: true # 使用 gofmt 的 `-s` 选项简化代码 | ||
gocyclo: | ||
min-complexity: 10 # 触发报告的最小代码复杂度 | ||
dupl: | ||
threshold: 100 # 触发报告的最小令牌数 | ||
goconst: | ||
min-len: 3 # 字符串常量的最小长度 | ||
min-occurrences: 3 # 触发报告的最小出现次数 | ||
gosec: | ||
severity: medium # 安全问题的最小严重性 | ||
unused: | ||
check-exported: true # 报告未使用的导出标识符 | ||
unparam: | ||
check-exported: false # 检查导出的函数 | ||
nakedret: | ||
max-func-lines: 0 # 允许带裸返回的函数的最大行数 | ||
staticcheck: # 使用 staticcheck 替代 govet | ||
checks: | ||
- SA1000 # 使用了某些无效操作 | ||
- SA1001 # 无效的时间格式或解析 | ||
- SA1012 # 非法的 waitGroup 使用 | ||
prealloc: | ||
simple: true # 在简单循环中报告预分配建议 | ||
range-loops: true # 在 range 循环中报告预分配建议 | ||
for-loops: true # 在 for 循环中报告预分配建议 | ||
|
||
linters: | ||
disable-all: true # 禁用所有 linter | ||
enable: | ||
- errcheck # 检查未处理的错误 | ||
- staticcheck # 静态代码分析工具,检测潜在的错误和反模式 | ||
- gofmt # 检查代码格式是否符合 gofmt 规范 | ||
- revive # 替代 golint 的代码风格检查工具 | ||
- gocyclo # 检测代码的圈复杂度 | ||
- dupl # 检查重复代码 | ||
- goconst # 检查重复的常量 | ||
- gosec # 检查安全问题 | ||
- unused # 检查未使用的代码 | ||
- unparam # 检查未使用的函数参数 | ||
- prealloc # 检查预分配建议 | ||
- gci # 检查并排序导入语句 | ||
|
||
issues: | ||
exclude-use-default: false # 禁用默认排除模式 | ||
max-per-linter: 0 # 每个 linter 的最大问题数量,设置为 0 禁用限制 | ||
max-same-issues: 0 # 同一问题的最大数量,设置为 0 禁用限制 | ||
new: false # 仅显示新问题,默认为 false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
//nolint:all | ||
package sdk | ||
|
||
import ( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters