Skip to content

Commit aa06e1c

Browse files
authored
[CI] Golangci-lint update part 1 (#343)
* Added linters and settings * golangci-lint --fix fixes * Fixed nolintlint and goconst errors * Temporarily disabled several linters * Addressed comments
1 parent 11db125 commit aa06e1c

20 files changed

+235
-60
lines changed

.golangci.yml

Lines changed: 179 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,202 @@
11
run:
22
timeout: 5m
3+
issues-exit-code: 1
4+
5+
output:
6+
formats:
7+
- format: colored-line-number
8+
9+
linters-settings:
10+
cyclop:
11+
max-complexity: 15
12+
13+
depguard:
14+
rules:
15+
main:
16+
files:
17+
- "$all"
18+
- "!$test"
19+
deny:
20+
- pkg: "reflect"
21+
desc: "Reflection is never clear."
22+
- pkg: "gob"
23+
desc: "Please convert types manually"
24+
25+
dupl:
26+
threshold: 100
27+
28+
errcheck:
29+
check-type-assertions: true
30+
check-blank: true
31+
exclude-functions:
32+
- fmt:.*
33+
- io/ioutil:^Read.*
34+
35+
gci:
36+
sections:
37+
- standard
38+
- default
39+
- blank
40+
- dot
41+
- prefix(github.com/linode/linode-cloud-controller-manager)
42+
43+
goconst:
44+
min-len: 3
45+
min-occurrences: 5
46+
47+
gocritic:
48+
enabled-tags:
49+
- diagnostic
50+
- experimental
51+
- opinionated
52+
- performance
53+
- style
54+
55+
settings:
56+
captLocal:
57+
paramsOnly: true
58+
rangeValCopy:
59+
sizeThreshold: 32
60+
61+
gofmt:
62+
simplify: true
63+
64+
goimports:
65+
local-prefixes: github.com/linode/linode-cloud-controller-manager
66+
67+
govet:
68+
enable:
69+
- shadow
70+
71+
gosec:
72+
confidence: "medium"
73+
excludes:
74+
- G115
75+
76+
nolintlint:
77+
require-explanation: true
78+
require-specific: true
79+
80+
prealloc:
81+
simple: true
82+
range-loops: true
83+
for-loops: true
84+
85+
varnamelen:
86+
min-name-length: 2
387

488
linters:
5-
disable-all: true
89+
#disable-all: true
90+
disable:
91+
- errcheck
92+
- errchkjson
93+
- errorlint
94+
- govet
95+
- testifylint
696
enable:
797
# these are enabled by default
8-
- errcheck
98+
#- errcheck
999
- gosimple
10-
- govet
100+
#- govet
11101
- ineffassign
12102
- staticcheck
13103
- typecheck
14104
- unused
15-
# cherry picked from https://golangci-lint.run/usage/linters/
16-
# - ginkgolinter # to be enabled once #158 is merged
105+
- ginkgolinter
106+
- asasalint
107+
- asciicheck
108+
- bidichk
17109
- bodyclose
110+
- containedctx
111+
- contextcheck
18112
- copyloopvar
113+
#- cyclop
114+
- decorder
115+
#- depguard
116+
- dogsled
117+
- dupl
118+
- dupword
119+
- durationcheck
120+
#- errchkjson
121+
- errname
122+
#- errorlint
123+
- exhaustive
124+
#- forbidigo
125+
#- forcetypeassert
126+
#- gci
19127
- gocheckcompilerdirectives
20128
- gofmt
21129
- goimports
130+
#- gocognit
131+
#- goconst
132+
#- gocritic
133+
- gofumpt
134+
- goprintffuncname
135+
#- gosec
22136
- importas
23137
- loggercheck
138+
- maintidx
24139
- makezero
140+
- misspell
141+
#- mnd
142+
- musttag
143+
#- nestif
25144
- nilerr
26-
- prealloc
145+
- nilnil
146+
- noctx
147+
- nolintlint
148+
- nosprintfhostport
149+
#- paralleltest
150+
#- prealloc
151+
- predeclared
27152
- reassign
28-
- tenv
153+
#- tenv
154+
#- thelper
29155
- unconvert
30-
- wastedassign
31156
- unparam
32-
- gofumpt
33-
- nosprintfhostport
34-
- musttag
35-
- exhaustive
36-
- nilnil
157+
- usestdlibvars
158+
#- varnamelen
159+
- wastedassign
160+
- whitespace
161+
162+
presets:
163+
- bugs
164+
- unused
165+
fast: false
166+
167+
issues:
168+
exclude-rules:
169+
# Exclude some linters from running on tests files.
170+
- path: _test(ing)?\.go
171+
linters:
172+
- gocyclo
173+
- maintidx
174+
- errcheck
175+
- dupl
176+
- gosec
177+
- copyloopvar
178+
- unparam
179+
- varnamelen
180+
181+
# Ease some gocritic warnings on test files.
182+
- path: _test\.go
183+
text: "(unnamedResult|exitAfterDefer)"
184+
linters:
185+
- gocritic
186+
187+
- text: "G101:"
188+
linters:
189+
- gosec
190+
- gas
191+
192+
- text: "G104:"
193+
linters:
194+
- gosec
195+
- gas
196+
197+
exclude-use-default: false
198+
new: false
199+
max-issues-per-linter: 0
200+
max-same-issues: 0
201+
exclude-files:
202+
- "zz_generated\\..+\\.go$"

cloud/linode/cilium_loadbalancers.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
ciliumclient "github.com/cilium/cilium/pkg/k8s/client/clientset/versioned/typed/cilium.io/v2alpha1"
1414
slimv1 "github.com/cilium/cilium/pkg/k8s/slim/k8s/apis/meta/v1"
1515
"github.com/google/uuid"
16-
"github.com/linode/linode-cloud-controller-manager/cloud/annotations"
1716
"github.com/linode/linodego"
1817
v1 "k8s.io/api/core/v1"
1918
k8serrors "k8s.io/apimachinery/pkg/api/errors"
@@ -23,6 +22,8 @@ import (
2322
"k8s.io/client-go/util/retry"
2423
"k8s.io/klog/v2"
2524
"k8s.io/utils/ptr"
25+
26+
"github.com/linode/linode-cloud-controller-manager/cloud/annotations"
2627
)
2728

2829
const (

cloud/linode/cilium_loadbalancers_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ import (
1010
k8sClient "github.com/cilium/cilium/pkg/k8s/client"
1111
fakev2alpha1 "github.com/cilium/cilium/pkg/k8s/client/clientset/versioned/typed/cilium.io/v2alpha1/fake"
1212
"github.com/golang/mock/gomock"
13-
"github.com/linode/linode-cloud-controller-manager/cloud/linode/client/mocks"
1413
"github.com/linode/linodego"
1514
v1 "k8s.io/api/core/v1"
1615
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1716
"k8s.io/client-go/kubernetes"
17+
18+
"github.com/linode/linode-cloud-controller-manager/cloud/linode/client/mocks"
1819
)
1920

2021
var (

cloud/linode/client/client.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ import (
1111
"os"
1212
"time"
1313

14-
_ "github.com/hexdigest/gowrap"
1514
"github.com/linode/linodego"
1615
"k8s.io/klog/v2"
16+
17+
_ "github.com/hexdigest/gowrap"
1718
)
1819

1920
const (

cloud/linode/cloud.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func init() {
7777
func newLinodeClientWithPrometheus(apiToken string, timeout time.Duration) (client.Client, error) {
7878
linodeClient, err := client.New(apiToken, timeout)
7979
if err != nil {
80-
return nil, fmt.Errorf("client was not created succesfully: %w", err)
80+
return nil, fmt.Errorf("client was not created successfully: %w", err)
8181
}
8282

8383
if Options.LinodeGoDebug {

cloud/linode/cloud_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ import (
66
"testing"
77

88
"github.com/golang/mock/gomock"
9-
"github.com/linode/linode-cloud-controller-manager/cloud/linode/client/mocks"
109
"github.com/stretchr/testify/assert"
1110
cloudprovider "k8s.io/cloud-provider"
11+
12+
"github.com/linode/linode-cloud-controller-manager/cloud/linode/client/mocks"
1213
)
1314

1415
func TestNewCloudRouteControllerDisabled(t *testing.T) {
@@ -75,7 +76,7 @@ func TestNewCloud(t *testing.T) {
7576
}()
7677
_, err := newCloud()
7778
assert.NoError(t, err, "expected no error if deprecated flag vpcname is set")
78-
assert.Equal(t, Options.VPCNames, "tt", "expected vpcnames to be set to vpcname")
79+
assert.Equal(t, "tt", Options.VPCNames, "expected vpcnames to be set to vpcname")
7980
})
8081

8182
t.Run("should fail if incorrect loadbalancertype is set", func(t *testing.T) {

cloud/linode/fake_linode_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ func (f *fakeAPI) setupRoutes() {
174174
f.mux.HandleFunc("GET /v4/nodebalancers/{nodeBalancerId}", func(w http.ResponseWriter, r *http.Request) {
175175
nb, found := f.nb[r.PathValue("nodeBalancerId")]
176176
if !found {
177-
w.WriteHeader(404)
177+
w.WriteHeader(http.StatusNotFound)
178178
resp := linodego.APIError{
179179
Errors: []linodego.APIErrorReason{
180180
{Reason: "Not Found"},
@@ -284,7 +284,7 @@ func (f *fakeAPI) setupRoutes() {
284284

285285
firewallDevices, found := f.fwd[fwdId]
286286
if !found {
287-
w.WriteHeader(404)
287+
w.WriteHeader(http.StatusNotFound)
288288
resp := linodego.APIError{
289289
Errors: []linodego.APIErrorReason{
290290
{Reason: "Not Found"},
@@ -728,7 +728,7 @@ func (f *fakeAPI) setupRoutes() {
728728
return
729729
}
730730

731-
w.WriteHeader(404)
731+
w.WriteHeader(http.StatusNotFound)
732732
resp := linodego.APIError{
733733
Errors: []linodego.APIErrorReason{
734734
{Reason: "Not Found"},
@@ -767,7 +767,7 @@ func (f *fakeAPI) setupRoutes() {
767767
return
768768
}
769769

770-
w.WriteHeader(404)
770+
w.WriteHeader(http.StatusNotFound)
771771
resp := linodego.APIError{
772772
Errors: []linodego.APIErrorReason{
773773
{Reason: "Not Found"},

0 commit comments

Comments
 (0)