Skip to content

Commit 34485e0

Browse files
authored
address linter settings (#926)
1 parent 26ea83e commit 34485e0

File tree

2 files changed

+200
-11
lines changed

2 files changed

+200
-11
lines changed

.golangci.yaml

Lines changed: 197 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,211 @@
11
run:
2-
timeout: 5m
3-
2+
timeout: 10m
3+
allow-parallel-runners: true
4+
exclude-dirs:
5+
- pkg/client
46
build-tags:
5-
- e2e
7+
- e2e
8+
9+
output:
10+
sort-results: true
11+
sort-order:
12+
- linter
13+
- file
14+
show-stats: true
615

7-
skip-dirs:
8-
- pkg/client
16+
17+
issues:
18+
uniq-by-line: true
19+
max-issues-per-linter: 0
20+
max-same-issues: 0
21+
exclude-rules:
22+
- path: test # Excludes /test, *_test.go etc.
23+
linters:
24+
- gosec
25+
- unparam
26+
- noctx
27+
- protogetter
28+
- linters: ["gocritic"]
29+
# Fixes are non-trivial do in a follow up
30+
text: "ifElseChain"
31+
32+
linters-settings:
33+
gomodguard:
34+
blocked:
35+
modules:
36+
- github.com/ghodss/yaml:
37+
recommendations:
38+
- sigs.k8s.io/yaml
39+
- go.uber.org/atomic:
40+
recommendations:
41+
- sync/atomic
42+
- io/ioutil:
43+
recommendations:
44+
- os
45+
- io
46+
- github.com/hashicorp/go-multierror:
47+
reason: "use errors.Join"
48+
recommendations:
49+
- errors
50+
- go.uber.org/multierr:
51+
reason: "use errors.Join"
52+
recommendations:
53+
- errors
54+
revive:
55+
rules:
56+
# use unparam linter instead - defaults are better
57+
- name: unused-parameter
58+
disabled: true
959

1060
linters:
61+
disable:
62+
- errcheck
1163
enable:
64+
# Check for pass []any as any in variadic func(...any).
65+
- asasalint
66+
67+
# Only use ASCII chars in indentifiers
1268
- asciicheck
69+
70+
# Dangerous unicode characters
71+
- bidichk
72+
73+
# Checks whether HTTP response body is closed successfully.
74+
- bodyclose
75+
76+
# Canonicalheader checks whether net/http.Header uses canonical header.
77+
- canonicalheader
78+
79+
# TODO - do a follow up PR
80+
# # Containedctx is a linter that detects struct contained context.Context
81+
# # field.
82+
# - containedctx
83+
84+
# TODO - do a follow up PR
85+
# # Check whether the function uses a non-inherited context.
86+
# - contextcheck
87+
88+
# Copyloopvar is a linter detects places where loop variables are copied.
89+
- copyloopvar
90+
91+
# Check declaration order of types, consts, vars and funcs.
92+
- decorder
93+
94+
# Check for two durations multiplied together.
95+
- durationcheck
96+
97+
# Checks that sentinel errors are prefixed with the Err- and error types
98+
# are suffixed with the -Error.
99+
- errname
100+
101+
# Errorlint is a linter for that can be used to find code that will cause
102+
# problems with the error wrapping scheme introduced in Go 1.13.
13103
- errorlint
104+
105+
# Detects nested contexts in loops.
106+
- fatcontext
107+
108+
# Checks that go compiler directive comments (//go:) are valid.
109+
- gocheckcompilerdirectives
110+
111+
# Provides diagnostics that check for bugs, performance and style issues.
112+
# Extensible without recompilation through dynamic rules.
113+
# Dynamic rules are written declaratively with AST patterns, filters,
114+
# report message and optional suggestion.
115+
- gocritic
116+
117+
# Gofmt checks whether code was gofmt-ed. By default this tool runs
118+
# with -s option to check for code simplification.
119+
- gofmt
120+
121+
# Gofumpt checks whether code was gofumpt-ed.
122+
- gofumpt
123+
124+
# Check import statements are formatted according to the 'goimport'
125+
# command. Reformat imports in autofix mode.
126+
- goimports
127+
128+
# See config below
129+
- gomodguard
130+
131+
# Inspects source code for security problems.
14132
- gosec
133+
134+
# Linter that specializes in simplifying code.
135+
- gosimple
136+
- govet
137+
138+
# Intrange is a linter to find places where for loops could make use of
139+
# an integer range.
140+
- intrange
141+
142+
# Checks key value pairs for common logger libraries (kitlog,klog,logr,zap).
143+
- loggercheck
144+
145+
# Finds slice declarations with non-zero initial length.
146+
- makezero
147+
148+
# Reports wrong mirror patterns of bytes/strings usage
149+
- mirror
150+
151+
# Finds commonly misspelled English words.
152+
- misspell
153+
154+
# Finds the code that returns nil even if it checks that the error is not nil.
155+
- nilerr
156+
157+
# Finds sending HTTP request without context.Context.
158+
- noctx
159+
160+
# Reports ill-formed or insufficient nolint directives.
161+
- nolintlint
162+
163+
# Checks for misuse of Sprintf to construct a host with port in a URL.
164+
- nosprintfhostport
165+
166+
# Checks that fmt.Sprintf can be replaced with a faster alternative.
167+
- perfsprint
168+
169+
# Finds slice declarations that could potentially be pre-allocated.
15170
- prealloc
171+
172+
# Reports direct reads from proto message fields when getters should be used.
173+
- protogetter
174+
175+
# Checks that package variables are not reassigned.
176+
- reassign
177+
178+
# Fast, configurable, extensible, flexible, and beautiful linter for
179+
# Go. Drop-in replacement of golint.
16180
- revive
181+
182+
# Checks for mistakes with OpenTelemetry/Census spans.
183+
- spancheck
184+
185+
# Stylecheck is a replacement for golint.
17186
- stylecheck
18-
- tparallel
187+
188+
# Tenv is analyzer that detects using os.Setenv instead of t.Setenv
189+
# since Go1.17.
190+
- tenv
191+
192+
# Linter checks if examples are testable (have an expected output).
193+
- testableexamples
194+
195+
# Remove unnecessary type conversions.
19196
- unconvert
197+
198+
# Reports unused function parameters and results in your code.
20199
- unparam
21-
disable:
22-
- errcheck
200+
201+
# A linter that detect the possibility to use variables/constants from the
202+
# Go standard library.
203+
- usestdlibvars
204+
205+
# Finds wasted assignment statements.
206+
- wastedassign
207+
208+
# Whitespace is a linter that checks for unnecessary newlines at the start
209+
# and end of functions, if, for, etc.
210+
- whitespace
211+

pkg/reconciler/simpledeployment/simpledeployment.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,13 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, d *samplesv1alpha1.Simpl
7575
}
7676
}
7777

78-
currentCount := int32(len(currentPods))
78+
currentCount := int32(len(currentPods)) //nolint // ignore overflow int -> int32
7979
if currentCount < d.Spec.Replicas {
8080
// We don't have as many replicas as we should, so create the remaining ones.
8181
toCreate := d.Spec.Replicas - currentCount
8282
logger.Infof("Got %d existing pods, want %d -> creating %d", currentCount, d.Spec.Replicas, toCreate)
8383
pod := makePod(d)
84-
for i := int32(0); i < toCreate; i++ {
84+
for range toCreate {
8585
if _, err := r.kubeclient.CoreV1().Pods(pod.Namespace).Create(ctx, pod, metav1.CreateOptions{}); err != nil {
8686
return fmt.Errorf("failed to create pod: %w", err)
8787
}
@@ -90,7 +90,7 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, d *samplesv1alpha1.Simpl
9090
// We have too many replicas, so remove the ones that are too much.
9191
toDelete := currentCount - d.Spec.Replicas
9292
logger.Infof("Got %d existing pods, want %d -> removing %d", currentCount, d.Spec.Replicas, toDelete)
93-
for i := int32(0); i < toDelete; i++ {
93+
for i := range toDelete {
9494
if err := r.kubeclient.CoreV1().Pods(d.Namespace).Delete(ctx, currentPods[i].Name, metav1.DeleteOptions{}); err != nil {
9595
return fmt.Errorf("failed to delete pod: %w", err)
9696
}

0 commit comments

Comments
 (0)