diff --git a/.golangci.yml b/.golangci.yml index 89162cd8bc..c1ca4b920e 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -4,27 +4,39 @@ linters: - depguard - dogsled - dupword # Detects duplicate words. + - durationcheck + - exportloopref # Detects pointers to enclosing loop variables. + - gocritic # Metalinter; detects bugs, performance, and styling issues. - gocyclo - - gofumpt + - gofumpt # Detects whether code was gofumpt-ed. - goimports - - gosec + - gosec # Detects security problems. - gosimple - govet - ineffassign - lll - megacheck - - misspell + - misspell # Detects commonly misspelled English words in comments. - nakedret - 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. - - predeclared - - revive + - prealloc # Detects slice declarations that could potentially be pre-allocated. + - predeclared # Detects code that shadows one of Go's predeclared identifiers + - reassign + - revive # Metalinter; drop-in replacement for golint. - 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 - - unconvert + - unconvert # Detects unnecessary type conversions. - unparam - unused + - usestdlibvars + - vet + - wastedassign disable: - errcheck @@ -110,7 +122,7 @@ issues: - gosec # EXC0008 # TODO: evaluate these and fix where needed: G307: Deferring unsafe method "*os.File" on type "Close" (gosec) - - text: "(G104|G307)" + - text: "G307" linters: - gosec # EXC0009 @@ -124,10 +136,13 @@ issues: # G113 Potential uncontrolled memory consumption in Rat.SetString (CVE-2022-23772) # 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: - gosec - # Looks like the match in "EXC0007" above doesn't catch this one # TODO: consider upstreaming this to golangci-lint's default exclusion rules - text: "G204: Subprocess launched with a potential tainted input or cmd arguments" @@ -152,6 +167,9 @@ issues: linters: - errcheck - 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. - text: '^shadow: declaration of "(err|ok)" shadows declaration' diff --git a/cli/command/formatter/image_test.go b/cli/command/formatter/image_test.go index d2388fd6c9..fcdf727c52 100644 --- a/cli/command/formatter/image_test.go +++ b/cli/command/formatter/image_test.go @@ -72,7 +72,7 @@ func TestImageContext(t *testing.T) { { imageCtx: imageContext{i: image.Summary{Size: 10000}}, 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}}, diff --git a/cli/command/formatter/tabwriter/tabwriter.go b/cli/command/formatter/tabwriter/tabwriter.go index fac1b96c58..bc155298f6 100644 --- a/cli/command/formatter/tabwriter/tabwriter.go +++ b/cli/command/formatter/tabwriter/tabwriter.go @@ -12,7 +12,7 @@ // 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 import ( diff --git a/cli/command/registry/formatter_search.go b/cli/command/registry/formatter_search.go index ec11298968..3f557dea6a 100644 --- a/cli/command/registry/formatter_search.go +++ b/cli/command/registry/formatter_search.go @@ -97,5 +97,5 @@ func (c *searchContext) IsOfficial() string { // // Deprecated: the "is_automated" field is deprecated and will always be "false" in the future. 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). } diff --git a/cli/command/registry/formatter_search_test.go b/cli/command/registry/formatter_search_test.go index 53d9f01e18..fd50a87f23 100644 --- a/cli/command/registry/formatter_search_test.go +++ b/cli/command/registry/formatter_search_test.go @@ -47,16 +47,16 @@ func TestSearchContext(t *testing.T) { }, { 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]", - call: ctx.IsAutomated, //nolint:staticcheck // ignore SA1019 (IsAutomated is deprecated). + call: ctx.IsAutomated, //nolint:nolintlint,staticcheck // ignore SA1019 (IsAutomated is deprecated). }, { searchCtx: searchContext{ 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{ {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 { diff --git a/cli/command/stack/loader/loader.go b/cli/command/stack/loader/loader.go index 2f41655b19..692681b3d1 100644 --- a/cli/command/stack/loader/loader.go +++ b/cli/command/stack/loader/loader.go @@ -28,9 +28,8 @@ func LoadComposefile(dockerCli command.Cli, opts options.Deploy) (*composetypes. config, err := loader.Load(configDetails) if err != nil { if fpe, ok := err.(*loader.ForbiddenPropertiesError); ok { - //nolint:revive // ignore capitalization error; this error is intentionally formatted multi-line - return nil, errors.Errorf("Compose file contains unsupported options:\n\n%s\n", - propertyWarnings(fpe.Properties)) + // this error is intentionally formatted multi-line + return nil, errors.Errorf("Compose file contains unsupported options:\n\n%s\n", propertyWarnings(fpe.Properties)) } return nil, err diff --git a/cli/connhelper/commandconn/pdeathsig_nolinux.go b/cli/connhelper/commandconn/pdeathsig_nolinux.go index 758fd1dfc4..149349e982 100644 --- a/cli/connhelper/commandconn/pdeathsig_nolinux.go +++ b/cli/connhelper/commandconn/pdeathsig_nolinux.go @@ -6,5 +6,4 @@ import ( "os/exec" ) -func setPdeathsig(cmd *exec.Cmd) { -} +func setPdeathsig(*exec.Cmd) {} diff --git a/templates/templates.go b/templates/templates.go index fc86841876..f0b62260ee 100644 --- a/templates/templates.go +++ b/templates/templates.go @@ -20,7 +20,7 @@ var basicFunctions = template.FuncMap{ }, "split": strings.Split, "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, "upper": strings.ToUpper, "pad": padWithSpace,