Skip to content

Commit 21579f0

Browse files
authored
Merge pull request #1124 from SergeyKanzhelev/morelinter
enabled a few more linter rules
2 parents 3fb81ae + 3e64800 commit 21579f0

File tree

8 files changed

+139
-9
lines changed

8 files changed

+139
-9
lines changed

.golangci.yml

Lines changed: 106 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,114 @@ run:
66
linters:
77
default: none
88
enable:
9-
- ineffassign
10-
- unused
11-
- govet
9+
- arangolint
10+
- asasalint
11+
- asciicheck
12+
- bidichk
13+
- bodyclose
14+
- canonicalheader
15+
- containedctx
16+
- contextcheck
17+
# - copyloopvar 1
18+
# - cyclop 15
19+
- decorder
20+
# - depguard 265
21+
- dogsled
22+
# - dupl 2
23+
- dupword
24+
- durationcheck
25+
# - embeddedstructfieldcheck 5
26+
# - err113 64
1227
- errcheck
28+
- errchkjson
29+
- errname
30+
# - errorlint 4
31+
# - exhaustive 2
32+
# - exhaustruct 260
33+
- exptostd
34+
- fatcontext
35+
# - forbidigo 6
36+
# - forcetypeassert: 5
37+
# - funcorder: 5
38+
# - funlen: 24
39+
- ginkgolinter
40+
- gocheckcompilerdirectives
41+
# - gochecknoglobals 31
42+
# - gochecknoinits 14
43+
- gochecksumtype
44+
# - gocognit 5
45+
- goconst
46+
# - gocritic 3
47+
# - gocyclo 1
48+
# - godot 24
49+
# - godox 8
50+
- goheader
51+
- gomoddirectives
52+
- gomodguard
53+
- goprintffuncname
54+
# - gosec 55
55+
# - gosmopolitan 5
56+
- govet
57+
- grouper
58+
- iface
59+
- importas
60+
# - inamedparam 6
61+
- ineffassign
62+
- interfacebloat
63+
# - intrange 1
64+
# - ireturn 15
65+
# - lll 59
66+
- loggercheck
67+
- maintidx
68+
- makezero
69+
- mirror
70+
- misspell
71+
# - mnd 29
72+
- musttag
73+
- nakedret
74+
# - nestif 7
75+
# - nilerr 2
76+
# - nilnesserr 2
77+
# - nilnil 3
78+
# - nlreturn 149
79+
- noctx
80+
# - noinlineerr 81
81+
- nolintlint
82+
# - nonamedreturns 2
83+
- nosprintfhostport
84+
# - paralleltest 54
85+
# - perfsprint 14
86+
# - prealloc 5
87+
# - predeclared 1
88+
- promlinter
89+
# - protogetter 7
90+
- reassign
91+
# - recvcheck 3
92+
# - revive 133
93+
- rowserrcheck
94+
- sloglint
95+
- spancheck
96+
- sqlclosecheck
1397
- staticcheck
98+
- tagalign
99+
# - tagliatelle 6
100+
- testableexamples
101+
# - testifylint 10
102+
# - testpackage 34
103+
# - thelper 4
104+
- tparallel
105+
- unconvert
106+
# - unparam 1
107+
- unused
108+
- usestdlibvars
109+
# - usetesting 3
110+
# - varnamelen 33
111+
- wastedassign
112+
- whitespace
113+
# - wrapcheck 26
114+
# - wsl 403
115+
# - wsl_v5 58
116+
- zerologlint
14117
exclusions:
15118
generated: lax
16119
paths:

pkg/healthchecker/health_checker.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,22 @@ func logPatternHealthCheck(service string, loopBackTime time.Duration, logPatter
126126
// healthCheckEndpointOKFunc returns a function to check the status of an http endpoint
127127
func healthCheckEndpointOKFunc(endpoint string, timeout time.Duration) func() (bool, error) {
128128
return func() (bool, error) {
129+
req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, endpoint, nil)
130+
if err != nil {
131+
return false, err
132+
}
129133
httpClient := http.Client{Timeout: timeout}
130-
response, err := httpClient.Get(endpoint)
131-
if err != nil || response.StatusCode != http.StatusOK {
134+
response, err := httpClient.Do(req)
135+
if err != nil {
136+
return false, nil
137+
}
138+
defer func() {
139+
err := response.Body.Close()
140+
if err != nil {
141+
klog.Warningf("failed to close http client: %v", err)
142+
}
143+
}()
144+
if response.StatusCode != http.StatusOK {
132145
return false, nil
133146
}
134147
return true, nil

pkg/systemlogmonitor/logwatchers/filelog/log_watcher_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ Jan 2 03:04:05 kernel: [2.000000] 3
148148
t.Logf("failed to remove temporary file %s: %v", f.Name(), err)
149149
}
150150
}()
151-
_, err = f.Write([]byte(test.log))
151+
_, err = f.WriteString(test.log)
152152
assert.NoError(t, err)
153153

154154
w := NewSyslogWatcherOrDie(types.WatcherConfig{

pkg/systemstatsmonitor/net_collector_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ func testCollectAux(t *testing.T, name string, excludeInterfaceRegexp ssmtypes.N
8585
}
8686

8787
func TestCollect(t *testing.T) {
88+
t.Parallel()
8889
tcs := []struct {
8990
Name string
9091
ExcludeInterfaceRegexp ssmtypes.NetStatsInterfaceRegexp

pkg/util/helpers_linux_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
)
2222

2323
func TestGetOSVersionLinux(t *testing.T) {
24+
t.Parallel()
2425
testCases := []struct {
2526
name string
2627
fakeOSReleasePath string

pkg/util/metrics/helpers_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func TestPrometheusMetricsParsingAndMatching(t *testing.T) {
5656
// Metric with non-existent label.
5757
{
5858
Name: "host_uptime",
59-
Labels: map[string]string{"non-existant-version": "0.0.1"},
59+
Labels: map[string]string{"non-existent-version": "0.0.1"},
6060
},
6161
// Metric with incorrect label.
6262
{

pkg/util/metrics/system/cmdline_args.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import (
1717
"encoding/json"
1818
"fmt"
1919
"strings"
20+
21+
"k8s.io/klog/v2"
2022
)
2123

2224
type CmdlineArg struct {
@@ -25,7 +27,11 @@ type CmdlineArg struct {
2527
}
2628

2729
func (d CmdlineArg) String() string {
28-
s, _ := json.Marshal(d)
30+
s, err := json.Marshal(d)
31+
if err != nil {
32+
klog.Errorf("failed to marshal cmdline arg: %v", err)
33+
return ""
34+
}
2935
return string(s)
3036
}
3137

pkg/util/metrics/system/module_stats.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import (
1818
"fmt"
1919
"strconv"
2020
"strings"
21+
22+
"k8s.io/klog/v2"
2123
)
2224

2325
type Module struct {
@@ -29,7 +31,11 @@ type Module struct {
2931
}
3032

3133
func (d Module) String() string {
32-
s, _ := json.Marshal(d)
34+
s, err := json.Marshal(d)
35+
if err != nil {
36+
klog.Errorf("failed to marshal module stat: %v", err)
37+
return ""
38+
}
3339
return string(s)
3440
}
3541

0 commit comments

Comments
 (0)