Skip to content

Commit b3a0167

Browse files
authored
transition to golangci-lint v2 and fixup linter warnings (#8)
1 parent c0c5303 commit b3a0167

File tree

13 files changed

+120
-87
lines changed

13 files changed

+120
-87
lines changed

.golangci.yml

Lines changed: 106 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,135 @@
11
# GolangCI-Lint settings
2-
2+
version: "2"
33
# Disable all linters and enable the required ones
44
linters:
5-
disable-all: true
5+
default: none
66

77
# Supported linters: https://golangci-lint.run/usage/linters/
88
enable:
9-
- errcheck
10-
- gosimple
11-
- govet
12-
- ineffassign
13-
- staticcheck
14-
- typecheck
15-
- unused
9+
- asasalint
10+
- asciicheck
11+
- bidichk
1612
- bodyclose
13+
- containedctx
14+
- copyloopvar
15+
- decorder
1716
- dupl
17+
- dupword
18+
- durationcheck
19+
- errcheck
20+
- errchkjson
21+
- errname
22+
- errorlint
23+
- exptostd
24+
- fatcontext
25+
- forbidigo
26+
- forcetypeassert
27+
- ginkgolinter
28+
- gocheckcompilerdirectives
1829
- gochecknoinits
30+
- gochecksumtype
31+
- gocognit
1932
- goconst
2033
- gocritic
2134
- gocyclo
22-
- gofmt
23-
- goimports
35+
- goprintffuncname
2436
- gosec
37+
- govet
38+
- grouper
39+
- iface
40+
- importas
41+
- ineffassign
42+
- interfacebloat
2543
- lll
44+
- loggercheck
45+
- makezero
46+
- mirror
2647
- misspell
48+
- musttag
2749
- nakedret
50+
- nestif
51+
- nilerr
52+
- nilnesserr
53+
- noctx
54+
- nolintlint
55+
- nosprintfhostport
2856
- prealloc
29-
- stylecheck
57+
- predeclared
58+
- reassign
59+
- rowserrcheck
60+
- sqlclosecheck
61+
- staticcheck
62+
- testableexamples
63+
- tparallel
3064
- unconvert
3165
- unparam
32-
- paralleltest
33-
- forbidigo
34-
fast: false
66+
- unused
67+
- usestdlibvars
68+
- usetesting
69+
- wastedassign
70+
- zerologlint
71+
72+
# Specific linter settings
73+
settings:
74+
gocognit:
75+
# Minimal code complexity to report
76+
min-complexity: 16
77+
gocyclo:
78+
# Minimal code complexity to report
79+
min-complexity: 16
80+
misspell:
81+
# Correct spellings using locale preferences for US
82+
locale: US
83+
staticcheck:
84+
# Default list with custom silencing of:
85+
86+
checks: [
87+
"all",
88+
# Disable the checks that staticcheck disables by default
89+
"-ST1000",
90+
"-ST1003",
91+
"-ST1016",
92+
"-ST1020",
93+
"-ST1021",
94+
"-ST1022",
95+
"-QF1008", # Omit embedded fields from selector expression.
96+
]
97+
exclusions:
98+
rules:
99+
# Exclude gochecknoinits and gosec from running on tests files
100+
- path: _test\.go
101+
linters:
102+
- dupl
103+
- gochecknoinits
104+
- gosec
105+
- errcheck
106+
- gocognit
107+
- musttag
108+
- noctx
109+
- usestdlibvars
110+
- exhaustruct
111+
- copyloopvar
112+
- goconst
113+
- path: test/*
114+
linters:
115+
- gochecknoinits
116+
- gosec
117+
- gocognit
118+
# Exclude lll issues for long lines with go:generate
119+
- linters:
120+
- lll
121+
source: "^//go:generate "
122+
paths:
123+
- .go/pkg/mod
124+
- vendor-fork
125+
- internal/logreporter/api/loki
35126

36127
# Run options
37128
run:
38129
# 10 minute timeout for analysis
39130
timeout: 10m
40-
# Specific linter settings
41-
linters-settings:
42-
gocyclo:
43-
# Minimal code complexity to report
44-
min-complexity: 16
45-
govet:
46-
disable-all: true
47-
enable:
48-
# Report shadowed variables
49-
- shadow
50-
51-
misspell:
52-
# Correct spellings using locale preferences for US
53-
locale: US
54-
goimports:
55-
# Put imports beginning with prefix after 3rd-party packages
56-
local-prefixes: gitswarm.f5net.com/indigo,gitlab.com/f5
57-
exhaustruct:
58-
# List of regular expressions to match struct packages and names.
59-
# If this list is empty, all structs are tested.
60-
# Default: []
61-
include:
62-
- "gitlab.com/f5/nginx/nginxazurelb/azure-resource-provider/pkg/token.TokenID"
63-
- "gitlab.com/f5/nginx/nginxazurelb/azure-resource-provider/internal/dpo/agent/certificates.CertGetRequest"
64131

65132
issues:
66-
exclude-dirs:
67-
- .go/pkg/mod
68-
# Exclude configuration
69-
exclude-rules:
70-
# Exclude gochecknoinits and gosec from running on tests files
71-
- path: _test\.go
72-
linters:
73-
- gochecknoinits
74-
- gosec
75-
- path: test/*
76-
linters:
77-
- gochecknoinits
78-
- gosec
79-
# Exclude lll issues for long lines with go:generate
80-
- linters:
81-
- lll
82-
source: "^//go:generate "
83-
# Exclude false positive paralleltest error : Range statement for test case does not use range value in test Run
84-
- linters:
85-
- paralleltest
86-
text: "does not use range value in test Run"
87-
88133
# Disable maximum issues count per one linter
89134
max-issues-per-linter: 0
90135

cmd/nginx-loadbalancer-kubernetes/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package main
77

88
import (
99
"context"
10+
"errors"
1011
"fmt"
1112
"log/slog"
1213
"os"
@@ -119,7 +120,7 @@ func initializeLogger(logLevel string) {
119120
func buildKubernetesClient() (*kubernetes.Clientset, error) {
120121
slog.Debug("Watcher::buildKubernetesClient")
121122
k8sConfig, err := rest.InClusterConfig()
122-
if err == rest.ErrNotInCluster {
123+
if errors.Is(err, rest.ErrNotInCluster) {
123124
return nil, fmt.Errorf(`not running in a Cluster: %w`, err)
124125
} else if err != nil {
125126
return nil, fmt.Errorf(`error occurred getting the Cluster config: %w`, err)

internal/application/application_common_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const (
2020
)
2121

2222
func buildTerrorizingBorderClient(clientType string) (Interface, error) {
23+
//nolint:dupword // dupword doesn't understand jokes
2324
nginxClient := mocks.NewErroringMockClient(errors.New(`something went horribly horribly wrong`))
2425
bc, err := NewBorderClient(clientType, nginxClient)
2526

internal/application/nginx_http_border_client_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22
* Copyright 2023 F5 Inc. All rights reserved.
33
* Use of this source code is governed by the Apache License that can be found in the LICENSE file.
44
*/
5-
6-
// dupl complains about duplicates with nginx_stream_border_client_test.go
7-
//
8-
//nolint:dupl
95
package application
106

117
import (

internal/application/nginx_stream_border_client_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
* Copyright 2023 F5 Inc. All rights reserved.
33
* Use of this source code is governed by the Apache License that can be found in the LICENSE file.
44
*/
5-
// dupl complains about duplicates with nginx_http_border_client_test.go
6-
//nolint:dupl
75
package application
86

97
import (

internal/communication/factory.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ func NewHeaders(apiKey string) []string {
4646

4747
// NewTransport is a factory method to create a new basic Http Transport.
4848
func NewTransport(skipVerify bool) *netHttp.Transport {
49+
//nolint:forcetypeassert
4950
transport := netHttp.DefaultTransport.(*netHttp.Transport).Clone()
5051
transport.TLSClientConfig.InsecureSkipVerify = skipVerify
5152

internal/communication/factory_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ func TestNewHTTPClient(t *testing.T) {
2424
}
2525
}
2626

27-
//nolint:goconst
2827
func TestNewHeaders(t *testing.T) {
2928
t.Parallel()
3029
headers := NewHeaders("fakeKey")

internal/observation/watcher.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ func (w *Watcher) buildEndpointSlicesEventHandlerForDelete() func(interface{}) {
211211
func (w *Watcher) buildServiceEventHandlerForAdd() func(interface{}) {
212212
slog.Info("Watcher::buildServiceEventHandlerForAdd")
213213
return func(obj interface{}) {
214+
//nolint:forcetypeassert
214215
service := obj.(*v1.Service)
215216
if !w.isDesiredService(service) {
216217
return
@@ -228,6 +229,7 @@ func (w *Watcher) buildServiceEventHandlerForAdd() func(interface{}) {
228229
func (w *Watcher) buildServiceEventHandlerForDelete() func(interface{}) {
229230
slog.Info("Watcher::buildServiceEventHandlerForDelete")
230231
return func(obj interface{}) {
232+
//nolint:forcetypeassert
231233
service := obj.(*v1.Service)
232234
if !w.isDesiredService(service) {
233235
return
@@ -245,7 +247,9 @@ func (w *Watcher) buildServiceEventHandlerForDelete() func(interface{}) {
245247
func (w *Watcher) buildServiceEventHandlerForUpdate() func(interface{}, interface{}) {
246248
slog.Info("Watcher::buildServiceEventHandlerForUpdate")
247249
return func(previous, updated interface{}) {
250+
//nolint:forcetypeassert
248251
previousService := previous.(*v1.Service)
252+
//nolint:forcetypeassert
249253
service := updated.(*v1.Service)
250254

251255
if w.isDesiredService(previousService) && !w.isDesiredService(service) {

internal/probation/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func (hs *HealthServer) Start() {
6060
mux.HandleFunc("/readyz", hs.HandleReady)
6161
mux.HandleFunc("/startupz", hs.HandleStartup)
6262

63-
listener, err := net.Listen("tcp", address)
63+
listener, err := net.Listen("tcp", address) //nolint:noctx
6464
if err != nil {
6565
slog.Error("failed to listen", "error", err)
6666
return

internal/synchronization/synchronizer.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,12 @@ func (s *Synchronizer) buildBorderClient(event *core.ServerUpdateEvent) (applica
133133
var err error
134134
httpClient, err := communication.NewHTTPClient(s.settings.APIKey, s.settings.SkipVerifyTLS)
135135
if err != nil {
136-
return nil, fmt.Errorf(`error creating HTTP client: %v`, err)
136+
return nil, fmt.Errorf(`error creating HTTP client: %w`, err)
137137
}
138138

139139
ngxClient, err := nginxClient.NewNginxClient(event.NginxHost, nginxClient.WithHTTPClient(httpClient))
140140
if err != nil {
141-
return nil, fmt.Errorf(`error creating Nginx Plus client: %v`, err)
141+
return nil, fmt.Errorf(`error creating Nginx Plus client: %w`, err)
142142
}
143143

144144
return application.NewBorderClient(event.ClientType, ngxClient)
@@ -164,6 +164,8 @@ func (s *Synchronizer) fanOutEventToHosts(event core.ServerUpdateEvents) core.Se
164164
// handleServiceEvent gets the latest state for the service from the shared
165165
// informer cache, translates the service event into server update events and
166166
// dispatches these events to the proper handler function.
167+
//
168+
//nolint:gocognit
167169
func (s *Synchronizer) handleServiceEvent(ctx context.Context, key ServiceKey) (err error) {
168170
logger := slog.With("service", key)
169171
logger.Debug(`Synchronizer::handleServiceEvent`)

0 commit comments

Comments
 (0)