Skip to content

Commit d36322f

Browse files
authored
Merge pull request kubernetes#129815 from dims/linter-to-ensure-go-cmp/cmp-is-used-only-in-tests
Linter to ensure go-cmp/cmp is used ONLY in tests
2 parents 03bf94b + 4e05bc2 commit d36322f

File tree

31 files changed

+72
-28
lines changed

31 files changed

+72
-28
lines changed

cmd/dependencyverifier/dependencyverifier.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626
"sort"
2727
"strings"
2828

29-
"github.com/google/go-cmp/cmp"
29+
"github.com/google/go-cmp/cmp" //nolint:depguard
3030
)
3131

3232
type Unwanted struct {

hack/golangci-hints.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ issues:
9191
linters:
9292
disable-all: false
9393
enable: # please keep this alphabetized
94+
- depguard
9495
- forbidigo
9596
- ginkgolinter
9697
- gocritic
@@ -176,6 +177,16 @@ linters-settings: # please keep this alphabetized
176177
# this restriction. Whether we then do a global search/replace remains
177178
# to be decided.
178179
with-helpers .*
180+
depguard:
181+
rules:
182+
main:
183+
files:
184+
- $all
185+
- "!$test"
186+
- "!**/test/**"
187+
deny:
188+
- pkg: "github.com/google/go-cmp/cmp"
189+
desc: "cmp is allowed only in test files"
179190
forbidigo:
180191
analyze-types: true
181192
forbid:

hack/golangci-strict.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ issues:
135135
linters:
136136
disable-all: false
137137
enable: # please keep this alphabetized
138+
- depguard
138139
- forbidigo
139140
- ginkgolinter
140141
- gocritic
@@ -222,6 +223,16 @@ linters-settings: # please keep this alphabetized
222223
# this restriction. Whether we then do a global search/replace remains
223224
# to be decided.
224225
with-helpers .*
226+
depguard:
227+
rules:
228+
main:
229+
files:
230+
- $all
231+
- "!$test"
232+
- "!**/test/**"
233+
deny:
234+
- pkg: "github.com/google/go-cmp/cmp"
235+
desc: "cmp is allowed only in test files"
225236
forbidigo:
226237
analyze-types: true
227238
forbid:

hack/golangci.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ issues:
141141
linters:
142142
disable-all: true
143143
enable: # please keep this alphabetized
144+
- depguard
144145
- forbidigo
145146
- ginkgolinter
146147
- gocritic
@@ -224,6 +225,16 @@ linters-settings: # please keep this alphabetized
224225
# this restriction. Whether we then do a global search/replace remains
225226
# to be decided.
226227
with-helpers .*
228+
depguard:
229+
rules:
230+
main:
231+
files:
232+
- $all
233+
- "!$test"
234+
- "!**/test/**"
235+
deny:
236+
- pkg: "github.com/google/go-cmp/cmp"
237+
desc: "cmp is allowed only in test files"
227238
forbidigo:
228239
analyze-types: true
229240
forbid:

hack/golangci.yaml.in

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ issues:
147147
linters:
148148
disable-all: {{if .Base -}} true {{- else -}} false {{- end}}
149149
enable: # please keep this alphabetized
150+
- depguard
150151
- forbidigo
151152
- ginkgolinter
152153
- gocritic
@@ -180,6 +181,16 @@ linters-settings: # please keep this alphabetized
180181
settings:
181182
config: |
182183
{{include "hack/logcheck.conf" | indent 10 | trim}}
184+
depguard:
185+
rules:
186+
main:
187+
files:
188+
- $all
189+
- "!$test"
190+
- "!**/test/**"
191+
deny:
192+
- pkg: "github.com/google/go-cmp/cmp"
193+
desc: "cmp is allowed only in test files"
183194
forbidigo:
184195
analyze-types: true
185196
forbid:

pkg/api/pod/util.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ package pod
1919
import (
2020
"strings"
2121

22-
"github.com/google/go-cmp/cmp"
22+
"github.com/google/go-cmp/cmp" //nolint:depguard
2323
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2424
metavalidation "k8s.io/apimachinery/pkg/apis/meta/v1/validation"
2525
"k8s.io/apimachinery/pkg/util/sets"

pkg/apis/certificates/validation/validation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"encoding/pem"
2323
"fmt"
2424

25-
"github.com/google/go-cmp/cmp"
25+
"github.com/google/go-cmp/cmp" //nolint:depguard
2626
v1 "k8s.io/api/core/v1"
2727
apiequality "k8s.io/apimachinery/pkg/api/equality"
2828
"k8s.io/apimachinery/pkg/util/sets"

pkg/apis/core/validation/validation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030
"unicode"
3131
"unicode/utf8"
3232

33-
"github.com/google/go-cmp/cmp"
33+
"github.com/google/go-cmp/cmp" //nolint:depguard
3434
netutils "k8s.io/utils/net"
3535

3636
v1 "k8s.io/api/core/v1"

pkg/controller/volume/persistentvolume/testing/testing.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
"strconv"
2525
"sync"
2626

27-
"github.com/google/go-cmp/cmp"
27+
"github.com/google/go-cmp/cmp" //nolint:depguard
2828
"k8s.io/klog/v2"
2929

3030
v1 "k8s.io/api/core/v1"

pkg/kubelet/status/status_manager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
"sync"
2626
"time"
2727

28-
"github.com/google/go-cmp/cmp"
28+
"github.com/google/go-cmp/cmp" //nolint:depguard
2929
clientset "k8s.io/client-go/kubernetes"
3030

3131
v1 "k8s.io/api/core/v1"

0 commit comments

Comments
 (0)