Skip to content

Commit b28554a

Browse files
committed
golangci-lint: enable more linters
fix some nolintlint false positives For some reason, nolintlint doesn't consider these used, but they seem to be legitimate cases where deprecated fields are used. templates/templates.go:27:29: directive `//nolint:staticcheck // strings.Title is deprecated, but we only use it for ASCII, so replacing with golang.org/x/text is out of scope` is unused for linter "staticcheck" (nolintlint) "title": strings.Title, //nolint:staticcheck // strings.Title is deprecated, but we only use it for ASCII, so replacing with golang.org/x/text is out of scope ^ cli/command/formatter/image_test.go:75:31: directive `//nolint:staticcheck // ignore SA1019: field is deprecated, but still set on API < v1.44.` is unused for linter "staticcheck" (nolintlint) call: ctx.VirtualSize, //nolint:staticcheck // ignore SA1019: field is deprecated, but still set on API < v1.44. ^ cli/command/registry/formatter_search.go:100:39: directive `//nolint:staticcheck // ignore SA1019 (IsAutomated is deprecated).` is unused for linter "staticcheck" (nolintlint) return c.formatBool(c.s.IsAutomated) //nolint:staticcheck // ignore SA1019 (IsAutomated is deprecated). ^ cli/command/registry/formatter_search_test.go:50:55: directive `//nolint:staticcheck // ignore SA1019 (IsAutomated is deprecated).` is unused for linter "staticcheck" (nolintlint) s: registrytypes.SearchResult{IsAutomated: true}, //nolint:staticcheck // ignore SA1019 (IsAutomated is deprecated). ^ cli/command/registry/formatter_search_test.go:53:31: directive `//nolint:staticcheck // ignore SA1019 (IsAutomated is deprecated).` is unused for linter "staticcheck" (nolintlint) call: ctx.IsAutomated, //nolint:staticcheck // ignore SA1019 (IsAutomated is deprecated). ^ cli/command/registry/formatter_search_test.go:59:27: directive `//nolint:staticcheck // ignore SA1019 (IsAutomated is deprecated).` is unused for linter "staticcheck" (nolintlint) call: ctx.IsAutomated, //nolint:staticcheck // ignore SA1019 (IsAutomated is deprecated). ^ cli/command/registry/formatter_search_test.go:202:84: directive `//nolint:staticcheck // ignore SA1019 (IsAutomated is deprecated).` is unused for linter "staticcheck" (nolintlint) {Name: "result2", Description: "Not official", StarCount: 5, IsAutomated: true}, //nolint:staticcheck // ignore SA1019 (IsAutomated is deprecated). ^ Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent 2affa47 commit b28554a

File tree

6 files changed

+36
-19
lines changed

6 files changed

+36
-19
lines changed

.golangci.yml

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,38 @@ linters:
44
- depguard
55
- dogsled
66
- dupword # Detects duplicate words.
7+
- durationcheck
8+
- exportloopref # Detects pointers to enclosing loop variables.
9+
- gocritic # Metalinter; detects bugs, performance, and styling issues.
710
- gocyclo
8-
- gofumpt
11+
- gofumpt # Detects whether code was gofumpt-ed.
912
- goimports
10-
- gosec
13+
- gosec # Detects security problems.
1114
- gosimple
1215
- govet
1316
- ineffassign
1417
- lll
1518
- megacheck
16-
- misspell
19+
- misspell # Detects commonly misspelled English words in comments.
1720
- nakedret
1821
- nilerr # Detects code that returns nil even if it checks that the error is not nil.
19-
- predeclared
20-
- revive
22+
- nolintlint # Detects ill-formed or insufficient nolint directives.
23+
- prealloc # Detects slice declarations that could potentially be pre-allocated.
24+
- predeclared # Detects code that shadows one of Go's predeclared identifiers
25+
- reassign
26+
- revive # Metalinter; drop-in replacement for golint.
2127
- staticcheck
22-
- thelper
28+
- stylecheck # Replacement for golint
29+
- tenv # Detects using os.Setenv instead of t.Setenv.
30+
- thelper # Detects test helpers without t.Helper().
31+
- tparallel # Detects inappropriate usage of t.Parallel().
2332
- typecheck
24-
- unconvert
33+
- unconvert # Detects unnecessary type conversions.
2534
- unparam
2635
- unused
36+
- usestdlibvars
37+
- vet
38+
- wastedassign
2739

2840
disable:
2941
- errcheck
@@ -90,7 +102,7 @@ issues:
90102
- gosec
91103
# EXC0008
92104
# TODO: evaluate these and fix where needed: G307: Deferring unsafe method "*os.File" on type "Close" (gosec)
93-
- text: "(G104|G307)"
105+
- text: "G307"
94106
linters:
95107
- gosec
96108
# EXC0009
@@ -104,10 +116,13 @@ issues:
104116

105117
# G113 Potential uncontrolled memory consumption in Rat.SetString (CVE-2022-23772)
106118
# only affects gp < 1.16.14. and go < 1.17.7
107-
- text: "(G113)"
119+
- text: "G113"
120+
linters:
121+
- gosec
122+
# TODO: G104: Errors unhandled. (gosec)
123+
- text: "G104"
108124
linters:
109125
- gosec
110-
111126
# Looks like the match in "EXC0007" above doesn't catch this one
112127
# TODO: consider upstreaming this to golangci-lint's default exclusion rules
113128
- text: "G204: Subprocess launched with a potential tainted input or cmd arguments"
@@ -132,6 +147,9 @@ issues:
132147
linters:
133148
- errcheck
134149
- gosec
150+
- text: "ST1000: at least one file in a package should have a package comment"
151+
linters:
152+
- stylecheck
135153

136154
# Allow "err" and "ok" vars to shadow existing declarations, otherwise we get too many false positives.
137155
- text: '^shadow: declaration of "(err|ok)" shadows declaration'

cli/command/formatter/image_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func TestImageContext(t *testing.T) {
7272
{
7373
imageCtx: imageContext{i: image.Summary{Size: 10000}},
7474
expValue: "10kB",
75-
call: ctx.VirtualSize, //nolint:staticcheck // ignore SA1019: field is deprecated, but still set on API < v1.44.
75+
call: ctx.VirtualSize, //nolint:nolintlint,staticcheck // ignore SA1019: field is deprecated, but still set on API < v1.44.
7676
},
7777
{
7878
imageCtx: imageContext{i: image.Summary{SharedSize: 10000}},

cli/command/registry/formatter_search.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,5 +97,5 @@ func (c *searchContext) IsOfficial() string {
9797
//
9898
// Deprecated: the "is_automated" field is deprecated and will always be "false" in the future.
9999
func (c *searchContext) IsAutomated() string {
100-
return c.formatBool(c.s.IsAutomated) //nolint:staticcheck // ignore SA1019 (IsAutomated is deprecated).
100+
return c.formatBool(c.s.IsAutomated) //nolint:nolintlint,staticcheck // ignore SA1019 (IsAutomated is deprecated).
101101
}

cli/command/registry/formatter_search_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,16 @@ func TestSearchContext(t *testing.T) {
4747
},
4848
{
4949
searchCtx: searchContext{
50-
s: registrytypes.SearchResult{IsAutomated: true}, //nolint:staticcheck // ignore SA1019 (IsAutomated is deprecated).
50+
s: registrytypes.SearchResult{IsAutomated: true}, //nolint:nolintlint,staticcheck // ignore SA1019 (IsAutomated is deprecated).
5151
},
5252
expValue: "[OK]",
53-
call: ctx.IsAutomated, //nolint:staticcheck // ignore SA1019 (IsAutomated is deprecated).
53+
call: ctx.IsAutomated, //nolint:nolintlint,staticcheck // ignore SA1019 (IsAutomated is deprecated).
5454
},
5555
{
5656
searchCtx: searchContext{
5757
s: registrytypes.SearchResult{},
5858
},
59-
call: ctx.IsAutomated, //nolint:staticcheck // ignore SA1019 (IsAutomated is deprecated).
59+
call: ctx.IsAutomated, //nolint:nolintlint,staticcheck // ignore SA1019 (IsAutomated is deprecated).
6060
},
6161
}
6262

@@ -199,7 +199,7 @@ result2 5
199199

200200
results := []registrytypes.SearchResult{
201201
{Name: "result1", Description: "Official build", StarCount: 5000, IsOfficial: true},
202-
{Name: "result2", Description: "Not official", StarCount: 5, IsAutomated: true}, //nolint:staticcheck // ignore SA1019 (IsAutomated is deprecated).
202+
{Name: "result2", Description: "Not official", StarCount: 5, IsAutomated: true},
203203
}
204204

205205
for _, tc := range cases {

cli/connhelper/commandconn/pdeathsig_nolinux.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,4 @@ import (
66
"os/exec"
77
)
88

9-
func setPdeathsig(cmd *exec.Cmd) {
10-
}
9+
func setPdeathsig(*exec.Cmd) {}

templates/templates.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ var basicFunctions = template.FuncMap{
2020
},
2121
"split": strings.Split,
2222
"join": strings.Join,
23-
"title": strings.Title, //nolint:staticcheck // strings.Title is deprecated, but we only use it for ASCII, so replacing with golang.org/x/text is out of scope
23+
"title": strings.Title, //nolint:nolintlint,staticcheck // strings.Title is deprecated, but we only use it for ASCII, so replacing with golang.org/x/text is out of scope
2424
"lower": strings.ToLower,
2525
"upper": strings.ToUpper,
2626
"pad": padWithSpace,

0 commit comments

Comments
 (0)