Skip to content

Commit 4e2477f

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 0e73168 commit 4e2477f

8 files changed

Lines changed: 39 additions & 23 deletions

File tree

.golangci.yml

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,39 @@ 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.
22+
- nolintlint # Detects ill-formed or insufficient nolint directives.
1923
- perfsprint # Detects fmt.Sprintf uses that can be replaced with a faster alternative.
20-
- predeclared
21-
- revive
24+
- prealloc # Detects slice declarations that could potentially be pre-allocated.
25+
- predeclared # Detects code that shadows one of Go's predeclared identifiers
26+
- reassign
27+
- revive # Metalinter; drop-in replacement for golint.
2228
- staticcheck
23-
- thelper
29+
- stylecheck # Replacement for golint
30+
- tenv # Detects using os.Setenv instead of t.Setenv.
31+
- thelper # Detects test helpers without t.Helper().
32+
- tparallel # Detects inappropriate usage of t.Parallel().
2433
- typecheck
25-
- unconvert
34+
- unconvert # Detects unnecessary type conversions.
2635
- unparam
2736
- unused
37+
- usestdlibvars
38+
- vet
39+
- wastedassign
2840

2941
disable:
3042
- errcheck
@@ -110,7 +122,7 @@ issues:
110122
- gosec
111123
# EXC0008
112124
# TODO: evaluate these and fix where needed: G307: Deferring unsafe method "*os.File" on type "Close" (gosec)
113-
- text: "(G104|G307)"
125+
- text: "G307"
114126
linters:
115127
- gosec
116128
# EXC0009
@@ -124,10 +136,13 @@ issues:
124136

125137
# G113 Potential uncontrolled memory consumption in Rat.SetString (CVE-2022-23772)
126138
# only affects gp < 1.16.14. and go < 1.17.7
127-
- text: "(G113)"
139+
- text: "G113"
140+
linters:
141+
- gosec
142+
# TODO: G104: Errors unhandled. (gosec)
143+
- text: "G104"
128144
linters:
129145
- gosec
130-
131146
# Looks like the match in "EXC0007" above doesn't catch this one
132147
# TODO: consider upstreaming this to golangci-lint's default exclusion rules
133148
- text: "G204: Subprocess launched with a potential tainted input or cmd arguments"
@@ -152,6 +167,9 @@ issues:
152167
linters:
153168
- errcheck
154169
- gosec
170+
- text: "ST1000: at least one file in a package should have a package comment"
171+
linters:
172+
- stylecheck
155173

156174
# Allow "err" and "ok" vars to shadow existing declarations, otherwise we get too many false positives.
157175
- 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/formatter/tabwriter/tabwriter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
// based on https://github.com/golang/go/blob/master/src/text/tabwriter/tabwriter.go Last modified 690ac40 on 31 Jan
1414

15-
//nolint:gocyclo,nakedret,revive,stylecheck,unused // ignore linting errors, so that we can stick close to upstream
15+
//nolint:gocyclo,nakedret,stylecheck,unused // ignore linting errors, so that we can stick close to upstream
1616
package tabwriter
1717

1818
import (

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/command/stack/loader/loader.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,8 @@ func LoadComposefile(dockerCli command.Cli, opts options.Deploy) (*composetypes.
2828
config, err := loader.Load(configDetails)
2929
if err != nil {
3030
if fpe, ok := err.(*loader.ForbiddenPropertiesError); ok {
31-
//nolint:revive // ignore capitalization error; this error is intentionally formatted multi-line
32-
return nil, errors.Errorf("Compose file contains unsupported options:\n\n%s\n",
33-
propertyWarnings(fpe.Properties))
31+
// this error is intentionally formatted multi-line
32+
return nil, errors.Errorf("Compose file contains unsupported options:\n\n%s\n", propertyWarnings(fpe.Properties))
3433
}
3534

3635
return nil, err

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)