- 新增 backend/.golangci.yml 配置 12 个 linter(forbidigo、errorlint、errcheck、staticcheck、revive、gocritic、gosec、bodyclose、noctx、nilerr、goimports、gocyclo) - 新增 lefthook.yml 配置 pre-commit hook 自动运行 lint - 修复存量代码违规:errors.Is/As 替换、zap.Error 替换、import 排序、errcheck 修复 - 更新 README 补充编码规范说明 - 归档 backend-code-lint 变更
92 lines
2.4 KiB
YAML
92 lines
2.4 KiB
YAML
run:
|
||
timeout: 5m
|
||
tests: true
|
||
|
||
linters:
|
||
disable-all: true
|
||
enable:
|
||
- forbidigo
|
||
- errorlint
|
||
- errcheck
|
||
- staticcheck
|
||
- revive
|
||
- gocritic
|
||
- gosec
|
||
- bodyclose
|
||
- noctx
|
||
- nilerr
|
||
- goimports
|
||
- gocyclo
|
||
|
||
linters-settings:
|
||
errcheck:
|
||
check-blank: true
|
||
check-type-assertions: true
|
||
exclude-functions:
|
||
- fmt.Fprintf
|
||
forbidigo:
|
||
analyze-types: true
|
||
forbid:
|
||
- p: '^fmt\.Print.*$'
|
||
msg: 使用 zap logger,不要直接输出到 stdout/stderr
|
||
- p: '^fmt\.Fprint.*$'
|
||
msg: 使用 zap logger,不要直接输出到 stdout/stderr
|
||
- p: '^log\.(Print|Println|Printf|Fatal|Fatalln|Fatalf|Panic|Panicln|Panicf)$'
|
||
msg: 使用 zap logger,不要使用标准库 log
|
||
- p: '^zap\.L$'
|
||
msg: 通过依赖注入传递 *zap.Logger,不要使用全局 logger
|
||
- p: '^zap\.S$'
|
||
msg: 不使用 Sugar logger
|
||
revive:
|
||
rules:
|
||
- name: exported
|
||
- name: var-naming
|
||
- name: indent-error-flow
|
||
- name: error-strings
|
||
- name: error-return
|
||
- name: blank-imports
|
||
- name: context-as-argument
|
||
- name: unexported-return
|
||
goimports:
|
||
local-prefixes: nex/backend
|
||
gocyclo:
|
||
min-complexity: 10
|
||
|
||
issues:
|
||
exclude-dirs:
|
||
- tests/mocks
|
||
exclude-generated: true
|
||
exclude-rules:
|
||
- path: '(_test\.go|tests/)'
|
||
linters:
|
||
- forbidigo
|
||
- path: '(_test\.go|tests/)'
|
||
linters:
|
||
- errcheck
|
||
source: '(^\s*_\s*=|,\s*_)'
|
||
- path: 'tests/integration/e2e_conversion_test\.go'
|
||
linters:
|
||
- errcheck
|
||
- path: '(_test\.go|tests/)'
|
||
linters:
|
||
- revive
|
||
text: '^exported:'
|
||
- path: '(_test\.go|tests/)'
|
||
linters:
|
||
- gosec
|
||
text: 'G(101|401|501)'
|
||
- path: '(_test\.go|tests/)'
|
||
linters:
|
||
- gocyclo
|
||
text: 'cyclomatic complexity (1[1-9]|20) of .* is high \(> 10\)'
|
||
- linters:
|
||
- revive
|
||
text: '(that stutters|BuildUrl should be BuildURL|ConvertHttpRequest should be ConvertHTTPRequest|ConvertHttpResponse should be ConvertHTTPResponse)'
|
||
- path: 'internal/conversion/.*\.go'
|
||
linters:
|
||
- gocyclo
|
||
- gocritic
|
||
- path: '(internal/provider/client\.go|internal/service/model_service_impl\.go|internal/service/stats_buffer\.go|internal/handler/proxy_handler\.go|cmd/(desktop|server)/main\.go)'
|
||
linters:
|
||
- gocyclo
|