Skip to content

Commit 702eeba

Browse files
author
tazhate
committed
fix(lint): migrate to golangci-lint v2, fix all lint issues
- Migrated .golangci.yml to v2 format (version: "2", formatters section, linters.exclusions.rules instead of issues.exclude-rules) - Updated CI workflow to golangci-lint-action@v7 + v2.11.4 (go1.26 build, supports go 1.25 directive from go.mod) - Removed gosimple (merged into staticcheck in v2), gofmt moved to formatters - Fixed errcheck: fmt.Sscanf → _, _ = fmt.Sscanf in evm.go, cosmos.go, helpers.go - Fixed errcheck: os.Setenv → _ = os.Setenv in reconcile_configmap.go - Fixed errcheck: added Body.Close exclude in errcheck settings - Removed 11 unused alias methods in controller (resolveImage, setPhase, updateAnnotations, updateStatus, isLagging, checkHeightStall, handleDegradedAutoRestart, calcSyncETA, checkRolloutHealth, detectCrashLoop, performRollback) — all were dead code forwarding to renamed functions - Removed unused logger param from restartIfDegradedTooLong - Fixed prealloc in reconcile_statefulset.go (mounts, vols) - Fixed staticcheck QF1002: tagged switch in registry/client.go - Fixed staticcheck QF1004: strings.ReplaceAll in test/utils/utils.go - Added nolint:unparam to tcpProbe/httpProbe (intentional flexible params) - Fixed gofmt issues in reconcile_health.go, upgrade.go, dashboard/server.go Context: ran golangci-lint locally, found binary was broken (JSON parse error), downloaded official v2.11.4 binary, migrated config, iterated through 156→0 issues.
1 parent 00fe4ca commit 702eeba

16 files changed

Lines changed: 71 additions & 144 deletions

File tree

.github/workflows/lint.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ jobs:
1818
go-version-file: go.mod
1919

2020
- name: Run linter
21-
uses: golangci/golangci-lint-action@v6
21+
uses: golangci/golangci-lint-action@v7
2222
with:
23-
version: v1.63.4
23+
version: v2.11.4

.golangci.yml

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,17 @@
1+
version: "2"
2+
13
run:
24
timeout: 5m
3-
allow-parallel-runners: true
45

5-
issues:
6-
# don't skip warning about doc comments
7-
# don't exclude the default set of lint
8-
exclude-use-default: false
9-
# restore some of the defaults
10-
# (fill in the rest as needed)
11-
exclude-rules:
12-
- path: "api/*"
13-
linters:
14-
- lll
15-
- path: "internal/*"
16-
linters:
17-
- dupl
18-
- lll
196
linters:
20-
disable-all: true
7+
default: none
218
enable:
229
- dupl
2310
- errcheck
2411
- copyloopvar
2512
- ginkgolinter
2613
- goconst
2714
- gocyclo
28-
- gofmt
29-
- goimports
30-
- gosimple
3115
- govet
3216
- ineffassign
3317
- lll
@@ -36,12 +20,39 @@ linters:
3620
- prealloc
3721
- revive
3822
- staticcheck
39-
- typecheck
4023
- unconvert
4124
- unparam
4225
- unused
43-
44-
linters-settings:
45-
revive:
26+
settings:
27+
errcheck:
28+
exclude-functions:
29+
- (io.Closer).Close
30+
- (io.ReadCloser).Close
31+
revive:
32+
rules:
33+
- name: comment-spacings
34+
exclusions:
4635
rules:
47-
- name: comment-spacings
36+
- path: "api/"
37+
linters:
38+
- lll
39+
- path: "internal/"
40+
linters:
41+
- dupl
42+
- lll
43+
- goconst
44+
- gocyclo
45+
- path: "_test\\.go"
46+
linters:
47+
- goconst
48+
- errcheck
49+
- dupl
50+
- unparam
51+
- copyloopvar
52+
- prealloc
53+
- staticcheck
54+
55+
formatters:
56+
enable:
57+
- gofmt
58+
- goimports

cmd/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import (
4242
nodesv1alpha1 "github.com/tazhate/blockchain-node-operator/api/v1alpha1"
4343
"github.com/tazhate/blockchain-node-operator/internal/controller"
4444
"github.com/tazhate/blockchain-node-operator/internal/health"
45+
4546
// Register all chain adapters via init().
4647
_ "github.com/tazhate/blockchain-node-operator/internal/adapters"
4748
// +kubebuilder:scaffold:imports

go.mod

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@ module github.com/tazhate/blockchain-node-operator
22

33
go 1.25.0
44

5-
godebug default=go1.23
6-
75
require (
86
github.com/onsi/ginkgo/v2 v2.21.0
97
github.com/onsi/gomega v1.35.1
108
github.com/prometheus/client_golang v1.19.1
9+
golang.org/x/mod v0.35.0
1110
k8s.io/api v0.32.0
1211
k8s.io/apimachinery v0.32.0
1312
k8s.io/client-go v0.32.0
@@ -71,7 +70,6 @@ require (
7170
go.uber.org/multierr v1.11.0 // indirect
7271
go.uber.org/zap v1.27.0 // indirect
7372
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect
74-
golang.org/x/mod v0.35.0 // indirect
7573
golang.org/x/net v0.52.0 // indirect
7674
golang.org/x/oauth2 v0.23.0 // indirect
7775
golang.org/x/sync v0.20.0 // indirect

go.sum

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -167,34 +167,24 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn
167167
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
168168
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
169169
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
170-
golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4=
171-
golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU=
172170
golang.org/x/net v0.52.0 h1:He/TN1l0e4mmR3QqHMT2Xab3Aj3L9qjbhRm78/6jrW0=
173171
golang.org/x/net v0.52.0/go.mod h1:R1MAz7uMZxVMualyPXb+VaqGSa3LIaUqk0eEt3w36Sw=
174172
golang.org/x/oauth2 v0.23.0 h1:PbgcYx2W7i4LvjJWEbf0ngHV6qJYr86PkAV3bXdLEbs=
175173
golang.org/x/oauth2 v0.23.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
176174
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
177175
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
178176
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
179-
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
180-
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
181177
golang.org/x/sync v0.20.0 h1:e0PTpb7pjO8GAtTs2dQ6jYa5BWYlMuX047Dco/pItO4=
182178
golang.org/x/sync v0.20.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
183179
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
184180
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
185181
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
186-
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
187-
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
188182
golang.org/x/sys v0.42.0 h1:omrd2nAlyT5ESRdCLYdm3+fMfNFE/+Rf4bDIQImRJeo=
189183
golang.org/x/sys v0.42.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
190-
golang.org/x/term v0.25.0 h1:WtHI/ltw4NvSUig5KARz9h521QvRC8RmF/cuYqifU24=
191-
golang.org/x/term v0.25.0/go.mod h1:RPyXicDX+6vLxogjjRxjgD2TKtmAO6NZBsBRfrOLu7M=
192184
golang.org/x/term v0.41.0 h1:QCgPso/Q3RTJx2Th4bDLqML4W6iJiaXFq2/ftQF13YU=
193185
golang.org/x/term v0.41.0/go.mod h1:3pfBgksrReYfZ5lvYM0kSO0LIkAl4Yl2bXOkKP7Ec2A=
194186
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
195187
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
196-
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=
197-
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
198188
golang.org/x/text v0.35.0 h1:JOVx6vVDFokkpaq1AEptVzLTpDe9KGpj5tR4/X+ybL8=
199189
golang.org/x/text v0.35.0/go.mod h1:khi/HExzZJ2pGnjenulevKNX1W67CUy0AsXcNubPGCA=
200190
golang.org/x/time v0.7.0 h1:ntUhktv3OPE6TgYxXWv9vKvUSJyIFJlyohwbkEwPrKQ=
@@ -203,8 +193,6 @@ golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGm
203193
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
204194
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
205195
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
206-
golang.org/x/tools v0.26.0 h1:v/60pFQmzmT9ExmjDv2gGIfi3OqfKoEP6I5+umXlbnQ=
207-
golang.org/x/tools v0.26.0/go.mod h1:TPVVj70c7JJ3WCazhD8OdXcZg/og+b9+tH/KxylGwH0=
208196
golang.org/x/tools v0.43.0 h1:12BdW9CeB3Z+J/I/wj34VMl8X+fEXBxVR90JeMX5E7s=
209197
golang.org/x/tools v0.43.0/go.mod h1:uHkMso649BX2cZK6+RpuIPXS3ho2hZo4FVwfoy1vIk0=
210198
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

internal/adapters/base.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func (b baseAdapter) LivenessProbe(_ nodesv1alpha1.BlockchainNodeSpec) *corev1.P
2929
// --------------------------------------------------------------------------
3030

3131
// tcpProbe builds a TCPSocket probe with the given parameters.
32-
func tcpProbe(port, initialDelay, period, timeout, failureThreshold int32) *corev1.Probe {
32+
func tcpProbe(port, initialDelay, period, timeout, failureThreshold int32) *corev1.Probe { //nolint:unparam
3333
return &corev1.Probe{
3434
ProbeHandler: corev1.ProbeHandler{
3535
TCPSocket: &corev1.TCPSocketAction{
@@ -44,7 +44,7 @@ func tcpProbe(port, initialDelay, period, timeout, failureThreshold int32) *core
4444
}
4545

4646
// httpProbe builds an HTTPGet probe with the given parameters.
47-
func httpProbe(path string, port, initialDelay, period, timeout, failureThreshold int32) *corev1.Probe {
47+
func httpProbe(path string, port, initialDelay, period, timeout, failureThreshold int32) *corev1.Probe { //nolint:unparam
4848
return &corev1.Probe{
4949
ProbeHandler: corev1.ProbeHandler{
5050
HTTPGet: &corev1.HTTPGetAction{

internal/adapters/cosmos.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,6 @@ func cosmosNetworkTip(ctx context.Context, rpcURL string) int64 {
316316
}
317317
// HeightRoundStep is formatted as "30178804/0/1"
318318
var h, r, s int64
319-
fmt.Sscanf(cs.Result.RoundState.HeightRoundStep, "%d/%d/%d", &h, &r, &s)
319+
_, _ = fmt.Sscanf(cs.Result.RoundState.HeightRoundStep, "%d/%d/%d", &h, &r, &s)
320320
return h
321321
}

internal/adapters/evm.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func hexToInt64(hex string) int64 {
2020
return 0
2121
}
2222
var n int64
23-
fmt.Sscanf(hex, "%x", &n)
23+
_, _ = fmt.Sscanf(hex, "%x", &n)
2424
return n
2525
}
2626

internal/controller/helpers.go

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424

2525
corev1 "k8s.io/api/core/v1"
2626
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
27-
ctrl "sigs.k8s.io/controller-runtime"
2827

2928
nodesv1alpha1 "github.com/tazhate/blockchain-node-operator/api/v1alpha1"
3029
"github.com/tazhate/blockchain-node-operator/internal/adapters"
@@ -332,7 +331,7 @@ func hexToInt64(s string) int64 {
332331
return 0
333332
}
334333
var n int64
335-
fmt.Sscanf(s, "%x", &n)
334+
_, _ = fmt.Sscanf(s, "%x", &n)
336335
return n
337336
}
338337

@@ -347,27 +346,3 @@ func tipHTTPClient() *http.Client {
347346
}
348347

349348
// ---------------------------------------------------------------------------
350-
// resolveImage (method form used by upgrade.go)
351-
// ---------------------------------------------------------------------------
352-
353-
// resolveImage delegates to resolveContainerImage. It exists as a method so
354-
// the upgrade reconciler can call it without importing the adapter.
355-
func (r *BlockchainNodeReconciler) resolveImage(node *nodesv1alpha1.BlockchainNode, adapter adapters.ChainAdapter) string {
356-
return resolveContainerImage(node, adapter)
357-
}
358-
359-
// ---------------------------------------------------------------------------
360-
// setPhase (alias kept for backward compatibility with tests)
361-
// ---------------------------------------------------------------------------
362-
363-
func (r *BlockchainNodeReconciler) setPhase(ctx context.Context, node *nodesv1alpha1.BlockchainNode, phase nodesv1alpha1.NodePhase) (ctrl.Result, error) {
364-
return r.patchPhase(ctx, node, phase)
365-
}
366-
367-
// ---------------------------------------------------------------------------
368-
// updateAnnotations (alias for persistAnnotations, used in health / ETA code)
369-
// ---------------------------------------------------------------------------
370-
371-
func (r *BlockchainNodeReconciler) updateAnnotations(ctx context.Context, node *nodesv1alpha1.BlockchainNode) error {
372-
return r.persistAnnotations(ctx, node)
373-
}

internal/controller/reconcile_configmap.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ func (r *BlockchainNodeReconciler) injectRPCSecretsIntoEnv(ctx context.Context,
8989
}
9090

9191
if v, exists := secret.Data["rpc-user"]; exists {
92-
os.Setenv(prefix+"_RPC_USER", string(v))
92+
_ = os.Setenv(prefix+"_RPC_USER", string(v))
9393
}
9494
if v, exists := secret.Data["rpc-password"]; exists {
95-
os.Setenv(prefix+"_RPC_PASSWORD", string(v))
95+
_ = os.Setenv(prefix+"_RPC_PASSWORD", string(v))
9696
}
9797
}

0 commit comments

Comments
 (0)