From 41eb9da194d10ada44ea46e17780eafe25c6d150 Mon Sep 17 00:00:00 2001 From: Matthieu MOREL Date: Thu, 24 Jul 2025 08:10:35 +0200 Subject: [PATCH 1/4] chore: update golangci-lint version and add configuration file Signed-off-by: Matthieu MOREL up --- .github/workflows/compile-test.yaml | 6 ++---- .golangci.yaml | 31 +++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 .golangci.yaml diff --git a/.github/workflows/compile-test.yaml b/.github/workflows/compile-test.yaml index 6f36c85..3fbe5eb 100644 --- a/.github/workflows/compile-test.yaml +++ b/.github/workflows/compile-test.yaml @@ -27,8 +27,6 @@ jobs: run: GO111MODULE=on go run .ci/prebuild/gofmt_check.go - name: Run linter - uses: golangci/golangci-lint-action@v6.1.1 + uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8.0.0 with: - version: v1.63.4 - only-new-issues: true - args: --timeout 5m + version: v2.3.0 diff --git a/.golangci.yaml b/.golangci.yaml new file mode 100644 index 0000000..80b1496 --- /dev/null +++ b/.golangci.yaml @@ -0,0 +1,31 @@ +version: "2" + +run: + # timeout for analysis, e.g. 30s, 5m, default is 0 + timeout: 5m + +formatters: + enable: + - gofmt + + settings: + gofmt: + # simplify code: gofmt with `-s` option, true by default + simplify: true + +linters: + disable: + - errcheck + enable: + - staticcheck + + settings: + staticcheck: + checks: + - all + - -QF1003 # Convert if/else-if chain to tagged switch + - -QF1012 # Use fmt.Fprintf(x, ...) instead of x.Write(fmt.Sprintf(...)) + - -ST1000 # Incorrect or missing package comment + - -ST1003 # Poorly chosen identifier + - -ST1005 # Incorrectly formatted error string + - -ST1020 # The documentation of an exported function should start with the function’s name From 625f95cbfa725e762c4068e4f10dcd755164ef21 Mon Sep 17 00:00:00 2001 From: Matthieu MOREL Date: Thu, 24 Jul 2025 08:25:51 +0200 Subject: [PATCH 2/4] ST1005: error strings should not be capitalized Signed-off-by: Matthieu MOREL --- .golangci.yaml | 1 - k8s/kube_config.go | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.golangci.yaml b/.golangci.yaml index 80b1496..076fd29 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -27,5 +27,4 @@ linters: - -QF1012 # Use fmt.Fprintf(x, ...) instead of x.Write(fmt.Sprintf(...)) - -ST1000 # Incorrect or missing package comment - -ST1003 # Poorly chosen identifier - - -ST1005 # Incorrectly formatted error string - -ST1020 # The documentation of an exported function should start with the function’s name diff --git a/k8s/kube_config.go b/k8s/kube_config.go index f5560c4..7cb8204 100644 --- a/k8s/kube_config.go +++ b/k8s/kube_config.go @@ -23,7 +23,7 @@ func FetchWorkloadConfig(clusterName, clusterNamespace, mgmtKubeConfigPath strin f, err := os.CreateTemp(os.TempDir(), fmt.Sprintf("%s-workload-config", clusterName)) if err != nil { - return filePath, fmt.Errorf("Cannot create temporary file: %w", err) + return filePath, fmt.Errorf("cannot create temporary file: %w", err) } filePath = f.Name() defer f.Close() From f424680a5c903abd5d3f4f8936228aad13d77122 Mon Sep 17 00:00:00 2001 From: Matthieu MOREL Date: Thu, 24 Jul 2025 08:27:40 +0200 Subject: [PATCH 3/4] QF1003 # Convert if/else-if chain to tagged switch Signed-off-by: Matthieu MOREL --- .golangci.yaml | 1 - k8s/result_writer.go | 7 ++++--- starlark/set_defaults.go | 7 ++++--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/.golangci.yaml b/.golangci.yaml index 076fd29..fb94bdd 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -23,7 +23,6 @@ linters: staticcheck: checks: - all - - -QF1003 # Convert if/else-if chain to tagged switch - -QF1012 # Use fmt.Fprintf(x, ...) instead of x.Write(fmt.Sprintf(...)) - -ST1000 # Incorrect or missing package comment - -ST1003 # Poorly chosen identifier diff --git a/k8s/result_writer.go b/k8s/result_writer.go index d036ed3..380e971 100644 --- a/k8s/result_writer.go +++ b/k8s/result_writer.go @@ -31,11 +31,12 @@ func NewResultWriter(workdir, what, outputFormat, outputMode string, restApi res writeLogs := what == "logs" || what == "all" var printer printers.ResourcePrinter - if outputFormat == "" || outputFormat == "json" { + switch outputFormat { + case "", "json": printer = &printers.JSONPrinter{} - } else if outputFormat == "yaml" { + case "yaml": printer = &printers.YAMLPrinter{} - } else { + default: return nil, fmt.Errorf("unsupported output format: %s", outputFormat) } diff --git a/starlark/set_defaults.go b/starlark/set_defaults.go index 3f3cfb6..e92e872 100644 --- a/starlark/set_defaults.go +++ b/starlark/set_defaults.go @@ -31,11 +31,12 @@ func SetDefaultsFunc(thread *starlark.Thread, _ *starlark.Builtin, args starlark if err != nil { return starlark.None, fmt.Errorf("%s: %w", UnknownDefaultErrStr, err) } - if constStr == identifiers.kubeCfg { + switch constStr { + case identifiers.kubeCfg: thread.SetLocal(identifiers.kubeCfg, val) - } else if constStr == identifiers.sshCfg { + case identifiers.sshCfg: thread.SetLocal(identifiers.sshCfg, val) - } else { + default: return starlark.None, errors.New(UnknownDefaultErrStr) } case "list": From d71bdc6b123beaeaa04002a1eb10203c94620b5e Mon Sep 17 00:00:00 2001 From: Matthieu MOREL Date: Thu, 24 Jul 2025 08:28:59 +0200 Subject: [PATCH 4/4] QF1012 - Use fmt.Fprintf(x, ...) instead of x.Write(fmt.Sprintf(...)) Signed-off-by: Matthieu MOREL --- .golangci.yaml | 1 - starlark/capture.go | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.golangci.yaml b/.golangci.yaml index fb94bdd..22e1aa5 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -23,7 +23,6 @@ linters: staticcheck: checks: - all - - -QF1012 # Use fmt.Fprintf(x, ...) instead of x.Write(fmt.Sprintf(...)) - -ST1000 # Incorrect or missing package comment - -ST1003 # Poorly chosen identifier - -ST1020 # The documentation of an exported function should start with the function’s name diff --git a/starlark/capture.go b/starlark/capture.go index ef3989c..ba01f9d 100644 --- a/starlark/capture.go +++ b/starlark/capture.go @@ -204,7 +204,7 @@ func captureOutput(source io.Reader, filePath, desc string, append bool) error { defer file.Close() if len(desc) > 0 { - if _, err := file.WriteString(fmt.Sprintf("%s\n", desc)); err != nil { + if _, err := fmt.Fprintf(file, "%s\n", desc); err != nil { return err } }