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..22e1aa5 --- /dev/null +++ b/.golangci.yaml @@ -0,0 +1,28 @@ +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 + - -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/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() 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/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 } } 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":