From f508e9a0b8c896f4fb0341d2c7d43adbea10a36d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Charles-Edouard=20Br=C3=A9t=C3=A9ch=C3=A9?= Date: Tue, 10 May 2022 21:28:45 +0200 Subject: [PATCH] chore: add unconvert linter (#3867) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Charles-Edouard Brétéché --- .golangci.yml | 1 + cmd/cli/kubectl-kyverno/jp/jp_command.go | 2 +- cmd/cli/kubectl-kyverno/test/test_command.go | 2 +- pkg/cosign/cosign.go | 2 +- pkg/engine/common/common.go | 2 +- pkg/engine/variables/operator/numeric.go | 6 +++--- test/e2e/utils.go | 2 +- 7 files changed, 9 insertions(+), 8 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 9ca64494da..797602f34c 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -10,6 +10,7 @@ linters: - staticcheck - structcheck - typecheck + - unconvert - unused - varcheck - whitespace diff --git a/cmd/cli/kubectl-kyverno/jp/jp_command.go b/cmd/cli/kubectl-kyverno/jp/jp_command.go index c89a053131..5d9b5c7a0d 100644 --- a/cmd/cli/kubectl-kyverno/jp/jp_command.go +++ b/cmd/cli/kubectl-kyverno/jp/jp_command.go @@ -118,7 +118,7 @@ func Command() *cobra.Command { func printFunctionList() { functions := []string{} for _, function := range jmespath.GetFunctions() { - functions = append(functions, string(function.String())) + functions = append(functions, function.String()) } sort.Strings(functions) fmt.Println(strings.Join(functions, "\n")) diff --git a/cmd/cli/kubectl-kyverno/test/test_command.go b/cmd/cli/kubectl-kyverno/test/test_command.go index bd75dea2ad..1ce6c258df 100644 --- a/cmd/cli/kubectl-kyverno/test/test_command.go +++ b/cmd/cli/kubectl-kyverno/test/test_command.go @@ -340,7 +340,7 @@ func testCommandExecute(dirPath []string, fileName string, gitBranch string, tes if err != nil { return rc, fmt.Errorf("unable to create open api controller, %w", err) } - if strings.Contains(string(dirPath[0]), "https://") { + if strings.Contains(dirPath[0], "https://") { gitURL, err := url.Parse(dirPath[0]) if err != nil { return rc, sanitizederror.NewWithError("failed to parse URL", err) diff --git a/pkg/cosign/cosign.go b/pkg/cosign/cosign.go index 006127b8af..1848af8591 100644 --- a/pkg/cosign/cosign.go +++ b/pkg/cosign/cosign.go @@ -90,7 +90,7 @@ func VerifySignature(opts Options) (digest string, err error) { // load cert and optionally a cert chain as a verifier cert, err := loadCert([]byte(opts.Cert)) if err != nil { - return "", errors.Wrapf(err, "failed to load certificate from %s", string(opts.Cert)) + return "", errors.Wrapf(err, "failed to load certificate from %s", opts.Cert) } if opts.CertChain == "" { diff --git a/pkg/engine/common/common.go b/pkg/engine/common/common.go index c6d3a83feb..4a5a876693 100644 --- a/pkg/engine/common/common.go +++ b/pkg/engine/common/common.go @@ -12,7 +12,7 @@ func convertNumberToString(value interface{}) (string, error) { } switch typed := value.(type) { case string: - return string(typed), nil + return typed, nil case float64: return fmt.Sprintf("%f", typed), nil case int64: diff --git a/pkg/engine/variables/operator/numeric.go b/pkg/engine/variables/operator/numeric.go index e0b99fb9fe..0d1dd22407 100644 --- a/pkg/engine/variables/operator/numeric.go +++ b/pkg/engine/variables/operator/numeric.go @@ -87,7 +87,7 @@ func (noh NumericOperatorHandler) validateValueWithIntPattern(key int64, value i case string: durationKey, durationValue, err := parseDuration(key, value) if err == nil { - return compareByCondition(float64(durationKey.Seconds()), float64(durationValue.Seconds()), noh.condition, noh.log) + return compareByCondition(durationKey.Seconds(), durationValue.Seconds(), noh.condition, noh.log) } // extract float64 and (if that fails) then, int64 from the string float64val, err := strconv.ParseFloat(typedValue, 64) @@ -117,7 +117,7 @@ func (noh NumericOperatorHandler) validateValueWithFloatPattern(key float64, val case string: durationKey, durationValue, err := parseDuration(key, value) if err == nil { - return compareByCondition(float64(durationKey.Seconds()), float64(durationValue.Seconds()), noh.condition, noh.log) + return compareByCondition(durationKey.Seconds(), durationValue.Seconds(), noh.condition, noh.log) } float64val, err := strconv.ParseFloat(typedValue, 64) if err == nil { @@ -154,7 +154,7 @@ func (noh NumericOperatorHandler) validateValueWithStringPattern(key string, val // We need to check duration first as it's the only type that can be compared to a different type durationKey, durationValue, err := parseDuration(key, value) if err == nil { - return compareByCondition(float64(durationKey.Seconds()), float64(durationValue.Seconds()), noh.condition, noh.log) + return compareByCondition(durationKey.Seconds(), durationValue.Seconds(), noh.condition, noh.log) } // attempt to extract resource quantity from string before parsing floats/ints as resources can also be ints/floats represented as string type resourceKey, resourceValue, err := parseQuantity(key, value) diff --git a/test/e2e/utils.go b/test/e2e/utils.go index b64d033ced..700707faf9 100644 --- a/test/e2e/utils.go +++ b/test/e2e/utils.go @@ -220,7 +220,7 @@ func CallAPI(request APIRequest) (*http.Response, error) { } response = resp case "POST", "PUT", "DELETE", "PATCH": - req, err := http.NewRequest(string(request.Type), request.URL, request.Body) + req, err := http.NewRequest(request.Type, request.URL, request.Body) if err != nil { return nil, fmt.Errorf("error occurred while calling %s: %w", request.URL, err) }