From 3d814c7be39bfc4a0d0a2a53d43224025025ee78 Mon Sep 17 00:00:00 2001 From: Joel Rebello Date: Wed, 3 Apr 2024 12:27:12 +0200 Subject: [PATCH] linter: update golangci-lint and lint files --- .golangci.yml | 26 ++++++++++++++------------ cmd/export.go | 2 +- cmd/install.go | 2 +- cmd/run.go | 2 +- cmd/version.go | 2 +- internal/install/task_handler.go | 2 +- internal/outofband/action_handlers.go | 1 + internal/runner/runner.go | 1 + internal/worker/worker.go | 12 ------------ 9 files changed, 21 insertions(+), 29 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 823d7724..1f14d6f7 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,12 +1,10 @@ # golangci.com configuration # https://github.com/golangci/golangci/wiki/Configuration service: - golangci-lint-version: 1.50.0 # use the fixed version to not introduce new linters unexpectedly + golangci-lint-version: v1.56.2 # use the fixed version to not introduce new linters unexpectedly linters-settings: govet: - enable: - - fieldalignment auto-fix: true check-shadowing: true settings: @@ -19,7 +17,7 @@ linters-settings: revive: min-confidence: 0 gocyclo: - min-complexity: 11 + min-complexity: 15 dupl: threshold: 100 goconst: @@ -47,6 +45,8 @@ linters-settings: - wrapperFunc gofumpt: extra-rules: true + whitespace: + auto-fix: true linters: enable: @@ -71,13 +71,21 @@ linters: - misspell - noctx - stylecheck - - whitespace - gosec + - contextcheck + - durationcheck + - errchkjson + - errorlint + - gochecksumtype + - nilerr + - reassign + - whitespace + - exportloopref enable-all: false disable-all: true run: -# build-tags: + # build-tags: skip-dirs: - internal/fixtures skip-files: @@ -92,10 +100,6 @@ issues: - linters: - stylecheck text: "ST1016" - - - linters: - - stylecheck - text: "ST1003" 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 @@ -119,5 +123,3 @@ issues: # EXC0010 gosec: False positive is triggered by 'src, err := ioutil.ReadFile(filename)' - Potential file inclusion via variable exclude-use-default: false - - diff --git a/cmd/export.go b/cmd/export.go index d05a4fc2..4306c119 100644 --- a/cmd/export.go +++ b/cmd/export.go @@ -29,7 +29,7 @@ var ( var cmdExportStatemachine = &cobra.Command{ Use: "export-statemachine --task|--action [--json|--mermaid]", Short: "Export a JSON dump of flasher statemachine(s) - writes to a file task-statemachine.json", - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, _ []string) { exportStatemachine() }, } diff --git a/cmd/install.go b/cmd/install.go index 35a16392..d005253c 100644 --- a/cmd/install.go +++ b/cmd/install.go @@ -13,7 +13,7 @@ import ( var cmdInstall = &cobra.Command{ Use: "install", Short: "Install given firmware for a component", - Run: func(cmd *cobra.Command, args []string) { + Run: func(cmd *cobra.Command, _ []string) { runInstall(cmd.Context()) }, } diff --git a/cmd/run.go b/cmd/run.go index d9836fa2..39f8f7a0 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -23,7 +23,7 @@ import ( var cmdRun = &cobra.Command{ Use: "run", Short: "Run flasher service to listen for events and install firmware", - Run: func(cmd *cobra.Command, args []string) { + Run: func(cmd *cobra.Command, _ []string) { runWorker(cmd.Context()) }, } diff --git a/cmd/version.go b/cmd/version.go index 6d9aa1ad..691275a0 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -10,7 +10,7 @@ import ( var cmdVersion = &cobra.Command{ Use: "version", Short: "Print Flasher version along with dependency information.", - Run: func(_ *cobra.Command, args []string) { + Run: func(_ *cobra.Command, _ []string) { fmt.Printf( "commit: %s\nbranch: %s\ngit summary: %s\nbuildDate: %s\nversion: %s\nGo version: %s\nbmclib version: %s\nFleetDB API version: %s", version.GitCommit, version.GitBranch, version.GitSummary, version.BuildDate, version.AppVersion, version.GoVersion, version.BmclibVersion, version.FleetDBAPIVersion) diff --git a/internal/install/task_handler.go b/internal/install/task_handler.go index 2456a3a8..a2c0a116 100644 --- a/internal/install/task_handler.go +++ b/internal/install/task_handler.go @@ -116,7 +116,7 @@ func (t *handler) RunActions(ctx context.Context) error { }).Debug("action state machine start") // run the action state machine - err := actionSM.Run(t.ctx.Ctx, action, t.ctx) + err := actionSM.Run(ctx, action, t.ctx) if err != nil { return errors.Wrap( err, diff --git a/internal/outofband/action_handlers.go b/internal/outofband/action_handlers.go index 16d3a986..5b365613 100644 --- a/internal/outofband/action_handlers.go +++ b/internal/outofband/action_handlers.go @@ -562,6 +562,7 @@ func (h *actionHandler) pollFirmwareTaskStatus(a sw.StateSwitch, c sw.Transition action.Firmware.Vendor, action.Firmware.Models, ) + // nolint:errorlint // TODO(joel): rework this to use errors.Is switch err { case nil: tctx.Logger.WithFields( diff --git a/internal/runner/runner.go b/internal/runner/runner.go index aea59f4a..a77ae159 100644 --- a/internal/runner/runner.go +++ b/internal/runner/runner.go @@ -103,6 +103,7 @@ func (r *Runner) conditionalFault(fname string, task *model.Task, handler Handle td, err := time.ParseDuration(task.Fault.DelayDuration) if err != nil { // invalid duration string is ignored + // nolint:nilerr // nil error returned intentionally return nil } diff --git a/internal/worker/worker.go b/internal/worker/worker.go index de4d55fe..a0a9e990 100644 --- a/internal/worker/worker.go +++ b/internal/worker/worker.go @@ -4,7 +4,6 @@ import ( "context" "encoding/json" "sync" - "time" "github.com/google/uuid" "github.com/metal-toolbox/flasher/internal/model" @@ -25,17 +24,6 @@ const ( ) var ( - fetchEventsInterval = 10 * time.Second - - // taskTimeout defines the time after which a task will be canceled. - taskTimeout = 180 * time.Minute - - // taskInprogressTicker is the interval at which tasks in progress - // will ack themselves as in progress on the event stream. - // - // This value should be set to less than the event stream Ack timeout value. - taskInprogressTick = 3 * time.Minute - errTaskFirmwareParam = errors.New("error in task firmware parameters") errInitTask = errors.New("error initializing new task from condition") )