From 8f628d873501a637612eb59c3ac2426de01d9d94 Mon Sep 17 00:00:00 2001 From: dongjiang Date: Thu, 3 Apr 2025 11:21:28 +0800 Subject: [PATCH] update golangci-lint v2 Signed-off-by: dongjiang revert by codereview and make generate Signed-off-by: dongjiang --- .github/workflows/lint-sample.yml | 4 +- .github/workflows/lint.yml | 4 +- .golangci.yml | 158 +++++++++--------- Makefile | 2 +- .../project/.github/workflows/lint.yml | 5 +- .../testdata/project/.golangci.yml | 67 +++++--- .../testdata/project/Makefile | 4 +- .../internal/controller/cronjob_controller.go | 4 +- .../internal/webhook/v1/cronjob_webhook.go | 6 +- .../testdata/project/test/utils/utils.go | 4 +- .../project/.github/workflows/lint.yml | 5 +- .../testdata/project/.golangci.yml | 67 +++++--- .../getting-started/testdata/project/Makefile | 4 +- .../testdata/project/test/utils/utils.go | 4 +- .../project/.github/workflows/lint.yml | 5 +- .../testdata/project/.golangci.yml | 67 +++++--- .../testdata/project/Makefile | 4 +- .../internal/controller/cronjob_controller.go | 4 +- .../internal/webhook/v1/cronjob_webhook.go | 6 +- .../internal/webhook/v2/cronjob_webhook.go | 6 +- .../testdata/project/test/utils/utils.go | 4 +- .../controller_implementation.go | 4 +- pkg/cli/cli.go | 2 +- pkg/cli/suite_test.go | 4 +- pkg/config/v3/config.go | 2 +- pkg/model/resource/resource.go | 2 +- pkg/model/resource/utils.go | 4 +- pkg/plugin/util/util.go | 4 +- pkg/plugins/external/helpers.go | 2 +- .../golang/deploy-image/v1alpha1/api.go | 8 +- .../scaffolds/internal/templates/api/types.go | 2 +- .../templates/controllers/controller-test.go | 2 +- .../templates/controllers/controller.go | 2 +- pkg/plugins/golang/v4/scaffolds/init.go | 2 +- .../scaffolds/internal/templates/api/hub.go | 2 +- .../scaffolds/internal/templates/api/types.go | 2 +- .../scaffolds/internal/templates/cmd/main.go | 2 +- .../templates/controllers/controller.go | 2 +- .../controllers/controller_suitetest.go | 2 +- .../controllers/controller_test_template.go | 2 +- .../internal/templates/github/lint.go | 3 +- .../scaffolds/internal/templates/golangci.go | 69 ++++---- .../scaffolds/internal/templates/makefile.go | 2 +- .../internal/templates/test/utils/utils.go | 4 +- .../internal/templates/webhooks/webhook.go | 10 +- .../templates/webhooks/webhook_suitetest.go | 2 +- .../webhooks/webhook_test_template.go | 2 +- .../optional/helm/v1alpha/scaffolds/init.go | 21 +-- .../.github/workflows/lint.yml | 5 +- testdata/project-v4-multigroup/.golangci.yml | 67 +++++--- testdata/project-v4-multigroup/Makefile | 4 +- .../webhook/apps/v1/deployment_webhook.go | 6 +- .../webhook/cert-manager/v1/issuer_webhook.go | 2 +- .../internal/webhook/core/v1/pod_webhook.go | 4 +- .../webhook/crew/v1/captain_webhook.go | 6 +- .../example.com/v1alpha1/memcached_webhook.go | 4 +- .../webhook/ship/v1/destroyer_webhook.go | 2 +- .../webhook/ship/v2alpha1/cruiser_webhook.go | 4 +- .../project-v4-multigroup/test/utils/utils.go | 4 +- .../.github/workflows/lint.yml | 5 +- .../project-v4-with-plugins/.golangci.yml | 67 +++++--- testdata/project-v4-with-plugins/Makefile | 4 +- .../webhook/v1alpha1/memcached_webhook.go | 4 +- .../test/utils/utils.go | 4 +- .../project-v4/.github/workflows/lint.yml | 5 +- testdata/project-v4/.golangci.yml | 67 +++++--- testdata/project-v4/Makefile | 4 +- .../internal/webhook/v1/admiral_webhook.go | 2 +- .../internal/webhook/v1/captain_webhook.go | 6 +- .../internal/webhook/v1/deployment_webhook.go | 6 +- .../internal/webhook/v1/issuer_webhook.go | 2 +- .../internal/webhook/v1/pod_webhook.go | 2 +- testdata/project-v4/test/utils/utils.go | 4 +- 73 files changed, 498 insertions(+), 391 deletions(-) diff --git a/.github/workflows/lint-sample.yml b/.github/workflows/lint-sample.yml index f0eb9323504..c8f5da11d11 100644 --- a/.github/workflows/lint-sample.yml +++ b/.github/workflows/lint-sample.yml @@ -36,10 +36,10 @@ jobs: working-directory: ${{ matrix.folder }} run: make lint-config - name: Run linter - uses: golangci/golangci-lint-action@v6 + uses: golangci/golangci-lint-action@v7 with: install-mode: goinstall - version: v1.63.4 + version: v2.0.2 working-directory: ${{ matrix.folder }} args: --config .golangci.yml ./... - name: Run linter via makefile target diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 5821d69e0ca..304870b28cb 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -24,10 +24,10 @@ jobs: - name: Check linter configuration run: make lint-config - name: Run linter - uses: golangci/golangci-lint-action@v6 + uses: golangci/golangci-lint-action@v7 with: install-mode: goinstall - version: v1.63.4 + version: v2.0.2 yamllint: runs-on: ubuntu-latest diff --git a/.golangci.yml b/.golangci.yml index e419c626b57..1cfc8280b81 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,98 +1,106 @@ +version: "2" run: - timeout: 5m allow-parallel-runners: true - -issues: - # don't skip warning about doc comments - # don't exclude the default set of lint - exclude-use-default: false - # restore some of the defaults - # (fill in the rest as needed) - exclude-rules: - - linters: [gosec] - path: "test/e2e/*" - - path: "hack/docs/*" - linters: - - lll - - gosec - -linters-settings: - ginkgolinter: - forbid-focus-container: true - forbid-spec-pollution: true - govet: - enable-all: true - disable: - - fieldalignment - nolintlint: - allow-unused: false - revive: - rules: - # The following rules are recommended https://github.com/mgechev/revive#recommended-configuration - - name: blank-imports - - name: context-as-argument - - name: context-keys-type - - name: dot-imports - arguments: - # dot import should be ONLY allowed for ginkgo testing packages - - allowedPackages: - - "github.com/onsi/ginkgo/v2" - - "github.com/onsi/gomega" - - name: error-return - - name: error-strings - - name: error-naming - - name: exported - - name: if-return - - name: import-shadowing - - name: increment-decrement - - name: var-naming - - name: var-declaration - - name: package-comments - disabled: true # TODO: Investigate if it should be enabled. Disabled for now due to many findings. - - name: range - - name: receiver-naming - - name: time-naming - - name: unexported-return - - name: indent-error-flow - - name: errorf - - name: empty-block - - name: superfluous-else - - name: unused-parameter - - name: unreachable-code - - name: redefines-builtin-id - # - # Rules in addition to the recommended configuration above. - # - - name: bool-literal-in-expr - - name: constant-logical-expr - - name: comment-spacings linters: - disable-all: true + default: none enable: - asciicheck - bidichk + - copyloopvar - dupl - errcheck - - copyloopvar - ginkgolinter - goconst - gocyclo - - gofmt - - gofumpt - - goimports - - gosimple - govet - ineffassign - lll - misspell - - nolintlint - nakedret + - nolintlint - prealloc - revive - staticcheck - - typecheck - unconvert - unparam - unused - whitespace - + settings: + ginkgolinter: + forbid-focus-container: true + forbid-spec-pollution: true + govet: + disable: + - fieldalignment + enable-all: true + nolintlint: + allow-unused: false + revive: + rules: + - name: blank-imports + - name: context-as-argument + - name: context-keys-type + - name: dot-imports + arguments: + - allowedPackages: + - github.com/onsi/ginkgo/v2 + - github.com/onsi/gomega + - name: error-return + - name: error-strings + - name: error-naming + - name: exported + - name: if-return + - name: import-shadowing + - name: increment-decrement + - name: var-naming + - name: var-declaration + - name: package-comments + disabled: true + - name: range + - name: receiver-naming + - name: time-naming + - name: unexported-return + - name: indent-error-flow + - name: errorf + - name: empty-block + - name: superfluous-else + - name: unused-parameter + - name: unreachable-code + - name: redefines-builtin-id + - name: bool-literal-in-expr + - name: constant-logical-expr + - name: comment-spacings + exclusions: + generated: lax + rules: + - linters: + - gosec + path: test/e2e/* + - linters: + - gosec + - lll + path: hack/docs/* + - linters: + - staticcheck + text: "ST1008:" + - linters: + - staticcheck + text: "ST1001:" + - linters: + - revive + text: 'should have comment or be unexported' + paths: + - third_party$ + - builtin$ + - examples$ +formatters: + enable: + - gofmt + - gofumpt + - goimports + exclusions: + generated: lax + paths: + - third_party$ + - builtin$ + - examples$ diff --git a/Makefile b/Makefile index 4c954360b82..a9f24385ed4 100644 --- a/Makefile +++ b/Makefile @@ -124,7 +124,7 @@ yamllint: GOLANGCI_LINT = $(shell pwd)/bin/golangci-lint golangci-lint: @[ -f $(GOLANGCI_LINT) ] || { \ - GOBIN=$(shell pwd)/bin go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.63.4 ;\ + GOBIN=$(shell pwd)/bin go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.0.2 ;\ } .PHONY: apidiff diff --git a/docs/book/src/cronjob-tutorial/testdata/project/.github/workflows/lint.yml b/docs/book/src/cronjob-tutorial/testdata/project/.github/workflows/lint.yml index 4951e3316c1..73fd9f7d12b 100644 --- a/docs/book/src/cronjob-tutorial/testdata/project/.github/workflows/lint.yml +++ b/docs/book/src/cronjob-tutorial/testdata/project/.github/workflows/lint.yml @@ -18,6 +18,7 @@ jobs: go-version-file: go.mod - name: Run linter - uses: golangci/golangci-lint-action@v6 + uses: golangci/golangci-lint-action@v7 with: - version: v1.63.4 + install-mode: goinstall + version: v2.0.2 diff --git a/docs/book/src/cronjob-tutorial/testdata/project/.golangci.yml b/docs/book/src/cronjob-tutorial/testdata/project/.golangci.yml index 070199921d5..ba317ca34dc 100644 --- a/docs/book/src/cronjob-tutorial/testdata/project/.golangci.yml +++ b/docs/book/src/cronjob-tutorial/testdata/project/.golangci.yml @@ -1,33 +1,15 @@ +version: "2" run: - timeout: 5m allow-parallel-runners: true - -issues: - # don't skip warning about doc comments - # don't exclude the default set of lint - exclude-use-default: false - # restore some of the defaults - # (fill in the rest as needed) - exclude-rules: - - path: "api/*" - linters: - - lll - - path: "internal/*" - linters: - - dupl - - lll linters: - disable-all: true + default: none enable: + - copyloopvar - dupl - errcheck - - copyloopvar - ginkgolinter - goconst - gocyclo - - gofmt - - goimports - - gosimple - govet - ineffassign - lll @@ -36,13 +18,44 @@ linters: - prealloc - revive - staticcheck - - typecheck - unconvert - unparam - unused - -linters-settings: - revive: + settings: + revive: + rules: + - name: comment-spacings + - name: import-shadowing + exclusions: + generated: lax rules: - - name: comment-spacings - - name: import-shadowing + - linters: + - lll + path: api/* + - linters: + - dupl + - lll + path: internal/* + - linters: + - staticcheck + text: "ST1019" + - linters: + - staticcheck + text: "ST1005" + - linters: + - staticcheck + text: "QF1008" + paths: + - third_party$ + - builtin$ + - examples$ +formatters: + enable: + - gofmt + - goimports + exclusions: + generated: lax + paths: + - third_party$ + - builtin$ + - examples$ diff --git a/docs/book/src/cronjob-tutorial/testdata/project/Makefile b/docs/book/src/cronjob-tutorial/testdata/project/Makefile index 46e98f8e623..395dff8e335 100644 --- a/docs/book/src/cronjob-tutorial/testdata/project/Makefile +++ b/docs/book/src/cronjob-tutorial/testdata/project/Makefile @@ -182,7 +182,7 @@ CONTROLLER_TOOLS_VERSION ?= v0.17.2 ENVTEST_VERSION ?= $(shell go list -m -f "{{ .Version }}" sigs.k8s.io/controller-runtime | awk -F'[v.]' '{printf "release-%d.%d", $$2, $$3}') #ENVTEST_K8S_VERSION is the version of Kubernetes to use for setting up ENVTEST binaries (i.e. 1.31) ENVTEST_K8S_VERSION ?= $(shell go list -m -f "{{ .Version }}" k8s.io/api | awk -F'[v.]' '{printf "1.%d", $$3}') -GOLANGCI_LINT_VERSION ?= v1.63.4 +GOLANGCI_LINT_VERSION ?= v2.0.2 .PHONY: kustomize kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary. @@ -210,7 +210,7 @@ $(ENVTEST): $(LOCALBIN) .PHONY: golangci-lint golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary. $(GOLANGCI_LINT): $(LOCALBIN) - $(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION)) + $(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/v2/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION)) # go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist # $1 - target path with name of binary diff --git a/docs/book/src/cronjob-tutorial/testdata/project/internal/controller/cronjob_controller.go b/docs/book/src/cronjob-tutorial/testdata/project/internal/controller/cronjob_controller.go index 79f3204be8f..d075028b6ae 100644 --- a/docs/book/src/cronjob-tutorial/testdata/project/internal/controller/cronjob_controller.go +++ b/docs/book/src/cronjob-tutorial/testdata/project/internal/controller/cronjob_controller.go @@ -58,7 +58,7 @@ the "real" clock just calls `time.Now`. */ type realClock struct{} -func (_ realClock) Now() time.Time { return time.Now() } +func (_ realClock) Now() time.Time { return time.Now() } //nolint:staticcheck // Clock knows how to get the current time. // It can be used to fake out timing for testing. @@ -388,7 +388,7 @@ func (r *CronJobReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct starts++ if starts > 100 { // We can't get the most recent times so just return an empty slice - return time.Time{}, time.Time{}, fmt.Errorf("Too many missed start times (> 100). Set or decrease .spec.startingDeadlineSeconds or check clock skew.") + return time.Time{}, time.Time{}, fmt.Errorf("Too many missed start times (> 100). Set or decrease .spec.startingDeadlineSeconds or check clock skew.") //nolint:staticcheck } } return lastMissed, sched.Next(now), nil diff --git a/docs/book/src/cronjob-tutorial/testdata/project/internal/webhook/v1/cronjob_webhook.go b/docs/book/src/cronjob-tutorial/testdata/project/internal/webhook/v1/cronjob_webhook.go index 7a1acf49d0b..82414a68478 100644 --- a/docs/book/src/cronjob-tutorial/testdata/project/internal/webhook/v1/cronjob_webhook.go +++ b/docs/book/src/cronjob-tutorial/testdata/project/internal/webhook/v1/cronjob_webhook.go @@ -98,7 +98,7 @@ The `Default`method is expected to mutate the receiver, setting the defaults. */ // Default implements webhook.CustomDefaulter so a webhook will be registered for the Kind CronJob. -func (d *CronJobCustomDefaulter) Default(ctx context.Context, obj runtime.Object) error { +func (d *CronJobCustomDefaulter) Default(_ context.Context, obj runtime.Object) error { cronjob, ok := obj.(*batchv1.CronJob) if !ok { @@ -169,7 +169,7 @@ type CronJobCustomValidator struct { var _ webhook.CustomValidator = &CronJobCustomValidator{} // ValidateCreate implements webhook.CustomValidator so a webhook will be registered for the type CronJob. -func (v *CronJobCustomValidator) ValidateCreate(ctx context.Context, obj runtime.Object) (admission.Warnings, error) { +func (v *CronJobCustomValidator) ValidateCreate(_ context.Context, obj runtime.Object) (admission.Warnings, error) { cronjob, ok := obj.(*batchv1.CronJob) if !ok { return nil, fmt.Errorf("expected a CronJob object but got %T", obj) @@ -180,7 +180,7 @@ func (v *CronJobCustomValidator) ValidateCreate(ctx context.Context, obj runtime } // ValidateUpdate implements webhook.CustomValidator so a webhook will be registered for the type CronJob. -func (v *CronJobCustomValidator) ValidateUpdate(ctx context.Context, oldObj, newObj runtime.Object) (admission.Warnings, error) { +func (v *CronJobCustomValidator) ValidateUpdate(_ context.Context, oldObj, newObj runtime.Object) (admission.Warnings, error) { cronjob, ok := newObj.(*batchv1.CronJob) if !ok { return nil, fmt.Errorf("expected a CronJob object for the newObj but got %T", newObj) diff --git a/docs/book/src/cronjob-tutorial/testdata/project/test/utils/utils.go b/docs/book/src/cronjob-tutorial/testdata/project/test/utils/utils.go index 0cbd734083f..3277312e4d6 100644 --- a/docs/book/src/cronjob-tutorial/testdata/project/test/utils/utils.go +++ b/docs/book/src/cronjob-tutorial/testdata/project/test/utils/utils.go @@ -24,7 +24,7 @@ import ( "os/exec" "strings" - . "github.com/onsi/ginkgo/v2" //nolint:golint,revive + . "github.com/onsi/ginkgo/v2" //nolint:golint,revive,staticcheck ) const ( @@ -197,7 +197,7 @@ func GetProjectDir() (string, error) { if err != nil { return wd, err } - wd = strings.Replace(wd, "/test/e2e", "", -1) + wd = strings.ReplaceAll(wd, "/test/e2e", "") return wd, nil } diff --git a/docs/book/src/getting-started/testdata/project/.github/workflows/lint.yml b/docs/book/src/getting-started/testdata/project/.github/workflows/lint.yml index 4951e3316c1..73fd9f7d12b 100644 --- a/docs/book/src/getting-started/testdata/project/.github/workflows/lint.yml +++ b/docs/book/src/getting-started/testdata/project/.github/workflows/lint.yml @@ -18,6 +18,7 @@ jobs: go-version-file: go.mod - name: Run linter - uses: golangci/golangci-lint-action@v6 + uses: golangci/golangci-lint-action@v7 with: - version: v1.63.4 + install-mode: goinstall + version: v2.0.2 diff --git a/docs/book/src/getting-started/testdata/project/.golangci.yml b/docs/book/src/getting-started/testdata/project/.golangci.yml index 070199921d5..ba317ca34dc 100644 --- a/docs/book/src/getting-started/testdata/project/.golangci.yml +++ b/docs/book/src/getting-started/testdata/project/.golangci.yml @@ -1,33 +1,15 @@ +version: "2" run: - timeout: 5m allow-parallel-runners: true - -issues: - # don't skip warning about doc comments - # don't exclude the default set of lint - exclude-use-default: false - # restore some of the defaults - # (fill in the rest as needed) - exclude-rules: - - path: "api/*" - linters: - - lll - - path: "internal/*" - linters: - - dupl - - lll linters: - disable-all: true + default: none enable: + - copyloopvar - dupl - errcheck - - copyloopvar - ginkgolinter - goconst - gocyclo - - gofmt - - goimports - - gosimple - govet - ineffassign - lll @@ -36,13 +18,44 @@ linters: - prealloc - revive - staticcheck - - typecheck - unconvert - unparam - unused - -linters-settings: - revive: + settings: + revive: + rules: + - name: comment-spacings + - name: import-shadowing + exclusions: + generated: lax rules: - - name: comment-spacings - - name: import-shadowing + - linters: + - lll + path: api/* + - linters: + - dupl + - lll + path: internal/* + - linters: + - staticcheck + text: "ST1019" + - linters: + - staticcheck + text: "ST1005" + - linters: + - staticcheck + text: "QF1008" + paths: + - third_party$ + - builtin$ + - examples$ +formatters: + enable: + - gofmt + - goimports + exclusions: + generated: lax + paths: + - third_party$ + - builtin$ + - examples$ diff --git a/docs/book/src/getting-started/testdata/project/Makefile b/docs/book/src/getting-started/testdata/project/Makefile index 9def9e8db11..3f03c3dae72 100644 --- a/docs/book/src/getting-started/testdata/project/Makefile +++ b/docs/book/src/getting-started/testdata/project/Makefile @@ -178,7 +178,7 @@ CONTROLLER_TOOLS_VERSION ?= v0.17.2 ENVTEST_VERSION ?= $(shell go list -m -f "{{ .Version }}" sigs.k8s.io/controller-runtime | awk -F'[v.]' '{printf "release-%d.%d", $$2, $$3}') #ENVTEST_K8S_VERSION is the version of Kubernetes to use for setting up ENVTEST binaries (i.e. 1.31) ENVTEST_K8S_VERSION ?= $(shell go list -m -f "{{ .Version }}" k8s.io/api | awk -F'[v.]' '{printf "1.%d", $$3}') -GOLANGCI_LINT_VERSION ?= v1.63.4 +GOLANGCI_LINT_VERSION ?= v2.0.2 .PHONY: kustomize kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary. @@ -206,7 +206,7 @@ $(ENVTEST): $(LOCALBIN) .PHONY: golangci-lint golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary. $(GOLANGCI_LINT): $(LOCALBIN) - $(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION)) + $(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/v2/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION)) # go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist # $1 - target path with name of binary diff --git a/docs/book/src/getting-started/testdata/project/test/utils/utils.go b/docs/book/src/getting-started/testdata/project/test/utils/utils.go index 0cbd734083f..3277312e4d6 100644 --- a/docs/book/src/getting-started/testdata/project/test/utils/utils.go +++ b/docs/book/src/getting-started/testdata/project/test/utils/utils.go @@ -24,7 +24,7 @@ import ( "os/exec" "strings" - . "github.com/onsi/ginkgo/v2" //nolint:golint,revive + . "github.com/onsi/ginkgo/v2" //nolint:golint,revive,staticcheck ) const ( @@ -197,7 +197,7 @@ func GetProjectDir() (string, error) { if err != nil { return wd, err } - wd = strings.Replace(wd, "/test/e2e", "", -1) + wd = strings.ReplaceAll(wd, "/test/e2e", "") return wd, nil } diff --git a/docs/book/src/multiversion-tutorial/testdata/project/.github/workflows/lint.yml b/docs/book/src/multiversion-tutorial/testdata/project/.github/workflows/lint.yml index 4951e3316c1..73fd9f7d12b 100644 --- a/docs/book/src/multiversion-tutorial/testdata/project/.github/workflows/lint.yml +++ b/docs/book/src/multiversion-tutorial/testdata/project/.github/workflows/lint.yml @@ -18,6 +18,7 @@ jobs: go-version-file: go.mod - name: Run linter - uses: golangci/golangci-lint-action@v6 + uses: golangci/golangci-lint-action@v7 with: - version: v1.63.4 + install-mode: goinstall + version: v2.0.2 diff --git a/docs/book/src/multiversion-tutorial/testdata/project/.golangci.yml b/docs/book/src/multiversion-tutorial/testdata/project/.golangci.yml index 070199921d5..ba317ca34dc 100644 --- a/docs/book/src/multiversion-tutorial/testdata/project/.golangci.yml +++ b/docs/book/src/multiversion-tutorial/testdata/project/.golangci.yml @@ -1,33 +1,15 @@ +version: "2" run: - timeout: 5m allow-parallel-runners: true - -issues: - # don't skip warning about doc comments - # don't exclude the default set of lint - exclude-use-default: false - # restore some of the defaults - # (fill in the rest as needed) - exclude-rules: - - path: "api/*" - linters: - - lll - - path: "internal/*" - linters: - - dupl - - lll linters: - disable-all: true + default: none enable: + - copyloopvar - dupl - errcheck - - copyloopvar - ginkgolinter - goconst - gocyclo - - gofmt - - goimports - - gosimple - govet - ineffassign - lll @@ -36,13 +18,44 @@ linters: - prealloc - revive - staticcheck - - typecheck - unconvert - unparam - unused - -linters-settings: - revive: + settings: + revive: + rules: + - name: comment-spacings + - name: import-shadowing + exclusions: + generated: lax rules: - - name: comment-spacings - - name: import-shadowing + - linters: + - lll + path: api/* + - linters: + - dupl + - lll + path: internal/* + - linters: + - staticcheck + text: "ST1019" + - linters: + - staticcheck + text: "ST1005" + - linters: + - staticcheck + text: "QF1008" + paths: + - third_party$ + - builtin$ + - examples$ +formatters: + enable: + - gofmt + - goimports + exclusions: + generated: lax + paths: + - third_party$ + - builtin$ + - examples$ diff --git a/docs/book/src/multiversion-tutorial/testdata/project/Makefile b/docs/book/src/multiversion-tutorial/testdata/project/Makefile index 46e98f8e623..395dff8e335 100644 --- a/docs/book/src/multiversion-tutorial/testdata/project/Makefile +++ b/docs/book/src/multiversion-tutorial/testdata/project/Makefile @@ -182,7 +182,7 @@ CONTROLLER_TOOLS_VERSION ?= v0.17.2 ENVTEST_VERSION ?= $(shell go list -m -f "{{ .Version }}" sigs.k8s.io/controller-runtime | awk -F'[v.]' '{printf "release-%d.%d", $$2, $$3}') #ENVTEST_K8S_VERSION is the version of Kubernetes to use for setting up ENVTEST binaries (i.e. 1.31) ENVTEST_K8S_VERSION ?= $(shell go list -m -f "{{ .Version }}" k8s.io/api | awk -F'[v.]' '{printf "1.%d", $$3}') -GOLANGCI_LINT_VERSION ?= v1.63.4 +GOLANGCI_LINT_VERSION ?= v2.0.2 .PHONY: kustomize kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary. @@ -210,7 +210,7 @@ $(ENVTEST): $(LOCALBIN) .PHONY: golangci-lint golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary. $(GOLANGCI_LINT): $(LOCALBIN) - $(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION)) + $(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/v2/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION)) # go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist # $1 - target path with name of binary diff --git a/docs/book/src/multiversion-tutorial/testdata/project/internal/controller/cronjob_controller.go b/docs/book/src/multiversion-tutorial/testdata/project/internal/controller/cronjob_controller.go index 79f3204be8f..d075028b6ae 100644 --- a/docs/book/src/multiversion-tutorial/testdata/project/internal/controller/cronjob_controller.go +++ b/docs/book/src/multiversion-tutorial/testdata/project/internal/controller/cronjob_controller.go @@ -58,7 +58,7 @@ the "real" clock just calls `time.Now`. */ type realClock struct{} -func (_ realClock) Now() time.Time { return time.Now() } +func (_ realClock) Now() time.Time { return time.Now() } //nolint:staticcheck // Clock knows how to get the current time. // It can be used to fake out timing for testing. @@ -388,7 +388,7 @@ func (r *CronJobReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct starts++ if starts > 100 { // We can't get the most recent times so just return an empty slice - return time.Time{}, time.Time{}, fmt.Errorf("Too many missed start times (> 100). Set or decrease .spec.startingDeadlineSeconds or check clock skew.") + return time.Time{}, time.Time{}, fmt.Errorf("Too many missed start times (> 100). Set or decrease .spec.startingDeadlineSeconds or check clock skew.") //nolint:staticcheck } } return lastMissed, sched.Next(now), nil diff --git a/docs/book/src/multiversion-tutorial/testdata/project/internal/webhook/v1/cronjob_webhook.go b/docs/book/src/multiversion-tutorial/testdata/project/internal/webhook/v1/cronjob_webhook.go index 55f3ce98012..1314c452dd6 100644 --- a/docs/book/src/multiversion-tutorial/testdata/project/internal/webhook/v1/cronjob_webhook.go +++ b/docs/book/src/multiversion-tutorial/testdata/project/internal/webhook/v1/cronjob_webhook.go @@ -103,7 +103,7 @@ The `Default`method is expected to mutate the receiver, setting the defaults. */ // Default implements webhook.CustomDefaulter so a webhook will be registered for the Kind CronJob. -func (d *CronJobCustomDefaulter) Default(ctx context.Context, obj runtime.Object) error { +func (d *CronJobCustomDefaulter) Default(_ context.Context, obj runtime.Object) error { cronjob, ok := obj.(*batchv1.CronJob) if !ok { @@ -174,7 +174,7 @@ type CronJobCustomValidator struct { var _ webhook.CustomValidator = &CronJobCustomValidator{} // ValidateCreate implements webhook.CustomValidator so a webhook will be registered for the type CronJob. -func (v *CronJobCustomValidator) ValidateCreate(ctx context.Context, obj runtime.Object) (admission.Warnings, error) { +func (v *CronJobCustomValidator) ValidateCreate(_ context.Context, obj runtime.Object) (admission.Warnings, error) { cronjob, ok := obj.(*batchv1.CronJob) if !ok { return nil, fmt.Errorf("expected a CronJob object but got %T", obj) @@ -185,7 +185,7 @@ func (v *CronJobCustomValidator) ValidateCreate(ctx context.Context, obj runtime } // ValidateUpdate implements webhook.CustomValidator so a webhook will be registered for the type CronJob. -func (v *CronJobCustomValidator) ValidateUpdate(ctx context.Context, oldObj, newObj runtime.Object) (admission.Warnings, error) { +func (v *CronJobCustomValidator) ValidateUpdate(_ context.Context, oldObj, newObj runtime.Object) (admission.Warnings, error) { cronjob, ok := newObj.(*batchv1.CronJob) if !ok { return nil, fmt.Errorf("expected a CronJob object for the newObj but got %T", newObj) diff --git a/docs/book/src/multiversion-tutorial/testdata/project/internal/webhook/v2/cronjob_webhook.go b/docs/book/src/multiversion-tutorial/testdata/project/internal/webhook/v2/cronjob_webhook.go index 4d7c2963e6c..fc29e325990 100644 --- a/docs/book/src/multiversion-tutorial/testdata/project/internal/webhook/v2/cronjob_webhook.go +++ b/docs/book/src/multiversion-tutorial/testdata/project/internal/webhook/v2/cronjob_webhook.go @@ -73,7 +73,7 @@ type CronJobCustomDefaulter struct { var _ webhook.CustomDefaulter = &CronJobCustomDefaulter{} // Default implements webhook.CustomDefaulter so a webhook will be registered for the Kind CronJob. -func (d *CronJobCustomDefaulter) Default(ctx context.Context, obj runtime.Object) error { +func (d *CronJobCustomDefaulter) Default(_ context.Context, obj runtime.Object) error { cronjob, ok := obj.(*batchv2.CronJob) if !ok { @@ -104,7 +104,7 @@ type CronJobCustomValidator struct { var _ webhook.CustomValidator = &CronJobCustomValidator{} // ValidateCreate implements webhook.CustomValidator so a webhook will be registered for the type CronJob. -func (v *CronJobCustomValidator) ValidateCreate(ctx context.Context, obj runtime.Object) (admission.Warnings, error) { +func (v *CronJobCustomValidator) ValidateCreate(_ context.Context, obj runtime.Object) (admission.Warnings, error) { cronjob, ok := obj.(*batchv2.CronJob) if !ok { return nil, fmt.Errorf("expected a CronJob object but got %T", obj) @@ -115,7 +115,7 @@ func (v *CronJobCustomValidator) ValidateCreate(ctx context.Context, obj runtime } // ValidateUpdate implements webhook.CustomValidator so a webhook will be registered for the type CronJob. -func (v *CronJobCustomValidator) ValidateUpdate(ctx context.Context, oldObj, newObj runtime.Object) (admission.Warnings, error) { +func (v *CronJobCustomValidator) ValidateUpdate(_ context.Context, oldObj, newObj runtime.Object) (admission.Warnings, error) { cronjob, ok := newObj.(*batchv2.CronJob) if !ok { return nil, fmt.Errorf("expected a CronJob object for the newObj but got %T", newObj) diff --git a/docs/book/src/multiversion-tutorial/testdata/project/test/utils/utils.go b/docs/book/src/multiversion-tutorial/testdata/project/test/utils/utils.go index 0cbd734083f..3277312e4d6 100644 --- a/docs/book/src/multiversion-tutorial/testdata/project/test/utils/utils.go +++ b/docs/book/src/multiversion-tutorial/testdata/project/test/utils/utils.go @@ -24,7 +24,7 @@ import ( "os/exec" "strings" - . "github.com/onsi/ginkgo/v2" //nolint:golint,revive + . "github.com/onsi/ginkgo/v2" //nolint:golint,revive,staticcheck ) const ( @@ -197,7 +197,7 @@ func GetProjectDir() (string, error) { if err != nil { return wd, err } - wd = strings.Replace(wd, "/test/e2e", "", -1) + wd = strings.ReplaceAll(wd, "/test/e2e", "") return wd, nil } diff --git a/hack/docs/internal/cronjob-tutorial/controller_implementation.go b/hack/docs/internal/cronjob-tutorial/controller_implementation.go index c141adc0140..cc69b720592 100644 --- a/hack/docs/internal/cronjob-tutorial/controller_implementation.go +++ b/hack/docs/internal/cronjob-tutorial/controller_implementation.go @@ -55,7 +55,7 @@ the "real" clock just calls` + " `" + `time.Now` + "`" + `. */ type realClock struct{} -func (_ realClock) Now() time.Time { return time.Now() } +func (_ realClock) Now() time.Time { return time.Now() } //nolint:staticcheck // Clock knows how to get the current time. // It can be used to fake out timing for testing. @@ -377,7 +377,7 @@ const controllerReconcileLogic = `log := logf.FromContext(ctx) starts++ if starts > 100 { // We can't get the most recent times so just return an empty slice - return time.Time{}, time.Time{}, fmt.Errorf("Too many missed start times (> 100). Set or decrease .spec.startingDeadlineSeconds or check clock skew.") + return time.Time{}, time.Time{}, fmt.Errorf("Too many missed start times (> 100). Set or decrease .spec.startingDeadlineSeconds or check clock skew.") //nolint:staticcheck } } return lastMissed, sched.Next(now), nil diff --git a/pkg/cli/cli.go b/pkg/cli/cli.go index 7c0427876fb..f7f788218e4 100644 --- a/pkg/cli/cli.go +++ b/pkg/cli/cli.go @@ -42,7 +42,7 @@ const ( ) // CLI is the command line utility that is used to scaffold kubebuilder project files. -type CLI struct { //nolint:maligned +type CLI struct { /* Fields set by Option */ // Root command name. It is injected downstream to provide correct help, usage, examples and errors. diff --git a/pkg/cli/suite_test.go b/pkg/cli/suite_test.go index b25970be22c..50108497183 100644 --- a/pkg/cli/suite_test.go +++ b/pkg/cli/suite_test.go @@ -37,7 +37,7 @@ var ( _ plugin.Plugin = mockDeprecatedPlugin{} ) -type mockPlugin struct { //nolint:maligned +type mockPlugin struct { name string version plugin.Version projectVersions []config.Version @@ -55,7 +55,7 @@ func (p mockPlugin) Name() string { return p.name func (p mockPlugin) Version() plugin.Version { return p.version } func (p mockPlugin) SupportedProjectVersions() []config.Version { return p.projectVersions } -type mockDeprecatedPlugin struct { //nolint:maligned +type mockDeprecatedPlugin struct { mockPlugin deprecation string } diff --git a/pkg/config/v3/config.go b/pkg/config/v3/config.go index 7a2a83d40fe..195ab714a88 100644 --- a/pkg/config/v3/config.go +++ b/pkg/config/v3/config.go @@ -234,7 +234,7 @@ func (c *Cfg) UpdateResource(res resource.Resource) error { } for i, r := range c.Resources { - if res.GVK.IsEqualTo(r.GVK) { + if res.IsEqualTo(r.GVK) { if err := c.Resources[i].Update(res); err != nil { return fmt.Errorf("failed to update resource %q: %w", res.GVK, err) } diff --git a/pkg/model/resource/resource.go b/pkg/model/resource/resource.go index 84000e958f0..03c8ecc3455 100644 --- a/pkg/model/resource/resource.go +++ b/pkg/model/resource/resource.go @@ -158,7 +158,7 @@ func (r *Resource) Update(other Resource) error { } // Make sure we are not merging resources for different GVKs. - if !r.GVK.IsEqualTo(other.GVK) { + if !r.IsEqualTo(other.GVK) { return fmt.Errorf("unable to update a Resource (GVK %+v) with another with non-matching GVK %+v", r.GVK, other.GVK) } diff --git a/pkg/model/resource/utils.go b/pkg/model/resource/utils.go index 31a6c83b6fa..8fd37e5a83c 100644 --- a/pkg/model/resource/utils.go +++ b/pkg/model/resource/utils.go @@ -39,8 +39,8 @@ func safeImport(unsafe string) string { safe := unsafe // Remove dashes and dots - safe = strings.Replace(safe, "-", "", -1) - safe = strings.Replace(safe, ".", "", -1) + safe = strings.ReplaceAll(safe, "-", "") + safe = strings.ReplaceAll(safe, ".", "") return safe } diff --git a/pkg/plugin/util/util.go b/pkg/plugin/util/util.go index ef60ca9be10..322de98dcd4 100644 --- a/pkg/plugin/util/util.go +++ b/pkg/plugin/util/util.go @@ -228,7 +228,7 @@ func EnsureExistAndReplace(input, match, replace string) (string, error) { if !strings.Contains(input, match) { return "", fmt.Errorf("can't find %q", match) } - return strings.Replace(input, match, replace, -1), nil + return strings.ReplaceAll(input, match, replace), nil } // ReplaceInFile replaces all instances of old with new in the file at path. @@ -245,7 +245,7 @@ func ReplaceInFile(path, oldValue, newValue string) error { if !strings.Contains(string(b), oldValue) { return errors.New("unable to find the content to be replaced") } - s := strings.Replace(string(b), oldValue, newValue, -1) + s := strings.ReplaceAll(string(b), oldValue, newValue) if err = os.WriteFile(path, []byte(s), info.Mode()); err != nil { return fmt.Errorf("failed to write file %q: %w", path, err) } diff --git a/pkg/plugins/external/helpers.go b/pkg/plugins/external/helpers.go index 42170e1fead..ddd4363d218 100644 --- a/pkg/plugins/external/helpers.go +++ b/pkg/plugins/external/helpers.go @@ -318,7 +318,7 @@ var ( // helpArgFilter filters out any flag named "help" as its already bound helpArgFilter = func(arg string) bool { arg = strings.Replace(arg, "--", "", 1) - return !(arg == "help") + return arg != "help" } ) diff --git a/pkg/plugins/golang/deploy-image/v1alpha1/api.go b/pkg/plugins/golang/deploy-image/v1alpha1/api.go index e5916df5226..668cd1c81b7 100644 --- a/pkg/plugins/golang/deploy-image/v1alpha1/api.go +++ b/pkg/plugins/golang/deploy-image/v1alpha1/api.go @@ -206,10 +206,10 @@ func (p *createAPISubcommand) Scaffold(fs machinery.Filesystem) error { RunAsUser: p.runAsUser, } cfg.Resources = append(cfg.Resources, ResourceData{ - Group: p.resource.GVK.Group, - Domain: p.resource.GVK.Domain, - Version: p.resource.GVK.Version, - Kind: p.resource.GVK.Kind, + Group: p.resource.Group, + Domain: p.resource.Domain, + Version: p.resource.Version, + Kind: p.resource.Kind, Options: configDataOptions, }) diff --git a/pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/internal/templates/api/types.go b/pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/internal/templates/api/types.go index 532775086e9..09bb14cb048 100644 --- a/pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/internal/templates/api/types.go +++ b/pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/internal/templates/api/types.go @@ -28,7 +28,7 @@ var _ machinery.Template = &Types{} // Types scaffolds the file that defines the schema for a CRD // -//nolint:maligned + type Types struct { machinery.TemplateMixin machinery.MultiGroupMixin diff --git a/pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/internal/templates/controllers/controller-test.go b/pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/internal/templates/controllers/controller-test.go index 244087a048e..44030348832 100644 --- a/pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/internal/templates/controllers/controller-test.go +++ b/pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/internal/templates/controllers/controller-test.go @@ -28,7 +28,7 @@ var _ machinery.Template = &ControllerTest{} // ControllerTest scaffolds the file that defines tests for the controller for a CRD or a builtin resource // -//nolint:maligned + type ControllerTest struct { machinery.TemplateMixin machinery.MultiGroupMixin diff --git a/pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/internal/templates/controllers/controller.go b/pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/internal/templates/controllers/controller.go index 4f2e14856e7..757c330a266 100644 --- a/pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/internal/templates/controllers/controller.go +++ b/pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/internal/templates/controllers/controller.go @@ -28,7 +28,7 @@ var _ machinery.Template = &Controller{} // Controller scaffolds the file that defines the controller for a CRD or a builtin resource // -//nolint:maligned + type Controller struct { machinery.TemplateMixin machinery.MultiGroupMixin diff --git a/pkg/plugins/golang/v4/scaffolds/init.go b/pkg/plugins/golang/v4/scaffolds/init.go index 4a14cc2e28e..a50747904e8 100644 --- a/pkg/plugins/golang/v4/scaffolds/init.go +++ b/pkg/plugins/golang/v4/scaffolds/init.go @@ -38,7 +38,7 @@ import ( const ( // GolangciLintVersion is the golangci-lint version to be used in the project - GolangciLintVersion = "v1.63.4" + GolangciLintVersion = "v2.0.2" // ControllerRuntimeVersion is the kubernetes-sigs/controller-runtime version to be used in the project ControllerRuntimeVersion = "v0.20.4" // ControllerToolsVersion is the kubernetes-sigs/controller-tools version to be used in the project diff --git a/pkg/plugins/golang/v4/scaffolds/internal/templates/api/hub.go b/pkg/plugins/golang/v4/scaffolds/internal/templates/api/hub.go index 01458b41ba4..f64f9ab6e71 100644 --- a/pkg/plugins/golang/v4/scaffolds/internal/templates/api/hub.go +++ b/pkg/plugins/golang/v4/scaffolds/internal/templates/api/hub.go @@ -28,7 +28,7 @@ var _ machinery.Template = &Hub{} // Hub scaffolds the file that defines hub // -//nolint:maligned + type Hub struct { machinery.TemplateMixin machinery.MultiGroupMixin diff --git a/pkg/plugins/golang/v4/scaffolds/internal/templates/api/types.go b/pkg/plugins/golang/v4/scaffolds/internal/templates/api/types.go index 7c0d506af6b..c83cc72c4b9 100644 --- a/pkg/plugins/golang/v4/scaffolds/internal/templates/api/types.go +++ b/pkg/plugins/golang/v4/scaffolds/internal/templates/api/types.go @@ -28,7 +28,7 @@ var _ machinery.Template = &Types{} // Types scaffolds the file that defines the schema for a CRD // -//nolint:maligned + type Types struct { machinery.TemplateMixin machinery.MultiGroupMixin diff --git a/pkg/plugins/golang/v4/scaffolds/internal/templates/cmd/main.go b/pkg/plugins/golang/v4/scaffolds/internal/templates/cmd/main.go index f14b6919c89..2301979e76f 100644 --- a/pkg/plugins/golang/v4/scaffolds/internal/templates/cmd/main.go +++ b/pkg/plugins/golang/v4/scaffolds/internal/templates/cmd/main.go @@ -55,7 +55,7 @@ func (f *Main) SetTemplateDefaults() error { var _ machinery.Inserter = &MainUpdater{} // MainUpdater updates cmd/main.go to run Controllers -type MainUpdater struct { //nolint:maligned +type MainUpdater struct { machinery.RepositoryMixin machinery.MultiGroupMixin machinery.ResourceMixin diff --git a/pkg/plugins/golang/v4/scaffolds/internal/templates/controllers/controller.go b/pkg/plugins/golang/v4/scaffolds/internal/templates/controllers/controller.go index 72d348a07da..f18142dc13e 100644 --- a/pkg/plugins/golang/v4/scaffolds/internal/templates/controllers/controller.go +++ b/pkg/plugins/golang/v4/scaffolds/internal/templates/controllers/controller.go @@ -28,7 +28,7 @@ var _ machinery.Template = &Controller{} // Controller scaffolds the file that defines the controller for a CRD or a builtin resource // -//nolint:maligned + type Controller struct { machinery.TemplateMixin machinery.MultiGroupMixin diff --git a/pkg/plugins/golang/v4/scaffolds/internal/templates/controllers/controller_suitetest.go b/pkg/plugins/golang/v4/scaffolds/internal/templates/controllers/controller_suitetest.go index 9bc9b4b178a..164ff214cc8 100644 --- a/pkg/plugins/golang/v4/scaffolds/internal/templates/controllers/controller_suitetest.go +++ b/pkg/plugins/golang/v4/scaffolds/internal/templates/controllers/controller_suitetest.go @@ -32,7 +32,7 @@ var ( // SuiteTest scaffolds the file that sets up the controller tests // -//nolint:maligned + type SuiteTest struct { machinery.TemplateMixin machinery.MultiGroupMixin diff --git a/pkg/plugins/golang/v4/scaffolds/internal/templates/controllers/controller_test_template.go b/pkg/plugins/golang/v4/scaffolds/internal/templates/controllers/controller_test_template.go index ce7b46abf2e..20c26c240c3 100644 --- a/pkg/plugins/golang/v4/scaffolds/internal/templates/controllers/controller_test_template.go +++ b/pkg/plugins/golang/v4/scaffolds/internal/templates/controllers/controller_test_template.go @@ -28,7 +28,7 @@ var _ machinery.Template = &ControllerTest{} // ControllerTest scaffolds the file that sets up the controller unit tests // -//nolint:maligned + type ControllerTest struct { machinery.TemplateMixin machinery.MultiGroupMixin diff --git a/pkg/plugins/golang/v4/scaffolds/internal/templates/github/lint.go b/pkg/plugins/golang/v4/scaffolds/internal/templates/github/lint.go index 5214e9226a1..612f7557058 100644 --- a/pkg/plugins/golang/v4/scaffolds/internal/templates/github/lint.go +++ b/pkg/plugins/golang/v4/scaffolds/internal/templates/github/lint.go @@ -66,7 +66,8 @@ jobs: go-version-file: go.mod - name: Run linter - uses: golangci/golangci-lint-action@v6 + uses: golangci/golangci-lint-action@v7 with: + install-mode: goinstall version: {{ .GolangciLintVersion }} ` diff --git a/pkg/plugins/golang/v4/scaffolds/internal/templates/golangci.go b/pkg/plugins/golang/v4/scaffolds/internal/templates/golangci.go index 89f3745ea37..750e44b321c 100644 --- a/pkg/plugins/golang/v4/scaffolds/internal/templates/golangci.go +++ b/pkg/plugins/golang/v4/scaffolds/internal/templates/golangci.go @@ -41,36 +41,18 @@ func (f *Golangci) SetTemplateDefaults() error { return nil } -const golangciTemplate = `run: - timeout: 5m +const golangciTemplate = `version: "2" +run: allow-parallel-runners: true - -issues: - # don't skip warning about doc comments - # don't exclude the default set of lint - exclude-use-default: false - # restore some of the defaults - # (fill in the rest as needed) - exclude-rules: - - path: "api/*" - linters: - - lll - - path: "internal/*" - linters: - - dupl - - lll linters: - disable-all: true + default: none enable: + - copyloopvar - dupl - errcheck - - copyloopvar - ginkgolinter - goconst - gocyclo - - gofmt - - goimports - - gosimple - govet - ineffassign - lll @@ -79,14 +61,45 @@ linters: - prealloc - revive - staticcheck - - typecheck - unconvert - unparam - unused - -linters-settings: - revive: + settings: + revive: + rules: + - name: comment-spacings + - name: import-shadowing + exclusions: + generated: lax rules: - - name: comment-spacings - - name: import-shadowing + - linters: + - lll + path: api/* + - linters: + - dupl + - lll + path: internal/* + - linters: + - staticcheck + text: "ST1019" + - linters: + - staticcheck + text: "ST1005" + - linters: + - staticcheck + text: "QF1008" + paths: + - third_party$ + - builtin$ + - examples$ +formatters: + enable: + - gofmt + - goimports + exclusions: + generated: lax + paths: + - third_party$ + - builtin$ + - examples$ ` diff --git a/pkg/plugins/golang/v4/scaffolds/internal/templates/makefile.go b/pkg/plugins/golang/v4/scaffolds/internal/templates/makefile.go index bb47e9eece0..6eed3c49865 100644 --- a/pkg/plugins/golang/v4/scaffolds/internal/templates/makefile.go +++ b/pkg/plugins/golang/v4/scaffolds/internal/templates/makefile.go @@ -285,7 +285,7 @@ $(ENVTEST): $(LOCALBIN) .PHONY: golangci-lint golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary. $(GOLANGCI_LINT): $(LOCALBIN) - $(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION)) + $(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/v2/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION)) # go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist # $1 - target path with name of binary diff --git a/pkg/plugins/golang/v4/scaffolds/internal/templates/test/utils/utils.go b/pkg/plugins/golang/v4/scaffolds/internal/templates/test/utils/utils.go index 4ab360effed..cdd478c099f 100644 --- a/pkg/plugins/golang/v4/scaffolds/internal/templates/test/utils/utils.go +++ b/pkg/plugins/golang/v4/scaffolds/internal/templates/test/utils/utils.go @@ -51,7 +51,7 @@ import ( "os/exec" "strings" - . "github.com/onsi/ginkgo/v2" //nolint:golint,revive + . "github.com/onsi/ginkgo/v2" //nolint:golint,revive,staticcheck ) const ( @@ -224,7 +224,7 @@ func GetProjectDir() (string, error) { if err != nil { return wd, err } - wd = strings.Replace(wd, "/test/e2e", "", -1) + wd = strings.ReplaceAll(wd, "/test/e2e", "") return wd, nil } diff --git a/pkg/plugins/golang/v4/scaffolds/internal/templates/webhooks/webhook.go b/pkg/plugins/golang/v4/scaffolds/internal/templates/webhooks/webhook.go index 5f71f400fa3..4392abb5c83 100644 --- a/pkg/plugins/golang/v4/scaffolds/internal/templates/webhooks/webhook.go +++ b/pkg/plugins/golang/v4/scaffolds/internal/templates/webhooks/webhook.go @@ -28,7 +28,7 @@ import ( var _ machinery.Template = &Webhook{} // Webhook scaffolds the file that defines a webhook for a CRD or a builtin resource -type Webhook struct { //nolint:maligned +type Webhook struct { machinery.TemplateMixin machinery.MultiGroupMixin machinery.BoilerplateMixin @@ -85,7 +85,7 @@ func (f *Webhook) SetTemplateDefaults() error { } f.AdmissionReviewVersions = "v1" - f.QualifiedGroupWithDash = strings.Replace(f.Resource.QualifiedGroup(), ".", "-", -1) + f.QualifiedGroupWithDash = strings.ReplaceAll(f.Resource.QualifiedGroup(), ".", "-") return nil } @@ -175,7 +175,7 @@ type {{ .Resource.Kind }}CustomDefaulter struct { var _ webhook.CustomDefaulter = &{{ .Resource.Kind }}CustomDefaulter{} // Default implements webhook.CustomDefaulter so a webhook will be registered for the Kind {{ .Resource.Kind }}. -func (d *{{ .Resource.Kind }}CustomDefaulter) Default(ctx context.Context, obj runtime.Object) error { +func (d *{{ .Resource.Kind }}CustomDefaulter) Default(_ context.Context, obj runtime.Object) error { {{- if .IsLegacyPath -}} {{ lower .Resource.Kind }}, ok := obj.(*{{ .Resource.Kind }}) {{- else }} @@ -215,7 +215,7 @@ type {{ .Resource.Kind }}CustomValidator struct{ var _ webhook.CustomValidator = &{{ .Resource.Kind }}CustomValidator{} // ValidateCreate implements webhook.CustomValidator so a webhook will be registered for the type {{ .Resource.Kind }}. -func (v *{{ .Resource.Kind }}CustomValidator) ValidateCreate(ctx context.Context, obj runtime.Object) (admission.Warnings, error) { +func (v *{{ .Resource.Kind }}CustomValidator) ValidateCreate(_ context.Context, obj runtime.Object) (admission.Warnings, error) { {{- if .IsLegacyPath -}} {{ lower .Resource.Kind }}, ok := obj.(*{{ .Resource.Kind }}) {{- else }} @@ -232,7 +232,7 @@ func (v *{{ .Resource.Kind }}CustomValidator) ValidateCreate(ctx context.Context } // ValidateUpdate implements webhook.CustomValidator so a webhook will be registered for the type {{ .Resource.Kind }}. -func (v *{{ .Resource.Kind }}CustomValidator) ValidateUpdate(ctx context.Context, oldObj, newObj runtime.Object) (admission.Warnings, error) { +func (v *{{ .Resource.Kind }}CustomValidator) ValidateUpdate(_ context.Context, oldObj, newObj runtime.Object) (admission.Warnings, error) { {{- if .IsLegacyPath -}} {{ lower .Resource.Kind }}, ok := newObj.(*{{ .Resource.Kind }}) {{- else }} diff --git a/pkg/plugins/golang/v4/scaffolds/internal/templates/webhooks/webhook_suitetest.go b/pkg/plugins/golang/v4/scaffolds/internal/templates/webhooks/webhook_suitetest.go index 5e7afdace3a..c2b6814e9f2 100644 --- a/pkg/plugins/golang/v4/scaffolds/internal/templates/webhooks/webhook_suitetest.go +++ b/pkg/plugins/golang/v4/scaffolds/internal/templates/webhooks/webhook_suitetest.go @@ -31,7 +31,7 @@ var ( ) // WebhookSuite scaffolds the file that sets up the webhook tests -type WebhookSuite struct { //nolint:maligned +type WebhookSuite struct { machinery.TemplateMixin machinery.MultiGroupMixin machinery.BoilerplateMixin diff --git a/pkg/plugins/golang/v4/scaffolds/internal/templates/webhooks/webhook_test_template.go b/pkg/plugins/golang/v4/scaffolds/internal/templates/webhooks/webhook_test_template.go index 4439a810ce0..2247c62bb1c 100644 --- a/pkg/plugins/golang/v4/scaffolds/internal/templates/webhooks/webhook_test_template.go +++ b/pkg/plugins/golang/v4/scaffolds/internal/templates/webhooks/webhook_test_template.go @@ -29,7 +29,7 @@ import ( var _ machinery.Template = &WebhookTest{} // WebhookTest scaffolds the file that sets up the webhook unit tests -type WebhookTest struct { //nolint:maligned +type WebhookTest struct { machinery.TemplateMixin machinery.MultiGroupMixin machinery.BoilerplateMixin diff --git a/pkg/plugins/optional/helm/v1alpha/scaffolds/init.go b/pkg/plugins/optional/helm/v1alpha/scaffolds/init.go index 986170c8ca0..6442e2ea866 100644 --- a/pkg/plugins/optional/helm/v1alpha/scaffolds/init.go +++ b/pkg/plugins/optional/helm/v1alpha/scaffolds/init.go @@ -214,9 +214,10 @@ func (s *initScaffolder) extractWebhooksFromGeneratedFiles() (mutatingWebhooks [ Rules: w.Rules, } - if webhookConfig.Kind == "MutatingWebhookConfiguration" { + switch webhookConfig.Kind { + case "MutatingWebhookConfiguration": mutatingWebhooks = append(mutatingWebhooks, webhook) - } else if webhookConfig.Kind == "ValidatingWebhookConfiguration" { + case "ValidatingWebhookConfiguration": validatingWebhooks = append(validatingWebhooks, webhook) } } @@ -310,16 +311,16 @@ func copyFileWithHelmLogic(srcFile, destFile, subDir, projectName string, hasCon // Apply RBAC-specific replacements if subDir == "rbac" { - contentStr = strings.Replace(contentStr, + contentStr = strings.ReplaceAll(contentStr, "name: controller-manager", - "name: {{ .Values.controllerManager.serviceAccountName }}", -1) + "name: {{ .Values.controllerManager.serviceAccountName }}") contentStr = strings.Replace(contentStr, "name: metrics-reader", fmt.Sprintf("name: %s-metrics-reader", projectName), 1) - contentStr = strings.Replace(contentStr, + contentStr = strings.ReplaceAll(contentStr, "name: metrics-auth-role", - fmt.Sprintf("name: %s-metrics-auth-role", projectName), -1) + fmt.Sprintf("name: %s-metrics-auth-role", projectName)) contentStr = strings.Replace(contentStr, "name: metrics-auth-rolebinding", fmt.Sprintf("name: %s-metrics-auth-rolebinding", projectName), 1) @@ -337,15 +338,15 @@ func copyFileWithHelmLogic(srcFile, destFile, subDir, projectName string, hasCon {{- end }} {{- end }}`, 1) } - contentStr = strings.Replace(contentStr, + contentStr = strings.ReplaceAll(contentStr, "name: leader-election-role", - fmt.Sprintf("name: %s-leader-election-role", projectName), -1) + fmt.Sprintf("name: %s-leader-election-role", projectName)) contentStr = strings.Replace(contentStr, "name: leader-election-rolebinding", fmt.Sprintf("name: %s-leader-election-rolebinding", projectName), 1) - contentStr = strings.Replace(contentStr, + contentStr = strings.ReplaceAll(contentStr, "name: manager-role", - fmt.Sprintf("name: %s-manager-role", projectName), -1) + fmt.Sprintf("name: %s-manager-role", projectName)) contentStr = strings.Replace(contentStr, "name: manager-rolebinding", fmt.Sprintf("name: %s-manager-rolebinding", projectName), 1) diff --git a/testdata/project-v4-multigroup/.github/workflows/lint.yml b/testdata/project-v4-multigroup/.github/workflows/lint.yml index 4951e3316c1..73fd9f7d12b 100644 --- a/testdata/project-v4-multigroup/.github/workflows/lint.yml +++ b/testdata/project-v4-multigroup/.github/workflows/lint.yml @@ -18,6 +18,7 @@ jobs: go-version-file: go.mod - name: Run linter - uses: golangci/golangci-lint-action@v6 + uses: golangci/golangci-lint-action@v7 with: - version: v1.63.4 + install-mode: goinstall + version: v2.0.2 diff --git a/testdata/project-v4-multigroup/.golangci.yml b/testdata/project-v4-multigroup/.golangci.yml index 070199921d5..ba317ca34dc 100644 --- a/testdata/project-v4-multigroup/.golangci.yml +++ b/testdata/project-v4-multigroup/.golangci.yml @@ -1,33 +1,15 @@ +version: "2" run: - timeout: 5m allow-parallel-runners: true - -issues: - # don't skip warning about doc comments - # don't exclude the default set of lint - exclude-use-default: false - # restore some of the defaults - # (fill in the rest as needed) - exclude-rules: - - path: "api/*" - linters: - - lll - - path: "internal/*" - linters: - - dupl - - lll linters: - disable-all: true + default: none enable: + - copyloopvar - dupl - errcheck - - copyloopvar - ginkgolinter - goconst - gocyclo - - gofmt - - goimports - - gosimple - govet - ineffassign - lll @@ -36,13 +18,44 @@ linters: - prealloc - revive - staticcheck - - typecheck - unconvert - unparam - unused - -linters-settings: - revive: + settings: + revive: + rules: + - name: comment-spacings + - name: import-shadowing + exclusions: + generated: lax rules: - - name: comment-spacings - - name: import-shadowing + - linters: + - lll + path: api/* + - linters: + - dupl + - lll + path: internal/* + - linters: + - staticcheck + text: "ST1019" + - linters: + - staticcheck + text: "ST1005" + - linters: + - staticcheck + text: "QF1008" + paths: + - third_party$ + - builtin$ + - examples$ +formatters: + enable: + - gofmt + - goimports + exclusions: + generated: lax + paths: + - third_party$ + - builtin$ + - examples$ diff --git a/testdata/project-v4-multigroup/Makefile b/testdata/project-v4-multigroup/Makefile index 3d2d6032f87..4ea57141547 100644 --- a/testdata/project-v4-multigroup/Makefile +++ b/testdata/project-v4-multigroup/Makefile @@ -178,7 +178,7 @@ CONTROLLER_TOOLS_VERSION ?= v0.17.2 ENVTEST_VERSION ?= $(shell go list -m -f "{{ .Version }}" sigs.k8s.io/controller-runtime | awk -F'[v.]' '{printf "release-%d.%d", $$2, $$3}') #ENVTEST_K8S_VERSION is the version of Kubernetes to use for setting up ENVTEST binaries (i.e. 1.31) ENVTEST_K8S_VERSION ?= $(shell go list -m -f "{{ .Version }}" k8s.io/api | awk -F'[v.]' '{printf "1.%d", $$3}') -GOLANGCI_LINT_VERSION ?= v1.63.4 +GOLANGCI_LINT_VERSION ?= v2.0.2 .PHONY: kustomize kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary. @@ -206,7 +206,7 @@ $(ENVTEST): $(LOCALBIN) .PHONY: golangci-lint golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary. $(GOLANGCI_LINT): $(LOCALBIN) - $(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION)) + $(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/v2/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION)) # go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist # $1 - target path with name of binary diff --git a/testdata/project-v4-multigroup/internal/webhook/apps/v1/deployment_webhook.go b/testdata/project-v4-multigroup/internal/webhook/apps/v1/deployment_webhook.go index d838f845377..2fbc30f48e0 100644 --- a/testdata/project-v4-multigroup/internal/webhook/apps/v1/deployment_webhook.go +++ b/testdata/project-v4-multigroup/internal/webhook/apps/v1/deployment_webhook.go @@ -56,7 +56,7 @@ type DeploymentCustomDefaulter struct { var _ webhook.CustomDefaulter = &DeploymentCustomDefaulter{} // Default implements webhook.CustomDefaulter so a webhook will be registered for the Kind Deployment. -func (d *DeploymentCustomDefaulter) Default(ctx context.Context, obj runtime.Object) error { +func (d *DeploymentCustomDefaulter) Default(_ context.Context, obj runtime.Object) error { deployment, ok := obj.(*appsv1.Deployment) if !ok { @@ -86,7 +86,7 @@ type DeploymentCustomValidator struct { var _ webhook.CustomValidator = &DeploymentCustomValidator{} // ValidateCreate implements webhook.CustomValidator so a webhook will be registered for the type Deployment. -func (v *DeploymentCustomValidator) ValidateCreate(ctx context.Context, obj runtime.Object) (admission.Warnings, error) { +func (v *DeploymentCustomValidator) ValidateCreate(_ context.Context, obj runtime.Object) (admission.Warnings, error) { deployment, ok := obj.(*appsv1.Deployment) if !ok { return nil, fmt.Errorf("expected a Deployment object but got %T", obj) @@ -99,7 +99,7 @@ func (v *DeploymentCustomValidator) ValidateCreate(ctx context.Context, obj runt } // ValidateUpdate implements webhook.CustomValidator so a webhook will be registered for the type Deployment. -func (v *DeploymentCustomValidator) ValidateUpdate(ctx context.Context, oldObj, newObj runtime.Object) (admission.Warnings, error) { +func (v *DeploymentCustomValidator) ValidateUpdate(_ context.Context, oldObj, newObj runtime.Object) (admission.Warnings, error) { deployment, ok := newObj.(*appsv1.Deployment) if !ok { return nil, fmt.Errorf("expected a Deployment object for the newObj but got %T", newObj) diff --git a/testdata/project-v4-multigroup/internal/webhook/cert-manager/v1/issuer_webhook.go b/testdata/project-v4-multigroup/internal/webhook/cert-manager/v1/issuer_webhook.go index 0577f525cc2..1ce37cdf796 100644 --- a/testdata/project-v4-multigroup/internal/webhook/cert-manager/v1/issuer_webhook.go +++ b/testdata/project-v4-multigroup/internal/webhook/cert-manager/v1/issuer_webhook.go @@ -54,7 +54,7 @@ type IssuerCustomDefaulter struct { var _ webhook.CustomDefaulter = &IssuerCustomDefaulter{} // Default implements webhook.CustomDefaulter so a webhook will be registered for the Kind Issuer. -func (d *IssuerCustomDefaulter) Default(ctx context.Context, obj runtime.Object) error { +func (d *IssuerCustomDefaulter) Default(_ context.Context, obj runtime.Object) error { issuer, ok := obj.(*certmanagerv1.Issuer) if !ok { diff --git a/testdata/project-v4-multigroup/internal/webhook/core/v1/pod_webhook.go b/testdata/project-v4-multigroup/internal/webhook/core/v1/pod_webhook.go index 30f274046e0..51b9182a859 100644 --- a/testdata/project-v4-multigroup/internal/webhook/core/v1/pod_webhook.go +++ b/testdata/project-v4-multigroup/internal/webhook/core/v1/pod_webhook.go @@ -58,7 +58,7 @@ type PodCustomValidator struct { var _ webhook.CustomValidator = &PodCustomValidator{} // ValidateCreate implements webhook.CustomValidator so a webhook will be registered for the type Pod. -func (v *PodCustomValidator) ValidateCreate(ctx context.Context, obj runtime.Object) (admission.Warnings, error) { +func (v *PodCustomValidator) ValidateCreate(_ context.Context, obj runtime.Object) (admission.Warnings, error) { pod, ok := obj.(*corev1.Pod) if !ok { return nil, fmt.Errorf("expected a Pod object but got %T", obj) @@ -71,7 +71,7 @@ func (v *PodCustomValidator) ValidateCreate(ctx context.Context, obj runtime.Obj } // ValidateUpdate implements webhook.CustomValidator so a webhook will be registered for the type Pod. -func (v *PodCustomValidator) ValidateUpdate(ctx context.Context, oldObj, newObj runtime.Object) (admission.Warnings, error) { +func (v *PodCustomValidator) ValidateUpdate(_ context.Context, oldObj, newObj runtime.Object) (admission.Warnings, error) { pod, ok := newObj.(*corev1.Pod) if !ok { return nil, fmt.Errorf("expected a Pod object for the newObj but got %T", newObj) diff --git a/testdata/project-v4-multigroup/internal/webhook/crew/v1/captain_webhook.go b/testdata/project-v4-multigroup/internal/webhook/crew/v1/captain_webhook.go index 8831faacf31..9becc8e8e05 100644 --- a/testdata/project-v4-multigroup/internal/webhook/crew/v1/captain_webhook.go +++ b/testdata/project-v4-multigroup/internal/webhook/crew/v1/captain_webhook.go @@ -57,7 +57,7 @@ type CaptainCustomDefaulter struct { var _ webhook.CustomDefaulter = &CaptainCustomDefaulter{} // Default implements webhook.CustomDefaulter so a webhook will be registered for the Kind Captain. -func (d *CaptainCustomDefaulter) Default(ctx context.Context, obj runtime.Object) error { +func (d *CaptainCustomDefaulter) Default(_ context.Context, obj runtime.Object) error { captain, ok := obj.(*crewv1.Captain) if !ok { @@ -87,7 +87,7 @@ type CaptainCustomValidator struct { var _ webhook.CustomValidator = &CaptainCustomValidator{} // ValidateCreate implements webhook.CustomValidator so a webhook will be registered for the type Captain. -func (v *CaptainCustomValidator) ValidateCreate(ctx context.Context, obj runtime.Object) (admission.Warnings, error) { +func (v *CaptainCustomValidator) ValidateCreate(_ context.Context, obj runtime.Object) (admission.Warnings, error) { captain, ok := obj.(*crewv1.Captain) if !ok { return nil, fmt.Errorf("expected a Captain object but got %T", obj) @@ -100,7 +100,7 @@ func (v *CaptainCustomValidator) ValidateCreate(ctx context.Context, obj runtime } // ValidateUpdate implements webhook.CustomValidator so a webhook will be registered for the type Captain. -func (v *CaptainCustomValidator) ValidateUpdate(ctx context.Context, oldObj, newObj runtime.Object) (admission.Warnings, error) { +func (v *CaptainCustomValidator) ValidateUpdate(_ context.Context, oldObj, newObj runtime.Object) (admission.Warnings, error) { captain, ok := newObj.(*crewv1.Captain) if !ok { return nil, fmt.Errorf("expected a Captain object for the newObj but got %T", newObj) diff --git a/testdata/project-v4-multigroup/internal/webhook/example.com/v1alpha1/memcached_webhook.go b/testdata/project-v4-multigroup/internal/webhook/example.com/v1alpha1/memcached_webhook.go index c7c005c80e3..19507ce9b01 100644 --- a/testdata/project-v4-multigroup/internal/webhook/example.com/v1alpha1/memcached_webhook.go +++ b/testdata/project-v4-multigroup/internal/webhook/example.com/v1alpha1/memcached_webhook.go @@ -59,7 +59,7 @@ type MemcachedCustomValidator struct { var _ webhook.CustomValidator = &MemcachedCustomValidator{} // ValidateCreate implements webhook.CustomValidator so a webhook will be registered for the type Memcached. -func (v *MemcachedCustomValidator) ValidateCreate(ctx context.Context, obj runtime.Object) (admission.Warnings, error) { +func (v *MemcachedCustomValidator) ValidateCreate(_ context.Context, obj runtime.Object) (admission.Warnings, error) { memcached, ok := obj.(*examplecomv1alpha1.Memcached) if !ok { return nil, fmt.Errorf("expected a Memcached object but got %T", obj) @@ -72,7 +72,7 @@ func (v *MemcachedCustomValidator) ValidateCreate(ctx context.Context, obj runti } // ValidateUpdate implements webhook.CustomValidator so a webhook will be registered for the type Memcached. -func (v *MemcachedCustomValidator) ValidateUpdate(ctx context.Context, oldObj, newObj runtime.Object) (admission.Warnings, error) { +func (v *MemcachedCustomValidator) ValidateUpdate(_ context.Context, oldObj, newObj runtime.Object) (admission.Warnings, error) { memcached, ok := newObj.(*examplecomv1alpha1.Memcached) if !ok { return nil, fmt.Errorf("expected a Memcached object for the newObj but got %T", newObj) diff --git a/testdata/project-v4-multigroup/internal/webhook/ship/v1/destroyer_webhook.go b/testdata/project-v4-multigroup/internal/webhook/ship/v1/destroyer_webhook.go index ca6497e3172..eccd97db9b9 100644 --- a/testdata/project-v4-multigroup/internal/webhook/ship/v1/destroyer_webhook.go +++ b/testdata/project-v4-multigroup/internal/webhook/ship/v1/destroyer_webhook.go @@ -55,7 +55,7 @@ type DestroyerCustomDefaulter struct { var _ webhook.CustomDefaulter = &DestroyerCustomDefaulter{} // Default implements webhook.CustomDefaulter so a webhook will be registered for the Kind Destroyer. -func (d *DestroyerCustomDefaulter) Default(ctx context.Context, obj runtime.Object) error { +func (d *DestroyerCustomDefaulter) Default(_ context.Context, obj runtime.Object) error { destroyer, ok := obj.(*shipv1.Destroyer) if !ok { diff --git a/testdata/project-v4-multigroup/internal/webhook/ship/v2alpha1/cruiser_webhook.go b/testdata/project-v4-multigroup/internal/webhook/ship/v2alpha1/cruiser_webhook.go index 133d7c9ad9d..b88b9d9287f 100644 --- a/testdata/project-v4-multigroup/internal/webhook/ship/v2alpha1/cruiser_webhook.go +++ b/testdata/project-v4-multigroup/internal/webhook/ship/v2alpha1/cruiser_webhook.go @@ -59,7 +59,7 @@ type CruiserCustomValidator struct { var _ webhook.CustomValidator = &CruiserCustomValidator{} // ValidateCreate implements webhook.CustomValidator so a webhook will be registered for the type Cruiser. -func (v *CruiserCustomValidator) ValidateCreate(ctx context.Context, obj runtime.Object) (admission.Warnings, error) { +func (v *CruiserCustomValidator) ValidateCreate(_ context.Context, obj runtime.Object) (admission.Warnings, error) { cruiser, ok := obj.(*shipv2alpha1.Cruiser) if !ok { return nil, fmt.Errorf("expected a Cruiser object but got %T", obj) @@ -72,7 +72,7 @@ func (v *CruiserCustomValidator) ValidateCreate(ctx context.Context, obj runtime } // ValidateUpdate implements webhook.CustomValidator so a webhook will be registered for the type Cruiser. -func (v *CruiserCustomValidator) ValidateUpdate(ctx context.Context, oldObj, newObj runtime.Object) (admission.Warnings, error) { +func (v *CruiserCustomValidator) ValidateUpdate(_ context.Context, oldObj, newObj runtime.Object) (admission.Warnings, error) { cruiser, ok := newObj.(*shipv2alpha1.Cruiser) if !ok { return nil, fmt.Errorf("expected a Cruiser object for the newObj but got %T", newObj) diff --git a/testdata/project-v4-multigroup/test/utils/utils.go b/testdata/project-v4-multigroup/test/utils/utils.go index 0cbd734083f..3277312e4d6 100644 --- a/testdata/project-v4-multigroup/test/utils/utils.go +++ b/testdata/project-v4-multigroup/test/utils/utils.go @@ -24,7 +24,7 @@ import ( "os/exec" "strings" - . "github.com/onsi/ginkgo/v2" //nolint:golint,revive + . "github.com/onsi/ginkgo/v2" //nolint:golint,revive,staticcheck ) const ( @@ -197,7 +197,7 @@ func GetProjectDir() (string, error) { if err != nil { return wd, err } - wd = strings.Replace(wd, "/test/e2e", "", -1) + wd = strings.ReplaceAll(wd, "/test/e2e", "") return wd, nil } diff --git a/testdata/project-v4-with-plugins/.github/workflows/lint.yml b/testdata/project-v4-with-plugins/.github/workflows/lint.yml index 4951e3316c1..73fd9f7d12b 100644 --- a/testdata/project-v4-with-plugins/.github/workflows/lint.yml +++ b/testdata/project-v4-with-plugins/.github/workflows/lint.yml @@ -18,6 +18,7 @@ jobs: go-version-file: go.mod - name: Run linter - uses: golangci/golangci-lint-action@v6 + uses: golangci/golangci-lint-action@v7 with: - version: v1.63.4 + install-mode: goinstall + version: v2.0.2 diff --git a/testdata/project-v4-with-plugins/.golangci.yml b/testdata/project-v4-with-plugins/.golangci.yml index 070199921d5..ba317ca34dc 100644 --- a/testdata/project-v4-with-plugins/.golangci.yml +++ b/testdata/project-v4-with-plugins/.golangci.yml @@ -1,33 +1,15 @@ +version: "2" run: - timeout: 5m allow-parallel-runners: true - -issues: - # don't skip warning about doc comments - # don't exclude the default set of lint - exclude-use-default: false - # restore some of the defaults - # (fill in the rest as needed) - exclude-rules: - - path: "api/*" - linters: - - lll - - path: "internal/*" - linters: - - dupl - - lll linters: - disable-all: true + default: none enable: + - copyloopvar - dupl - errcheck - - copyloopvar - ginkgolinter - goconst - gocyclo - - gofmt - - goimports - - gosimple - govet - ineffassign - lll @@ -36,13 +18,44 @@ linters: - prealloc - revive - staticcheck - - typecheck - unconvert - unparam - unused - -linters-settings: - revive: + settings: + revive: + rules: + - name: comment-spacings + - name: import-shadowing + exclusions: + generated: lax rules: - - name: comment-spacings - - name: import-shadowing + - linters: + - lll + path: api/* + - linters: + - dupl + - lll + path: internal/* + - linters: + - staticcheck + text: "ST1019" + - linters: + - staticcheck + text: "ST1005" + - linters: + - staticcheck + text: "QF1008" + paths: + - third_party$ + - builtin$ + - examples$ +formatters: + enable: + - gofmt + - goimports + exclusions: + generated: lax + paths: + - third_party$ + - builtin$ + - examples$ diff --git a/testdata/project-v4-with-plugins/Makefile b/testdata/project-v4-with-plugins/Makefile index 49f659fa94a..608de404f45 100644 --- a/testdata/project-v4-with-plugins/Makefile +++ b/testdata/project-v4-with-plugins/Makefile @@ -178,7 +178,7 @@ CONTROLLER_TOOLS_VERSION ?= v0.17.2 ENVTEST_VERSION ?= $(shell go list -m -f "{{ .Version }}" sigs.k8s.io/controller-runtime | awk -F'[v.]' '{printf "release-%d.%d", $$2, $$3}') #ENVTEST_K8S_VERSION is the version of Kubernetes to use for setting up ENVTEST binaries (i.e. 1.31) ENVTEST_K8S_VERSION ?= $(shell go list -m -f "{{ .Version }}" k8s.io/api | awk -F'[v.]' '{printf "1.%d", $$3}') -GOLANGCI_LINT_VERSION ?= v1.63.4 +GOLANGCI_LINT_VERSION ?= v2.0.2 .PHONY: kustomize kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary. @@ -206,7 +206,7 @@ $(ENVTEST): $(LOCALBIN) .PHONY: golangci-lint golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary. $(GOLANGCI_LINT): $(LOCALBIN) - $(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION)) + $(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/v2/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION)) # go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist # $1 - target path with name of binary diff --git a/testdata/project-v4-with-plugins/internal/webhook/v1alpha1/memcached_webhook.go b/testdata/project-v4-with-plugins/internal/webhook/v1alpha1/memcached_webhook.go index b6f559f8759..f84e6ffc441 100644 --- a/testdata/project-v4-with-plugins/internal/webhook/v1alpha1/memcached_webhook.go +++ b/testdata/project-v4-with-plugins/internal/webhook/v1alpha1/memcached_webhook.go @@ -59,7 +59,7 @@ type MemcachedCustomValidator struct { var _ webhook.CustomValidator = &MemcachedCustomValidator{} // ValidateCreate implements webhook.CustomValidator so a webhook will be registered for the type Memcached. -func (v *MemcachedCustomValidator) ValidateCreate(ctx context.Context, obj runtime.Object) (admission.Warnings, error) { +func (v *MemcachedCustomValidator) ValidateCreate(_ context.Context, obj runtime.Object) (admission.Warnings, error) { memcached, ok := obj.(*examplecomv1alpha1.Memcached) if !ok { return nil, fmt.Errorf("expected a Memcached object but got %T", obj) @@ -72,7 +72,7 @@ func (v *MemcachedCustomValidator) ValidateCreate(ctx context.Context, obj runti } // ValidateUpdate implements webhook.CustomValidator so a webhook will be registered for the type Memcached. -func (v *MemcachedCustomValidator) ValidateUpdate(ctx context.Context, oldObj, newObj runtime.Object) (admission.Warnings, error) { +func (v *MemcachedCustomValidator) ValidateUpdate(_ context.Context, oldObj, newObj runtime.Object) (admission.Warnings, error) { memcached, ok := newObj.(*examplecomv1alpha1.Memcached) if !ok { return nil, fmt.Errorf("expected a Memcached object for the newObj but got %T", newObj) diff --git a/testdata/project-v4-with-plugins/test/utils/utils.go b/testdata/project-v4-with-plugins/test/utils/utils.go index 0cbd734083f..3277312e4d6 100644 --- a/testdata/project-v4-with-plugins/test/utils/utils.go +++ b/testdata/project-v4-with-plugins/test/utils/utils.go @@ -24,7 +24,7 @@ import ( "os/exec" "strings" - . "github.com/onsi/ginkgo/v2" //nolint:golint,revive + . "github.com/onsi/ginkgo/v2" //nolint:golint,revive,staticcheck ) const ( @@ -197,7 +197,7 @@ func GetProjectDir() (string, error) { if err != nil { return wd, err } - wd = strings.Replace(wd, "/test/e2e", "", -1) + wd = strings.ReplaceAll(wd, "/test/e2e", "") return wd, nil } diff --git a/testdata/project-v4/.github/workflows/lint.yml b/testdata/project-v4/.github/workflows/lint.yml index 4951e3316c1..73fd9f7d12b 100644 --- a/testdata/project-v4/.github/workflows/lint.yml +++ b/testdata/project-v4/.github/workflows/lint.yml @@ -18,6 +18,7 @@ jobs: go-version-file: go.mod - name: Run linter - uses: golangci/golangci-lint-action@v6 + uses: golangci/golangci-lint-action@v7 with: - version: v1.63.4 + install-mode: goinstall + version: v2.0.2 diff --git a/testdata/project-v4/.golangci.yml b/testdata/project-v4/.golangci.yml index 070199921d5..ba317ca34dc 100644 --- a/testdata/project-v4/.golangci.yml +++ b/testdata/project-v4/.golangci.yml @@ -1,33 +1,15 @@ +version: "2" run: - timeout: 5m allow-parallel-runners: true - -issues: - # don't skip warning about doc comments - # don't exclude the default set of lint - exclude-use-default: false - # restore some of the defaults - # (fill in the rest as needed) - exclude-rules: - - path: "api/*" - linters: - - lll - - path: "internal/*" - linters: - - dupl - - lll linters: - disable-all: true + default: none enable: + - copyloopvar - dupl - errcheck - - copyloopvar - ginkgolinter - goconst - gocyclo - - gofmt - - goimports - - gosimple - govet - ineffassign - lll @@ -36,13 +18,44 @@ linters: - prealloc - revive - staticcheck - - typecheck - unconvert - unparam - unused - -linters-settings: - revive: + settings: + revive: + rules: + - name: comment-spacings + - name: import-shadowing + exclusions: + generated: lax rules: - - name: comment-spacings - - name: import-shadowing + - linters: + - lll + path: api/* + - linters: + - dupl + - lll + path: internal/* + - linters: + - staticcheck + text: "ST1019" + - linters: + - staticcheck + text: "ST1005" + - linters: + - staticcheck + text: "QF1008" + paths: + - third_party$ + - builtin$ + - examples$ +formatters: + enable: + - gofmt + - goimports + exclusions: + generated: lax + paths: + - third_party$ + - builtin$ + - examples$ diff --git a/testdata/project-v4/Makefile b/testdata/project-v4/Makefile index b8f4b95e623..1ae9c86b9f4 100644 --- a/testdata/project-v4/Makefile +++ b/testdata/project-v4/Makefile @@ -178,7 +178,7 @@ CONTROLLER_TOOLS_VERSION ?= v0.17.2 ENVTEST_VERSION ?= $(shell go list -m -f "{{ .Version }}" sigs.k8s.io/controller-runtime | awk -F'[v.]' '{printf "release-%d.%d", $$2, $$3}') #ENVTEST_K8S_VERSION is the version of Kubernetes to use for setting up ENVTEST binaries (i.e. 1.31) ENVTEST_K8S_VERSION ?= $(shell go list -m -f "{{ .Version }}" k8s.io/api | awk -F'[v.]' '{printf "1.%d", $$3}') -GOLANGCI_LINT_VERSION ?= v1.63.4 +GOLANGCI_LINT_VERSION ?= v2.0.2 .PHONY: kustomize kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary. @@ -206,7 +206,7 @@ $(ENVTEST): $(LOCALBIN) .PHONY: golangci-lint golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary. $(GOLANGCI_LINT): $(LOCALBIN) - $(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION)) + $(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/v2/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION)) # go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist # $1 - target path with name of binary diff --git a/testdata/project-v4/internal/webhook/v1/admiral_webhook.go b/testdata/project-v4/internal/webhook/v1/admiral_webhook.go index 3099166b584..a30f4394364 100644 --- a/testdata/project-v4/internal/webhook/v1/admiral_webhook.go +++ b/testdata/project-v4/internal/webhook/v1/admiral_webhook.go @@ -55,7 +55,7 @@ type AdmiralCustomDefaulter struct { var _ webhook.CustomDefaulter = &AdmiralCustomDefaulter{} // Default implements webhook.CustomDefaulter so a webhook will be registered for the Kind Admiral. -func (d *AdmiralCustomDefaulter) Default(ctx context.Context, obj runtime.Object) error { +func (d *AdmiralCustomDefaulter) Default(_ context.Context, obj runtime.Object) error { admiral, ok := obj.(*crewv1.Admiral) if !ok { diff --git a/testdata/project-v4/internal/webhook/v1/captain_webhook.go b/testdata/project-v4/internal/webhook/v1/captain_webhook.go index e8f5f95666c..f6d80fb6562 100644 --- a/testdata/project-v4/internal/webhook/v1/captain_webhook.go +++ b/testdata/project-v4/internal/webhook/v1/captain_webhook.go @@ -57,7 +57,7 @@ type CaptainCustomDefaulter struct { var _ webhook.CustomDefaulter = &CaptainCustomDefaulter{} // Default implements webhook.CustomDefaulter so a webhook will be registered for the Kind Captain. -func (d *CaptainCustomDefaulter) Default(ctx context.Context, obj runtime.Object) error { +func (d *CaptainCustomDefaulter) Default(_ context.Context, obj runtime.Object) error { captain, ok := obj.(*crewv1.Captain) if !ok { @@ -87,7 +87,7 @@ type CaptainCustomValidator struct { var _ webhook.CustomValidator = &CaptainCustomValidator{} // ValidateCreate implements webhook.CustomValidator so a webhook will be registered for the type Captain. -func (v *CaptainCustomValidator) ValidateCreate(ctx context.Context, obj runtime.Object) (admission.Warnings, error) { +func (v *CaptainCustomValidator) ValidateCreate(_ context.Context, obj runtime.Object) (admission.Warnings, error) { captain, ok := obj.(*crewv1.Captain) if !ok { return nil, fmt.Errorf("expected a Captain object but got %T", obj) @@ -100,7 +100,7 @@ func (v *CaptainCustomValidator) ValidateCreate(ctx context.Context, obj runtime } // ValidateUpdate implements webhook.CustomValidator so a webhook will be registered for the type Captain. -func (v *CaptainCustomValidator) ValidateUpdate(ctx context.Context, oldObj, newObj runtime.Object) (admission.Warnings, error) { +func (v *CaptainCustomValidator) ValidateUpdate(_ context.Context, oldObj, newObj runtime.Object) (admission.Warnings, error) { captain, ok := newObj.(*crewv1.Captain) if !ok { return nil, fmt.Errorf("expected a Captain object for the newObj but got %T", newObj) diff --git a/testdata/project-v4/internal/webhook/v1/deployment_webhook.go b/testdata/project-v4/internal/webhook/v1/deployment_webhook.go index d838f845377..2fbc30f48e0 100644 --- a/testdata/project-v4/internal/webhook/v1/deployment_webhook.go +++ b/testdata/project-v4/internal/webhook/v1/deployment_webhook.go @@ -56,7 +56,7 @@ type DeploymentCustomDefaulter struct { var _ webhook.CustomDefaulter = &DeploymentCustomDefaulter{} // Default implements webhook.CustomDefaulter so a webhook will be registered for the Kind Deployment. -func (d *DeploymentCustomDefaulter) Default(ctx context.Context, obj runtime.Object) error { +func (d *DeploymentCustomDefaulter) Default(_ context.Context, obj runtime.Object) error { deployment, ok := obj.(*appsv1.Deployment) if !ok { @@ -86,7 +86,7 @@ type DeploymentCustomValidator struct { var _ webhook.CustomValidator = &DeploymentCustomValidator{} // ValidateCreate implements webhook.CustomValidator so a webhook will be registered for the type Deployment. -func (v *DeploymentCustomValidator) ValidateCreate(ctx context.Context, obj runtime.Object) (admission.Warnings, error) { +func (v *DeploymentCustomValidator) ValidateCreate(_ context.Context, obj runtime.Object) (admission.Warnings, error) { deployment, ok := obj.(*appsv1.Deployment) if !ok { return nil, fmt.Errorf("expected a Deployment object but got %T", obj) @@ -99,7 +99,7 @@ func (v *DeploymentCustomValidator) ValidateCreate(ctx context.Context, obj runt } // ValidateUpdate implements webhook.CustomValidator so a webhook will be registered for the type Deployment. -func (v *DeploymentCustomValidator) ValidateUpdate(ctx context.Context, oldObj, newObj runtime.Object) (admission.Warnings, error) { +func (v *DeploymentCustomValidator) ValidateUpdate(_ context.Context, oldObj, newObj runtime.Object) (admission.Warnings, error) { deployment, ok := newObj.(*appsv1.Deployment) if !ok { return nil, fmt.Errorf("expected a Deployment object for the newObj but got %T", newObj) diff --git a/testdata/project-v4/internal/webhook/v1/issuer_webhook.go b/testdata/project-v4/internal/webhook/v1/issuer_webhook.go index 0577f525cc2..1ce37cdf796 100644 --- a/testdata/project-v4/internal/webhook/v1/issuer_webhook.go +++ b/testdata/project-v4/internal/webhook/v1/issuer_webhook.go @@ -54,7 +54,7 @@ type IssuerCustomDefaulter struct { var _ webhook.CustomDefaulter = &IssuerCustomDefaulter{} // Default implements webhook.CustomDefaulter so a webhook will be registered for the Kind Issuer. -func (d *IssuerCustomDefaulter) Default(ctx context.Context, obj runtime.Object) error { +func (d *IssuerCustomDefaulter) Default(_ context.Context, obj runtime.Object) error { issuer, ok := obj.(*certmanagerv1.Issuer) if !ok { diff --git a/testdata/project-v4/internal/webhook/v1/pod_webhook.go b/testdata/project-v4/internal/webhook/v1/pod_webhook.go index 99af588c106..16e5b3d80dc 100644 --- a/testdata/project-v4/internal/webhook/v1/pod_webhook.go +++ b/testdata/project-v4/internal/webhook/v1/pod_webhook.go @@ -54,7 +54,7 @@ type PodCustomDefaulter struct { var _ webhook.CustomDefaulter = &PodCustomDefaulter{} // Default implements webhook.CustomDefaulter so a webhook will be registered for the Kind Pod. -func (d *PodCustomDefaulter) Default(ctx context.Context, obj runtime.Object) error { +func (d *PodCustomDefaulter) Default(_ context.Context, obj runtime.Object) error { pod, ok := obj.(*corev1.Pod) if !ok { diff --git a/testdata/project-v4/test/utils/utils.go b/testdata/project-v4/test/utils/utils.go index 0cbd734083f..3277312e4d6 100644 --- a/testdata/project-v4/test/utils/utils.go +++ b/testdata/project-v4/test/utils/utils.go @@ -24,7 +24,7 @@ import ( "os/exec" "strings" - . "github.com/onsi/ginkgo/v2" //nolint:golint,revive + . "github.com/onsi/ginkgo/v2" //nolint:golint,revive,staticcheck ) const ( @@ -197,7 +197,7 @@ func GetProjectDir() (string, error) { if err != nil { return wd, err } - wd = strings.Replace(wd, "/test/e2e", "", -1) + wd = strings.ReplaceAll(wd, "/test/e2e", "") return wd, nil }