Skip to content

Commit 5d1f913

Browse files
committed
Upgrade golangci-lint to v2.4.0 and adjust linting configurations
Signed-off-by: wei-chenglai <[email protected]>
1 parent 979b909 commit 5d1f913

File tree

7 files changed

+104
-81
lines changed

7 files changed

+104
-81
lines changed

.golangci.yml

Lines changed: 97 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,14 @@
1-
linters-settings:
2-
gofmt:
3-
simplify: true
4-
gosec:
5-
excludes:
6-
- G601
7-
ginkgolinter:
8-
forbid-focus-container: true
9-
goimports:
10-
local-prefixes: github.com/ray-project/kuberay
11-
misspell:
12-
locale: US
13-
nolintlint:
14-
require-explanation: true
15-
require-specific: true
16-
revive:
17-
ignore-generated-header: true
18-
rules:
19-
- name: blank-imports
20-
- name: context-as-argument
21-
- name: context-keys-type
22-
- name: empty-block
23-
- name: error-naming
24-
- name: error-return
25-
- name: error-strings
26-
- name: errorf
27-
- name: exported
28-
disabled: true
29-
- name: if-return
30-
- name: increment-decrement
31-
- name: indent-error-flow
32-
- name: package-comments
33-
- name: range
34-
- name: receiver-naming
35-
- name: redefines-builtin-id
36-
- name: superfluous-else
37-
- name: time-naming
38-
- name: unexported-return
39-
- name: unreachable-code
40-
- name: unused-parameter
41-
- name: var-declaration
42-
- name: var-naming
43-
exclude:
44-
- "**/ray-operator/apis/config/v1alpha1/*.go"
45-
- "**/ray-operator/apis/ray/v1alpha1/*.go"
46-
- "**/ray-operator/apis/ray/v1/*.go"
47-
arguments:
48-
- ["ID", "JSON", "HTTP", "IP"] # AllowList
49-
- [] # DenyList
50-
- - upperCaseConst: true
51-
gocyclo:
52-
min-complexity: 15
53-
govet:
54-
enable:
55-
- fieldalignment
56-
lll:
57-
line-length: 120
58-
gci: # Splits all import blocks into different sections and sorts them.
59-
sections:
60-
- standard # Go official imports, like "fmt"
61-
- default # Third-party libraries (anything not in standard or prefix)
62-
- prefix(github.com/ray-project/kuberay) # kuberay packages
63-
skip-generated: true
1+
version: "2"
642
linters:
3+
default: none
654
enable:
665
- asciicheck
676
- errcheck
687
- errorlint
69-
- gci
708
- ginkgolinter
71-
# - gocyclo
72-
- gofmt
73-
- gofumpt
74-
- goimports
759
- gosec
76-
- gosimple
7710
- govet
7811
- ineffassign
79-
# - lll
8012
- makezero
8113
- misspell
8214
- nilerr
@@ -85,15 +17,106 @@ linters:
8517
- predeclared
8618
- revive
8719
- staticcheck
88-
- typecheck
20+
- testifylint
8921
- unconvert
9022
- unparam
9123
- unused
9224
- wastedassign
93-
- testifylint
94-
disable-all: true
25+
settings:
26+
staticcheck:
27+
checks:
28+
- all
29+
# Exclude the SA1019 check which checks the usage of deprecated fields.
30+
- "-SA1019"
31+
ginkgolinter:
32+
forbid-focus-container: true
33+
gocyclo:
34+
min-complexity: 15
35+
gosec:
36+
excludes:
37+
- G601
38+
govet:
39+
enable:
40+
- fieldalignment
41+
lll:
42+
line-length: 120
43+
misspell:
44+
locale: US
45+
nolintlint:
46+
require-explanation: true
47+
require-specific: true
48+
revive:
49+
rules:
50+
- name: blank-imports
51+
- name: context-as-argument
52+
- name: context-keys-type
53+
- name: empty-block
54+
- name: error-naming
55+
- name: error-return
56+
- name: error-strings
57+
- name: errorf
58+
- name: exported
59+
disabled: true
60+
- name: if-return
61+
- name: increment-decrement
62+
- name: indent-error-flow
63+
- name: package-comments
64+
- name: range
65+
- name: receiver-naming
66+
- name: redefines-builtin-id
67+
- name: superfluous-else
68+
- name: time-naming
69+
- name: unexported-return
70+
- name: unreachable-code
71+
- name: unused-parameter
72+
- name: var-declaration
73+
- name: var-naming
74+
arguments:
75+
- ["ID", "JSON", "HTTP", "IP"] # AllowList
76+
- [] # DenyList
77+
- - upperCaseConst: true
78+
exclude:
79+
- '**/ray-operator/apis/config/v1alpha1/*.go'
80+
- '**/ray-operator/apis/ray/v1alpha1/*.go'
81+
- '**/ray-operator/apis/ray/v1/*.go'
82+
exclusions:
83+
generated: strict
84+
presets:
85+
- comments
86+
- common-false-positives
87+
- legacy
88+
- std-error-handling
89+
paths:
90+
- third_party$
91+
- builtin$
92+
- examples$
93+
- _generated.go
9594
issues:
9695
max-issues-per-linter: 0
9796
max-same-issues: 0
97+
formatters:
98+
enable:
99+
- gci
100+
- gofmt
101+
- gofumpt
102+
- goimports
103+
settings:
104+
gci: # Splits all import blocks into different sections and sorts them.
105+
sections:
106+
- standard # Go official imports, like "fmt"
107+
- default # Third-party libraries (anything not in standard or prefix)
108+
- prefix(github.com/ray-project/kuberay) # kuberay packages
109+
gofmt:
110+
simplify: true
111+
goimports:
112+
local-prefixes:
113+
- github.com/ray-project/kuberay
114+
exclusions:
115+
generated: lax
116+
paths:
117+
- third_party$
118+
- builtin$
119+
- examples$
98120
run:
99-
timeout: 3m
121+
# timeout for analysis, e.g. 30s, 5m, default timeout is disabled
122+
timeout: 10m

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ repos:
4646
always_run: true
4747
pass_filenames: false
4848
additional_dependencies:
49-
- github.com/golangci/golangci-lint/cmd/golangci-lint@v1.64.8
49+
- github.com/golangci/golangci-lint/cmd/golangci-lint@v2.4.0
5050
- id: generate-crd-schema
5151
name: generate CRD schemas for use of kubeconform
5252
entry: ./scripts/generate-crd-schema.sh

apiserver/DEVELOPMENT.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Typing `make dev-tools` will download and install all of them. The `make clean-d
2222
| Software | Version | Link |
2323
| :------- | :------: | -----------------------------------------------------------------------:|
2424
| kind | v0.19.0 | [Install](https://kind.sigs.k8s.io/docs/user/quick-start/#installation) |
25-
| golangci-lint | v1.64.8 | [Install](https://golangci-lint.run/usage/install/) |
25+
| golangci-lint | v2.4.0 | [Install](https://golangci-lint.run/usage/install/) |
2626
| kustomize | v3.8.7 | [install](https://kubectl.docs.kubernetes.io/installation/kustomize/) |
2727
| gofumpt | v0.3.1 | To install `go install mvdan.cc/[email protected]` |
2828
| goimports | latest | To install `go install golang.org/x/tools/cmd/goimports@latest` |

apiserver/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ imports: goimports ## Run goimports against code.
8787
.PHONY: lint
8888
lint: golangci-lint fmt vet fumpt imports ## Run the linter.
8989
# exclude the SA1019 check which checks the usage of deprecated fields.
90-
test -s $(GOLANGCI_LINT) || ($(GOLANGCI_LINT) run --timeout=3m --exclude='SA1019' --no-config --allow-parallel-runners)
90+
test -s $(GOLANGCI_LINT) || ($(GOLANGCI_LINT) run --timeout=3m --no-config --allow-parallel-runners)
9191

9292
build: fmt vet fumpt imports ## Build api server binary.
9393
go build -o ${REPO_ROOT_BIN}/kuberay-apiserver cmd/main.go
@@ -248,7 +248,7 @@ MOCKGEN = $(REPO_ROOT_BIN)/mockgen
248248
KUSTOMIZE_VERSION ?= v5.4.3
249249
GOFUMPT_VERSION ?= v0.3.1
250250
GOIMPORTS_VERSION ?= v0.14.0
251-
GOLANGCI_LINT_VERSION ?= v1.64.8
251+
GOLANGCI_LINT_VERSION ?= v2.4.0
252252
KIND_VERSION ?= v0.19.0
253253
GOBINDATA_VERSION ?= v4.0.2
254254
MOCKGEN_VERSION ?= v1.6.0

apiserversdk/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ golangci-lint: ## Download golangci_lint locally if necessary.
2626
.PHONY: lint
2727
lint: golangci-lint fmt vet ## Run the linter.
2828
# exclude the SA1019 check which checks the usage of deprecated fields.
29-
test -s $(GOLANGCI_LINT) || ($(GOLANGCI_LINT) run --timeout=3m --exclude='SA1019' --no-config --allow-parallel-runners)
29+
test -s $(GOLANGCI_LINT) || ($(GOLANGCI_LINT) run --timeout=3m --no-config --allow-parallel-runners)
3030

3131
test: WHAT ?= $(shell go list ./... | grep -v /test/)
3232
test: ENVTEST_K8S_VERSION ?= 1.24.2

experimental/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ GOBINDATA ?= $(REPO_ROOT_BIN)/go-bindata
8585
## Tool Versions
8686
GOFUMPT_VERSION ?= v0.3.1
8787
GOIMPORTS_VERSION ?= v0.14.0
88-
GOLANGCI_LINT_VERSION ?= v1.64.8
88+
GOLANGCI_LINT_VERSION ?= v2.4.0
8989
KIND_VERSION ?= v0.19.0
9090
GOBINDATA_VERSION ?= v4.0.2
9191

scripts/lint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ dirs_to_lint="ray-operator kubectl-plugin apiserver apiserversdk"
77
for dir in $dirs_to_lint; do
88
pushd "$dir"
99
# exclude the SA1019 check which checks the usage of deprecated fields.
10-
golangci-lint run --fix --exclude-files _generated.go --exclude='SA1019' --timeout 10m0s
10+
golangci-lint run --fix --timeout 10m0s
1111
popd
1212
done

0 commit comments

Comments
 (0)