Skip to content

Commit 14db0c0

Browse files
authored
bump linter to v2 (#1721)
* bump to latest v1 linter prep for v2 Fixes #1719 upgrade to latest v1 linter which support go1.23 Signed-off-by: Tiger Kaovilai <[email protected]> * updated lint to v2.1.2 run bin/golang-ci-lint migrate v2 linter configuration Fixes #1713 Signed-off-by: Tiger Kaovilai <[email protected]> --------- Signed-off-by: Tiger Kaovilai <[email protected]>
1 parent 538bd23 commit 14db0c0

File tree

2 files changed

+91
-107
lines changed

2 files changed

+91
-107
lines changed

.golangci.yaml

Lines changed: 79 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -1,127 +1,102 @@
1-
# Documentation reference https://github.com/golangci/golangci-lint/blob/v1.55.2/.golangci.reference.yml
1+
version: "2"
22
run:
3-
skip-dirs-use-default: false
43
modules-download-mode: readonly
54
allow-parallel-runners: false
6-
7-
output:
8-
format: colored-line-number
9-
print-issued-lines: true
10-
print-linter-name: true
11-
uniq-by-line: true
12-
sort-results: true
13-
14-
linters-settings:
15-
dogsled:
16-
max-blank-identifiers: 2
17-
errcheck:
18-
check-type-assertions: true
19-
check-blank: true
20-
gci:
21-
sections:
22-
- standard
23-
- default
24-
- prefix(github.com/openshift/oadp-operator)
25-
goconst:
26-
min-len: 3
27-
min-occurrences: 5
28-
gofmt:
29-
simplify: true
30-
goheader:
31-
# copy from ./hack/boilerplate.go.txt
32-
template: |-
33-
Copyright 2021.
34-
35-
Licensed under the Apache License, Version 2.0 (the "License");
36-
you may not use this file except in compliance with the License.
37-
You may obtain a copy of the License at
38-
39-
http://www.apache.org/licenses/LICENSE-2.0
40-
41-
Unless required by applicable law or agreed to in writing, software
42-
distributed under the License is distributed on an "AS IS" BASIS,
43-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
44-
See the License for the specific language governing permissions and
45-
limitations under the License.
46-
govet:
47-
enable-all: true
48-
misspell:
49-
locale: US
50-
nakedret:
51-
max-func-lines: 30
52-
nolintlint:
53-
allow-unused: false
54-
allow-no-explanation: []
55-
require-explanation: true
56-
require-specific: true
57-
revive:
58-
# TODO enable!
59-
# enable-all-rules: true
60-
rules:
61-
- name: line-length-limit
62-
disabled: true
63-
# TODO delete after
64-
- name: blank-imports
65-
- name: dot-imports
66-
- name: duplicated-imports
67-
- name: import-alias-naming
68-
- name: import-shadowing
69-
- name: redundant-import-alias
70-
unparam:
71-
check-exported: true
72-
735
linters:
74-
disable-all: true
75-
# TODO enable commented ones
6+
default: none
767
enable:
778
- asasalint
789
- asciicheck
7910
- bidichk
80-
# - bodyclose
8111
- dogsled
82-
# - dupword
83-
# - durationcheck
84-
# - errcheck
8512
- errchkjson
86-
- exportloopref
87-
- gci
88-
# - ginkgolinter
89-
# - goconst
90-
- gofmt
91-
# - goheader
9213
- goprintffuncname
93-
# - gosec
94-
# - gosimple
95-
# - govet
96-
# - ineffassign
9714
- loggercheck
98-
# - misspell
9915
- nakedret
100-
# - nilerr
101-
# - noctx
10216
- nolintlint
10317
- nosprintfhostport
10418
- revive
105-
# - staticcheck
106-
# - stylecheck
107-
# - unconvert
10819
- unparam
109-
# - unused
11020
- usestdlibvars
111-
fast: false
21+
settings:
22+
dogsled:
23+
max-blank-identifiers: 2
24+
errcheck:
25+
check-type-assertions: true
26+
check-blank: true
27+
goconst:
28+
min-len: 3
29+
min-occurrences: 5
30+
goheader:
31+
template: |-
32+
Copyright 2021.
33+
34+
Licensed under the Apache License, Version 2.0 (the "License");
35+
you may not use this file except in compliance with the License.
36+
You may obtain a copy of the License at
11237
38+
http://www.apache.org/licenses/LICENSE-2.0
39+
40+
Unless required by applicable law or agreed to in writing, software
41+
distributed under the License is distributed on an "AS IS" BASIS,
42+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
43+
See the License for the specific language governing permissions and
44+
limitations under the License.
45+
govet:
46+
enable-all: true
47+
misspell:
48+
locale: US
49+
nakedret:
50+
max-func-lines: 30
51+
nolintlint:
52+
require-explanation: true
53+
require-specific: true
54+
allow-unused: false
55+
revive:
56+
rules:
57+
- name: line-length-limit
58+
disabled: true
59+
- name: blank-imports
60+
- name: dot-imports
61+
- name: duplicated-imports
62+
- name: import-alias-naming
63+
- name: import-shadowing
64+
- name: redundant-import-alias
65+
unparam:
66+
check-exported: true
67+
exclusions:
68+
generated: lax
69+
rules:
70+
- linters:
71+
- revive
72+
text: '^struct-tag: unknown option ''inline'' in JSON tag$'
73+
- linters:
74+
- staticcheck
75+
text: 'ST1000:|ST1020:|ST1021:|ST1022:'
76+
paths:
77+
- third_party$
78+
- builtin$
79+
- examples$
11380
issues:
114-
exclude-use-default: false
115-
exclude-rules:
116-
- linters:
117-
- revive
118-
text: "^struct-tag: unknown option 'inline' in JSON tag$"
119-
- linters:
120-
- stylecheck
121-
text: "ST1000:|ST1020:|ST1021:|ST1022:"
12281
max-issues-per-linter: 0
12382
max-same-issues: 0
124-
12583
severity:
126-
default-severity: error
127-
case-sensitive: false
84+
default: error
85+
formatters:
86+
enable:
87+
- gci
88+
- gofmt
89+
settings:
90+
gci:
91+
sections:
92+
- standard
93+
- default
94+
- prefix(github.com/openshift/oadp-operator)
95+
gofmt:
96+
simplify: true
97+
exclusions:
98+
generated: lax
99+
paths:
100+
- third_party$
101+
- builtin$
102+
- examples$

Makefile

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,21 @@ test: vet envtest ## Run unit tests; run Go linters checks; check if api and bun
140140
@make bundle-isupdated
141141
@make check-go-dependencies
142142

143+
# Extract the toolchain directive from go.mod
144+
GO_TOOLCHAIN_VERSION := $(shell grep -E "^toolchain" go.mod | awk '{print $$2}')
145+
146+
# Lint CLI needs to be built from the same toolchain version
143147
GOLANGCI_LINT = $(shell pwd)/bin/golangci-lint
144-
GOLANGCI_LINT_VERSION ?= v1.55.2
145-
.PHONY: golangci-lint
148+
GOLANGCI_LINT_VERSION ?= v2.1.2
149+
.PHONY: golangci-lint $(GOLANGCI_LINT)
146150
golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
147151
$(GOLANGCI_LINT): $(LOCALBIN)
148-
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION))
152+
@if [ -f $(GOLANGCI_LINT) ] && $(GOLANGCI_LINT) --version | grep -q $(GOLANGCI_LINT_VERSION); then \
153+
echo "golangci-lint $(GOLANGCI_LINT_VERSION) is already installed"; \
154+
else \
155+
echo "Installing golangci-lint $(GOLANGCI_LINT_VERSION)"; \
156+
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)); \
157+
fi
149158

150159
.PHONY: lint
151160
lint: golangci-lint ## Run Go linters checks against all project's Go files.

0 commit comments

Comments
 (0)