chore: migrate golangci-lint config to v2

- Add version field and migrate to v2 config format
- Replace deprecated linters with modern equivalents
- Add new linters: bidichk, depguard, forbidigo, revive, testifylint, etc.
- Move gofmt, gofumpt, golines to formatters section
- Configure revive rules, depguard deny list, and exclusion presets
This commit is contained in:
Bo-Yi Wu
2026-04-08 23:00:38 +08:00
parent 0bc6220388
commit cbae1a3737
+100 -23
View File
@@ -1,37 +1,114 @@
version: "2"
output:
sort-order:
- file
linters: linters:
disable-all: true default: none
enable: enable:
- bidichk
- bodyclose - bodyclose
- dogsled - depguard
- errcheck - errcheck
- exportloopref - forbidigo
- exhaustive - gocheckcompilerdirectives
- gochecknoinits
- goconst
- gocritic - gocritic
- gofmt
- goimports
- goprintffuncname
- gosec
- gosimple
- govet - govet
- ineffassign - ineffassign
- misspell - mirror
- modernize
- nakedret - nakedret
- noctx - nilnil
- nolintlint - nolintlint
- perfsprint
- revive
- staticcheck - staticcheck
- stylecheck - testifylint
- typecheck
- unconvert - unconvert
- unparam - unparam
- unused - unused
- whitespace - usestdlibvars
- gofumpt - usetesting
- wastedassign
issues: settings:
exclude-rules: depguard:
# Exclude `lll` issues for long lines with `go:generate`. rules:
main:
deny:
- pkg: io/ioutil
desc: use os or io instead
- pkg: golang.org/x/exp
desc: it's experimental and unreliable
- pkg: github.com/pkg/errors
desc: use builtin errors package instead
nolintlint:
allow-unused: false
require-explanation: true
require-specific: true
gocritic:
enabled-checks:
- equalFold
disabled-checks: []
revive:
severity: error
rules:
- name: blank-imports
- name: constant-logical-expr
- name: context-as-argument
- name: context-keys-type
- name: dot-imports
- name: empty-lines
- name: error-return
- name: error-strings
- name: exported
- name: identical-branches
- name: if-return
- name: increment-decrement
- name: modifies-value-receiver
- name: package-comments
- name: redefines-builtin-id
- name: superfluous-else
- name: time-naming
- name: unexported-return
- name: var-declaration
- name: var-naming
disabled: true
staticcheck:
checks:
- all
testifylint: {}
usetesting:
os-temp-dir: true
perfsprint:
concat-loop: false
govet:
enable:
- nilness
- unusedwrite
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
rules:
- linters: - linters:
- lll - errcheck
source: "^//go:generate " - staticcheck
- unparam
path: _test\.go
issues:
max-issues-per-linter: 0
max-same-issues: 0
formatters:
enable:
- gofmt
- gofumpt
- golines
settings:
gofumpt:
extra-rules: true
exclusions:
generated: lax
run:
timeout: 10m