Skip to content

✨Update golangci-lint to v2.0.2 and adjust configuration #4752

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/lint-sample.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
158 changes: 83 additions & 75 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -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$
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
67 changes: 40 additions & 27 deletions docs/book/src/cronjob-tutorial/testdata/project/.golangci.yml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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$
4 changes: 2 additions & 2 deletions docs/book/src/cronjob-tutorial/testdata/project/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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
}

Expand Down
Loading