Linter to ensure go-cmp/cmp is used ONLY in tests

Signed-off-by: Davanum Srinivas <davanum@gmail.com>
This commit is contained in:
Davanum Srinivas 2025-01-24 17:03:29 -05:00
parent c5c19a6487
commit 4e05bc20db
No known key found for this signature in database
GPG Key ID: 80D83A796103BF59
31 changed files with 72 additions and 28 deletions

View File

@ -26,7 +26,7 @@ import (
"sort"
"strings"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp" //nolint:depguard
)
type Unwanted struct {

View File

@ -91,6 +91,7 @@ issues:
linters:
disable-all: false
enable: # please keep this alphabetized
- depguard
- forbidigo
- ginkgolinter
- gocritic
@ -176,6 +177,16 @@ linters-settings: # please keep this alphabetized
# this restriction. Whether we then do a global search/replace remains
# to be decided.
with-helpers .*
depguard:
rules:
main:
files:
- $all
- "!$test"
- "!**/test/**"
deny:
- pkg: "github.com/google/go-cmp/cmp"
desc: "cmp is allowed only in test files"
forbidigo:
analyze-types: true
forbid:

View File

@ -135,6 +135,7 @@ issues:
linters:
disable-all: false
enable: # please keep this alphabetized
- depguard
- forbidigo
- ginkgolinter
- gocritic
@ -222,6 +223,16 @@ linters-settings: # please keep this alphabetized
# this restriction. Whether we then do a global search/replace remains
# to be decided.
with-helpers .*
depguard:
rules:
main:
files:
- $all
- "!$test"
- "!**/test/**"
deny:
- pkg: "github.com/google/go-cmp/cmp"
desc: "cmp is allowed only in test files"
forbidigo:
analyze-types: true
forbid:

View File

@ -141,6 +141,7 @@ issues:
linters:
disable-all: true
enable: # please keep this alphabetized
- depguard
- forbidigo
- ginkgolinter
- gocritic
@ -224,6 +225,16 @@ linters-settings: # please keep this alphabetized
# this restriction. Whether we then do a global search/replace remains
# to be decided.
with-helpers .*
depguard:
rules:
main:
files:
- $all
- "!$test"
- "!**/test/**"
deny:
- pkg: "github.com/google/go-cmp/cmp"
desc: "cmp is allowed only in test files"
forbidigo:
analyze-types: true
forbid:

View File

@ -147,6 +147,7 @@ issues:
linters:
disable-all: {{if .Base -}} true {{- else -}} false {{- end}}
enable: # please keep this alphabetized
- depguard
- forbidigo
- ginkgolinter
- gocritic
@ -180,6 +181,16 @@ linters-settings: # please keep this alphabetized
settings:
config: |
{{include "hack/logcheck.conf" | indent 10 | trim}}
depguard:
rules:
main:
files:
- $all
- "!$test"
- "!**/test/**"
deny:
- pkg: "github.com/google/go-cmp/cmp"
desc: "cmp is allowed only in test files"
forbidigo:
analyze-types: true
forbid:

View File

@ -19,7 +19,7 @@ package pod
import (
"strings"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp" //nolint:depguard
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
metavalidation "k8s.io/apimachinery/pkg/apis/meta/v1/validation"
"k8s.io/apimachinery/pkg/util/sets"

View File

@ -22,7 +22,7 @@ import (
"encoding/pem"
"fmt"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp" //nolint:depguard
v1 "k8s.io/api/core/v1"
apiequality "k8s.io/apimachinery/pkg/api/equality"
"k8s.io/apimachinery/pkg/util/sets"

View File

@ -30,7 +30,7 @@ import (
"unicode"
"unicode/utf8"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp" //nolint:depguard
netutils "k8s.io/utils/net"
v1 "k8s.io/api/core/v1"

View File

@ -24,7 +24,7 @@ import (
"strconv"
"sync"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp" //nolint:depguard
"k8s.io/klog/v2"
v1 "k8s.io/api/core/v1"

View File

@ -25,7 +25,7 @@ import (
"sync"
"time"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp" //nolint:depguard
clientset "k8s.io/client-go/kubernetes"
v1 "k8s.io/api/core/v1"

View File

@ -21,7 +21,7 @@ import (
"fmt"
"strconv"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp" //nolint:depguard
flowcontrolv1 "k8s.io/api/flowcontrol/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

View File

@ -26,8 +26,8 @@ import (
"sync"
"time"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/google/go-cmp/cmp" //nolint:depguard
"github.com/google/go-cmp/cmp/cmpopts" //nolint:depguard
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"

View File

@ -23,7 +23,7 @@ import (
"slices"
"sync"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp" //nolint:depguard
v1 "k8s.io/api/core/v1"
resourceapi "k8s.io/api/resource/v1beta1"

View File

@ -21,7 +21,7 @@ import (
"fmt"
"strings"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp" //nolint:depguard
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"

View File

@ -17,7 +17,7 @@ limitations under the License.
package noderesources
import (
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/google/go-cmp/cmp/cmpopts" //nolint:depguard
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"

View File

@ -22,7 +22,7 @@ import (
"errors"
"fmt"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp" //nolint:depguard
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/kubernetes/scheme"

View File

@ -23,7 +23,7 @@ import (
"io"
"strings"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp" //nolint:depguard
v1 "k8s.io/api/core/v1"
apiequality "k8s.io/apimachinery/pkg/api/equality"

View File

@ -28,7 +28,7 @@ import (
"strings"
"testing"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp" //nolint:depguard
apiequality "k8s.io/apimachinery/pkg/api/equality"
"k8s.io/apimachinery/pkg/runtime"

View File

@ -24,7 +24,7 @@ import (
"strings"
"testing"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp" //nolint:depguard
fuzz "github.com/google/gofuzz"
flag "github.com/spf13/pflag"

View File

@ -37,7 +37,7 @@ import (
jsonserializer "k8s.io/apimachinery/pkg/runtime/serializer/json"
"k8s.io/apimachinery/pkg/util/sets"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp" //nolint:depguard
)
// RoundtripToUnstructured verifies the roundtrip faithfulness of all external types in a scheme

View File

@ -23,7 +23,7 @@ import (
"strings"
"text/tabwriter"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp" //nolint:depguard
"k8s.io/apimachinery/pkg/util/dump"
)

View File

@ -21,7 +21,7 @@ import (
"reflect"
"testing"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp" //nolint:depguard
apiequality "k8s.io/apimachinery/pkg/api/equality"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apiserver/pkg/admission"

View File

@ -25,7 +25,7 @@ import (
"time"
"github.com/emicklei/go-restful/v3"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp" //nolint:depguard
apidiscoveryv2 "k8s.io/api/apidiscovery/v2"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"

View File

@ -28,7 +28,7 @@ import (
"sync"
"testing"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp" //nolint:depguard
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/fields"

View File

@ -27,7 +27,7 @@ import (
"testing"
"time"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp" //nolint:depguard
"k8s.io/apimachinery/pkg/api/meta"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/fields"

View File

@ -28,7 +28,7 @@ import (
"sync"
"time"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp" //nolint:depguard
apiequality "k8s.io/apimachinery/pkg/api/equality"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

View File

@ -22,7 +22,7 @@ import (
"sort"
"time"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp" //nolint:depguard
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

View File

@ -23,7 +23,7 @@ import (
"path/filepath"
"testing"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp" //nolint:depguard
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/runtime/serializer"

View File

@ -22,7 +22,7 @@ import (
"path/filepath"
"testing"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp" //nolint:depguard
apiequality "k8s.io/apimachinery/pkg/api/equality"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"

View File

@ -27,7 +27,7 @@ import (
"sync/atomic"
"time"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp" //nolint:depguard
"github.com/spf13/pflag"
"k8s.io/klog/v2"

View File

@ -24,7 +24,7 @@ import (
"sync/atomic"
"time"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp" //nolint:depguard
v1 "k8s.io/api/core/v1"
resourceapi "k8s.io/api/resource/v1beta1"