Skip to content

Commit 2d80439

Browse files
committed
CLEANUP/MEDIUM: lint: upgrade linter and fix linting errors
1 parent 9189525 commit 2d80439

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+561
-561
lines changed

.golangci.yml

Lines changed: 96 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,112 @@
1-
linters-settings:
2-
govet:
3-
shadow: true
4-
golint:
5-
min-confidence: 0
6-
gocyclo:
7-
min-complexity: 42
8-
cyclop:
9-
max-complexity: 42
10-
maligned:
11-
suggest-new: true
12-
dupl:
13-
threshold: 200
14-
goconst:
15-
min-len: 2
16-
min-occurrences: 2
17-
revive:
18-
rules:
19-
- name: var-naming
20-
severity: warning
21-
disabled: true
1+
version: "2"
222
linters:
23-
enable-all: true
3+
default: all
244
disable:
5+
- containedctx
6+
- contextcheck
7+
- depguard
258
- dupl
9+
- err113
10+
- errcheck
11+
- errorlint
2612
- exhaustive
13+
- exhaustruct
14+
- forbidigo
15+
- forcetypeassert
16+
- funcorder
2717
- funlen
28-
- gci
2918
- gochecknoglobals
3019
- gocognit
3120
- goconst
21+
- gocritic
3222
- gocyclo
23+
- godoclint
3324
- godot
25+
- godox
26+
- gomoddirectives
27+
- ireturn
3428
- lll
29+
- mnd
30+
- nakedret
3531
- nestif
3632
- nlreturn
37-
- wrapcheck
38-
- wsl
39-
- nakedret
40-
- paralleltest
41-
- testpackage
42-
- varnamelen
43-
- exhaustruct
44-
- nonamedreturns
45-
- forcetypeassert
46-
- rowserrcheck #rowserrcheck is disabled because of generics
47-
- sqlclosecheck #rowserrcheck is disabled because of generics
48-
- wastedassign #rowserrcheck is disabled because of generics
49-
- ireturn
50-
- tagliatelle
5133
- noctx
52-
- errorlint
53-
- contextcheck
54-
- godox
55-
- containedctx
56-
- unused
57-
- unparam
34+
- noinlineerr
35+
- nonamedreturns
36+
- paralleltest
5837
- prealloc
59-
- forbidigo
60-
- errcheck
61-
- gocritic
62-
- tagalign
63-
- depguard
64-
- mnd
65-
- err113
66-
- tenv # deprecated
6738
- recvcheck
68-
69-
issues:
70-
exclude:
71-
# bugs of typecheck linter
72-
- "undeclared name: `shellquote`"
73-
- 'github.com/kballard/go-shellquote" imported but not used'
74-
- 'github.com/haproxytech/client-native/v5/config-parser/types" imported but not used'
75-
exclude-rules:
76-
- linters:
77-
- staticcheck
78-
text: "duplicate struct tag"
79-
- linters:
80-
- gosec
81-
text: "G[501]"
82-
- linters:
83-
- gosec
84-
text: "G[404]"
85-
exclude-dirs:
86-
- test
39+
- rowserrcheck
40+
- sqlclosecheck
41+
- tagalign
42+
- tagliatelle
43+
- testpackage
44+
- unparam
45+
- unused
46+
- varnamelen
47+
- wastedassign
48+
- wrapcheck
49+
- wsl
50+
- wsl_v5
51+
settings:
52+
cyclop:
53+
max-complexity: 42
54+
dupl:
55+
threshold: 200
56+
goconst:
57+
min-len: 2
58+
min-occurrences: 2
59+
gocyclo:
60+
min-complexity: 42
61+
revive:
62+
rules:
63+
- name: var-naming
64+
severity: warning
65+
disabled: true
66+
exclusions:
67+
generated: lax
68+
presets:
69+
- comments
70+
- common-false-positives
71+
- legacy
72+
- std-error-handling
73+
rules:
74+
- linters:
75+
- govet
76+
- whitespace
77+
- gosmopolitan
78+
- cyclop
79+
- maintidx
80+
path: metrics/logs/inputs/parsers/
81+
- linters:
82+
- staticcheck
83+
text: duplicate struct tag
84+
- linters:
85+
- gosec
86+
text: G[501]
87+
- linters:
88+
- gosec
89+
text: G[404]
90+
- path: (.+)\.go$
91+
text: 'undeclared name: `shellquote`'
92+
- path: (.+)\.go$
93+
text: github.com/kballard/go-shellquote" imported but not used
94+
- path: (.+)\.go$
95+
text: github.com/haproxytech/client-native/v6/config-parser/types" imported but not used
96+
paths:
97+
- test
98+
- third_party$
99+
- builtin$
100+
- examples$
101+
formatters:
102+
enable:
103+
- gofmt
104+
- gofumpt
105+
- goimports
106+
exclusions:
107+
generated: lax
108+
paths:
109+
- test
110+
- third_party$
111+
- builtin$
112+
- examples$

adapters/adapters.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func RecoverMiddleware(logger *log.Logger) func(h http.Handler) http.Handler {
8585
if err := recover(); err != nil {
8686
frames := callers()
8787

88-
fields := make(map[string]interface{})
88+
fields := make(map[string]any)
8989
fields["stack_trace"] = frames.String()
9090
logger.WithFieldsf(fields, log.ErrorLevel, "Panic %v", err)
9191

client-native/cn.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,7 @@ func ConfigureConfigurationClient(haproxyOptions dataplaneapi_config.HAProxyConf
4545

4646
p := confClient.Parser()
4747
comments, err := p.Get(parser.Comments, parser.CommentsSectionName, "#")
48-
insertDisclaimer := false
49-
if err != nil {
50-
insertDisclaimer = true
51-
}
48+
insertDisclaimer := err != nil
5249
data, ok := comments.([]types.Comments)
5350
if !ok {
5451
insertDisclaimer = true

cmd/dataplaneapi/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ func startServer(cfg *configuration.Configuration, cancelDebugServer context.Can
207207
api.BasicAuthenticator = func(authentication security.UserPassAuthentication) runtime.Authenticator {
208208
// if mTLS is enabled with backing Certificate Authority, skipping basic authentication
209209
if len(server.TLSCACertificate) > 0 && server.TLSPort > 0 {
210-
return runtime.AuthenticatorFunc(func(i interface{}) (bool, interface{}, error) {
210+
return runtime.AuthenticatorFunc(func(i any) (bool, any, error) {
211211
return true, "", nil
212212
})
213213
}

cmd/govulncheck-report/main.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,14 @@ func main() {
7070
}
7171
currentBranch = string(out)
7272
}
73-
slog.Info("Current branch: " + currentBranch)
73+
slog.Info("Current branch: " + currentBranch) //nolint:gosec // log message from trusted CI environment variables
7474

7575
cmd := exec.Command("govulncheck", "./...")
7676
out, _ := cmd.Output()
7777

7878
vulnMessage := string(out)
7979
fmt.Println(vulnMessage)
80-
noVuln := false
81-
if !strings.Contains(vulnMessage, "Vulnerability #") {
82-
noVuln = true
83-
}
80+
noVuln := !strings.Contains(vulnMessage, "Vulnerability #")
8481

8582
if currentBranch == "" {
8683
if strings.Contains(vulnMessage, "Vulnerability #") {
@@ -138,9 +135,9 @@ func main() {
138135
}
139136

140137
func createIssue(baseURL, token, projectID string, title, commentBody string) {
141-
slog.Info("Active issue with title '" + title + "' not found in project " + projectID)
138+
slog.Info("Active issue with title '" + title + "' not found in project " + projectID) //nolint:gosec // log message from trusted CI environment variables
142139
// Create the issue here
143-
issueData := map[string]interface{}{
140+
issueData := map[string]any{
144141
"title": title,
145142
"description": commentBody,
146143
"labels": "bot,critical",
@@ -188,7 +185,7 @@ func closeTheIssue(baseURL, token, projectID string, issueIID int, commentBody s
188185
addCommentToIssue(baseURL, token, projectID, issueIID, commentBody)
189186

190187
client := &http.Client{}
191-
issueData := map[string]interface{}{
188+
issueData := map[string]any{
192189
"state_event": "close",
193190
}
194191
issueDataBytes, err := json.Marshal(issueData)
@@ -230,7 +227,7 @@ func closeTheIssue(baseURL, token, projectID string, issueIID int, commentBody s
230227

231228
func addCommentToIssue(baseURL, token, projectID string, issueIID int, commentBody string) {
232229
client := &http.Client{}
233-
noteData := map[string]interface{}{
230+
noteData := map[string]any{
234231
"body": commentBody,
235232
}
236233
noteDataBytes, err := json.Marshal(noteData)

configuration/bool.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func (s *AtomicBool) String() string {
4242
return "false"
4343
}
4444

45-
func (s *AtomicBool) UnmarshalYAML(unmarshal func(interface{}) error) error {
45+
func (s *AtomicBool) UnmarshalYAML(unmarshal func(any) error) error {
4646
var buf bool
4747
err := unmarshal(&buf)
4848
if err != nil {
@@ -53,6 +53,6 @@ func (s *AtomicBool) UnmarshalYAML(unmarshal func(interface{}) error) error {
5353
return nil
5454
}
5555

56-
func (s AtomicBool) MarshalYAML() (interface{}, error) {
56+
func (s AtomicBool) MarshalYAML() (any, error) {
5757
return s.Load(), nil
5858
}

configuration/configuration.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ func (c *Configuration) Load() error {
247247
}
248248

249249
func (c *Configuration) LoadRuntimeVars(swaggerJSON json.RawMessage, host string, port int) error {
250-
var m map[string]interface{}
250+
var m map[string]any
251251
json := jsoniter.ConfigCompatibleWithStandardLibrary
252252
err := json.Unmarshal(swaggerJSON, &m)
253253
if err != nil {

configuration/int.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func (s *AtomicInt) String() string {
4040
return strconv.Itoa(s.Load())
4141
}
4242

43-
func (s *AtomicInt) UnmarshalYAML(unmarshal func(interface{}) error) error {
43+
func (s *AtomicInt) UnmarshalYAML(unmarshal func(any) error) error {
4444
var buf int
4545
err := unmarshal(&buf)
4646
if err != nil {
@@ -51,6 +51,6 @@ func (s *AtomicInt) UnmarshalYAML(unmarshal func(interface{}) error) error {
5151
return nil
5252
}
5353

54-
func (s AtomicInt) MarshalYAML() (interface{}, error) {
54+
func (s AtomicInt) MarshalYAML() (any, error) {
5555
return s.Load(), nil
5656
}

configuration/map_sync.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,7 @@ func equalSomeEntries(fEntries, rEntries models.MapEntries, index ...int) bool {
139139
maxNo = l
140140
}
141141

142-
maxRandom := 10
143-
if maxNo < 10 {
144-
maxRandom = maxNo
145-
}
142+
maxRandom := min(10, maxNo)
146143

147144
for range maxRandom {
148145
// There's no need for strong number generation, here, just need for performance

configuration/string.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func (s *AtomicString) String() string {
3939
return s.Load()
4040
}
4141

42-
func (s *AtomicString) UnmarshalYAML(unmarshal func(interface{}) error) error {
42+
func (s *AtomicString) UnmarshalYAML(unmarshal func(any) error) error {
4343
var buf string
4444
err := unmarshal(&buf)
4545
if err != nil {
@@ -50,6 +50,6 @@ func (s *AtomicString) UnmarshalYAML(unmarshal func(interface{}) error) error {
5050
return nil
5151
}
5252

53-
func (s AtomicString) MarshalYAML() (interface{}, error) {
53+
func (s AtomicString) MarshalYAML() (any, error) {
5454
return s.Load(), nil
5555
}

0 commit comments

Comments
 (0)