Skip to content

Commit c7d7744

Browse files
committed
Use depguard linter to forbid dependencies
Introduce the depguard linter to forbid required dependencies in the submodules. This is a clean way to achieve what we had before in the go.mod by using a replacement and pointing the forbidden package to a virtual non-existent directory "FORBIDDEN_DEPENDENCY". Now, if a package requires a forbidden dependency, the linter will fail, rather than having Go fail to compile/fetch dependencies. Signed-off-by: Ivan Valdes <[email protected]>
1 parent 7931e70 commit c7d7744

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

tools/.golangci.yaml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ version: "2"
33
linters:
44
default: none
55
enable: # please keep this alphabetized
6+
- depguard # Implement forbidden dependencies
67
- errorlint
78
- ineffassign
89
- nakedret
@@ -17,6 +18,47 @@ linters:
1718
- usetesting
1819
- whitespace
1920
settings:
21+
depguard:
22+
rules:
23+
api:
24+
list-mode: lax
25+
files:
26+
- '**/api/**/*.go'
27+
- '!**/server/etcdserver/api/**/*.go'
28+
deny:
29+
- pkg: go.etcd.io/etcd/api/v3$
30+
- pkg: go.etcd.io/etcd/pkg/v3
31+
- pkg: go.etcd.io/etcd/v3
32+
- pkg: go.etcd.io/tests/v3
33+
- pkg: go.etcd.io/v3
34+
client:
35+
list-mode: lax
36+
files:
37+
- "**/client/v3/**/*.go"
38+
deny:
39+
- pkg: go.etcd.io/etcd/pkg/v3
40+
- pkg: go.etcd.io/etcd/v3
41+
- pkg: go.etcd.io/tests/v3
42+
cli-and-server:
43+
list-mode: lax
44+
files:
45+
- "**/etcdctl/**/*.go"
46+
- "**/etcdutl/**/*.go"
47+
- "**/server/**/*.go"
48+
- "!**/tests/antithesis/server/**/*.go"
49+
deny:
50+
- pkg: go.etcd.io/etcd/v3
51+
- pkg: go.etcd.io/tests/v3
52+
pkg:
53+
list-mode: lax
54+
files:
55+
- "**/pkg/**/*.go"
56+
- "!**/client/pkg/**/*.go"
57+
- "!**/tools/rw-heatmaps/pkg/**/*.go"
58+
deny:
59+
- pkg: go.etcd.io/etcd/api/v3
60+
- pkg: go.etcd.io/etcd/v3
61+
- pkg: go.etcd.io/tests/v3
2062
nakedret:
2163
# Align with https://github.com/alexkohler/nakedret/blob/v1.0.2/cmd/nakedret/main.go#L10
2264
max-func-lines: 5

0 commit comments

Comments
 (0)