Merge pull request #6237 from seanlaii/golangci-lint-v2

Upgrade golangci-lint from v1.64.8 to v2.0.2
This commit is contained in:
karmada-bot 2025-04-12 10:21:59 +08:00 committed by GitHub
commit 71e103fb4e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 98 additions and 95 deletions

View File

@ -1,8 +1,9 @@
# This files contains all configuration options for analysis running. # This files contains all configuration options for analysis running.
# More details please refer to: https://golangci-lint.run/usage/configuration/ # More details please refer to: https://golangci-lint.run/usage/configuration/
version: "2"
run: run:
# timeout for analysis, e.g. 30s, 5m, default is 1m # timeout for analysis, e.g. 30s, 5m, default timeout is disabled
timeout: 10m timeout: 10m
# One of 'readonly' and 'vendor'. # One of 'readonly' and 'vendor'.
@ -14,43 +15,22 @@ run:
modules-download-mode: readonly modules-download-mode: readonly
linters: linters:
enable: enable:
# linters maintained by golang.org - depguard
- gofmt
- goimports
- govet
# linters default enabled by golangci-lint .
- errcheck
- gosimple
- ineffassign
- staticcheck
- typecheck
- unused
# other linters supported by golangci-lint.
- gci
- gocyclo - gocyclo
- gosec - gosec
- misspell - misspell
- whitespace
- revive - revive
- depguard - whitespace
settings:
linters-settings:
depguard: depguard:
rules: rules:
main: main:
deny: deny:
- pkg: "io/ioutil" - pkg: io/ioutil
desc: "replaced by io and os packages since Go 1.16: https://tip.golang.org/doc/go1.16#ioutil" desc: 'replaced by io and os packages since Go 1.16: https://tip.golang.org/doc/go1.16#ioutil'
goimports:
local-prefixes: github.com/karmada-io/karmada
gocyclo: gocyclo:
# minimal cyclomatic complexity to report # minimal cyclomatic complexity to report
min-complexity: 15 min-complexity: 15
gci:
sections:
- Standard
- Default
- Prefix(github.com/karmada-io/karmada)
revive: revive:
rules: rules:
# Disable if-return as it is too strict and not always useful. # Disable if-return as it is too strict and not always useful.
@ -58,6 +38,7 @@ linters-settings:
- name: if-return - name: if-return
disabled: true disabled: true
- name: package-comments - name: package-comments
disabled: true
- name: superfluous-else - name: superfluous-else
arguments: arguments:
- preserveScope - preserveScope
@ -82,27 +63,49 @@ linters-settings:
- name: unexported-return - name: unexported-return
- name: time-naming - name: time-naming
- name: empty-block - name: empty-block
staticcheck:
issues: checks:
# The list of ids of default excludes to include or disable. By default it's empty. - all
include: # Exclude the following checks temporarily.
# disable excluding of issues about comments from revive # Will fix the issues in the following PRs.
# see https://golangci-lint.run/usage/configuration/#command-line-options for more info # Issue: https://github.com/karmada-io/karmada/issues/6273.
- EXC0012 - "-QF1008"
- EXC0013 - "-ST1019"
- EXC0014 - "-ST1005"
# Which dirs to exclude: issues from them won't be reported. - "-QF1004"
# Can use regexp here: `generated.*`, regexp is applied on full path, - "-ST1011"
# including the path prefix if one is set. - "-QF1003"
# Default dirs are skipped independently of this option's value (see exclude-dirs-use-default). - "-QF1001"
# "/" will be replaced by current OS file path separator to properly work on Windows. - "-ST1000"
# Default: [] exclusions:
exclude-dirs: generated: lax
- hack/tools/preferredimports # This code is directly lifted from the Kubernetes codebase, skip checking presets:
- common-false-positives
- legacy
- std-error-handling
paths:
- hack/tools/preferredimports
- (^|/)vendor($|/) - (^|/)vendor($|/)
- (^|/)third_party($|/) - (^|/)third_party($|/)
- pkg/util/lifted # This code is lifted from other projects(Kubernetes, Kubefed, and so on), skip checking. - pkg/util/lifted
# Enables exclude of directories: formatters:
# - vendor$, third_party$, testdata$, examples$, Godeps$, builtin$ enable:
# Default: true - gci
exclude-dirs-use-default: false - gofmt
- goimports
settings:
gci:
sections:
- Standard
- Default
- Prefix(github.com/karmada-io/karmada)
goimports:
local-prefixes:
- github.com/karmada-io/karmada
exclusions:
generated: lax
paths:
- hack/tools/preferredimports
- (^|/)vendor($|/)
- (^|/)third_party($|/)
- pkg/util/lifted

View File

@ -19,7 +19,7 @@ set -o nounset
set -o pipefail set -o pipefail
REPO_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. REPO_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
GOLANGCI_LINT_VER="v1.64.8" GOLANGCI_LINT_VER="v2.0.2"
cd "${REPO_ROOT}" cd "${REPO_ROOT}"
source "hack/util.sh" source "hack/util.sh"