mirror of
https://github.com/open-cluster-management-io/ocm.git
synced 2026-02-14 10:00:11 +00:00
Upgrade golangci-lint from version 1 to version 2 (#1171)
Some checks failed
Scorecard supply-chain security / Scorecard analysis (push) Failing after 34s
Post / coverage (push) Failing after 36s
Post / images (amd64, addon-manager) (push) Failing after 34s
Post / images (amd64, placement) (push) Failing after 23s
Post / images (amd64, registration) (push) Failing after 39s
Post / images (amd64, registration-operator) (push) Failing after 29s
Post / images (amd64, work) (push) Failing after 22s
Post / images (arm64, addon-manager) (push) Failing after 29s
Post / images (arm64, placement) (push) Failing after 24s
Post / images (arm64, registration) (push) Failing after 37s
Post / images (arm64, registration-operator) (push) Failing after 22s
Post / images (arm64, work) (push) Failing after 35s
Post / image manifest (addon-manager) (push) Has been skipped
Post / image manifest (placement) (push) Has been skipped
Post / image manifest (registration) (push) Has been skipped
Post / image manifest (registration-operator) (push) Has been skipped
Post / image manifest (work) (push) Has been skipped
Post / trigger clusteradm e2e (push) Has been skipped
Some checks failed
Scorecard supply-chain security / Scorecard analysis (push) Failing after 34s
Post / coverage (push) Failing after 36s
Post / images (amd64, addon-manager) (push) Failing after 34s
Post / images (amd64, placement) (push) Failing after 23s
Post / images (amd64, registration) (push) Failing after 39s
Post / images (amd64, registration-operator) (push) Failing after 29s
Post / images (amd64, work) (push) Failing after 22s
Post / images (arm64, addon-manager) (push) Failing after 29s
Post / images (arm64, placement) (push) Failing after 24s
Post / images (arm64, registration) (push) Failing after 37s
Post / images (arm64, registration-operator) (push) Failing after 22s
Post / images (arm64, work) (push) Failing after 35s
Post / image manifest (addon-manager) (push) Has been skipped
Post / image manifest (placement) (push) Has been skipped
Post / image manifest (registration) (push) Has been skipped
Post / image manifest (registration-operator) (push) Has been skipped
Post / image manifest (work) (push) Has been skipped
Post / trigger clusteradm e2e (push) Has been skipped
- Updated .golangci.yaml configuration format for v2 compatibility - Updated Makefile to use golangci-lint v2.4.0 - Reorganized configuration structure to match v2 schema - Changed linter configuration from disable-all/enable to default: standard - Updated formatters and exclusions configuration syntax 🤖 Generated with [Claude Code](https://claude.ai/code) Signed-off-by: zhujian <jiazhu@redhat.com> Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
441
.golangci.yaml
441
.golangci.yaml
@@ -1,234 +1,239 @@
|
||||
# Copyright Contributors to the Open Cluster Management project
|
||||
|
||||
version: "2"
|
||||
|
||||
run:
|
||||
# default concurrency is an available CPU number
|
||||
concurrency: 10
|
||||
# timeout for analysis, e.g. 30s, 5m, default is 1m
|
||||
deadline: 5m
|
||||
timeout: 5m
|
||||
# The mode used to evaluate relative paths.
|
||||
# It's used by exclusions, Go plugins, and some linters.
|
||||
relative-path-mode: cfg
|
||||
# # Include test files or not.
|
||||
# tests: false
|
||||
|
||||
# which dirs to skip: they won't be analyzed;
|
||||
# can use regexp here: generated.*, regexp is applied on full path;
|
||||
# default value is empty list, but next dirs are always skipped independently
|
||||
# from this option's value:
|
||||
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
|
||||
skip-dirs:
|
||||
- genfiles$
|
||||
- vendor$
|
||||
- bindata$
|
||||
|
||||
# which files to skip: they will be analyzed, but issues from them
|
||||
# won't be reported. Default value is empty list, but there is
|
||||
# no need to include all autogenerated files, we confidently recognize
|
||||
# autogenerated files. If it's not please let us know.
|
||||
skip-files:
|
||||
- ".*\\.pb\\.go"
|
||||
- ".*\\.gen\\.go"
|
||||
formatters:
|
||||
enable:
|
||||
- gci
|
||||
- gofmt
|
||||
# - gofumpt
|
||||
- goimports
|
||||
# - golines
|
||||
# - swaggo
|
||||
settings:
|
||||
gofmt:
|
||||
# simplify code: gofmt with `-s` option, true by default
|
||||
simplify: true
|
||||
goimports:
|
||||
# put imports beginning with prefix after 3rd-party packages;
|
||||
# it's a comma-separated list of prefixes
|
||||
local-prefixes:
|
||||
- open-cluster-management.io/ocm/
|
||||
gci:
|
||||
# Section configuration to compare against.
|
||||
# Section names are case-insensitive and may contain parameters in ().
|
||||
# The default order of sections is `standard > default > custom > blank > dot`,
|
||||
# If `custom-order` is `true`, it follows the order of `sections` option.
|
||||
# Default: ["standard", "default"]
|
||||
sections:
|
||||
- standard # Standard section: captures all standard packages.
|
||||
- default # Default section: contains all imports that could not be matched to another section type.
|
||||
- prefix(open-cluster-management.io) # Custom section: groups all imports with the specified Prefix.
|
||||
# - prefix(open-cluster-management.io/ocm)
|
||||
# - blank # Blank section: contains all blank imports. This section is not present unless explicitly enabled.
|
||||
# - dot # Dot section: contains all dot imports. This section is not present unless explicitly enabled.
|
||||
# - alias # Alias section: contains all alias imports. This section is not present unless explicitly enabled.
|
||||
- localmodule # Local module section: contains all local packages. This section is not present unless explicitly enabled.
|
||||
# Enable custom order of sections.
|
||||
# If `true`, make the section order the same as the order of `sections`.
|
||||
# Default: false
|
||||
custom-order: true
|
||||
|
||||
linters:
|
||||
# please, do not use `enable-all`: it's deprecated and will be removed soon.
|
||||
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
|
||||
disable-all: true
|
||||
enable:
|
||||
- unused
|
||||
- errcheck
|
||||
- goconst
|
||||
- gocritic
|
||||
- gofmt
|
||||
- goimports
|
||||
- gosec
|
||||
- gosimple
|
||||
- govet
|
||||
- ineffassign
|
||||
- lll
|
||||
- misspell
|
||||
- typecheck
|
||||
- unconvert
|
||||
- gci
|
||||
# don't enable:
|
||||
# - gocyclo
|
||||
# - bodyclose
|
||||
# - depguard
|
||||
# - dogsled
|
||||
# - dupl
|
||||
# - funlen
|
||||
# - gochecknoglobals
|
||||
# - gochecknoinits
|
||||
# - gocognit
|
||||
# - godox
|
||||
# - maligned
|
||||
# - nakedret
|
||||
# - prealloc
|
||||
# - scopelint
|
||||
# - whitespace
|
||||
# Explicitly disable all default linters
|
||||
default: standard # standard | all | none | fast
|
||||
# Enable specific linters
|
||||
# enable:
|
||||
# - unused
|
||||
# - errcheck
|
||||
# - goconst
|
||||
# - gocritic
|
||||
# - gosec
|
||||
# - staticcheck
|
||||
# - govet
|
||||
# - ineffassign
|
||||
# - lll
|
||||
# - misspell
|
||||
# - unconvert
|
||||
# - revive
|
||||
# disable:
|
||||
# - gocyclo
|
||||
# - bodyclose
|
||||
# - depguard
|
||||
# - dogsled
|
||||
# - dupl
|
||||
# - funlen
|
||||
# - gochecknoglobals
|
||||
# - gochecknoinits
|
||||
# - gocognit
|
||||
# - godox
|
||||
# - nakedret
|
||||
# - prealloc
|
||||
# - whitespace
|
||||
exclusions:
|
||||
# Mode of the generated files analysis.
|
||||
generated: strict # strict | lax | disable
|
||||
# Log a warning if an exclusion rule is unused.
|
||||
warn-unused: true
|
||||
# Predefined exclusion rules
|
||||
presets:
|
||||
- comments
|
||||
- std-error-handling
|
||||
- common-false-positives
|
||||
- legacy
|
||||
paths:
|
||||
- ".*_test\\.go"
|
||||
# # Excluding configuration per-path, per-linter, per-text and per-source.
|
||||
# rules:
|
||||
# # Exclude some linters from running on tests files.
|
||||
# - path: ".*_test\\.go"
|
||||
# linters:
|
||||
# - gocyclo
|
||||
# - errcheck
|
||||
# - dupl
|
||||
# - gosec
|
||||
# - staticcheck
|
||||
# - revive
|
||||
# - lll
|
||||
settings:
|
||||
errcheck:
|
||||
# report about not checking of errors in type assetions: `a := b.(MyStruct)`;
|
||||
# default is false: such cases aren't reported by default.
|
||||
check-type-assertions: false
|
||||
# report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`;
|
||||
# default is false: such cases aren't reported by default.
|
||||
check-blank: false
|
||||
# Display function signature instead of selector.
|
||||
verbose: true
|
||||
# govet:
|
||||
# settings:
|
||||
# shadow:
|
||||
# # Whether to be strict about shadowing; can be noisy.
|
||||
# strict: true
|
||||
revive:
|
||||
# Sets the default failure confidence.
|
||||
# This means that linting errors with less than 0.8 confidence will be ignored.
|
||||
# Default: 0.8
|
||||
confidence: 0.1
|
||||
misspell:
|
||||
# Correct spellings using locale preferences for US or UK.
|
||||
# Default is to use a neutral variety of English.
|
||||
# Setting locale to US will correct the British spelling of 'colour' to 'color'.
|
||||
locale: US
|
||||
ignore-rules:
|
||||
- cancelled
|
||||
- cancelling
|
||||
# Mode of the analysis:
|
||||
# - default: checks all the file content.
|
||||
# - restricted: checks only comments.
|
||||
mode: default
|
||||
lll:
|
||||
# max line length, lines longer will be reported. Default is 120.
|
||||
# '\t' is counted as 1 character by default, and can be changed with the tab-width option
|
||||
line-length: 160
|
||||
# tab width in spaces. Default to 1.
|
||||
tab-width: 1
|
||||
unused:
|
||||
# Treat IncDec statement (e.g. `i++` or `i--`) as both read and write operation instead of just write.
|
||||
# Default: false
|
||||
post-statements-are-reads: true
|
||||
# Mark all function parameters as used.
|
||||
# default: true
|
||||
parameters-are-used: true
|
||||
# Mark all local variables as used.
|
||||
# default: true
|
||||
local-variables-are-used: false
|
||||
# Mark all identifiers inside generated files as used.
|
||||
# Default: true
|
||||
generated-is-used: true
|
||||
gocritic:
|
||||
enabled-checks:
|
||||
- appendCombine
|
||||
- argOrder
|
||||
# - assignOp
|
||||
- badCond
|
||||
- boolExprSimplify
|
||||
# - builtinShadow
|
||||
- captLocal
|
||||
- caseOrder
|
||||
- codegenComment
|
||||
# - commentedOutCode
|
||||
- commentedOutImport
|
||||
- defaultCaseOrder
|
||||
- deprecatedComment
|
||||
- docStub
|
||||
- dupArg
|
||||
- dupBranchBody
|
||||
- dupCase
|
||||
- dupSubExpr
|
||||
- elseif
|
||||
- emptyFallthrough
|
||||
- equalFold
|
||||
- flagDeref
|
||||
- flagName
|
||||
- hexLiteral
|
||||
- indexAlloc
|
||||
- initClause
|
||||
- methodExprCall
|
||||
- nilValReturn
|
||||
# - octalLiteral
|
||||
- offBy1
|
||||
- rangeExprCopy
|
||||
- regexpMust
|
||||
- sloppyLen
|
||||
- stringXbytes
|
||||
- switchTrue
|
||||
- typeAssertChain
|
||||
- typeSwitchVar
|
||||
- typeUnparen
|
||||
- underef
|
||||
- unlambda
|
||||
- unnecessaryBlock
|
||||
- unslice
|
||||
- valSwap
|
||||
- weakCond
|
||||
|
||||
# Unused
|
||||
# - yodaStyleExpr
|
||||
# - appendAssign
|
||||
# - commentFormatting
|
||||
# - emptyStringTest
|
||||
# - exitAfterDefer
|
||||
# - ifElseChain
|
||||
# - hugeParam
|
||||
# - importShadow
|
||||
# - nestingReduce
|
||||
# - paramTypeCombine
|
||||
# - ptrToRefParam
|
||||
# - rangeValCopy
|
||||
# - singleCaseSwitch
|
||||
# - sloppyReassign
|
||||
# - unlabelStmt
|
||||
# - unnamedResult
|
||||
# - wrapperFunc
|
||||
staticcheck:
|
||||
checks:
|
||||
# Omit embedded fields from selector expression.
|
||||
# https://staticcheck.dev/docs/checks/#QF1008
|
||||
- "-QF1008" # Disable
|
||||
|
||||
linters-settings:
|
||||
errcheck:
|
||||
# report about not checking of errors in type assetions: `a := b.(MyStruct)`;
|
||||
# default is false: such cases aren't reported by default.
|
||||
check-type-assertions: false
|
||||
|
||||
# report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`;
|
||||
# default is false: such cases aren't reported by default.
|
||||
check-blank: false
|
||||
govet:
|
||||
# report about shadowed variables
|
||||
check-shadowing: false
|
||||
golint:
|
||||
# minimal confidence for issues, default is 0.8
|
||||
min-confidence: 0.0
|
||||
gofmt:
|
||||
# simplify code: gofmt with `-s` option, true by default
|
||||
simplify: true
|
||||
# goimports:
|
||||
# # put imports beginning with prefix after 3rd-party packages;
|
||||
# # it's a comma-separated list of prefixes
|
||||
# local-prefixes: open-cluster-management.io/ocm/
|
||||
maligned:
|
||||
# print struct with more effective memory layout or not, false by default
|
||||
suggest-new: true
|
||||
misspell:
|
||||
# Correct spellings using locale preferences for US or UK.
|
||||
# Default is to use a neutral variety of English.
|
||||
# Setting locale to US will correct the British spelling of 'colour' to 'color'.
|
||||
locale: US
|
||||
ignore-words:
|
||||
- cancelled
|
||||
- cancelling
|
||||
lll:
|
||||
# max line length, lines longer will be reported. Default is 120.
|
||||
# '\t' is counted as 1 character by default, and can be changed with the tab-width option
|
||||
line-length: 160
|
||||
# tab width in spaces. Default to 1.
|
||||
tab-width: 1
|
||||
unused:
|
||||
# treat code as a program (not a library) and report unused exported identifiers; default is false.
|
||||
# XXX: if you enable this setting, unused will report a lot of false-positives in text editors:
|
||||
# if it's called for subdir of a project it can't find funcs usages. All text editor integrations
|
||||
# with golangci-lint call it on a directory with the changed file.
|
||||
check-exported: false
|
||||
unparam:
|
||||
# call graph construction algorithm (cha, rta). In general, use cha for libraries,
|
||||
# and rta for programs with main packages. Default is cha.
|
||||
algo: cha
|
||||
|
||||
# Inspect exported functions, default is false. Set to true if no external program/library imports your code.
|
||||
# XXX: if you enable this setting, unparam will report a lot of false-positives in text editors:
|
||||
# if it's called for subdir of a project it can't find external interfaces. All text editor integrations
|
||||
# with golangci-lint call it on a directory with the changed file.
|
||||
check-exported: false
|
||||
gocritic:
|
||||
enabled-checks:
|
||||
- appendCombine
|
||||
- argOrder
|
||||
# - assignOp
|
||||
- badCond
|
||||
- boolExprSimplify
|
||||
# - builtinShadow
|
||||
- captLocal
|
||||
- caseOrder
|
||||
- codegenComment
|
||||
# - commentedOutCode
|
||||
- commentedOutImport
|
||||
- defaultCaseOrder
|
||||
- deprecatedComment
|
||||
- docStub
|
||||
- dupArg
|
||||
- dupBranchBody
|
||||
- dupCase
|
||||
- dupSubExpr
|
||||
- elseif
|
||||
- emptyFallthrough
|
||||
- equalFold
|
||||
- flagDeref
|
||||
- flagName
|
||||
- hexLiteral
|
||||
- indexAlloc
|
||||
- initClause
|
||||
- methodExprCall
|
||||
- nilValReturn
|
||||
# - octalLiteral
|
||||
- offBy1
|
||||
- rangeExprCopy
|
||||
- regexpMust
|
||||
- sloppyLen
|
||||
- stringXbytes
|
||||
- switchTrue
|
||||
- typeAssertChain
|
||||
- typeSwitchVar
|
||||
- typeUnparen
|
||||
- underef
|
||||
- unlambda
|
||||
- unnecessaryBlock
|
||||
- unslice
|
||||
- valSwap
|
||||
- weakCond
|
||||
|
||||
# Unused
|
||||
# - yodaStyleExpr
|
||||
# - appendAssign
|
||||
# - commentFormatting
|
||||
# - emptyStringTest
|
||||
# - exitAfterDefer
|
||||
# - ifElseChain
|
||||
# - hugeParam
|
||||
# - importShadow
|
||||
# - nestingReduce
|
||||
# - paramTypeCombine
|
||||
# - ptrToRefParam
|
||||
# - rangeValCopy
|
||||
# - singleCaseSwitch
|
||||
# - sloppyReassign
|
||||
# - unlabelStmt
|
||||
# - unnamedResult
|
||||
# - wrapperFunc
|
||||
gci:
|
||||
# Section configuration to compare against.
|
||||
# Section names are case-insensitive and may contain parameters in ().
|
||||
# The default order of sections is `standard > default > custom > blank > dot`,
|
||||
# If `custom-order` is `true`, it follows the order of `sections` option.
|
||||
# Default: ["standard", "default"]
|
||||
sections:
|
||||
- standard # Standard section: captures all standard packages.
|
||||
- default # Default section: contains all imports that could not be matched to another section type.
|
||||
- prefix(open-cluster-management.io) # Custom section: groups all imports with the specified Prefix.
|
||||
- prefix(open-cluster-management.io/ocm)
|
||||
# - blank # Blank section: contains all blank imports. This section is not present unless explicitly enabled.
|
||||
# - dot # Dot section: contains all dot imports. This section is not present unless explicitly enabled.
|
||||
# Skip generated files.
|
||||
# Default: true
|
||||
skip-generated: true
|
||||
# Enable custom order of sections.
|
||||
# If `true`, make the section order the same as the order of `sections`.
|
||||
# Default: false
|
||||
custom-order: true
|
||||
issues:
|
||||
# We want to make sure we get a full report every time. Setting these
|
||||
# to zero disables the limit.
|
||||
max-issues-per-linter: 0
|
||||
|
||||
# List of regexps of issue texts to exclude, empty list by default.
|
||||
# But independently from this option we use default exclude patterns,
|
||||
# it can be disabled by `exclude-use-default: false`. To list all
|
||||
# excluded by default patterns execute `golangci-lint run --help`
|
||||
exclude:
|
||||
- composite literal uses unkeyed fields
|
||||
|
||||
exclude-rules:
|
||||
# Exclude some linters from running on test files.
|
||||
- path: _test\.go$|^tests/|^samples/
|
||||
linters:
|
||||
- errcheck
|
||||
- maligned
|
||||
- goconst
|
||||
|
||||
# Independently from option `exclude` we use default exclude patterns,
|
||||
# it can be disabled by this option. To list all
|
||||
# excluded by default patterns execute `golangci-lint run --help`.
|
||||
# Default value for this option is true.
|
||||
exclude-use-default: true
|
||||
|
||||
# Maximum issues count per one linter. Set to 0 to disable. Default is 50.
|
||||
max-per-linter: 0
|
||||
|
||||
# Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
|
||||
max-same-issues: 0
|
||||
# # Fix found issues (if it's supported by the linter).
|
||||
# # Default: false
|
||||
# fix: true
|
||||
|
||||
24
Makefile
24
Makefile
@@ -25,6 +25,10 @@ HELM?=$(PERMANENT_TMP_GOPATH)/bin/helm
|
||||
HELM_VERSION?=v3.14.0
|
||||
helm_gen_dir:=$(dir $(HELM))
|
||||
|
||||
GOLANGCI_LINT?=$(PERMANENT_TMP_GOPATH)/bin/golangci-lint
|
||||
GOLANGCI_LINT_VERSION?=v2.4.0
|
||||
golangci_lint_gen_dir:=$(dir $(GOLANGCI_LINT))
|
||||
|
||||
# RELEASED_CSV_VERSION indicates the last released operator version.
|
||||
# can find the released operator version from
|
||||
# https://github.com/k8s-operatorhub/community-operators/tree/main/operators/cluster-manager
|
||||
@@ -85,18 +89,17 @@ update-csv: ensure-operator-sdk ensure-helm
|
||||
verify-crds:
|
||||
bash -x hack/verify-crds.sh $(YAML_PATCH)
|
||||
|
||||
verify-gocilint:
|
||||
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.64.6
|
||||
golangci-lint run --timeout=5m --modules-download-mode vendor ./...
|
||||
verify-gocilint: ensure-golangci-lint
|
||||
$(GOLANGCI_LINT) run --timeout=5m --modules-download-mode vendor ./...
|
||||
|
||||
install-golang-gci:
|
||||
go install github.com/daixiang0/gci@v0.13.6
|
||||
go install github.com/daixiang0/gci@v0.13.7
|
||||
|
||||
fmt-imports: install-golang-gci
|
||||
gci write --skip-generated -s standard -s default -s "prefix(open-cluster-management.io)" -s "prefix(open-cluster-management.io/ocm)" cmd pkg test dependencymagnet
|
||||
gci write --skip-generated -s standard -s default -s "prefix(open-cluster-management.io)" -s localmodule cmd pkg test dependencymagnet
|
||||
|
||||
verify-fmt-imports: install-golang-gci
|
||||
@output=$$(gci diff --skip-generated -s standard -s default -s "prefix(open-cluster-management.io)" -s "prefix(open-cluster-management.io/ocm)" cmd pkg test dependencymagnet); \
|
||||
@output=$$(gci diff --skip-generated -s standard -s default -s "prefix(open-cluster-management.io)" -s localmodule cmd pkg test dependencymagnet); \
|
||||
if [ -n "$$output" ]; then \
|
||||
echo "Diff output is not empty: $$output"; \
|
||||
echo "Please run 'make fmt-imports' to format the golang files imports automatically."; \
|
||||
@@ -129,3 +132,12 @@ ifeq "" "$(wildcard $(HELM))"
|
||||
else
|
||||
$(info Using existing helm from "$(HELM)")
|
||||
endif
|
||||
|
||||
ensure-golangci-lint:
|
||||
ifeq "" "$(wildcard $(GOLANGCI_LINT))"
|
||||
$(info Installing golangci-lint into '$(GOLANGCI_LINT)')
|
||||
mkdir -p '$(golangci_lint_gen_dir)'
|
||||
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b '$(golangci_lint_gen_dir)' $(GOLANGCI_LINT_VERSION)
|
||||
else
|
||||
$(info Using existing golangci-lint from "$(GOLANGCI_LINT)")
|
||||
endif
|
||||
|
||||
Reference in New Issue
Block a user