Skip to content

Commit fc1c9e1

Browse files
Improve golang ci lint (#18)
Signed-off-by: Aniruddha Basak <[email protected]>
1 parent 168960c commit fc1c9e1

File tree

9 files changed

+137
-194
lines changed

9 files changed

+137
-194
lines changed

.golangci.yaml

Lines changed: 83 additions & 146 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,20 @@ linters:
66
- bidichk
77
- bodyclose
88
- containedctx
9-
# - depguard
10-
- dogsled
9+
- contextcheck
1110
- durationcheck
12-
- errcheck
1311
- errchkjson
12+
- errname
13+
- errorlint
14+
- exhaustive
1415
- exportloopref
16+
- forcetypeassert
1517
- gci
1618
- goconst
1719
- gocritic
1820
- godot
1921
- gofmt
22+
- gofumpt
2023
- goimports
2124
- goprintffuncname
2225
- gosec
@@ -25,37 +28,29 @@ linters:
2528
- importas
2629
- ineffassign
2730
- loggercheck
31+
- makezero
2832
- misspell
2933
- nakedret
3034
- nilerr
3135
- noctx
3236
- nolintlint
37+
- nosprintfhostport
3338
- prealloc
3439
- predeclared
40+
- reassign
3541
- revive
3642
- rowserrcheck
3743
- staticcheck
3844
- stylecheck
45+
- tagliatelle
3946
- thelper
47+
- tparallel
4048
- typecheck
4149
- unconvert
42-
- unparam
43-
- unused
44-
- whitespace
45-
- wrapcheck
46-
- contextcheck
47-
- errname
48-
- errorlint
49-
- exhaustive
50-
- forcetypeassert
51-
- gofmt
52-
- gofumpt
53-
- makezero
54-
- nosprintfhostport
55-
- tagliatelle
56-
- tparallel
5750
- usestdlibvars
51+
- unused
5852
- wastedassign
53+
- wrapcheck
5954

6055
linters-settings:
6156
godot:
@@ -85,58 +80,27 @@ linters-settings:
8580
# Controller Runtime
8681
- pkg: sigs.k8s.io/controller-runtime
8782
alias: ctrl
83+
gofumpt:
84+
extra-rules: true
8885
nolintlint:
8986
allow-unused: false
9087
allow-leading-space: false
9188
require-specific: true
9289
staticcheck:
93-
go: "1.20"
90+
go: "1.21"
9491
stylecheck:
95-
go: "1.20"
92+
go: "1.21"
9693
checks: ["all", "-ST1006"]
9794
dot-import-whitelist:
9895
- "github.com/onsi/gomega"
9996
- "github.com/onsi/ginkgo/v2"
100-
gosec:
101-
excludes:
102-
- G307 # Deferring unsafe method "Close" on type "\*os.File"
103-
- G108 # Profiling endpoint is automatically exposed on /debug/pprof
104-
- G106 # Allowing for insecure ssh
10597
gocritic:
10698
enabled-tags:
10799
- diagnostic
108-
- experimental
100+
- style
109101
- performance
110-
disabled-checks:
111-
- appendAssign
112-
- dupImport # https://github.com/go-critic/go-critic/issues/845
113-
- evalOrder
114-
- ifElseChain
115-
- octalLiteral
116-
- regexpSimplify
117-
- sloppyReassign
118-
- truncateCmp
119-
- typeDefFirst
120-
- unnamedResult
121-
- unnecessaryDefer
122-
- whyNoLint
123-
- wrapperFunc
124-
- rangeValCopy
125-
- hugeParam
126-
unused:
127-
go: "1.20"
128-
wrapcheck:
129-
ignoreSigs:
130-
- status.Error(
131-
- .Errorf(
132-
- errors.New(
133-
- errors.Unwrap(
134-
- .Wrap(
135-
- .Wrapf(
136-
- .WithMessage(
137-
- .WithMessagef(
138-
- .WithStack(
139-
- .Complete(
102+
- experimental
103+
- opinionated
140104
revive:
141105
enable-all-rules: true
142106
rules:
@@ -145,11 +109,12 @@ linters-settings:
145109
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#add-constant
146110
- name: add-constant
147111
severity: warning
148-
disabled: false
112+
disabled: true
149113
arguments:
150114
- maxLitCount: "3"
151115
allowStrs: '""'
152116
allowInts: "0,1,2,3,42,100"
117+
153118
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#argument-limit
154119
- name: argument-limit
155120
severity: warning
@@ -242,113 +207,85 @@ linters-settings:
242207
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#comment-spacings
243208
- name: comment-spacings
244209
disabled: true
245-
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#add-constant
246-
- name: add-constant
247-
disabled: true
248210
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#use-any
249211
- name: use-any
250212
disabled: true
251213
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#deep-exit
252214
- name: deep-exit
253215
disabled: true
254-
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#struct-tag
255-
- name: struct-tag
256-
disabled: true
257-
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#receiver-naming
258-
- name: receiver-naming
259-
disabled: true
260216
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#receiver-naming
261217
- name: nested-structs
262218
disabled: true
219+
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#struct-tag
220+
- name: struct-tag
221+
disabled: true
222+
unused:
223+
go: "1.21"
224+
usestdlibvars:
225+
# Suggest the use of http.MethodXX.
226+
# Default: true
227+
http-method: true
228+
# Suggest the use of http.StatusXX.
229+
# Default: true
230+
http-status-code: true
231+
# Suggest the use of time.Weekday.String().
232+
# Default: true
233+
time-weekday: true
234+
# Suggest the use of time.Month.String().
235+
# Default: false
236+
time-month: true
237+
# Suggest the use of time.Layout.
238+
# Default: false
239+
time-layout: true
240+
# Suggest the use of crypto.Hash.String().
241+
# Default: false
242+
crypto-hash: true
243+
# Suggest the use of rpc.DefaultXXPath.
244+
# Default: false
245+
default-rpc-path: true
246+
# Suggest the use of os.DevNull.
247+
# Default: false
248+
os-dev-null: true
249+
# Suggest the use of sql.LevelXX.String().
250+
# Default: false
251+
sql-isolation-level: true
252+
# Suggest the use of tls.SignatureScheme.String().
253+
# Default: false
254+
tls-signature-scheme: true
255+
# Suggest the use of constant.Kind.String().
256+
# Default: false
257+
constant-kind: true
258+
# Suggest the use of syslog.Priority.
259+
# Default: false
260+
syslog-priority: true
261+
wrapcheck:
262+
ignoreSigs:
263+
- status.Error(
264+
- .Errorf(
265+
- errors.New(
266+
- errors.Unwrap(
267+
- .Wrap(
268+
- .Wrapf(
269+
- .WithMessage(
270+
- .WithMessagef(
271+
- .WithStack(
272+
- .Complete(
263273
issues:
264274
max-same-issues: 0
265275
max-issues-per-linter: 0
266-
# We are disabling default golangci exclusions because we want to help reviewers to focus on reviewing the most relevant
276+
# We are disabling default golangci exclusions
277+
# because we want to help reviewers to focus on reviewing the most relevant
267278
# changes in PRs and avoid nitpicking.
268279
exclude-use-default: false
269280
exclude-rules:
270281
- linters:
271282
- wrapcheck
272283
path: _test\.go
273-
- linters:
274-
- revive
275-
text: "exported: exported method .*\\.(Reconcile|SetupWithManager|SetupWebhookWithManager) should have comment or be unexported"
276-
- linters:
277-
- errcheck
278-
text: Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*print(f|ln)?|os\.(Un)?Setenv). is not checked
279-
# Exclude some packages or code to require comments, for example test code, or fake clients.
280-
- linters:
281-
- revive
282-
text: exported (method|function|type|const) (.+) should have comment or be unexported
283-
source: (func|type).*Fake.*
284-
- linters:
285-
- revive
286-
text: exported (method|function|type|const) (.+) should have comment or be unexported
287-
path: fake_\.go
288-
- linters:
289-
- revive
290-
text: exported (method|function|type|const) (.+) should have comment or be unexported
291-
path: "(framework|e2e)/.*.go"
292-
# Disable unparam "always receives" which might not be really
293-
# useful when building libraries.
294-
- linters:
295-
- unparam
296-
text: always receives
297-
# Dot imports for gomega or ginkgo are allowed
298-
# within test files.
299-
- path: _test\.go
300-
text: should not use dot imports
301-
- path: (framework|e2e)/.*.go
302-
text: should not use dot imports
303-
- path: _test\.go
304-
text: cyclomatic complexity
305-
# Append should be able to assign to a different var/slice.
306-
- linters:
307-
- gocritic
308-
text: "appendAssign: append result not assigned to the same slice"
309-
# Disable linters for conversion
310-
- linters:
311-
- staticcheck
312-
text: "SA1019: in.(.+) is deprecated"
313-
path: .*(api|types)\/.*\/conversion.*\.go$
314-
- linters:
315-
- revive
316-
text: exported (method|function|type|const) (.+) should have comment or be unexported
317-
path: .*(api|types|test)\/.*\/conversion.*\.go$
318-
- linters:
319-
- revive
320-
text: "var-naming: don't use underscores in Go names;"
321-
path: .*(api|types|test)\/.*\/conversion.*\.go$
322-
- linters:
323-
- revive
324-
text: "receiver-naming: receiver name"
325-
path: .*(api|types)\/.*\/conversion.*\.go$
326-
- linters:
327-
- stylecheck
328-
text: "ST1003: should not use underscores in Go names;"
329-
path: .*(api|types|test)\/.*\/conversion.*\.go$
330-
- linters:
331-
- stylecheck
332-
text: "ST1016: methods on the same type should have the same receiver name"
333-
path: .*(api|types)\/.*\/conversion.*\.go$
334-
# hack/tools
335-
- linters:
336-
- typecheck
337-
text: import (".+") is a program, not an importable package
338-
path: ^tools\.go$
339-
# We don't care about defer in for loops in test files.
340-
- linters:
341-
- gocritic
342-
text: "deferInLoop: Possible resource leak, 'defer' is called in the 'for' loop"
343-
path: _test\.go
344284
run:
345285
timeout: 10m
346-
skip-files:
347-
- "zz_generated.*\\.go$"
348-
- ".*conversion.*\\.go$"
349-
- "test/e2e/*\\.go$"
350-
skip-dirs:
351-
- "third_party"
352-
- "tilt_modules"
286+
go: "1.21"
353287
allow-parallel-runners: true
354-
modules-download-mode: readonly
288+
modules-download-mode: vendor
289+
skip-dirs:
290+
- vendor$
291+
- test/vendor$

config/default/kustomization.yaml

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,14 @@ commonLabels:
66
cluster.x-k8s.io/provider: "infrastructure-cluster-stack-operator"
77

88
resources:
9-
- ../crd
10-
- ../rbac
11-
- ../manager
12-
#- ../webhook
13-
- ../certmanager
9+
- ../crd
10+
- ../rbac
11+
- ../manager
12+
- ../certmanager
1413

1514
patchesStrategicMerge:
16-
- manager_config_patch.yaml
17-
#- manager_webhook_patch.yaml
18-
#- webhookcainjection_patch.yaml
19-
- manager_pull_policy.yaml
20-
15+
- manager_config_patch.yaml
16+
- manager_pull_policy.yaml
2117
# vars:
2218
# - name: CERTIFICATE_NAMESPACE # namespace of the certificate CR
2319
# objref:
@@ -44,4 +40,4 @@ patchesStrategicMerge:
4440
# objref:
4541
# kind: Service
4642
# version: v1
47-
# name: webhook-service
43+
# name: webhook-service

internal/clusterstackrelease/util.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,12 @@ func Summary(csr *csov1alpha1.ClusterStackRelease) (csov1alpha1.ClusterStackRele
4848

4949
// if provider-specific work is done, we are left with applying objects
5050
// We don't expect the condition to be not set at all, hence no else case here
51-
if conditions.IsTrue(csr, csov1alpha1.ProviderClusterStackReleaseReadyCondition) {
51+
switch {
52+
case conditions.IsTrue(csr, csov1alpha1.ProviderClusterStackReleaseReadyCondition):
5253
summary.Phase = csov1alpha1.ClusterStackReleasePhaseApplyingObjects
53-
} else if conditions.IsTrue(csr, csov1alpha1.ClusterStackReleaseAssetsReadyCondition) {
54+
case conditions.IsTrue(csr, csov1alpha1.ClusterStackReleaseAssetsReadyCondition):
5455
summary.Phase = csov1alpha1.ClusterStackReleasePhaseProviderSpecificWork
55-
} else if conditions.IsFalse(csr, csov1alpha1.ClusterStackReleaseAssetsReadyCondition) {
56+
case conditions.IsFalse(csr, csov1alpha1.ClusterStackReleaseAssetsReadyCondition):
5657
summary.Phase = csov1alpha1.ClusterStackReleasePhaseDownloadingAssets
5758
}
5859

0 commit comments

Comments
 (0)