Skip to content

Commit 5d57bf3

Browse files
authored
ci: enhanced linting (#158)
Add a configuration file which makes it much more strict. Fix shadowed error variables flagged by linter. Remove CI timeout as its now present in the config.
1 parent 93b3db4 commit 5d57bf3

File tree

4 files changed

+93
-8
lines changed

4 files changed

+93
-8
lines changed

.github/workflows/golangci-lint.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,3 @@ jobs:
2121
uses: golangci/golangci-lint-action@aaa42aa0628b4ae2578232a66b541047968fac86 # v6.1.0
2222
with:
2323
version: v1.60.3
24-
args: --timeout=3m

.golangci.yaml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
run:
2+
timeout: 2m
3+
4+
linters-settings:
5+
gosec:
6+
excludes:
7+
- G601 ## Implicit memory aliasing of items from a range statement - not possible in go 1.22.
8+
cyclop:
9+
max-complexity: 15
10+
nestif:
11+
min-complexity: 10
12+
govet:
13+
settings:
14+
shadow:
15+
strict: true
16+
enable-all: true
17+
nolintlint:
18+
require-explanation: true
19+
godot:
20+
scope: all
21+
nakedret:
22+
max-func-lines: 0
23+
24+
linters:
25+
enable-all: true
26+
disable:
27+
# Spammy / low value
28+
- nonamedreturns
29+
- varnamelen
30+
- exhaustruct
31+
- nlreturn
32+
- wsl
33+
- lll
34+
- paralleltest
35+
# Duplicate functionality.
36+
- funlen
37+
- gocognit
38+
# Deprecated.
39+
- execinquery
40+
- gomnd
41+
# Good but gets in the way too often.
42+
- testpackage
43+
# Unknown details about how Artemis works are flagged with TODO's.
44+
- godox
45+
# Seems to be broken.
46+
- depguard
47+
# Makes it messy for multiple optional tags.
48+
- tagalign
49+
# Not needed for go 1.22+.
50+
- exportloopref
51+
- errchkjson # Duplicate functionality for errcheck.
52+
53+
issues:
54+
include:
55+
- EXC0012
56+
- EXC0014
57+
exclude-rules:
58+
# Exclude linters which aren't an issue in tests.
59+
- path: _test\.go
60+
linters:
61+
- gochecknoglobals
62+
- wrapcheck
63+
64+
# File mode permissions are fine for constants.
65+
- text: "Magic number: 0o\\d+"
66+
linters:
67+
- mnd
68+
69+
# Field alignment in tests isn't a performance issue.
70+
- text: fieldalignment
71+
path: _test\.go
72+
73+
# Dynamic errors can provide useful context.
74+
- text: "do not define dynamic errors, use wrapped static errors instead:"
75+
linters:
76+
- err113
77+
78+
# We need to use the `err` named return for error handling.
79+
- text: 'named return "err" with type "error" found'
80+
linters:
81+
- nonamedreturns
82+
83+
# Interface casting is fine in mock.
84+
- path: mock_test\.go
85+
linters:
86+
- forcetypeassert

reaper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ func (r *reaper) handle(conn net.Conn) {
239239
default:
240240
if err := r.addFilter(msg); err != nil {
241241
logger.Error("add filter", fieldError, err)
242-
if _, err := conn.Write(ackResponse); err != nil {
242+
if _, err = conn.Write(ackResponse); err != nil {
243243
logger.Error("ack write", fieldError, err)
244244
}
245245
continue

reaper_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ func TestReapContainer(t *testing.T) {
578578

579579
t.Cleanup(func() {
580580
// Ensure the container was / is removed.
581-
err := cli.ContainerRemove(ctx, resp.ID, container.RemoveOptions{})
581+
err = cli.ContainerRemove(ctx, resp.ID, container.RemoveOptions{})
582582
require.Error(t, err)
583583
require.True(t, errdefs.IsNotFound(err))
584584
})
@@ -607,7 +607,7 @@ func TestReapNetwork(t *testing.T) {
607607

608608
t.Cleanup(func() {
609609
// Ensure the network was / is removed.
610-
err := cli.NetworkRemove(ctx, resp.ID)
610+
err = cli.NetworkRemove(ctx, resp.ID)
611611
require.Error(t, err)
612612
require.True(t, errdefs.IsNotFound(err))
613613
})
@@ -631,7 +631,7 @@ func TestReapVolume(t *testing.T) {
631631

632632
t.Cleanup(func() {
633633
// Ensure the volume was / is removed.
634-
err := cli.VolumeRemove(ctx, resp.Name, false)
634+
err = cli.VolumeRemove(ctx, resp.Name, false)
635635
require.Error(t, err)
636636
require.True(t, errdefs.IsNotFound(err))
637637
})
@@ -667,7 +667,7 @@ func TestReapImage(t *testing.T) {
667667
return
668668
}
669669
var result types.BuildResult
670-
err := json.Unmarshal(*msg.Aux, &result)
670+
err = json.Unmarshal(*msg.Aux, &result)
671671
require.NoError(t, err)
672672
imageID = result.ID
673673
}
@@ -677,8 +677,8 @@ func TestReapImage(t *testing.T) {
677677

678678
t.Cleanup(func() {
679679
// Ensure the image was / is removed.
680-
resp, err := cli.ImageRemove(ctx, imageID, image.RemoveOptions{})
681-
require.Error(t, err)
680+
resp, errc := cli.ImageRemove(ctx, imageID, image.RemoveOptions{})
681+
require.Error(t, errc)
682682
require.Empty(t, resp)
683683
})
684684

0 commit comments

Comments
 (0)