diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 88202180b..ef3c61b1d 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -31,8 +31,8 @@ jobs: with: go-version: ${{ steps.vars.outputs.go_version }} - name: golangci-lint - uses: golangci/golangci-lint-action@55c2c1448f86e01eaae002a5a3a9624417608d84 # tag=v6.5.2 + uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # tag=v8.0.0 with: - version: v1.64.8 - args: --out-format=colored-line-number + version: v2.1.6 + args: --output.text.print-linter-name=true --output.text.colors=true --timeout 10m working-directory: ${{matrix.working-directory}} diff --git a/.golangci.yml b/.golangci.yml index 112ae58ad..58706c462 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,14 +1,12 @@ +version: "2" run: - allow-parallel-runners: true - modules-download-mode: readonly - # Increase the default deadline from 1m as some module operations can take a - # while if uncached! - timeout: 10m go: "1.24" - + timeout: 10m + modules-download-mode: readonly + allow-parallel-runners: true linters: # sync from https://github.com/kubernetes-sigs/controller-runtime/blob/main/.golangci.yml - disable-all: true + default: none enable: - asasalint - asciicheck @@ -25,10 +23,7 @@ linters: - goconst - gocritic - gocyclo - - gofmt - - goimports - goprintffuncname - - gosimple - govet - importas - ineffassign @@ -40,74 +35,95 @@ linters: - prealloc - revive - staticcheck - - stylecheck - tagliatelle - - typecheck - unconvert - unparam - unused - whitespace - -issues: - exclude-rules: - # Dot imports for gomega and ginkgo are allowed - # within test files. - - path: _test\.go - text: should not use dot imports - # Ignore error type switch case - - path: "pkg/loader/loader.go" - linters: - - errorlint - # Ignore test files - - linters: - - dupl - - ginkgolinter - path: _test\.go - - linters: - - gocritic - path: "pkg/markers/help.go" - - linters: - - exhaustive - path: "pkg/markers/parse.go|pkg/deepcopy/traverse.go|pkg/genall/help/types.go|pkg/crd/schema.go|pkg/crd/flatten.go" - # Ignore consider pre-allocating variables - - linters: - - prealloc - text: Consider pre-allocating -linters-settings: - govet: - enable-all: true - disable: - - fieldalignment - - shadow - importas: - no-unaliased: true - revive: - # By default, revive will enable only the linting rules that are named in the configuration file. - # So, it's needed to explicitly enable all required rules here. + settings: + govet: + disable: + - fieldalignment + - shadow + enable-all: true + importas: + no-unaliased: true + revive: + # By default, revive will enable only the linting rules that are named in the configuration file. + # So, it's needed to explicitly enable all required rules here. + 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 + - name: error-return + - name: error-strings + - name: error-naming + - name: if-return + - name: increment-decrement + - name: var-naming + - name: var-declaration + - name: range + - name: receiver-naming + - name: time-naming + - name: unexported-return + - name: indent-error-flow + - name: errorf + - name: superfluous-else + - name: unreachable-code + - name: redefines-builtin-id + # + # Rules in addition to the recommended configuration above. + # + - name: bool-literal-in-expr + - name: constant-logical-expr + exclusions: + generated: strict + paths: + - zz_generated.*\.go$ + - .*conversion.*\.go$ + presets: + - comments + - common-false-positives + - legacy + - std-error-handling 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 - - name: error-return - - name: error-strings - - name: error-naming - - name: if-return - - name: increment-decrement - - name: var-naming - - name: var-declaration - - name: range - - name: receiver-naming - - name: time-naming - - name: unexported-return - - name: indent-error-flow - - name: errorf - - name: superfluous-else - - name: unreachable-code - - name: redefines-builtin-id - # - # Rules in addition to the recommended configuration above. - # - - name: bool-literal-in-expr - - name: constant-logical-expr + # Dot imports for gomega and ginkgo are allowed + # within test files. + - linters: + - revive + path: _test\.go + text: should not use dot imports + # Ignore error type switch case + - linters: + - errorlint + path: pkg/loader/loader.go + # Ignore test files + - linters: + - dupl + - ginkgolinter + path: _test\.go + - linters: + - gocritic + path: pkg/markers/help.go + - linters: + - exhaustive + path: pkg/markers/parse.go|pkg/deepcopy/traverse.go|pkg/genall/help/types.go|pkg/crd/schema.go|pkg/crd/flatten.go + # Ignore consider pre-allocating variables + - linters: + - prealloc + text: Consider pre-allocating + - linters: + - staticcheck + path: (.+)\.go$ + text: (QF1008) +formatters: + enable: + - gofmt + - goimports + exclusions: + generated: strict + paths: + - zz_generated.*\.go$ + - .*conversion.*\.go$ diff --git a/Makefile b/Makefile index 570d5f956..48df4470e 100644 --- a/Makefile +++ b/Makefile @@ -63,7 +63,7 @@ GO_INSTALL := ./hack/go-install.sh GOLANGCI_LINT_BIN := golangci-lint GOLANGCI_LINT_VER := $(shell cat .github/workflows/golangci-lint.yml | grep [[:space:]]version: | sed 's/.*version: //') GOLANGCI_LINT := $(abspath $(TOOLS_BIN_DIR)/$(GOLANGCI_LINT_BIN)-$(GOLANGCI_LINT_VER)) -GOLANGCI_LINT_PKG := github.com/golangci/golangci-lint/cmd/golangci-lint +GOLANGCI_LINT_PKG := github.com/golangci/golangci-lint/v2/cmd/golangci-lint $(GOLANGCI_LINT): # Build golangci-lint from tools folder. GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) $(GOLANGCI_LINT_PKG) $(GOLANGCI_LINT_BIN) $(GOLANGCI_LINT_VER) diff --git a/pkg/markers/parse.go b/pkg/markers/parse.go index f42dec0cf..f75f21295 100644 --- a/pkg/markers/parse.go +++ b/pkg/markers/parse.go @@ -868,11 +868,8 @@ func (d *Definition) Parse(rawMarker string) (interface{}, error) { seen[""] = struct{}{} // mark as seen for strict definitions } else if !d.Empty() && scanner.Peek() != sc.EOF { // if we expect *and* actually have arguments passed - for { - // parse the argument name - if !expect(scanner, sc.Ident, "argument name") { - break - } + // parse the argument name + for expect(scanner, sc.Ident, "argument name") { argName := scanner.TokenText() if !expect(scanner, '=', "equals") { break