Skip to content

Commit d3e363f

Browse files
committed
Sync golangci-lint configuration to core CAPI
1 parent cf7352a commit d3e363f

File tree

10 files changed

+266
-47
lines changed

10 files changed

+266
-47
lines changed

.golangci.yml

Lines changed: 258 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,29 @@
1+
run:
2+
timeout: 10m
3+
go: "1.20"
4+
skip-files:
5+
- "zz_generated.*\\.go$"
6+
- apis/v1alpha3
7+
allow-parallel-runners: true
8+
19
linters:
210
disable-all: true
311
enable:
12+
- asasalint
413
- asciicheck
14+
- bidichk
515
- bodyclose
16+
# - containedctx
617
- dogsled
18+
# - dupword
19+
- durationcheck
720
- errcheck
21+
# - errchkjson
822
- exportloopref
923
- gci
24+
# - ginkgolinter
1025
- goconst
1126
- gocritic
12-
- gocyclo
1327
- godot
1428
- gofmt
1529
- goimports
@@ -23,7 +37,8 @@ linters:
2337
- nakedret
2438
- nilerr
2539
- noctx
26-
- nolintlint
40+
# - nolintlint
41+
- nosprintfhostport
2742
- prealloc
2843
- predeclared
2944
- revive
@@ -35,42 +50,250 @@ linters:
3550
- unconvert
3651
- unparam
3752
- unused
53+
- usestdlibvars
3854
- whitespace
3955

4056
linters-settings:
4157
gci:
42-
local-prefixes: sigs.k8s.io/cluster-api-provider-vsphere
43-
run:
44-
skip-files:
45-
- ".*zz_generated.*\\.go"
46-
- "contrib/.*"
47-
- "apis/v1alpha3/.*"
48-
- "apis/v1alpha4/.*"
49-
timeout: 5m
50-
issue:
51-
max-same-issues: 0
52-
max-per-linter: 0
58+
local-prefixes: "sigs.k8s.io/cluster-api-provider-vsphere"
59+
godot:
60+
# declarations - for top level declaration comments (default);
61+
# toplevel - for top level comments;
62+
# all - for all comments.
63+
scope: toplevel
64+
exclude:
65+
- '^ \+.*'
66+
- '^ ANCHOR.*'
67+
# gocritic:
68+
# enabled-tags:
69+
# - diagnostic
70+
# - experimental
71+
# - performance
72+
# disabled-checks:
73+
# - appendAssign
74+
# - dupImport # https://github.com/go-critic/go-critic/issues/845
75+
# - evalOrder
76+
# - ifElseChain
77+
# - octalLiteral
78+
# - regexpSimplify
79+
# - sloppyReassign
80+
# - truncateCmp
81+
# - typeDefFirst
82+
# - unnamedResult
83+
# - unnecessaryDefer
84+
# - whyNoLint
85+
# - wrapperFunc
86+
# - rangeValCopy
87+
# - hugeParam
88+
# importas:
89+
# no-unaliased: true
90+
# alias:
91+
# # Kubernetes
92+
# - pkg: k8s.io/api/core/v1
93+
# alias: corev1
94+
# - pkg: k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1
95+
# alias: apiextensionsv1
96+
# - pkg: k8s.io/apimachinery/pkg/apis/meta/v1
97+
# alias: metav1
98+
# - pkg: k8s.io/apimachinery/pkg/api/errors
99+
# alias: apierrors
100+
# - pkg: k8s.io/apimachinery/pkg/util/errors
101+
# alias: kerrors
102+
# - pkg: k8s.io/component-base/logs/api/v1
103+
# alias: logsv1
104+
# # Controller Runtime
105+
# - pkg: sigs.k8s.io/controller-runtime
106+
# alias: ctrl
107+
# # CAPV
108+
# - pkg: sigs.k8s.io/cluster-api-provider-vsphere/apis/v1beta1
109+
# alias: infrav1
110+
# - pkg: sigs.k8s.io/cluster-api-provider-vsphere/apis/v1alpha3
111+
# alias: infrav1alpha3
112+
# - pkg: sigs.k8s.io/cluster-api-provider-vsphere/apis/v1alpha4
113+
# alias: infrav1alpha4
114+
# - pkg: sigs.k8s.io/cluster-api-provider-vsphere/apis/vmware/v1beta1
115+
# alias: vmwarev1
116+
# # VMware Operator
117+
# - pkg: "github.com/vmware-tanzu/vm-operator/api/v1alpha1"
118+
# alias: vmoprv1
119+
# # CABPK
120+
# - pkg: sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1beta1
121+
# alias: bootstrapv1
122+
# # KCP
123+
# - pkg: sigs.k8s.io/cluster-api/controlplane/kubeadm/api/v1beta1
124+
# alias: controlplanev1
125+
# # CAPI
126+
# - pkg: sigs.k8s.io/cluster-api/api/v1alpha3
127+
# alias: clusterv1alpha3
128+
# - pkg: sigs.k8s.io/cluster-api/api/v1alpha4
129+
# alias: clusterv1alpha4
130+
# - pkg: sigs.k8s.io/cluster-api/api/v1beta1
131+
# alias: clusterv1
132+
# # CAPI exp
133+
# - pkg: sigs.k8s.io/cluster-api/exp/api/v1beta1
134+
# alias: expv1
135+
# # CAPI exp addons
136+
# - pkg: sigs.k8s.io/cluster-api/exp/addons/api/v1beta1
137+
# alias: addonsv1
138+
nolintlint:
139+
allow-unused: false
140+
allow-leading-space: false
141+
require-specific: true
142+
revive:
143+
rules:
144+
# The following rules are recommended https://github.com/mgechev/revive#recommended-configuration
145+
- name: blank-imports
146+
- name: context-as-argument
147+
- name: context-keys-type
148+
- name: dot-imports
149+
- name: error-return
150+
- name: error-strings
151+
- name: error-naming
152+
- name: exported
153+
- name: if-return
154+
- name: increment-decrement
155+
- name: var-naming
156+
- name: var-declaration
157+
- name: package-comments
158+
- name: range
159+
- name: receiver-naming
160+
- name: time-naming
161+
- name: unexported-return
162+
- name: indent-error-flow
163+
- name: errorf
164+
- name: empty-block
165+
- name: superfluous-else
166+
- name: unused-parameter
167+
- name: unreachable-code
168+
- name: redefines-builtin-id
169+
#
170+
# Rules in addition to the recommended configuration above.
171+
#
172+
- name: bool-literal-in-expr
173+
- name: constant-logical-expr
174+
53175
issues:
176+
max-same-issues: 0
177+
max-issues-per-linter: 0
178+
# We are disabling default golangci exclusions because we want to help reviewers to focus on reviewing the most relevant
179+
# changes in PRs and avoid nitpicking.
180+
exclude-use-default: false
54181
exclude-rules:
55-
# Specific exclude rules for deprecated fields that are still part of the codebase. These
56-
# should be removed as the referenced deprecated item is removed from the project.
57-
- linters:
58-
- staticcheck
59-
text: "SA1019: failureDomain.AutoConfigure is deprecated"
60-
# Specific exclude rules for deprecated packages that are still part of the codebase. These
61-
# should be removed as the referenced deprecated packages are removed from the project.
62-
- linters:
63-
- staticcheck
64-
text: "SA1019: .* is deprecated: This package will be removed in one of the next releases."
65-
- path: "test/e2e/*"
66-
linters:
67-
- gosec
68-
text: "G106:"
69-
- linters:
70-
- revive
71-
text: "dot-imports"
72-
path: ".*test.*"
73-
- linters:
74-
- stylecheck
75-
text: "ST1001"
76-
path: ".*test.*"
182+
# Specific exclude rules for deprecated fields that are still part of the codebase. These
183+
# should be removed as the referenced deprecated item is removed from the project.
184+
# Specific exclude rules for deprecated packages that are still part of the codebase. These
185+
# should be removed as the referenced deprecated packages are removed from the project.
186+
- linters:
187+
- staticcheck
188+
text: "SA1019: .* is deprecated: This package will be removed in one of the next releases."
189+
- linters:
190+
- revive
191+
text: "exported: exported method .*\\.(Reconcile|SetupWithManager|SetupWebhookWithManager) should have comment or be unexported"
192+
- linters:
193+
- errcheck
194+
text: Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*print(f|ln)?|os\.(Un)?Setenv). is not checked
195+
# Exclude some packages or code to require comments, for example test code, or fake clients.
196+
- linters:
197+
- revive
198+
text: exported (method|function|type|const) (.+) should have comment or be unexported
199+
source: (func|type).*Fake.*
200+
- linters:
201+
- revive
202+
text: exported (.+) (.+) should have comment (.*)or be unexported
203+
path: "^(test/|packaging/|pkg/.*/fake/|pkg/util/testutil).*.go"
204+
# Disable unparam "always receives" which might not be really
205+
# useful when building libraries.
206+
- linters:
207+
- unparam
208+
text: always receives
209+
# Dot imports for gomega and ginkgo are allowed
210+
# within test files and test utils.
211+
- linters:
212+
- revive
213+
- stylecheck
214+
path: test/.*.go
215+
text: should not use dot imports
216+
# Append should be able to assign to a different var/slice.
217+
- linters:
218+
- gocritic
219+
text: "appendAssign: append result not assigned to the same slice"
220+
# Disable linters for conversion
221+
- linters:
222+
- staticcheck
223+
text: "SA1019: in.(.+) is deprecated"
224+
path: ^apis\/.*\/.*conversion.*\.go$
225+
- linters:
226+
- revive
227+
# Checking if an error is nil to just after return the error or nil is redundant
228+
text: "if-return: redundant if ...; err != nil check, just return error instead"
229+
# Ignoring stylistic checks for generated code
230+
path: ^apis\/.*\/.*conversion.*\.go$
231+
- linters:
232+
- revive
233+
# Exported function and methods should have comments. This warns on undocumented exported functions and methods.
234+
text: exported (method|function|type|const) (.+) should have comment or be unexported
235+
# Ignoring stylistic checks for generated code
236+
path: ^apis\/.*\/.*conversion.*\.go$
237+
- linters:
238+
- revive
239+
# This rule warns when initialism, variable or package naming conventions are not followed.
240+
text: "var-naming: don't use underscores in Go names;"
241+
# Ignoring stylistic checks for generated code
242+
path: ^apis\/.*\/.*conversion.*\.go$
243+
- linters:
244+
- revive
245+
# By convention, receiver names in a method should reflect their identity.
246+
text: "receiver-naming: receiver name"
247+
# Ignoring stylistic checks for generated code
248+
path: ^apis\/.*\/.*conversion.*\.go$
249+
- linters:
250+
- stylecheck
251+
text: "ST1003: should not use underscores in Go names;"
252+
path: ^apis\/.*\/.*conversion.*\.go$
253+
- linters:
254+
- stylecheck
255+
text: "ST1016: methods on the same type should have the same receiver name"
256+
path: ^apis\/.*\/.*conversion.*\.go$
257+
258+
# FIXME: All below excludes should get removed over time.
259+
- linters:
260+
- staticcheck
261+
text: "SA1019: failureDomain.AutoConfigure is deprecated"
262+
- path: "test/e2e/*"
263+
linters:
264+
- gosec
265+
text: "G106:"
266+
267+
# missing comments
268+
- linters:
269+
- revive
270+
text: "package-comments"
271+
path: ^(main|(packaging|apis|controllers|feature|test|pkg)\/.*)\.go$
272+
- linters:
273+
- stylecheck
274+
text: "ST1000"
275+
path: ^(main|(packaging|apis|controllers|feature|test|pkg)\/.*)\.go$
276+
- linters:
277+
- revive
278+
text: exported (.*) should have comment (.*)or be unexported
279+
path: "^(apis|controllers|packaging|pkg)/.*.go"
280+
281+
# wrong comment
282+
- linters:
283+
- revive
284+
text: comment on exported (.*) should be of the form (.*)
285+
path: "^(apis|packaging|pkg/(constants|services|util))/"
286+
- linters:
287+
- stylecheck
288+
text: ST1021|ST1020
289+
path: "^(apis|packaging|pkg/(constants|services|util))/"
290+
291+
# gosec
292+
- linters:
293+
- gosec
294+
text: "G104: Errors unhandled."
295+
path: ^(controllers/vspherecluster_reconciler|pkg/manager/options_test|test/helpers/webhook)\.go$
296+
- linters:
297+
- gosec
298+
text: "(G204|G301|G304): "
299+
path: ^test/

controllers/clustermodule_reconciler_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,6 @@ func TestReconciler_fetchMachineOwnerObjects(t *testing.T) {
518518
})
519519
}
520520

521-
//nolint:unparam
522521
func machineDeployment(name, namespace, cluster string) *clusterv1.MachineDeployment {
523522
return &clusterv1.MachineDeployment{
524523
TypeMeta: metav1.TypeMeta{
@@ -532,7 +531,6 @@ func machineDeployment(name, namespace, cluster string) *clusterv1.MachineDeploy
532531
}
533532
}
534533

535-
//nolint:unparam
536534
func controlPlane(name, namespace, cluster string) *controlplanev1.KubeadmControlPlane {
537535
return &controlplanev1.KubeadmControlPlane{
538536
TypeMeta: metav1.TypeMeta{

controllers/serviceaccount_controller_suite_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func assertServiceAccountAndUpdateSecret(ctx goctx.Context, ctrlClient client.Cl
102102
Expect(ctrlClient.Update(ctx, secret)).To(Succeed())
103103
}
104104

105-
func assertTargetSecret(ctx goctx.Context, guestClient client.Client, namespace, name string) { //nolint
105+
func assertTargetSecret(ctx goctx.Context, guestClient client.Client, namespace, name string) {
106106
secret := &corev1.Secret{}
107107
assertEventuallyExistsInNamespace(ctx, guestClient, namespace, name, secret)
108108
EventuallyWithOffset(2, func() []byte {
@@ -157,7 +157,7 @@ func assertRoleBinding(_ *helpers.UnitTestContextForController, ctrlClient clien
157157
}
158158

159159
// assertProviderServiceAccountsCondition asserts the condition on the ProviderServiceAccount CR.
160-
func assertProviderServiceAccountsCondition(vCluster *vmwarev1.VSphereCluster, status corev1.ConditionStatus, message string, reason string, severity clusterv1.ConditionSeverity) { //nolint
160+
func assertProviderServiceAccountsCondition(vCluster *vmwarev1.VSphereCluster, status corev1.ConditionStatus, message string, reason string, severity clusterv1.ConditionSeverity) {
161161
c := conditions.Get(vCluster, vmwarev1.ProviderServiceAccountsReadyCondition)
162162
Expect(c).NotTo(BeNil())
163163
Expect(c.Status).To(Equal(status))

controllers/svcdiscovery_controller_suite_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func assertHeadlessSvc(ctx context.Context, guestClient client.Client, namespace
8181
Expect(headlessSvc.Spec.Ports[0].TargetPort.IntVal).To(Equal(int32(supervisorAPIServerPort)))
8282
}
8383

84-
func assertHeadlessSvcWithNoEndpoints(ctx context.Context, guestClient client.Client, namespace, name string) { //nolint
84+
func assertHeadlessSvcWithNoEndpoints(ctx context.Context, guestClient client.Client, namespace, name string) {
8585
assertHeadlessSvc(ctx, guestClient, namespace, name)
8686
headlessEndpoints := &corev1.Endpoints{}
8787
assertEventuallyDoesNotExistInNamespace(ctx, guestClient, namespace, name, headlessEndpoints)

controllers/vsphereclusteridentity_controller_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ var _ = Describe("VSphereClusterIdentity Reconciler", func() {
160160
return false
161161
}
162162

163-
if i.Status.Ready == false && conditions.GetReason(i, infrav1.CredentialsAvailableCondidtion) == infrav1.SecretAlreadyInUseReason {
163+
if !i.Status.Ready && conditions.GetReason(i, infrav1.CredentialsAvailableCondidtion) == infrav1.SecretAlreadyInUseReason {
164164
return true
165165
}
166166
return false
@@ -184,7 +184,7 @@ var _ = Describe("VSphereClusterIdentity Reconciler", func() {
184184
return false
185185
}
186186

187-
if i.Status.Ready == false && conditions.GetReason(i, infrav1.CredentialsAvailableCondidtion) == infrav1.SecretNotAvailableReason {
187+
if !i.Status.Ready && conditions.GetReason(i, infrav1.CredentialsAvailableCondidtion) == infrav1.SecretNotAvailableReason {
188188
return true
189189
}
190190
return false

pkg/services/govmomi/cluster/vmgroup.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ type VMGroup struct {
5353
// Add a VSphere VM object to the VM Group.
5454
func (vg VMGroup) Add(ctx context.Context, vmObj types.ManagedObjectReference) (*object.Task, error) {
5555
vms := vg.listVMs()
56-
vg.ClusterVmGroup.Vm = append(vms, vmObj) //nolint:gocritic
56+
vg.ClusterVmGroup.Vm = append(vms, vmObj)
5757

5858
spec := &types.ClusterConfigSpecEx{
5959
GroupSpec: []types.ClusterGroupSpec{

0 commit comments

Comments
 (0)