From d2a85d9e0b4379047f4c2966568d70b38fee17b7 Mon Sep 17 00:00:00 2001 From: wei-chenglai Date: Thu, 28 Aug 2025 21:03:25 -0400 Subject: [PATCH] Upgrade golangci-lint to v2.4.0 and adjust linting configurations Signed-off-by: wei-chenglai --- .golangci.yml | 171 ++++++++++++++++++++++----------------- .pre-commit-config.yaml | 2 +- apiserver/DEVELOPMENT.md | 2 +- apiserver/Makefile | 4 +- apiserversdk/Makefile | 2 +- experimental/Makefile | 2 +- scripts/lint.sh | 2 +- 7 files changed, 104 insertions(+), 81 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 34b316b3797..82cbd43f598 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,82 +1,14 @@ -linters-settings: - gofmt: - simplify: true - gosec: - excludes: - - G601 - ginkgolinter: - forbid-focus-container: true - goimports: - local-prefixes: github.com/ray-project/kuberay - misspell: - locale: US - nolintlint: - require-explanation: true - require-specific: true - revive: - ignore-generated-header: true - rules: - - name: blank-imports - - name: context-as-argument - - name: context-keys-type - - name: empty-block - - name: error-naming - - name: error-return - - name: error-strings - - name: errorf - - name: exported - disabled: true - - name: if-return - - name: increment-decrement - - name: indent-error-flow - - name: package-comments - - name: range - - name: receiver-naming - - name: redefines-builtin-id - - name: superfluous-else - - name: time-naming - - name: unexported-return - - name: unreachable-code - - name: unused-parameter - - name: var-declaration - - name: var-naming - exclude: - - "**/ray-operator/apis/config/v1alpha1/*.go" - - "**/ray-operator/apis/ray/v1alpha1/*.go" - - "**/ray-operator/apis/ray/v1/*.go" - arguments: - - ["ID", "JSON", "HTTP", "IP"] # AllowList - - [] # DenyList - - - upperCaseConst: true - gocyclo: - min-complexity: 15 - govet: - enable: - - fieldalignment - lll: - line-length: 120 - gci: # Splits all import blocks into different sections and sorts them. - sections: - - standard # Go official imports, like "fmt" - - default # Third-party libraries (anything not in standard or prefix) - - prefix(github.com/ray-project/kuberay) # kuberay packages - skip-generated: true +version: "2" linters: + default: none enable: - asciicheck - errcheck - errorlint - - gci - ginkgolinter -# - gocyclo - - gofmt - - gofumpt - - goimports - gosec - - gosimple - govet - ineffassign -# - lll - makezero - misspell - nilerr @@ -85,15 +17,106 @@ linters: - predeclared - revive - staticcheck - - typecheck + - testifylint - unconvert - unparam - unused - wastedassign - - testifylint - disable-all: true + settings: + staticcheck: + checks: + - all + # Exclude the SA1019 check which checks the usage of deprecated fields. + - "-SA1019" + ginkgolinter: + forbid-focus-container: true + gocyclo: + min-complexity: 15 + gosec: + excludes: + - G601 + govet: + enable: + - fieldalignment + lll: + line-length: 120 + misspell: + locale: US + nolintlint: + require-explanation: true + require-specific: true + revive: + rules: + - name: blank-imports + - name: context-as-argument + - name: context-keys-type + - name: empty-block + - name: error-naming + - name: error-return + - name: error-strings + - name: errorf + - name: exported + disabled: true + - name: if-return + - name: increment-decrement + - name: indent-error-flow + - name: package-comments + - name: range + - name: receiver-naming + - name: redefines-builtin-id + - name: superfluous-else + - name: time-naming + - name: unexported-return + - name: unreachable-code + - name: unused-parameter + - name: var-declaration + - name: var-naming + arguments: + - ["ID", "JSON", "HTTP", "IP"] # AllowList + - [] # DenyList + - - upperCaseConst: true + exclude: + - '**/ray-operator/apis/config/v1alpha1/*.go' + - '**/ray-operator/apis/ray/v1alpha1/*.go' + - '**/ray-operator/apis/ray/v1/*.go' + exclusions: + generated: strict + presets: + - comments + - common-false-positives + - legacy + - std-error-handling + paths: + - third_party$ + - builtin$ + - examples$ + - _generated.go issues: max-issues-per-linter: 0 max-same-issues: 0 +formatters: + enable: + - gci + - gofmt + - gofumpt + - goimports + settings: + gci: # Splits all import blocks into different sections and sorts them. + sections: + - standard # Go official imports, like "fmt" + - default # Third-party libraries (anything not in standard or prefix) + - prefix(github.com/ray-project/kuberay) # kuberay packages + gofmt: + simplify: true + goimports: + local-prefixes: + - github.com/ray-project/kuberay + exclusions: + generated: lax + paths: + - third_party$ + - builtin$ + - examples$ run: - timeout: 3m + # timeout for analysis, e.g. 30s, 5m, default timeout is disabled + timeout: 10m diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3678c3052fc..e3bbd85799c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -46,7 +46,7 @@ repos: always_run: true pass_filenames: false additional_dependencies: - - github.com/golangci/golangci-lint/cmd/golangci-lint@v1.64.8 + - github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.4.0 - id: generate-crd-schema name: generate CRD schemas for use of kubeconform entry: ./scripts/generate-crd-schema.sh diff --git a/apiserver/DEVELOPMENT.md b/apiserver/DEVELOPMENT.md index 61b38ea8605..b7a5ec53f5f 100644 --- a/apiserver/DEVELOPMENT.md +++ b/apiserver/DEVELOPMENT.md @@ -22,7 +22,7 @@ Typing `make dev-tools` will download and install all of them. The `make clean-d | Software | Version | Link | | :------- | :------: | -----------------------------------------------------------------------:| | kind | v0.19.0 | [Install](https://kind.sigs.k8s.io/docs/user/quick-start/#installation) | -| golangci-lint | v1.64.8 | [Install](https://golangci-lint.run/usage/install/) | +| golangci-lint | v2.4.0 | [Install](https://golangci-lint.run/usage/install/) | | kustomize | v3.8.7 | [install](https://kubectl.docs.kubernetes.io/installation/kustomize/) | | gofumpt | v0.3.1 | To install `go install mvdan.cc/gofumpt@v0.3.1` | | goimports | latest | To install `go install golang.org/x/tools/cmd/goimports@latest` | diff --git a/apiserver/Makefile b/apiserver/Makefile index 617d96bf02a..c0e96021f0c 100644 --- a/apiserver/Makefile +++ b/apiserver/Makefile @@ -87,7 +87,7 @@ imports: goimports ## Run goimports against code. .PHONY: lint lint: golangci-lint fmt vet fumpt imports ## Run the linter. # exclude the SA1019 check which checks the usage of deprecated fields. - test -s $(GOLANGCI_LINT) || ($(GOLANGCI_LINT) run --timeout=3m --exclude='SA1019' --no-config --allow-parallel-runners) + test -s $(GOLANGCI_LINT) || ($(GOLANGCI_LINT) run --timeout=3m --no-config --allow-parallel-runners) build: fmt vet fumpt imports ## Build api server binary. go build -o ${REPO_ROOT_BIN}/kuberay-apiserver cmd/main.go @@ -248,7 +248,7 @@ MOCKGEN = $(REPO_ROOT_BIN)/mockgen KUSTOMIZE_VERSION ?= v5.4.3 GOFUMPT_VERSION ?= v0.3.1 GOIMPORTS_VERSION ?= v0.14.0 -GOLANGCI_LINT_VERSION ?= v1.64.8 +GOLANGCI_LINT_VERSION ?= v2.4.0 KIND_VERSION ?= v0.19.0 GOBINDATA_VERSION ?= v4.0.2 MOCKGEN_VERSION ?= v1.6.0 diff --git a/apiserversdk/Makefile b/apiserversdk/Makefile index 065636cb66d..746da2967b3 100644 --- a/apiserversdk/Makefile +++ b/apiserversdk/Makefile @@ -26,7 +26,7 @@ golangci-lint: ## Download golangci_lint locally if necessary. .PHONY: lint lint: golangci-lint fmt vet ## Run the linter. # exclude the SA1019 check which checks the usage of deprecated fields. - test -s $(GOLANGCI_LINT) || ($(GOLANGCI_LINT) run --timeout=3m --exclude='SA1019' --no-config --allow-parallel-runners) + test -s $(GOLANGCI_LINT) || ($(GOLANGCI_LINT) run --timeout=3m --no-config --allow-parallel-runners) test: WHAT ?= $(shell go list ./... | grep -v /test/) test: ENVTEST_K8S_VERSION ?= 1.24.2 diff --git a/experimental/Makefile b/experimental/Makefile index 1b36a2d6a28..3a783caf9ad 100644 --- a/experimental/Makefile +++ b/experimental/Makefile @@ -85,7 +85,7 @@ GOBINDATA ?= $(REPO_ROOT_BIN)/go-bindata ## Tool Versions GOFUMPT_VERSION ?= v0.3.1 GOIMPORTS_VERSION ?= v0.14.0 -GOLANGCI_LINT_VERSION ?= v1.64.8 +GOLANGCI_LINT_VERSION ?= v2.4.0 KIND_VERSION ?= v0.19.0 GOBINDATA_VERSION ?= v4.0.2 diff --git a/scripts/lint.sh b/scripts/lint.sh index 3d2515ec607..f00c491df67 100755 --- a/scripts/lint.sh +++ b/scripts/lint.sh @@ -7,6 +7,6 @@ dirs_to_lint="ray-operator kubectl-plugin apiserver apiserversdk" for dir in $dirs_to_lint; do pushd "$dir" # exclude the SA1019 check which checks the usage of deprecated fields. - golangci-lint run --fix --exclude-files _generated.go --exclude='SA1019' --timeout 10m0s + golangci-lint run --fix --timeout 10m0s popd done