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💯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>
This commit is contained in:
Sebastiaan van Stijn 2022-09-02 21:50:18 +02:00
parent 0e73168b7e
commit 4e2477f85f
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
8 changed files with 39 additions and 23 deletions

View File

@ -4,27 +4,39 @@ linters:
- depguard - depguard
- dogsled - dogsled
- dupword # Detects duplicate words. - dupword # Detects duplicate words.
- durationcheck
- exportloopref # Detects pointers to enclosing loop variables.
- gocritic # Metalinter; detects bugs, performance, and styling issues.
- gocyclo - gocyclo
- gofumpt - gofumpt # Detects whether code was gofumpt-ed.
- goimports - goimports
- gosec - gosec # Detects security problems.
- gosimple - gosimple
- govet - govet
- ineffassign - ineffassign
- lll - lll
- megacheck - megacheck
- misspell - misspell # Detects commonly misspelled English words in comments.
- nakedret - nakedret
- nilerr # Detects code that returns nil even if it checks that the error is not nil. - nilerr # Detects code that returns nil even if it checks that the error is not nil.
- nolintlint # Detects ill-formed or insufficient nolint directives.
- perfsprint # Detects fmt.Sprintf uses that can be replaced with a faster alternative. - perfsprint # Detects fmt.Sprintf uses that can be replaced with a faster alternative.
- predeclared - prealloc # Detects slice declarations that could potentially be pre-allocated.
- revive - predeclared # Detects code that shadows one of Go's predeclared identifiers
- reassign
- revive # Metalinter; drop-in replacement for golint.
- staticcheck - staticcheck
- thelper - stylecheck # Replacement for golint
- tenv # Detects using os.Setenv instead of t.Setenv.
- thelper # Detects test helpers without t.Helper().
- tparallel # Detects inappropriate usage of t.Parallel().
- typecheck - typecheck
- unconvert - unconvert # Detects unnecessary type conversions.
- unparam - unparam
- unused - unused
- usestdlibvars
- vet
- wastedassign
disable: disable:
- errcheck - errcheck
@ -110,7 +122,7 @@ issues:
- gosec - gosec
# EXC0008 # EXC0008
# TODO: evaluate these and fix where needed: G307: Deferring unsafe method "*os.File" on type "Close" (gosec) # TODO: evaluate these and fix where needed: G307: Deferring unsafe method "*os.File" on type "Close" (gosec)
- text: "(G104|G307)" - text: "G307"
linters: linters:
- gosec - gosec
# EXC0009 # EXC0009
@ -124,10 +136,13 @@ issues:
# G113 Potential uncontrolled memory consumption in Rat.SetString (CVE-2022-23772) # G113 Potential uncontrolled memory consumption in Rat.SetString (CVE-2022-23772)
# only affects gp < 1.16.14. and go < 1.17.7 # only affects gp < 1.16.14. and go < 1.17.7
- text: "(G113)" - text: "G113"
linters:
- gosec
# TODO: G104: Errors unhandled. (gosec)
- text: "G104"
linters: linters:
- gosec - gosec
# Looks like the match in "EXC0007" above doesn't catch this one # Looks like the match in "EXC0007" above doesn't catch this one
# TODO: consider upstreaming this to golangci-lint's default exclusion rules # TODO: consider upstreaming this to golangci-lint's default exclusion rules
- text: "G204: Subprocess launched with a potential tainted input or cmd arguments" - text: "G204: Subprocess launched with a potential tainted input or cmd arguments"
@ -152,6 +167,9 @@ issues:
linters: linters:
- errcheck - errcheck
- gosec - gosec
- text: "ST1000: at least one file in a package should have a package comment"
linters:
- stylecheck
# Allow "err" and "ok" vars to shadow existing declarations, otherwise we get too many false positives. # Allow "err" and "ok" vars to shadow existing declarations, otherwise we get too many false positives.
- text: '^shadow: declaration of "(err|ok)" shadows declaration' - text: '^shadow: declaration of "(err|ok)" shadows declaration'

View File

@ -72,7 +72,7 @@ func TestImageContext(t *testing.T) {
{ {
imageCtx: imageContext{i: image.Summary{Size: 10000}}, imageCtx: imageContext{i: image.Summary{Size: 10000}},
expValue: "10kB", expValue: "10kB",
call: ctx.VirtualSize, //nolint:staticcheck // ignore SA1019: field is deprecated, but still set on API < v1.44. call: ctx.VirtualSize, //nolint:nolintlint,staticcheck // ignore SA1019: field is deprecated, but still set on API < v1.44.
}, },
{ {
imageCtx: imageContext{i: image.Summary{SharedSize: 10000}}, imageCtx: imageContext{i: image.Summary{SharedSize: 10000}},

View File

@ -12,7 +12,7 @@
// based on https://github.com/golang/go/blob/master/src/text/tabwriter/tabwriter.go Last modified 690ac40 on 31 Jan // based on https://github.com/golang/go/blob/master/src/text/tabwriter/tabwriter.go Last modified 690ac40 on 31 Jan
//nolint:gocyclo,nakedret,revive,stylecheck,unused // ignore linting errors, so that we can stick close to upstream //nolint:gocyclo,nakedret,stylecheck,unused // ignore linting errors, so that we can stick close to upstream
package tabwriter package tabwriter
import ( import (

View File

@ -97,5 +97,5 @@ func (c *searchContext) IsOfficial() string {
// //
// Deprecated: the "is_automated" field is deprecated and will always be "false" in the future. // Deprecated: the "is_automated" field is deprecated and will always be "false" in the future.
func (c *searchContext) IsAutomated() string { func (c *searchContext) IsAutomated() string {
return c.formatBool(c.s.IsAutomated) //nolint:staticcheck // ignore SA1019 (IsAutomated is deprecated). return c.formatBool(c.s.IsAutomated) //nolint:nolintlint,staticcheck // ignore SA1019 (IsAutomated is deprecated).
} }

View File

@ -47,16 +47,16 @@ func TestSearchContext(t *testing.T) {
}, },
{ {
searchCtx: searchContext{ searchCtx: searchContext{
s: registrytypes.SearchResult{IsAutomated: true}, //nolint:staticcheck // ignore SA1019 (IsAutomated is deprecated). s: registrytypes.SearchResult{IsAutomated: true}, //nolint:nolintlint,staticcheck // ignore SA1019 (IsAutomated is deprecated).
}, },
expValue: "[OK]", expValue: "[OK]",
call: ctx.IsAutomated, //nolint:staticcheck // ignore SA1019 (IsAutomated is deprecated). call: ctx.IsAutomated, //nolint:nolintlint,staticcheck // ignore SA1019 (IsAutomated is deprecated).
}, },
{ {
searchCtx: searchContext{ searchCtx: searchContext{
s: registrytypes.SearchResult{}, s: registrytypes.SearchResult{},
}, },
call: ctx.IsAutomated, //nolint:staticcheck // ignore SA1019 (IsAutomated is deprecated). call: ctx.IsAutomated, //nolint:nolintlint,staticcheck // ignore SA1019 (IsAutomated is deprecated).
}, },
} }
@ -199,7 +199,7 @@ result2 5
results := []registrytypes.SearchResult{ results := []registrytypes.SearchResult{
{Name: "result1", Description: "Official build", StarCount: 5000, IsOfficial: true}, {Name: "result1", Description: "Official build", StarCount: 5000, IsOfficial: true},
{Name: "result2", Description: "Not official", StarCount: 5, IsAutomated: true}, //nolint:staticcheck // ignore SA1019 (IsAutomated is deprecated). {Name: "result2", Description: "Not official", StarCount: 5, IsAutomated: true},
} }
for _, tc := range cases { for _, tc := range cases {

View File

@ -28,9 +28,8 @@ func LoadComposefile(dockerCli command.Cli, opts options.Deploy) (*composetypes.
config, err := loader.Load(configDetails) config, err := loader.Load(configDetails)
if err != nil { if err != nil {
if fpe, ok := err.(*loader.ForbiddenPropertiesError); ok { if fpe, ok := err.(*loader.ForbiddenPropertiesError); ok {
//nolint:revive // ignore capitalization error; this error is intentionally formatted multi-line // this error is intentionally formatted multi-line
return nil, errors.Errorf("Compose file contains unsupported options:\n\n%s\n", return nil, errors.Errorf("Compose file contains unsupported options:\n\n%s\n", propertyWarnings(fpe.Properties))
propertyWarnings(fpe.Properties))
} }
return nil, err return nil, err

View File

@ -6,5 +6,4 @@ import (
"os/exec" "os/exec"
) )
func setPdeathsig(cmd *exec.Cmd) { func setPdeathsig(*exec.Cmd) {}
}

View File

@ -20,7 +20,7 @@ var basicFunctions = template.FuncMap{
}, },
"split": strings.Split, "split": strings.Split,
"join": strings.Join, "join": strings.Join,
"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 "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
"lower": strings.ToLower, "lower": strings.ToLower,
"upper": strings.ToUpper, "upper": strings.ToUpper,
"pad": padWithSpace, "pad": padWithSpace,