Skip to content

Commit 83868ae

Browse files
Stricter linting (#159)
1 parent 2520087 commit 83868ae

11 files changed

Lines changed: 172 additions & 152 deletions

File tree

.golangci.yml

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,36 @@
1+
run:
2+
timeout: 5m
3+
14
linters:
5+
disable-all: true
26
enable:
7+
# these are enabled by default
8+
- errcheck
9+
- gosimple
10+
- govet
11+
- ineffassign
12+
- staticcheck
13+
- typecheck
14+
- unused
15+
# cherry picked from https://golangci-lint.run/usage/linters/
16+
# - ginkgolinter # to be enabled once #158 is merged
17+
- bodyclose
18+
- exportloopref
19+
- gocheckcompilerdirectives
320
- gofmt
421
- goimports
5-
- structcheck
6-
- varcheck
7-
- staticcheck
22+
- importas
23+
- loggercheck
24+
- makezero
25+
- nilerr
26+
- prealloc
27+
- reassign
28+
- tenv
829
- unconvert
9-
- revive
10-
- ineffassign
11-
- vet
12-
- unused
13-
- misspell
14-
disable:
15-
- errcheck
16-
17-
run:
18-
tests: false
19-
timeout: 8m
20-
skip-dirs:
21-
- api
22-
- design
23-
- docs
24-
- docs/man
30+
- wastedassign
31+
- unparam
32+
- gofumpt
33+
- nosprintfhostport
34+
- musttag
35+
- exhaustive
36+
- nilnil

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ codegen:
1818
lint:
1919
docker run --rm -v "$(shell pwd):/var/work:ro" -w /var/work \
2020
golangci/golangci-lint:v1.55.2 golangci-lint run -v --timeout=5m
21+
docker run --rm -v "$(shell pwd):/var/work:ro" -w /var/work/e2e \
22+
golangci/golangci-lint:v1.55.2 golangci-lint run -v --timeout=5m
2123

2224
.PHONY: fmt
2325
fmt:

cloud/linode/common_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,3 @@ func TestParseProviderID(t *testing.T) {
4646
})
4747
}
4848
}
49-
50-
func stringPtr(s string) *string {
51-
return &s
52-
}

cloud/linode/fake_linode_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,6 @@ func (f *fakeAPI) ServeHTTP(w http.ResponseWriter, r *http.Request) {
240240
_, _ = w.Write(rr)
241241
return
242242
}
243-
244243
}
245244

246245
case "POST":
@@ -596,9 +595,9 @@ func (f *fakeAPI) ServeHTTP(w http.ResponseWriter, r *http.Request) {
596595
}
597596
}
598597

599-
func randString(n int) string {
598+
func randString() string {
600599
const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
601-
b := make([]byte, n)
600+
b := make([]byte, 10)
602601
for i := range b {
603602
b[i] = letterBytes[rand.Intn(len(letterBytes))]
604603
}

cloud/linode/instances_test.go

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,12 @@ func TestInstanceExists(t *testing.T) {
5757
instances := newInstances(client)
5858
node := nodeWithProviderID(providerIDPrefix + "123")
5959
client.EXPECT().ListInstances(gomock.Any(), nil).Times(1).Return([]linodego.Instance{
60-
{ID: 123,
60+
{
61+
ID: 123,
6162
Label: "mock",
6263
Region: "us-east",
63-
Type: "g6-standard-2"},
64+
Type: "g6-standard-2",
65+
},
6466
}, nil)
6567

6668
exists, err := instances.InstanceExists(ctx, node)
@@ -154,16 +156,36 @@ func TestMetadataRetrieval(t *testing.T) {
154156
expectedErr error
155157
}{
156158
{"no IPs", nil, nil, instanceNoIPAddressesError{192910}},
157-
{"one public, one private", []string{"32.74.121.25", "192.168.121.42"},
158-
[]v1.NodeAddress{{Type: v1.NodeExternalIP, Address: "32.74.121.25"}, {Type: v1.NodeInternalIP, Address: "192.168.121.42"}}, nil},
159-
{"one public, no private", []string{"32.74.121.25"},
160-
[]v1.NodeAddress{{Type: v1.NodeExternalIP, Address: "32.74.121.25"}}, nil},
161-
{"one private, no public", []string{"192.168.121.42"},
162-
[]v1.NodeAddress{{Type: v1.NodeInternalIP, Address: "192.168.121.42"}}, nil},
163-
{"two public addresses", []string{"32.74.121.25", "32.74.121.22"},
164-
[]v1.NodeAddress{{Type: v1.NodeExternalIP, Address: "32.74.121.25"}, {Type: v1.NodeExternalIP, Address: "32.74.121.22"}}, nil},
165-
{"two private addresses", []string{"192.168.121.42", "10.0.2.15"},
166-
[]v1.NodeAddress{{Type: v1.NodeInternalIP, Address: "192.168.121.42"}, {Type: v1.NodeInternalIP, Address: "10.0.2.15"}}, nil},
159+
{
160+
"one public, one private",
161+
[]string{"32.74.121.25", "192.168.121.42"},
162+
[]v1.NodeAddress{{Type: v1.NodeExternalIP, Address: "32.74.121.25"}, {Type: v1.NodeInternalIP, Address: "192.168.121.42"}},
163+
nil,
164+
},
165+
{
166+
"one public, no private",
167+
[]string{"32.74.121.25"},
168+
[]v1.NodeAddress{{Type: v1.NodeExternalIP, Address: "32.74.121.25"}},
169+
nil,
170+
},
171+
{
172+
"one private, no public",
173+
[]string{"192.168.121.42"},
174+
[]v1.NodeAddress{{Type: v1.NodeInternalIP, Address: "192.168.121.42"}},
175+
nil,
176+
},
177+
{
178+
"two public addresses",
179+
[]string{"32.74.121.25", "32.74.121.22"},
180+
[]v1.NodeAddress{{Type: v1.NodeExternalIP, Address: "32.74.121.25"}, {Type: v1.NodeExternalIP, Address: "32.74.121.22"}},
181+
nil,
182+
},
183+
{
184+
"two private addresses",
185+
[]string{"192.168.121.42", "10.0.2.15"},
186+
[]v1.NodeAddress{{Type: v1.NodeInternalIP, Address: "192.168.121.42"}, {Type: v1.NodeInternalIP, Address: "10.0.2.15"}},
187+
nil,
188+
},
167189
}
168190

169191
for _, test := range ipTests {
@@ -281,7 +303,8 @@ func TestInstanceShutdown(t *testing.T) {
281303
id := 12345
282304
node := nodeWithProviderID(providerIDPrefix + strconv.Itoa(id))
283305
client.EXPECT().ListInstances(gomock.Any(), nil).Times(1).Return([]linodego.Instance{
284-
{ID: id, Label: "shutting-down-linode", Status: linodego.InstanceShuttingDown}}, nil)
306+
{ID: id, Label: "shutting-down-linode", Status: linodego.InstanceShuttingDown},
307+
}, nil)
285308
shutdown, err := instances.InstanceShutdown(ctx, node)
286309

287310
assert.NoError(t, err)

cloud/linode/loadbalancers.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,7 @@ const (
5555
annLinodeNodePrivateIP = "node.k8s.linode.com/private-ip"
5656
)
5757

58-
var (
59-
errNoNodesAvailable = errors.New("no nodes available for nodebalancer")
60-
)
58+
var errNoNodesAvailable = errors.New("no nodes available for nodebalancer")
6159

6260
type lbNotFoundError struct {
6361
serviceNn string
@@ -547,7 +545,7 @@ func (l *loadbalancers) buildNodeBalancerConfig(ctx context.Context, service *v1
547545

548546
health, err := getHealthCheckType(service)
549547
if err != nil {
550-
return linodego.NodeBalancerConfig{}, nil
548+
return linodego.NodeBalancerConfig{}, err
551549
}
552550

553551
config := linodego.NodeBalancerConfig{

0 commit comments

Comments
 (0)