From 21fa8d12bbd74e1d3e6dcac007ab398b4a368368 Mon Sep 17 00:00:00 2001 From: Oscar Utbult Date: Fri, 21 Oct 2022 15:25:12 +0200 Subject: [PATCH] hack/tools enable additional linter in golangci-lint Enables linter gocritic with two checks enabled for a subset of the project --- .golangci.yaml | 12 +++++++++++- .../src/k8s.io/cli-runtime/pkg/resource/scheme.go | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/.golangci.yaml b/.golangci.yaml index e70851dd798..dd674bafa39 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -7,14 +7,20 @@ issues: max-same-issues: 0 # Excluding configuration per-path, per-linter, per-text and per-source exclude-rules: - # exclude ineffassing linter for generated files for conversion + # exclude ineffassign linter for generated files for conversion - path: conversion\.go linters: - ineffassign + # TODO(oscr) Remove these excluded directories and fix findings. Due to large amount of findings in different components + # with different owners it's hard to fix everything in a single pr. This will therefore be done in multiple prs. + - path: (pkg/volume/*|test/*|cmd/kubeadm/*|azure/*|pkg/cmd/wait*|request/bearertoken/*|metrics/*|filters/*) + linters: + - gocritic linters: disable-all: true enable: # please keep this alphabetized + - gocritic - ineffassign - logcheck - staticcheck @@ -28,6 +34,10 @@ linters-settings: # please keep this alphabetized path: _output/local/bin/logcheck.so description: structured logging checker original-url: k8s.io/klog/hack/tools + gocritic: + enabled-checks: + - equalFold + - boolExprSimplify staticcheck: checks: [ "all", diff --git a/staging/src/k8s.io/cli-runtime/pkg/resource/scheme.go b/staging/src/k8s.io/cli-runtime/pkg/resource/scheme.go index 0a47d159628..858a46202c0 100644 --- a/staging/src/k8s.io/cli-runtime/pkg/resource/scheme.go +++ b/staging/src/k8s.io/cli-runtime/pkg/resource/scheme.go @@ -41,7 +41,7 @@ func (dynamicCodec) Decode(data []byte, gvk *schema.GroupVersionKind, obj runtim return nil, nil, err } - if strings.ToLower(gvk.Kind) == "status" && gvk.Version == "v1" && (gvk.Group == "" || gvk.Group == "meta.k8s.io") { + if strings.EqualFold(gvk.Kind, "status") && gvk.Version == "v1" && (gvk.Group == "" || gvk.Group == "meta.k8s.io") { if _, ok := obj.(*metav1.Status); !ok { obj = &metav1.Status{} err := json.Unmarshal(data, obj)