enabled a few more linter rules

This commit is contained in:
Sergey Kanzhelev
2025-09-11 18:47:20 +00:00
parent 0fe2979ff1
commit 3e64800668
8 changed files with 139 additions and 9 deletions

View File

@@ -6,11 +6,114 @@ run:
linters:
default: none
enable:
- ineffassign
- unused
- govet
- arangolint
- asasalint
- asciicheck
- bidichk
- bodyclose
- canonicalheader
- containedctx
- contextcheck
# - copyloopvar 1
# - cyclop 15
- decorder
# - depguard 265
- dogsled
# - dupl 2
- dupword
- durationcheck
# - embeddedstructfieldcheck 5
# - err113 64
- errcheck
- errchkjson
- errname
# - errorlint 4
# - exhaustive 2
# - exhaustruct 260
- exptostd
- fatcontext
# - forbidigo 6
# - forcetypeassert: 5
# - funcorder: 5
# - funlen: 24
- ginkgolinter
- gocheckcompilerdirectives
# - gochecknoglobals 31
# - gochecknoinits 14
- gochecksumtype
# - gocognit 5
- goconst
# - gocritic 3
# - gocyclo 1
# - godot 24
# - godox 8
- goheader
- gomoddirectives
- gomodguard
- goprintffuncname
# - gosec 55
# - gosmopolitan 5
- govet
- grouper
- iface
- importas
# - inamedparam 6
- ineffassign
- interfacebloat
# - intrange 1
# - ireturn 15
# - lll 59
- loggercheck
- maintidx
- makezero
- mirror
- misspell
# - mnd 29
- musttag
- nakedret
# - nestif 7
# - nilerr 2
# - nilnesserr 2
# - nilnil 3
# - nlreturn 149
- noctx
# - noinlineerr 81
- nolintlint
# - nonamedreturns 2
- nosprintfhostport
# - paralleltest 54
# - perfsprint 14
# - prealloc 5
# - predeclared 1
- promlinter
# - protogetter 7
- reassign
# - recvcheck 3
# - revive 133
- rowserrcheck
- sloglint
- spancheck
- sqlclosecheck
- staticcheck
- tagalign
# - tagliatelle 6
- testableexamples
# - testifylint 10
# - testpackage 34
# - thelper 4
- tparallel
- unconvert
# - unparam 1
- unused
- usestdlibvars
# - usetesting 3
# - varnamelen 33
- wastedassign
- whitespace
# - wrapcheck 26
# - wsl 403
# - wsl_v5 58
- zerologlint
exclusions:
generated: lax
paths:

View File

@@ -126,9 +126,22 @@ func logPatternHealthCheck(service string, loopBackTime time.Duration, logPatter
// healthCheckEndpointOKFunc returns a function to check the status of an http endpoint
func healthCheckEndpointOKFunc(endpoint string, timeout time.Duration) func() (bool, error) {
return func() (bool, error) {
req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, endpoint, nil)
if err != nil {
return false, err
}
httpClient := http.Client{Timeout: timeout}
response, err := httpClient.Get(endpoint)
if err != nil || response.StatusCode != http.StatusOK {
response, err := httpClient.Do(req)
if err != nil {
return false, nil
}
defer func() {
err := response.Body.Close()
if err != nil {
klog.Warningf("failed to close http client: %v", err)
}
}()
if response.StatusCode != http.StatusOK {
return false, nil
}
return true, nil

View File

@@ -148,7 +148,7 @@ Jan 2 03:04:05 kernel: [2.000000] 3
t.Logf("failed to remove temporary file %s: %v", f.Name(), err)
}
}()
_, err = f.Write([]byte(test.log))
_, err = f.WriteString(test.log)
assert.NoError(t, err)
w := NewSyslogWatcherOrDie(types.WatcherConfig{

View File

@@ -85,6 +85,7 @@ func testCollectAux(t *testing.T, name string, excludeInterfaceRegexp ssmtypes.N
}
func TestCollect(t *testing.T) {
t.Parallel()
tcs := []struct {
Name string
ExcludeInterfaceRegexp ssmtypes.NetStatsInterfaceRegexp

View File

@@ -21,6 +21,7 @@ import (
)
func TestGetOSVersionLinux(t *testing.T) {
t.Parallel()
testCases := []struct {
name string
fakeOSReleasePath string

View File

@@ -56,7 +56,7 @@ func TestPrometheusMetricsParsingAndMatching(t *testing.T) {
// Metric with non-existent label.
{
Name: "host_uptime",
Labels: map[string]string{"non-existant-version": "0.0.1"},
Labels: map[string]string{"non-existent-version": "0.0.1"},
},
// Metric with incorrect label.
{

View File

@@ -17,6 +17,8 @@ import (
"encoding/json"
"fmt"
"strings"
"k8s.io/klog/v2"
)
type CmdlineArg struct {
@@ -25,7 +27,11 @@ type CmdlineArg struct {
}
func (d CmdlineArg) String() string {
s, _ := json.Marshal(d)
s, err := json.Marshal(d)
if err != nil {
klog.Errorf("failed to marshal cmdline arg: %v", err)
return ""
}
return string(s)
}

View File

@@ -18,6 +18,8 @@ import (
"fmt"
"strconv"
"strings"
"k8s.io/klog/v2"
)
type Module struct {
@@ -29,7 +31,11 @@ type Module struct {
}
func (d Module) String() string {
s, _ := json.Marshal(d)
s, err := json.Marshal(d)
if err != nil {
klog.Errorf("failed to marshal module stat: %v", err)
return ""
}
return string(s)
}