mirror of
https://github.com/kubernetes/kubernetes.git
synced 2026-06-09 00:34:10 -04:00
Disable unwanted gocritic checks instead of filtering them
The golangci-lint docs indicate that, for gocritic, disabled-checks and enabled-checks can't be combined. That is however not accurate; enabled-checks adds checks, disabled-checks disables them, in that order. If disable-all isn't set, then the setup starts with the checks enabled by default, adds any additional checks specified in enabled-checks, and removes checks specified in disabled-checks. This means that instead of filtering unwanted checks, we can disable them entirely. This makes the set of disabled checks easier to read, and perhaps easier to clean up in future. For singleCaseSwitch and wrapperFunc, we only want to ignore specific instances, so this is still done by filtering. Signed-off-by: Stephen Kitt <skitt@redhat.com>
This commit is contained in:
parent
34f2a0f6cc
commit
5bfc9aba9f
2 changed files with 38 additions and 16 deletions
|
|
@ -126,12 +126,7 @@ linters:
|
|||
|
||||
- linters:
|
||||
- gocritic
|
||||
text: "append result not assigned to the same slice|put a space between `//` and comment text|sloppyLen|elseif|should rewrite switch statement to if statement|regexpMust|wrapperFunc: use strings.ReplaceAll|singleCaseSwitch|deprecatedComment|exitAfterDefer|captLocal|unlambda|underef|unslice|valSwap|typeSwitchVar"
|
||||
|
||||
# https://github.com/kubernetes/kubernetes/issues/117288#issuecomment-1507008918
|
||||
- linters:
|
||||
- gocritic
|
||||
text: "assignOp:"
|
||||
text: "wrapperFunc: use strings.ReplaceAll|should rewrite switch statement to if statement"
|
||||
|
||||
# Kube-API-Linter should only be run on the API definitions
|
||||
- linters:
|
||||
|
|
@ -391,9 +386,25 @@ linters:
|
|||
pkg: ^k8s\.io/component-base/featuregate$
|
||||
msg: should not use Add, use AddVersioned instead
|
||||
gocritic:
|
||||
enabled-checks:
|
||||
- equalFold
|
||||
enabled-checks: # These are in addition to the default checks - see https://golangci-lint.run/docs/linters/configuration/#gocritic
|
||||
- boolExprSimplify
|
||||
- equalFold
|
||||
disabled-checks: # This disables checks that are enabled by default (this can be combined with enabled-checks, contrary to the docs)
|
||||
- appendAssign
|
||||
- assignOp # https://github.com/kubernetes/kubernetes/issues/117288#issuecomment-1507008918
|
||||
- captLocal
|
||||
- commentFormatting
|
||||
- deprecatedComment
|
||||
- elseif
|
||||
# The following have few (single-digit) occurrences left in k/k and wouldn't be too onerous to enable
|
||||
- exitAfterDefer
|
||||
- regexpMust
|
||||
- sloppyLen
|
||||
- typeSwitchVar
|
||||
- underef
|
||||
- unlambda
|
||||
- unslice
|
||||
- valSwap
|
||||
revive:
|
||||
# Only these rules are enabled.
|
||||
rules:
|
||||
|
|
|
|||
|
|
@ -141,12 +141,7 @@ linters:
|
|||
|
||||
- linters:
|
||||
- gocritic
|
||||
text: "append result not assigned to the same slice|put a space between `//` and comment text|sloppyLen|elseif|should rewrite switch statement to if statement|regexpMust|wrapperFunc: use strings.ReplaceAll|singleCaseSwitch|deprecatedComment|exitAfterDefer|captLocal|unlambda|underef|unslice|valSwap|typeSwitchVar"
|
||||
|
||||
# https://github.com/kubernetes/kubernetes/issues/117288#issuecomment-1507008918
|
||||
- linters:
|
||||
- gocritic
|
||||
text: "assignOp:"
|
||||
text: "wrapperFunc: use strings.ReplaceAll|should rewrite switch statement to if statement"
|
||||
|
||||
{{- end}}
|
||||
|
||||
|
|
@ -238,9 +233,25 @@ linters:
|
|||
{{- end}}
|
||||
{{- if .Base }}
|
||||
gocritic:
|
||||
enabled-checks:
|
||||
- equalFold
|
||||
enabled-checks: # These are in addition to the default checks - see https://golangci-lint.run/docs/linters/configuration/#gocritic
|
||||
- boolExprSimplify
|
||||
- equalFold
|
||||
disabled-checks: # This disables checks that are enabled by default (this can be combined with enabled-checks, contrary to the docs)
|
||||
- appendAssign
|
||||
- assignOp # https://github.com/kubernetes/kubernetes/issues/117288#issuecomment-1507008918
|
||||
- captLocal
|
||||
- commentFormatting
|
||||
- deprecatedComment
|
||||
- elseif
|
||||
# The following have few (single-digit) occurrences left in k/k and wouldn't be too onerous to enable
|
||||
- exitAfterDefer
|
||||
- regexpMust
|
||||
- sloppyLen
|
||||
- typeSwitchVar
|
||||
- underef
|
||||
- unlambda
|
||||
- unslice
|
||||
- valSwap
|
||||
{{- end}}
|
||||
revive:
|
||||
# Only these rules are enabled.
|
||||
|
|
|
|||
Loading…
Reference in a new issue