Skip to content

Commit 64c9e1d

Browse files
add and fix linter findings (#611)
Signed-off-by: Prajyot-Parab <[email protected]>
1 parent 6af922e commit 64c9e1d

File tree

74 files changed

+1288
-793
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+1288
-793
lines changed

.golangci.yml

Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,209 @@
11
linters:
22
disable-all: true
33
enable:
4+
- asciicheck
5+
- bodyclose
46
- deadcode
7+
- depguard
8+
- dogsled
59
- errcheck
10+
- exportloopref
11+
- gci
12+
- goconst
13+
- gocritic
14+
- godot
15+
- gofmt
16+
- goimports
17+
- goprintffuncname
18+
- gosec
619
- gosimple
720
- govet
21+
- ifshort
22+
- importas
823
- ineffassign
24+
- misspell
25+
- nakedret
26+
- nilerr
27+
- noctx
28+
- nolintlint
29+
- prealloc
30+
- predeclared
31+
- revive
32+
- rowserrcheck
933
- staticcheck
1034
- structcheck
35+
- stylecheck
36+
- thelper
1137
- typecheck
38+
- unconvert
39+
- unparam
1240
- unused
1341
- varcheck
42+
- whitespace
43+
44+
linters-settings:
45+
godot:
46+
# declarations - for top level declaration comments (default);
47+
# toplevel - for top level comments;
48+
# all - for all comments.
49+
scope: toplevel
50+
exclude:
51+
- '^ \+.*'
52+
- '^ ANCHOR.*'
53+
ifshort:
54+
# Maximum length of variable declaration measured in number of characters, after which linter won't suggest using short syntax.
55+
max-decl-chars: 50
56+
gci:
57+
local-prefixes: "sigs.k8s.io/cluster-api-provider-ibmcloud"
58+
importas:
59+
no-unaliased: true
60+
alias:
61+
# Kubernetes
62+
- pkg: k8s.io/api/core/v1
63+
alias: corev1
64+
- pkg: k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1
65+
alias: apiextensionsv1
66+
- pkg: k8s.io/apimachinery/pkg/apis/meta/v1
67+
alias: metav1
68+
- pkg: k8s.io/apimachinery/pkg/api/errors
69+
alias: apierrors
70+
- pkg: k8s.io/apimachinery/pkg/util/errors
71+
alias: kerrors
72+
# Controller Runtime
73+
- pkg: sigs.k8s.io/controller-runtime
74+
alias: ctrl
75+
# CAPI
76+
- pkg: sigs.k8s.io/cluster-api/api/v1alpha3
77+
alias: capiv1alpha3
78+
- pkg: sigs.k8s.io/cluster-api/api/v1alpha4
79+
alias: capiv1alpha4
80+
- pkg: sigs.k8s.io/cluster-api/api/v1beta1
81+
alias: capiv1beta1
82+
# CAPI-IBMCLOUD
83+
- pkg: sigs.k8s.io/cluster-api-provider-ibmcloud/api/v1alpha3
84+
alias: infrav1alpha3
85+
- pkg: sigs.k8s.io/cluster-api-provider-ibmcloud/api/v1alpha4
86+
alias: infrav1alpha4
87+
- pkg: sigs.k8s.io/cluster-api-provider-ibmcloud/api/v1beta1
88+
alias: infrav1beta1
89+
nolintlint:
90+
allow-unused: false
91+
allow-leading-space: false
92+
require-specific: true
93+
staticcheck:
94+
go: "1.17"
95+
stylecheck:
96+
go: "1.17"
97+
gosec:
98+
excludes:
99+
- G307 # Deferring unsafe method "Close" on type "\*os.File"
100+
- G108 # Profiling endpoint is automatically exposed on /debug/pprof
101+
gocritic:
102+
enabled-tags:
103+
- experimental
104+
disabled-checks:
105+
- appendAssign
106+
- dupImport # https://github.com/go-critic/go-critic/issues/845
107+
- evalOrder
108+
- ifElseChain
109+
- octalLiteral
110+
- regexpSimplify
111+
- sloppyReassign
112+
- truncateCmp
113+
- typeDefFirst
114+
- unnamedResult
115+
- unnecessaryDefer
116+
- whyNoLint
117+
- wrapperFunc
118+
unused:
119+
go: "1.17"
120+
issues:
121+
max-same-issues: 0
122+
max-issues-per-linter: 0
123+
# We are disabling default golangci exclusions because we want to help reviewers to focus on reviewing the most relevant
124+
# changes in PRs and avoid nitpicking.
125+
exclude-use-default: false
126+
exclude-rules:
127+
- linters:
128+
- gci
129+
path: _test\.go
130+
- linters:
131+
- revive
132+
text: "exported: exported method .*\\.(Reconcile|SetupWithManager|SetupWebhookWithManager) should have comment or be unexported"
133+
- linters:
134+
- errcheck
135+
text: Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*print(f|ln)?|os\.(Un)?Setenv). is not checked
136+
# Exclude some packages or code to require comments, for example test code, or fake clients.
137+
- linters:
138+
- revive
139+
text: exported (method|function|type|const) (.+) should have comment or be unexported
140+
source: (func|type).*Fake.*
141+
- linters:
142+
- revive
143+
text: exported (method|function|type|const) (.+) should have comment or be unexported
144+
path: fake_\.go
145+
- linters:
146+
- revive
147+
text: exported (method|function|type|const) (.+) should have comment or be unexported
148+
path: "(framework|e2e)/.*.go"
149+
# Disable unparam "always receives" which might not be really
150+
# useful when building libraries.
151+
- linters:
152+
- unparam
153+
text: always receives
154+
# Dot imports for gomega or ginkgo are allowed
155+
# within test files.
156+
- path: _test\.go
157+
text: should not use dot imports
158+
- path: (framework|e2e)/.*.go
159+
text: should not use dot imports
160+
- path: _test\.go
161+
text: cyclomatic complexity
162+
# Append should be able to assign to a different var/slice.
163+
- linters:
164+
- gocritic
165+
text: "appendAssign: append result not assigned to the same slice"
166+
# Disable linters for conversion
167+
- linters:
168+
- staticcheck
169+
text: "SA1019: in.(.+) is deprecated"
170+
path: .*(api|types)\/.*\/.*conversion.*\.go$
171+
- linters:
172+
- revive
173+
text: exported (method|function|type|const) (.+) should have comment or be unexported
174+
path: .*(api|types)\/.*\/.*conversion.*\.go$
175+
- linters:
176+
- revive
177+
text: "var-naming: don't use underscores in Go names;"
178+
path: .*(api|types)\/.*\/.*conversion.*\.go$
179+
- linters:
180+
- revive
181+
text: "receiver-naming: receiver name"
182+
path: .*(api|types)\/.*\/.*conversion.*\.go$
183+
- linters:
184+
- stylecheck
185+
text: "ST1003: should not use underscores in Go names;"
186+
path: .*(api|types)\/.*\/.*conversion.*\.go$
187+
- linters:
188+
- stylecheck
189+
text: "ST1016: methods on the same type should have the same receiver name"
190+
path: .*(api|types)\/.*\/.*conversion.*\.go$
191+
# hack/tools
192+
- linters:
193+
- typecheck
194+
text: import (".+") is a program, not an importable package
195+
path: ^tools\.go$
196+
# We don't care about defer in for loops in test files.
197+
- linters:
198+
- gocritic
199+
text: "deferInLoop: Possible resource leak, 'defer' is called in the 'for' loop"
200+
path: _test\.go
14201

15202
run:
16203
timeout: 10m
204+
build-tags:
205+
- tools
206+
- e2e
207+
skip-files:
208+
- "zz_generated.*\\.go$"
209+
allow-parallel-runners: true

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,10 @@ endif
152152
lint: $(GOLANGCI_LINT) ## Lint codebase
153153
$(GOLANGCI_LINT) run -v --fast=false
154154

155+
.PHONY: lint-fix
156+
lint-fix: $(GOLANGCI_LINT) ## Lint the codebase and run auto-fixers if supported by the linter
157+
GOLANGCI_LINT_EXTRA_ARGS=--fix $(MAKE) lint
158+
155159
## --------------------------------------
156160
## Testing
157161
## --------------------------------------

api/v1alpha3/conversion.go

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,88 +18,89 @@ package v1alpha3
1818

1919
import (
2020
apiconversion "k8s.io/apimachinery/pkg/conversion"
21-
"sigs.k8s.io/cluster-api-provider-ibmcloud/api/v1beta1"
22-
clusterv1alpha3 "sigs.k8s.io/cluster-api/api/v1alpha3"
23-
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
21+
capiv1alpha3 "sigs.k8s.io/cluster-api/api/v1alpha3"
22+
capiv1beta1 "sigs.k8s.io/cluster-api/api/v1beta1"
2423
"sigs.k8s.io/controller-runtime/pkg/conversion"
24+
25+
infrav1beta1 "sigs.k8s.io/cluster-api-provider-ibmcloud/api/v1beta1"
2526
)
2627

27-
func Convert_v1alpha3_APIEndpoint_To_v1beta1_APIEndpoint(in *clusterv1alpha3.APIEndpoint, out *clusterv1.APIEndpoint, s apiconversion.Scope) error {
28-
return clusterv1alpha3.Convert_v1alpha3_APIEndpoint_To_v1beta1_APIEndpoint(in, out, s)
28+
func Convert_v1alpha3_APIEndpoint_To_v1beta1_APIEndpoint(in *capiv1alpha3.APIEndpoint, out *capiv1beta1.APIEndpoint, s apiconversion.Scope) error {
29+
return capiv1alpha3.Convert_v1alpha3_APIEndpoint_To_v1beta1_APIEndpoint(in, out, s)
2930
}
3031

31-
func Convert_v1beta1_APIEndpoint_To_v1alpha3_APIEndpoint(in *clusterv1.APIEndpoint, out *clusterv1alpha3.APIEndpoint, s apiconversion.Scope) error {
32-
return clusterv1alpha3.Convert_v1beta1_APIEndpoint_To_v1alpha3_APIEndpoint(in, out, s)
32+
func Convert_v1beta1_APIEndpoint_To_v1alpha3_APIEndpoint(in *capiv1beta1.APIEndpoint, out *capiv1alpha3.APIEndpoint, s apiconversion.Scope) error {
33+
return capiv1alpha3.Convert_v1beta1_APIEndpoint_To_v1alpha3_APIEndpoint(in, out, s)
3334
}
3435

3536
func (src *IBMVPCCluster) ConvertTo(dstRaw conversion.Hub) error {
36-
dst := dstRaw.(*v1beta1.IBMVPCCluster)
37+
dst := dstRaw.(*infrav1beta1.IBMVPCCluster)
3738

3839
return Convert_v1alpha3_IBMVPCCluster_To_v1beta1_IBMVPCCluster(src, dst, nil)
3940
}
4041

4142
func (dst *IBMVPCCluster) ConvertFrom(srcRaw conversion.Hub) error {
42-
src := srcRaw.(*v1beta1.IBMVPCCluster)
43+
src := srcRaw.(*infrav1beta1.IBMVPCCluster)
4344

4445
return Convert_v1beta1_IBMVPCCluster_To_v1alpha3_IBMVPCCluster(src, dst, nil)
4546
}
4647

4748
func (src *IBMVPCClusterList) ConvertTo(dstRaw conversion.Hub) error {
48-
dst := dstRaw.(*v1beta1.IBMVPCClusterList)
49+
dst := dstRaw.(*infrav1beta1.IBMVPCClusterList)
4950

5051
return Convert_v1alpha3_IBMVPCClusterList_To_v1beta1_IBMVPCClusterList(src, dst, nil)
5152
}
5253

5354
func (dst *IBMVPCClusterList) ConvertFrom(srcRaw conversion.Hub) error {
54-
src := srcRaw.(*v1beta1.IBMVPCClusterList)
55+
src := srcRaw.(*infrav1beta1.IBMVPCClusterList)
5556

5657
return Convert_v1beta1_IBMVPCClusterList_To_v1alpha3_IBMVPCClusterList(src, dst, nil)
5758
}
5859

5960
func (src *IBMVPCMachine) ConvertTo(dstRaw conversion.Hub) error {
60-
dst := dstRaw.(*v1beta1.IBMVPCMachine)
61+
dst := dstRaw.(*infrav1beta1.IBMVPCMachine)
6162

6263
return Convert_v1alpha3_IBMVPCMachine_To_v1beta1_IBMVPCMachine(src, dst, nil)
6364
}
6465

6566
func (dst *IBMVPCMachine) ConvertFrom(srcRaw conversion.Hub) error {
66-
src := srcRaw.(*v1beta1.IBMVPCMachine)
67+
src := srcRaw.(*infrav1beta1.IBMVPCMachine)
6768

6869
return Convert_v1beta1_IBMVPCMachine_To_v1alpha3_IBMVPCMachine(src, dst, nil)
6970
}
7071

7172
func (src *IBMVPCMachineList) ConvertTo(dstRaw conversion.Hub) error {
72-
dst := dstRaw.(*v1beta1.IBMVPCMachineList)
73+
dst := dstRaw.(*infrav1beta1.IBMVPCMachineList)
7374

7475
return Convert_v1alpha3_IBMVPCMachineList_To_v1beta1_IBMVPCMachineList(src, dst, nil)
7576
}
7677

7778
func (dst *IBMVPCMachineList) ConvertFrom(srcRaw conversion.Hub) error {
78-
src := srcRaw.(*v1beta1.IBMVPCMachineList)
79+
src := srcRaw.(*infrav1beta1.IBMVPCMachineList)
7980

8081
return Convert_v1beta1_IBMVPCMachineList_To_v1alpha3_IBMVPCMachineList(src, dst, nil)
8182
}
8283

8384
func (src *IBMVPCMachineTemplate) ConvertTo(dstRaw conversion.Hub) error {
84-
dst := dstRaw.(*v1beta1.IBMVPCMachineTemplate)
85+
dst := dstRaw.(*infrav1beta1.IBMVPCMachineTemplate)
8586

8687
return Convert_v1alpha3_IBMVPCMachineTemplate_To_v1beta1_IBMVPCMachineTemplate(src, dst, nil)
8788
}
8889

8990
func (dst *IBMVPCMachineTemplate) ConvertFrom(srcRaw conversion.Hub) error {
90-
src := srcRaw.(*v1beta1.IBMVPCMachineTemplate)
91+
src := srcRaw.(*infrav1beta1.IBMVPCMachineTemplate)
9192

9293
return Convert_v1beta1_IBMVPCMachineTemplate_To_v1alpha3_IBMVPCMachineTemplate(src, dst, nil)
9394
}
9495

9596
func (src *IBMVPCMachineTemplateList) ConvertTo(dstRaw conversion.Hub) error {
96-
dst := dstRaw.(*v1beta1.IBMVPCMachineTemplateList)
97+
dst := dstRaw.(*infrav1beta1.IBMVPCMachineTemplateList)
9798

9899
return Convert_v1alpha3_IBMVPCMachineTemplateList_To_v1beta1_IBMVPCMachineTemplateList(src, dst, nil)
99100
}
100101

101102
func (dst *IBMVPCMachineTemplateList) ConvertFrom(srcRaw conversion.Hub) error {
102-
src := srcRaw.(*v1beta1.IBMVPCMachineTemplateList)
103+
src := srcRaw.(*infrav1beta1.IBMVPCMachineTemplateList)
103104

104105
return Convert_v1beta1_IBMVPCMachineTemplateList_To_v1alpha3_IBMVPCMachineTemplateList(src, dst, nil)
105106
}

api/v1alpha3/groupversion_info.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ import (
2525
)
2626

2727
var (
28-
// GroupVersion is group version used to register these objects
28+
// GroupVersion is group version used to register these objects.
2929
GroupVersion = schema.GroupVersion{Group: "infrastructure.cluster.x-k8s.io", Version: "v1alpha3"}
3030

31-
// SchemeBuilder is used to add go types to the GroupVersionKind scheme
31+
// SchemeBuilder is used to add go types to the GroupVersionKind scheme.
3232
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
3333

3434
// AddToScheme adds the types in this group-version to the given scheme.

0 commit comments

Comments
 (0)