Skip to content

Commit 5644d8c

Browse files
committed
upadte golangci-lint rules and fix lints
Signed-off-by: cpanato <[email protected]>
1 parent 6aa9c72 commit 5644d8c

27 files changed

+293
-227
lines changed

.github/workflows/lint.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,4 @@ jobs:
2323
- name: golangci-lint
2424
uses: golangci/golangci-lint-action@a4f60bb28d35aeee14e6880718e0c85ff1882e64 # v6.0.1
2525
with:
26-
timeout: 10m
27-
version: v1.57
26+
version: v1.58

.golangci.yml

Lines changed: 160 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,111 @@
1+
---
12
linters:
23
disable-all: true
34
enable:
4-
- asciicheck
5-
- bodyclose
6-
- depguard
7-
- dogsled
8-
- errcheck
9-
- exportloopref
10-
- goconst
11-
- gocritic
12-
- gocyclo
13-
- godot
14-
- gofmt
15-
- goimports
16-
- goprintffuncname
17-
- gosec
18-
- gosimple
19-
- govet
20-
- importas
21-
- ineffassign
22-
- misspell
23-
- nakedret
24-
- nilerr
25-
- noctx
26-
- nolintlint
27-
- prealloc
28-
- predeclared
29-
- revive
30-
- rowserrcheck
31-
- staticcheck
32-
- stylecheck
33-
- thelper
34-
- typecheck
35-
- unconvert
36-
- unparam
37-
- unused
38-
- whitespace
5+
- asasalint
6+
- asciicheck
7+
- bidichk
8+
- bodyclose
9+
- canonicalheader
10+
# - copyloopvar // only on go1.22
11+
- decorder
12+
- dogsled
13+
- durationcheck
14+
- errcheck
15+
- errchkjson
16+
- errname
17+
- exportloopref
18+
- fatcontext
19+
- ginkgolinter
20+
- gocheckcompilerdirectives
21+
- gochecksumtype
22+
- goconst
23+
- gocritic
24+
- gocyclo
25+
- godox
26+
- gofmt
27+
- gofumpt
28+
- goheader
29+
- goimports
30+
- gomodguard
31+
- goprintffuncname
32+
- gosec
33+
- gosimple
34+
- gosmopolitan
35+
- govet
36+
- grouper
37+
- importas
38+
- ineffassign
39+
# - intrange // only on go1.22
40+
- loggercheck
41+
- makezero
42+
- mirror
43+
- misspell
44+
- musttag
45+
- nakedret
46+
- nolintlint
47+
- nosprintfhostport
48+
- perfsprint
49+
- prealloc
50+
- predeclared
51+
- promlinter
52+
- protogetter
53+
- reassign
54+
- revive
55+
- rowserrcheck
56+
- sloglint
57+
- spancheck
58+
- sqlclosecheck
59+
- staticcheck
60+
- stylecheck
61+
- tagalign
62+
- tenv
63+
- testableexamples
64+
- typecheck
65+
- unconvert
66+
- unparam
67+
- unused
68+
- usestdlibvars
69+
- wastedassign
70+
- whitespace
71+
- zerologlint
72+
# - containedctx
73+
# - cyclop
74+
# - depguard
75+
# - dupword
76+
# - err113
77+
# - errorlint
78+
# - exhaustive
79+
# - exhaustruct
80+
# - forbidigo
81+
# - forcetypeassert
82+
# - funlen
83+
# - gci
84+
# - gochecknoglobals
85+
# - gochecknoinits
86+
# - gocognit
87+
# - godot
88+
# - inamedparam
89+
# - interfacebloat
90+
# - ireturn
91+
# - lll
92+
# - maintidx
93+
# - mnd
94+
# - nestif
95+
# - nilerr
96+
# - nilnil
97+
# - nlreturn
98+
# - noctx
99+
# - nonamedreturns
100+
# - paralleltest
101+
# - tagliatelle
102+
# - testifylint
103+
# - testpackage
104+
# - thelper
105+
# - tparallel
106+
# - varnamelen
107+
# - wrapcheck
108+
# - wsl
39109

40110
linters-settings:
41111
importas:
@@ -55,84 +125,72 @@ linters-settings:
55125
# Controller Runtime
56126
- pkg: sigs.k8s.io/controller-runtime
57127
alias: ctrl
58-
staticcheck:
59-
go: "1.18"
60-
stylecheck:
61-
go: "1.18"
62-
depguard:
63-
rules:
64-
main:
65-
deny:
66-
- pkg: "io/ioutil"
67-
desc: "ioutil is deprecated starting with Go 1.16"
68-
69128

70129
issues:
71130
max-same-issues: 0
72131
max-issues-per-linter: 0
73132
# We are disabling default golangci exclusions because we want to help reviewers to focus on reviewing the most relevant
74133
# changes in PRs and avoid nitpicking.
75134
exclude-use-default: false
135+
exclude-files:
136+
- "zz_generated.*\\.go$"
137+
- ".*conversion.*\\.go$"
138+
exclude-dirs:
139+
- mock*
76140
# List of regexps of issue texts to exclude, empty list by default.
77141
exclude:
78-
# The following are being worked on to remove their exclusion. This list should be reduced or go away all together over time.
79-
# If it is decided they will not be addressed they should be moved above this comment.
80-
- Subprocess launch(ed with variable|ing should be audited)
81-
- (Expect directory permissions to be 0750 or less|Expect file permissions to be 0600 or less)
82-
- (G104|G307)
142+
# The following are being worked on to remove their exclusion. This list should be reduced or go away all together over time.
143+
# If it is decided they will not be addressed they should be moved above this comment.
144+
- Subprocess launch(ed with variable|ing should be audited)
145+
- (Expect directory permissions to be 0750 or less|Expect file permissions to be 0600 or less)
146+
- (G104|G307)
83147
exclude-rules:
84-
- linters:
85-
- gosec
86-
text: "G108: Profiling endpoint is automatically exposed on /debug/pprof"
87-
- linters:
88-
- revive
89-
text: "exported: exported method .*\\.(Reconcile|SetupWithManager|SetupWebhookWithManager) should have comment or be unexported"
90-
- linters:
91-
- errcheck
92-
text: Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*print(f|ln)?|os\.(Un)?Setenv). is not checked
93-
# With Go 1.16, the new embed directive can be used with an un-named import,
94-
# revive (previously, golint) only allows these to be imported in a main.go, which wouldn't work for us.
95-
# This directive allows the embed package to be imported with an underscore everywhere.
96-
- linters:
97-
- revive
98-
source: _ "embed"
99-
# Exclude some packages or code to require comments, for example test code, or fake clients.
100-
- linters:
101-
- revive
102-
text: exported (method|function|type|const) (.+) should have comment or be unexported
103-
source: (func|type).*Fake.*
104-
- linters:
105-
- revive
106-
text: exported (method|function|type|const) (.+) should have comment or be unexported
107-
path: fake_\.go
108-
- linters:
109-
- revive
110-
text: exported (method|function|type|const) (.+) should have comment or be unexported
111-
path: "(framework|e2e|infrastructure/docker)/.*.go"
112-
# Disable unparam "always receives" which might not be really
113-
# useful when building libraries.
114-
- linters:
115-
- unparam
116-
text: always receives
117-
# Dot imports for gomega or ginkgo are allowed
118-
# within test files.
119-
- path: _test\.go
120-
text: should not use dot imports
121-
- path: (framework|e2e)/.*.go
122-
text: should not use dot imports
123-
- path: _test\.go
124-
text: cyclomatic complexity
125-
# Append should be able to assign to a different var/slice.
126-
- linters:
127-
- gocritic
128-
text: "appendAssign: append result not assigned to the same slice"
129-
148+
- linters:
149+
- gosec
150+
text: "G108: Profiling endpoint is automatically exposed on /debug/pprof"
151+
- linters:
152+
- revive
153+
text: "exported: exported method .*\\.(Reconcile|SetupWithManager|SetupWebhookWithManager) should have comment or be unexported"
154+
- linters:
155+
- errcheck
156+
text: Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*print(f|ln)?|os\.(Un)?Setenv). is not checked
157+
# With Go 1.16, the new embed directive can be used with an un-named import,
158+
# revive (previously, golint) only allows these to be imported in a main.go, which wouldn't work for us.
159+
# This directive allows the embed package to be imported with an underscore everywhere.
160+
- linters:
161+
- revive
162+
source: _ "embed"
163+
# Exclude some packages or code to require comments, for example test code, or fake clients.
164+
- linters:
165+
- revive
166+
text: exported (method|function|type|const) (.+) should have comment or be unexported
167+
source: (func|type).*Fake.*
168+
- linters:
169+
- revive
170+
text: exported (method|function|type|const) (.+) should have comment or be unexported
171+
path: fake_\.go
172+
- linters:
173+
- revive
174+
text: exported (method|function|type|const) (.+) should have comment or be unexported
175+
path: "(framework|e2e|infrastructure/docker)/.*.go"
176+
# Disable unparam "always receives" which might not be really
177+
# useful when building libraries.
178+
- linters:
179+
- unparam
180+
text: always receives
181+
# Dot imports for gomega or ginkgo are allowed
182+
# within test files.
183+
- path: _test\.go
184+
text: should not use dot imports
185+
- path: (framework|e2e)/.*.go
186+
text: should not use dot imports
187+
- path: _test\.go
188+
text: cyclomatic complexity
189+
# Append should be able to assign to a different var/slice.
190+
- linters:
191+
- gocritic
192+
text: "appendAssign: append result not assigned to the same slice"
130193

131194
run:
132195
timeout: 10m
133-
skip-files:
134-
- "zz_generated.*\\.go$"
135-
- ".*conversion.*\\.go$"
136-
skip-dirs:
137-
- mock*
138196
allow-parallel-runners: true

api/v1beta1/gcpcluster_webhook.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,10 @@ func (c *GCPCluster) SetupWebhookWithManager(mgr ctrl.Manager) error {
4141
// +kubebuilder:webhook:verbs=create;update,path=/validate-infrastructure-cluster-x-k8s-io-v1beta1-gcpcluster,mutating=false,failurePolicy=fail,matchPolicy=Equivalent,groups=infrastructure.cluster.x-k8s.io,resources=gcpclusters,versions=v1beta1,name=validation.gcpcluster.infrastructure.cluster.x-k8s.io,sideEffects=None,admissionReviewVersions=v1beta1
4242
// +kubebuilder:webhook:verbs=create;update,path=/mutate-infrastructure-cluster-x-k8s-io-v1beta1-gcpcluster,mutating=true,failurePolicy=fail,matchPolicy=Equivalent,groups=infrastructure.cluster.x-k8s.io,resources=gcpclusters,versions=v1beta1,name=default.gcpcluster.infrastructure.cluster.x-k8s.io,sideEffects=None,admissionReviewVersions=v1beta1
4343

44-
var _ webhook.Validator = &GCPCluster{}
45-
var _ webhook.Defaulter = &GCPCluster{}
44+
var (
45+
_ webhook.Validator = &GCPCluster{}
46+
_ webhook.Defaulter = &GCPCluster{}
47+
)
4648

4749
// Default implements webhook.Defaulter so a webhook will be registered for the type.
4850
func (c *GCPCluster) Default() {

api/v1beta1/gcpclustertemplate_webhook_test.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ func TestGCPClusterTemplate_ValidateUpdate(t *testing.T) {
3939
Spec: GCPClusterSpec{
4040
Project: "test-gcp-cluster",
4141
Region: "ap-south-1",
42-
}},
42+
},
43+
},
4344
},
4445
},
4546
oldTemplate: &GCPClusterTemplate{
@@ -48,7 +49,8 @@ func TestGCPClusterTemplate_ValidateUpdate(t *testing.T) {
4849
Spec: GCPClusterSpec{
4950
Project: "test-gcp-cluster",
5051
Region: "ap-south-1",
51-
}},
52+
},
53+
},
5254
},
5355
},
5456
wantErr: false,
@@ -61,7 +63,8 @@ func TestGCPClusterTemplate_ValidateUpdate(t *testing.T) {
6163
Spec: GCPClusterSpec{
6264
Project: "test-gcp-cluster",
6365
Region: "ap-south-1",
64-
}},
66+
},
67+
},
6568
},
6669
},
6770
oldTemplate: &GCPClusterTemplate{
@@ -70,7 +73,8 @@ func TestGCPClusterTemplate_ValidateUpdate(t *testing.T) {
7073
Spec: GCPClusterSpec{
7174
Project: "test-gcp-cluster",
7275
Region: "ap-east-1",
73-
}},
76+
},
77+
},
7478
},
7579
},
7680
wantErr: true,

api/v1beta1/gcpmachine_webhook.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,14 @@ func checkKeyType(key *CustomerEncryptionKey) error {
126126
switch key.KeyType {
127127
case CustomerManagedKey:
128128
if key.ManagedKey == nil || key.SuppliedKey != nil {
129-
return fmt.Errorf("CustomerEncryptionKey KeyType of Managed requires only ManagedKey to be set")
129+
return errors.New("CustomerEncryptionKey KeyType of Managed requires only ManagedKey to be set")
130130
}
131131
case CustomerSuppliedKey:
132132
if key.SuppliedKey == nil || key.ManagedKey != nil {
133-
return fmt.Errorf("CustomerEncryptionKey KeyType of Supplied requires only SuppliedKey to be set")
133+
return errors.New("CustomerEncryptionKey KeyType of Supplied requires only SuppliedKey to be set")
134134
}
135135
if len(key.SuppliedKey.RawKey) > 0 && len(key.SuppliedKey.RSAEncryptedKey) > 0 {
136-
return fmt.Errorf("CustomerEncryptionKey KeyType of Supplied requires either RawKey or RSAEncryptedKey to be set, not both")
136+
return errors.New("CustomerEncryptionKey KeyType of Supplied requires either RawKey or RSAEncryptedKey to be set, not both")
137137
}
138138
default:
139139
return fmt.Errorf("invalid value for CustomerEncryptionKey KeyType %s", key.KeyType)

0 commit comments

Comments
 (0)