diff --git a/backend/.golangci.yml b/backend/.golangci.yml index b436b9a0fd..27246b9bde 100644 --- a/backend/.golangci.yml +++ b/backend/.golangci.yml @@ -1,34 +1,46 @@ -# golangci-lint configuration -# https://golangci-lint.run/usage/configuration/ +version: "2" run: tests: true linters: enable: - copyloopvar - - errcheck - - gosimple - - govet - - ineffassign - misspell - revive - - staticcheck - - unused -linters-settings: - copyloopvar: - check-alias: true - govet: - enable: - - shadow - misspell: - locale: US - revive: - rules: - - name: package-comments - disabled: true - gci: - sections: - - standard - - default - - prefix(github.com/stolostron/console/backend) - - blank - - dot + settings: + copyloopvar: + check-alias: true + govet: + enable: + - shadow + misspell: + locale: US + revive: + rules: + - name: package-comments + disabled: true + exclusions: + generated: lax + presets: + - comments + - common-false-positives + - legacy + - std-error-handling + paths: + - third_party$ + - builtin$ + - examples$ +formatters: + settings: + gci: + sections: + - standard + - default + - prefix(github.com/stolostron/console/backend) + - blank + - dot + exclusions: + generated: lax + paths: + - third_party$ + - builtin$ + - examples$ diff --git a/backend/internal/aggregate/status.go b/backend/internal/aggregate/status.go index 6c0af988a3..35f5b56928 100644 --- a/backend/internal/aggregate/status.go +++ b/backend/internal/aggregate/status.go @@ -162,7 +162,7 @@ func computeDeployedPodStatuses(related []mapKind, appStatusesMap map[string]Sta podMap := createResourceMap(related, "Pod") for appKey, clusterMap := range appStatusesMap { for clusterKey, appStatuses := range clusterMap { - if !(appStatuses.Health.Counts[scoreHealthy] > 0 && appStatuses.Synced.Counts[scoreHealthy] > 0) && !ignoreHealthCheck { + if (appStatuses.Health.Counts[scoreHealthy] <= 0 || appStatuses.Synced.Counts[scoreHealthy] <= 0) && !ignoreHealthCheck { continue } id := ids[statusIDKey(appKey, clusterKey)] diff --git a/backend/internal/auth/auth.go b/backend/internal/auth/auth.go index 91955d0bbd..e481bcbc1c 100644 --- a/backend/internal/auth/auth.go +++ b/backend/internal/auth/auth.go @@ -143,7 +143,7 @@ func RESTConfig(cfg *config.Config, sa ServiceAccount) (*rest.Config, error) { }, } if len(sa.CACert) == 0 { - restCfg.TLSClientConfig.Insecure = true + restCfg.Insecure = true } return restCfg, nil } diff --git a/backend/internal/vmproxy/units.go b/backend/internal/vmproxy/units.go index 69ed876a8b..76a996477c 100644 --- a/backend/internal/vmproxy/units.go +++ b/backend/internal/vmproxy/units.go @@ -51,19 +51,19 @@ func convertBytesToGibibytes(bytes float64) float64 { func toMillicores(cpuRequest string) (float64, error) { trimmed := strings.TrimSpace(cpuRequest) if trimmed == "" { - return 0, fmt.Errorf("Invalid input: cpuRequest must be a non-empty string.") + return 0, fmt.Errorf("invalid input: cpuRequest must be a non-empty string") } if strings.HasSuffix(trimmed, "m") { numericPart := trimmed[:len(trimmed)-1] millicores, err := strconv.Atoi(numericPart) if err != nil || strconv.Itoa(millicores) != numericPart { - return 0, fmt.Errorf("Invalid millicore value: %q. The part before \"m\" must be an integer.", cpuRequest) + return 0, fmt.Errorf("invalid millicore value: %q, the part before \"m\" must be an integer", cpuRequest) } return float64(millicores), nil } coreValue, err := strconv.ParseFloat(trimmed, 64) if err != nil { - return 0, fmt.Errorf("Invalid core value: %q. Must be a number or end with 'm'.", cpuRequest) + return 0, fmt.Errorf("invalid core value: %q, must be a number or end with 'm'", cpuRequest) } return coreValue * 1000, nil } @@ -73,11 +73,11 @@ var memoryRE = regexp.MustCompile(`^(\d+(\.\d+)?)\s*([A-Za-z]+)?$`) func toMebibytes(memoryRequest string) (float64, error) { trimmed := strings.TrimSpace(memoryRequest) if trimmed == "" { - return 0, fmt.Errorf("Invalid input: memoryRequest must be a non-empty string.") + return 0, fmt.Errorf("invalid input: memoryRequest must be a non-empty string") } match := memoryRE.FindStringSubmatch(trimmed) if match == nil { - return 0, fmt.Errorf("Invalid memory format: %q. Expected a number followed by an optional unit.", memoryRequest) + return 0, fmt.Errorf("invalid memory format: %q, expected a number followed by an optional unit", memoryRequest) } numericValue, err := strconv.ParseFloat(match[1], 64) if err != nil { @@ -105,7 +105,7 @@ func toMebibytes(memoryRequest string) (float64, error) { case multipliers[unit] != 0: bytes = numericValue * multipliers[unit] default: - return 0, fmt.Errorf("Invalid memory unit: %q.", unit) + return 0, fmt.Errorf("invalid memory unit: %q", unit) } return bytes / (1024 * 1024), nil } diff --git a/scripts/golangci-lint-backend.sh b/scripts/golangci-lint-backend.sh index 41220b9dce..bd8930e249 100755 --- a/scripts/golangci-lint-backend.sh +++ b/scripts/golangci-lint-backend.sh @@ -3,7 +3,7 @@ set -euo pipefail -readonly GOLANGCI_LINT_VERSION=v1.64.8 +readonly GOLANGCI_LINT_VERSION=v2.13.2 readonly ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" if ! command -v go >/dev/null 2>&1; then @@ -12,7 +12,7 @@ if ! command -v go >/dev/null 2>&1; then fi if ! command -v golangci-lint >/dev/null 2>&1; then - go install "github.com/golangci/golangci-lint/cmd/golangci-lint@${GOLANGCI_LINT_VERSION}" + go install "github.com/golangci/golangci-lint/v2/cmd/golangci-lint@${GOLANGCI_LINT_VERSION}" fi export PATH="$(go env GOPATH)/bin:${PATH}"