Skip to content

Commit b85b189

Browse files
authored
add linter and fix any warnings (#941)
1 parent 99e6352 commit b85b189

File tree

5 files changed

+234
-13
lines changed

5 files changed

+234
-13
lines changed

.golangci.yaml

Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
version: "2"
2+
run:
3+
build-tags:
4+
- e2e
5+
- hpa
6+
- upgrade
7+
allow-parallel-runners: true
8+
output:
9+
sort-order:
10+
- linter
11+
- file
12+
linters:
13+
enable:
14+
# Check for pass []any as any in variadic func(...any).
15+
- asasalint
16+
17+
# Only use ASCII chars in indentifiers
18+
- asciicheck
19+
20+
# Dangerous unicode characters
21+
- bidichk
22+
23+
# Checks whether HTTP response body is closed successfully.
24+
- bodyclose
25+
26+
# Canonicalheader checks whether net/http.Header uses canonical header.
27+
- canonicalheader
28+
29+
# TODO - do a follow up PR
30+
# # Containedctx is a linter that detects struct contained context.Context
31+
# # field.
32+
# - containedctx
33+
#
34+
# TODO - do a follow up PR
35+
# # Check whether the function uses a non-inherited context.
36+
# - contextcheck
37+
38+
# Copyloopvar is a linter detects places where loop variables are copied.
39+
- copyloopvar
40+
41+
# Check declaration order of types, consts, vars and funcs.
42+
- decorder
43+
44+
# Check for two durations multiplied together.
45+
- durationcheck
46+
47+
# Checks that sentinel errors are prefixed with the Err- and error types
48+
# are suffixed with the -Error.
49+
- errname
50+
51+
# Errorlint is a linter for that can be used to find code that will cause
52+
# problems with the error wrapping scheme introduced in Go 1.13.
53+
- errorlint
54+
55+
# Detects nested contexts in loops.
56+
- fatcontext
57+
58+
# Checks that go compiler directive comments (//go:) are valid.
59+
- gocheckcompilerdirectives
60+
61+
# Provides diagnostics that check for bugs, performance and style issues.
62+
# Extensible without recompilation through dynamic rules.
63+
# Dynamic rules are written declaratively with AST patterns, filters,
64+
# report message and optional suggestion.
65+
- gocritic
66+
67+
# See config below
68+
- gomodguard
69+
70+
# Inspects source code for security problems.
71+
- gosec
72+
73+
# Intrange is a linter to find places where for loops could make use of
74+
# an integer range.
75+
- intrange
76+
77+
# Checks key value pairs for common logger libraries (kitlog,klog,logr,zap).
78+
- loggercheck
79+
80+
# Finds slice declarations with non-zero initial length.
81+
- makezero
82+
83+
# Reports wrong mirror patterns of bytes/strings usage
84+
- mirror
85+
86+
# Finds commonly misspelled English words.
87+
- misspell
88+
89+
# Finds the code that returns nil even if it checks that the error is not nil.
90+
- nilerr
91+
92+
# Finds sending HTTP request without context.Context.
93+
- noctx
94+
95+
# Reports ill-formed or insufficient nolint directives.
96+
- nolintlint
97+
98+
# Checks for misuse of Sprintf to construct a host with port in a URL.
99+
- nosprintfhostport
100+
101+
# Checks that fmt.Sprintf can be replaced with a faster alternative.
102+
- perfsprint
103+
104+
# Finds slice declarations that could potentially be pre-allocated.
105+
- prealloc
106+
107+
# Reports direct reads from proto message fields when getters should be used.
108+
- protogetter
109+
110+
# Checks that package variables are not reassigned.
111+
- reassign
112+
113+
# Fast, configurable, extensible, flexible, and beautiful linter for
114+
# Go. Drop-in replacement of golint.
115+
- revive
116+
117+
# Checks for mistakes with OpenTelemetry/Census spans.
118+
- spancheck
119+
120+
- staticcheck
121+
122+
# Linter checks if examples are testable (have an expected output).
123+
- testableexamples
124+
125+
# Remove unnecessary type conversions.
126+
- unconvert
127+
128+
# Reports unused function parameters and results in your code.
129+
- unparam
130+
131+
# A linter that detect the possibility to use variables/constants from the
132+
# Go standard library.
133+
- usestdlibvars
134+
135+
# Finds wasted assignment statements.
136+
- wastedassign
137+
138+
# Whitespace is a linter that checks for unnecessary newlines at the start
139+
# and end of functions, if, for, etc.
140+
- whitespace
141+
disable:
142+
- errcheck
143+
settings:
144+
staticcheck:
145+
checks:
146+
- all
147+
- "-QF1008" # Disable https://staticcheck.dev/docs/checks/#QF1008
148+
gocritic:
149+
disabled-checks:
150+
- exitAfterDefer
151+
- appendAssign
152+
gomodguard:
153+
blocked:
154+
modules:
155+
- github.com/ghodss/yaml:
156+
recommendations:
157+
- sigs.k8s.io/yaml
158+
- go.uber.org/atomic:
159+
recommendations:
160+
- sync/atomic
161+
- io/ioutil:
162+
recommendations:
163+
- os
164+
- io
165+
- github.com/hashicorp/go-multierror:
166+
recommendations:
167+
- errors
168+
reason: use errors.Join
169+
- go.uber.org/multierr:
170+
recommendations:
171+
- errors
172+
reason: use errors.Join
173+
revive:
174+
rules:
175+
- name: unused-parameter
176+
disabled: true
177+
exclusions:
178+
generated: lax
179+
presets:
180+
- comments
181+
- common-false-positives
182+
- legacy
183+
- std-error-handling
184+
rules:
185+
- linters:
186+
- staticcheck
187+
text: corev1.Endpoint.* is deprecated
188+
- linters:
189+
- gosec
190+
- noctx
191+
- protogetter
192+
- unparam
193+
path: test
194+
- linters:
195+
- gocritic
196+
text: ifElseChain
197+
paths:
198+
- pkg/client
199+
- third_party$
200+
- builtin$
201+
- examples$
202+
issues:
203+
max-issues-per-linter: 0
204+
max-same-issues: 0
205+
uniq-by-line: true
206+
formatters:
207+
enable:
208+
- gofmt
209+
- gofumpt
210+
- goimports
211+
exclusions:
212+
generated: lax
213+
paths:
214+
- pkg/client
215+
- third_party$
216+
- builtin$
217+
- examples$

pkg/apis/caching/v1alpha1/image_defaults.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ package v1alpha1
1818

1919
import "context"
2020

21-
func (r *Image) SetDefaults(ctx context.Context) {
21+
func (i *Image) SetDefaults(ctx context.Context) {
2222
// TODO(mattmoor): This
2323
}

pkg/apis/caching/v1alpha1/image_lifecycle_test.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,13 @@ func TestIsReady(t *testing.T) {
4141
status: ImageStatus{
4242
Status: duckv1.Status{
4343
ObservedGeneration: 0,
44-
Conditions: duckv1.Conditions{{
45-
Type: "foo",
46-
Status: corev1.ConditionTrue,
44+
Conditions: duckv1.Conditions{
45+
{
46+
Type: "foo",
47+
Status: corev1.ConditionTrue,
48+
},
4749
},
48-
}},
50+
},
4951
},
5052
isReady: false,
5153
}, {
@@ -155,7 +157,8 @@ func TestIsReady(t *testing.T) {
155157
ObjectMeta: metav1.ObjectMeta{
156158
Generation: tc.generation,
157159
},
158-
Status: tc.status}
160+
Status: tc.status,
161+
}
159162
if e, a := tc.isReady, m.IsReady(); e != a {
160163
t.Errorf("Ready = %v, want: %v", a, e)
161164
}

pkg/apis/caching/v1alpha1/image_types.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,15 @@ type Image struct {
4646
}
4747

4848
// Check that Image can be validated and defaulted.
49-
var _ apis.Validatable = (*Image)(nil)
50-
var _ apis.Defaultable = (*Image)(nil)
51-
var _ kmeta.OwnerRefable = (*Image)(nil)
52-
var _ duckv1.KRShaped = (*Image)(nil)
49+
var (
50+
_ apis.Validatable = (*Image)(nil)
51+
_ apis.Defaultable = (*Image)(nil)
52+
_ kmeta.OwnerRefable = (*Image)(nil)
53+
_ duckv1.KRShaped = (*Image)(nil)
54+
)
5355

5456
// ImageSpec holds the desired state of the Image (from the client).
5557
type ImageSpec struct {
56-
5758
// Image is the name of the container image url to cache across the cluster.
5859
Image string `json:"image"`
5960

pkg/apis/caching/v1alpha1/image_validation.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ import (
2626
"knative.dev/pkg/apis"
2727
)
2828

29-
func (rt *Image) Validate(ctx context.Context) *apis.FieldError {
30-
return rt.Spec.Validate(ctx).ViaField("spec")
29+
func (i *Image) Validate(ctx context.Context) *apis.FieldError {
30+
return i.Spec.Validate(ctx).ViaField("spec")
3131
}
3232

3333
func (rs *ImageSpec) Validate(ctx context.Context) (errs *apis.FieldError) {

0 commit comments

Comments
 (0)