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,95 +15,97 @@ run:
modules-download-mode: readonly modules-download-mode: readonly
linters: linters:
enable: enable:
# linters maintained by golang.org - depguard
- gofmt - gocyclo
- goimports - gosec
- govet - misspell
# linters default enabled by golangci-lint . - revive
- errcheck - whitespace
- gosimple settings:
- ineffassign depguard:
- staticcheck rules:
- typecheck main:
- unused deny:
# other linters supported by golangci-lint. - pkg: io/ioutil
- gci desc: 'replaced by io and os packages since Go 1.16: https://tip.golang.org/doc/go1.16#ioutil'
- gocyclo gocyclo:
- gosec # minimal cyclomatic complexity to report
- misspell min-complexity: 15
- whitespace revive:
- revive rules:
- depguard # Disable if-return as it is too strict and not always useful.
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#if-return
linters-settings: - name: if-return
depguard: disabled: true
rules: - name: package-comments
main: disabled: true
deny: - name: superfluous-else
- pkg: "io/ioutil" arguments:
desc: "replaced by io and os packages since Go 1.16: https://tip.golang.org/doc/go1.16#ioutil" - preserveScope
goimports: - name: error-strings
local-prefixes: github.com/karmada-io/karmada - name: error-return
gocyclo: - name: receiver-naming
# minimal cyclomatic complexity to report - name: increment-decrement
min-complexity: 15 - name: range
gci: - name: error-naming
sections: - name: dot-imports
- Standard - name: errorf
- Default - name: exported
- Prefix(github.com/karmada-io/karmada) - name: var-declaration
revive: - name: blank-imports
rules: - name: indent-error-flow
# Disable if-return as it is too strict and not always useful. - name: unreachable-code
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#if-return - name: var-naming
- name: if-return - name: redefines-builtin-id
disabled: true - name: unused-parameter
- name: package-comments - name: context-as-argument
- name: superfluous-else - name: context-keys-type
arguments: - name: unexported-return
- preserveScope - name: time-naming
- name: error-strings - name: empty-block
- name: error-return staticcheck:
- name: receiver-naming checks:
- name: increment-decrement - all
- name: range # Exclude the following checks temporarily.
- name: error-naming # Will fix the issues in the following PRs.
- name: dot-imports # Issue: https://github.com/karmada-io/karmada/issues/6273.
- name: errorf - "-QF1008"
- name: exported - "-ST1019"
- name: var-declaration - "-ST1005"
- name: blank-imports - "-QF1004"
- name: indent-error-flow - "-ST1011"
- name: unreachable-code - "-QF1003"
- name: var-naming - "-QF1001"
- name: redefines-builtin-id - "-ST1000"
- name: unused-parameter exclusions:
- name: context-as-argument generated: lax
- name: context-keys-type presets:
- name: unexported-return - common-false-positives
- name: time-naming - legacy
- name: empty-block - std-error-handling
paths:
issues: - hack/tools/preferredimports
# The list of ids of default excludes to include or disable. By default it's empty. - (^|/)vendor($|/)
include: - (^|/)third_party($|/)
# disable excluding of issues about comments from revive - pkg/util/lifted
# see https://golangci-lint.run/usage/configuration/#command-line-options for more info formatters:
- EXC0012 enable:
- EXC0013 - gci
- EXC0014 - gofmt
# Which dirs to exclude: issues from them won't be reported. - goimports
# Can use regexp here: `generated.*`, regexp is applied on full path, settings:
# including the path prefix if one is set. gci:
# Default dirs are skipped independently of this option's value (see exclude-dirs-use-default). sections:
# "/" will be replaced by current OS file path separator to properly work on Windows. - Standard
# Default: [] - Default
exclude-dirs: - Prefix(github.com/karmada-io/karmada)
- hack/tools/preferredimports # This code is directly lifted from the Kubernetes codebase, skip checking goimports:
- (^|/)vendor($|/) local-prefixes:
- (^|/)third_party($|/) - github.com/karmada-io/karmada
- pkg/util/lifted # This code is lifted from other projects(Kubernetes, Kubefed, and so on), skip checking. exclusions:
# Enables exclude of directories: generated: lax
# - vendor$, third_party$, testdata$, examples$, Godeps$, builtin$ paths:
# Default: true - hack/tools/preferredimports
exclude-dirs-use-default: false - (^|/)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"