diff --git a/.github/workflows/push-pr-lint.yaml b/.github/workflows/push-pr-lint.yaml index 7a296d0c..0e384330 100644 --- a/.github/workflows/push-pr-lint.yaml +++ b/.github/workflows/push-pr-lint.yaml @@ -14,10 +14,10 @@ jobs: go-version-file: go.mod - name: golangci-lint - uses: golangci/golangci-lint-action@v6 + uses: golangci/golangci-lint-action@v8 with: args: --config .golangci.yml --timeout 2m - version: v1.64.5 + version: v2.3.0 - name: Test run: go test ./... diff --git a/.golangci.yml b/.golangci.yml index 92edcf3e..e647f120 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,105 +1,109 @@ -# golangci.com configuration -# https://github.com/golangci/golangci/wiki/Configuration - -linters-settings: - govet: - settings: - printf: - funcs: - - (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof - - (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf - - (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf - - (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf - gocyclo: - min-complexity: 15 - dupl: - threshold: 100 - goconst: - min-len: 2 - min-occurrences: 2 - misspell: - locale: US - lll: - line-length: 140 - goimports: - local-prefixes: github.com/golangci/golangci-lint - gocritic: - enabled-tags: - - performance - - style - - experimental - disabled-checks: - - wrapperFunc - gofumpt: - extra-rules: true - +version: "2" linters: + default: none enable: - - errcheck - - gosimple - - govet - - gofmt - - gocyclo - - ineffassign - - stylecheck - - misspell - - staticcheck - - unused - - prealloc - - typecheck - # additional linters - bodyclose - - gocritic - - err113 - - goimports - - revive - - misspell - - noctx - - stylecheck - - gosec - contextcheck - durationcheck + - err113 + - errcheck - errchkjson - errorlint - gochecksumtype + - gocritic + - gocyclo + - gosec + - govet + - ineffassign + - misspell - nilerr + - noctx + - prealloc - reassign + - revive + - staticcheck + - unused - whitespace - enable-all: false - disable-all: true - -issues: - exclude-files: - - "(.*/)*.*_test.go" - exclude-dirs: - - internal/fixtures - exclude-rules: - - linters: - - gosec - text: "weak cryptographic primitive" - - - linters: - - stylecheck - text: "ST1016" - exclude: - # Default excludes from `golangci-lint run --help` with EXC0002 removed - # EXC0001 errcheck: Almost all programs ignore errors on these functions and in most cases it's ok - - Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*print(f|ln)?|os\.(Un)?Setenv). is not checked - # EXC0002 golint: Annoying issue about not having a comment. The rare codebase has such comments - # - (comment on exported (method|function|type|const)|should have( a package)? comment|comment should be of the form) - # EXC0003 golint: False positive when tests are defined in package 'test' - - func name will be used as test\.Test.* by other packages, and that stutters; consider calling this - # EXC0004 govet: Common false positives - - (possible misuse of unsafe.Pointer|should have signature) - # EXC0005 staticcheck: Developers tend to write in C-style with an explicit 'break' in a 'switch', so it's ok to ignore - - ineffective break statement. Did you mean to break out of the outer loop - # EXC0006 gosec: Too many false-positives on 'unsafe' usage - - Use of unsafe calls should be audited - # EXC0007 gosec: Too many false-positives for parametrized shell calls - - Subprocess launch(ed with variable|ing should be audited) - # EXC0008 gosec: Duplicated errcheck checks - - (G104|G307) - # EXC0009 gosec: Too many issues in popular repos - - (Expect directory permissions to be 0750 or less|Expect file permissions to be 0600 or less) - # EXC0010 gosec: False positive is triggered by 'src, err := ioutil.ReadFile(filename)' - - Potential file inclusion via variable + settings: + dupl: + threshold: 100 + goconst: + min-len: 2 + min-occurrences: 2 + gocritic: + disabled-checks: + - wrapperFunc + enabled-tags: + - performance + - style + - experimental + gocyclo: + min-complexity: 15 + govet: + settings: + printf: + funcs: + - (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof + - (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf + - (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf + - (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf + lll: + line-length: 140 + misspell: + locale: US + exclusions: + generated: lax + presets: + - comments + - common-false-positives + - legacy + - std-error-handling + rules: + - linters: + - gosec + text: weak cryptographic primitive + - linters: + - staticcheck + text: ST1016 + - path: (.+)\.go$ + text: Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*print(f|ln)?|os\.(Un)?Setenv). is not checked + - path: (.+)\.go$ + text: func name will be used as test\.Test.* by other packages, and that stutters; consider calling this + - path: (.+)\.go$ + text: (possible misuse of unsafe.Pointer|should have signature) + - path: (.+)\.go$ + text: ineffective break statement. Did you mean to break out of the outer loop + - path: (.+)\.go$ + text: Use of unsafe calls should be audited + - path: (.+)\.go$ + text: Subprocess launch(ed with variable|ing should be audited) + - path: (.+)\.go$ + text: (G104|G307) + - path: (.+)\.go$ + text: (Expect directory permissions to be 0750 or less|Expect file permissions to be 0600 or less) + - path: (.+)\.go$ + text: Potential file inclusion via variable + paths: + - (.*/)*.*_test.go + - internal/fixtures + - third_party$ + - builtin$ + - examples$ +formatters: + enable: + - gofmt + - goimports + settings: + gofumpt: + extra-rules: true + goimports: + local-prefixes: + - github.com/golangci/golangci-lint + exclusions: + generated: lax + paths: + - (.*/)*.*_test.go + - internal/fixtures + - third_party$ + - builtin$ + - examples$ diff --git a/internal/app/app.go b/internal/app/app.go index 7573baaa..a21644fe 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -98,7 +98,7 @@ func enableProfilingEndpoint() { go func() { server := &http.Server{ Addr: ProfilingEndpoint, - ReadHeaderTimeout: 2 * time.Second, // nolint:gomnd // time duration value is clear as is. + ReadHeaderTimeout: 2 * time.Second, } if err := server.ListenAndServe(); err != nil { diff --git a/internal/inband/actions.go b/internal/inband/actions.go index ca3ad667..f002bc34 100644 --- a/internal/inband/actions.go +++ b/internal/inband/actions.go @@ -61,7 +61,7 @@ func (i *ActionHandler) identifyComponent(ctx context.Context, component string, found := components.ByNameModel(component, models) if found == nil { - // nolint:goerr113 // its clearer to define this error here + // nolint:err113 // its clearer to define this error here errComponentMatch := fmt.Errorf( "unable to identify component '%s' from inventory for given models: %s", component, diff --git a/internal/metrics/metrics.go b/internal/metrics/metrics.go index 6ad2f1c7..a767bdaf 100644 --- a/internal/metrics/metrics.go +++ b/internal/metrics/metrics.go @@ -108,7 +108,7 @@ func ListenAndServe() { server := &http.Server{ Addr: MetricsEndpoint, - ReadHeaderTimeout: 2 * time.Second, // nolint:gomnd // time duration value is clear as is. + ReadHeaderTimeout: 2 * time.Second, } if err := server.ListenAndServe(); err != nil { diff --git a/internal/model/firmware.go b/internal/model/firmware.go index 2288398c..2882a19f 100644 --- a/internal/model/firmware.go +++ b/internal/model/firmware.go @@ -10,7 +10,6 @@ var ( // FirmwareInstallOrder defines the order in which firmware is installed. // // TODO(joel): fix up bmc-toolbox/common slugs to be of lower case instead of upper - // nolint:gomnd // component install order number is clear as is. FirmwareInstallOrder = map[string]int{ strings.ToLower(common.SlugBMC): 0, strings.ToLower(common.SlugBIOS): 1, diff --git a/internal/outofband/bmc_helpers.go b/internal/outofband/bmc_helpers.go index f8d56321..168985cc 100644 --- a/internal/outofband/bmc_helpers.go +++ b/internal/outofband/bmc_helpers.go @@ -52,7 +52,6 @@ func newHTTPClient() *http.Client { panic(err) } - // nolint:gomnd // time duration declarations are clear as is. return &http.Client{ Timeout: time.Second * 600, Jar: jar, @@ -256,7 +255,6 @@ func (b *bmc) loginWithRetries(ctx context.Context, maxAttempts int, provider st // method returns nil if a retry is required and an error when a retry cannot proceed func (b *bmc) retry(ctx context.Context, maxAttempts, attempts int, cause error, provider string) (int, error) { - // nolint:gomnd // time duration definitions are clear as is. delay := &backoff.Backoff{ Min: 5 * time.Second, Max: 30 * time.Second, diff --git a/internal/runner/runner.go b/internal/runner/runner.go index 217ef12b..73e01aca 100644 --- a/internal/runner/runner.go +++ b/internal/runner/runner.go @@ -313,7 +313,7 @@ func (r *Runner) runActionSteps(ctx context.Context, task *model.Task, action *m if step.Handler == nil { publish(model.StateFailed, action, step, logger) - // nolint:goerr113 // for this case, its preferable to have the error be defined within its context of use + // nolint:err113 // for this case, its preferable to have the error be defined within its context of use return false, fmt.Errorf( "error while running step=%s to install firmware on component=%s, handler was nil", step.Name, diff --git a/types/types.go b/types/types.go index 71c88440..fa0fd33d 100644 --- a/types/types.go +++ b/types/types.go @@ -1,3 +1,4 @@ +// nolint:revive // legacy naming package types import (