diff --git a/api/go.mod b/api/go.mod index 3ab001257101..349b6f16518f 100644 --- a/api/go.mod +++ b/api/go.mod @@ -26,13 +26,3 @@ require ( google.golang.org/genproto/googleapis/rpc v0.0.0-20250825161204-c5933d9347a5 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) - -// Bad imports are sometimes causing attempts to pull that code. -// This makes the error more explicit. -replace ( - go.etcd.io/etcd => ./FORBIDDEN_DEPENDENCY - go.etcd.io/etcd/api/v3 => ./FORBIDDEN_DEPENDENCY - go.etcd.io/etcd/pkg/v3 => ./FORBIDDEN_DEPENDENCY - go.etcd.io/etcd/tests/v3 => ./FORBIDDEN_DEPENDENCY - go.etcd.io/etcd/v3 => ./FORBIDDEN_DEPENDENCY -) diff --git a/client/v3/go.mod b/client/v3/go.mod index c10e9e37e741..e18a70ae9fd0 100644 --- a/client/v3/go.mod +++ b/client/v3/go.mod @@ -46,12 +46,3 @@ replace ( go.etcd.io/etcd/api/v3 => ../../api go.etcd.io/etcd/client/pkg/v3 => ../pkg ) - -// Bad imports are sometimes causing attempts to pull that code. -// This makes the error more explicit. -replace ( - go.etcd.io/etcd => ./FORBIDDEN_DEPENDENCY - go.etcd.io/etcd/pkg/v3 => ./FORBIDDEN_DEPENDENCY - go.etcd.io/etcd/v3 => ./FORBIDDEN_DEPENDENCY - go.etcd.io/tests/v3 => ./FORBIDDEN_DEPENDENCY -) diff --git a/etcdctl/go.mod b/etcdctl/go.mod index 7e985588404d..c3989321df6c 100644 --- a/etcdctl/go.mod +++ b/etcdctl/go.mod @@ -54,11 +54,3 @@ replace ( go.etcd.io/etcd/client/v3 => ../client/v3 go.etcd.io/etcd/pkg/v3 => ../pkg ) - -// Bad imports are sometimes causing attempts to pull that code. -// This makes the error more explicit. -replace ( - go.etcd.io/etcd => ./FORBIDDEN_DEPENDENCY - go.etcd.io/etcd/v3 => ./FORBIDDEN_DEPENDENCY - go.etcd.io/tests/v3 => ./FORBIDDEN_DEPENDENCY -) diff --git a/etcdutl/go.mod b/etcdutl/go.mod index 0614220c1e5a..215d4428ce68 100644 --- a/etcdutl/go.mod +++ b/etcdutl/go.mod @@ -12,14 +12,6 @@ replace ( go.etcd.io/etcd/server/v3 => ../server ) -// Bad imports are sometimes causing attempts to pull that code. -// This makes the error more explicit. -replace ( - go.etcd.io/etcd => ./FORBIDDEN_DEPENDENCY - go.etcd.io/etcd/v3 => ./FORBIDDEN_DEPENDENCY - go.etcd.io/tests/v3 => ./FORBIDDEN_DEPENDENCY -) - require ( github.com/coreos/go-semver v0.3.1 github.com/dustin/go-humanize v1.0.1 diff --git a/pkg/go.mod b/pkg/go.mod index d3ea4e6eafe5..33171dfd2ef5 100644 --- a/pkg/go.mod +++ b/pkg/go.mod @@ -32,14 +32,3 @@ require ( ) replace go.etcd.io/etcd/client/pkg/v3 => ../client/pkg - -// Bad imports are sometimes causing attempts to pull that code. -// This makes the error more explicit. -// Etcd contains lots of packages and dependency relationship. -// Shouldn't import unnecessary dependencies -replace ( - go.etcd.io/etcd => ./FORBIDDEN_DEPENDENCY - go.etcd.io/etcd/api/v3 => ./FORBIDDEN_DEPENDENCY - go.etcd.io/etcd/tests/v3 => ./FORBIDDEN_DEPENDENCY - go.etcd.io/etcd/v3 => ./FORBIDDEN_DEPENDENCY -) diff --git a/server/go.mod b/server/go.mod index 983a259becf3..3ac1e83fb094 100644 --- a/server/go.mod +++ b/server/go.mod @@ -82,9 +82,3 @@ replace ( go.etcd.io/etcd/client/v3 => ../client/v3 go.etcd.io/etcd/pkg/v3 => ../pkg ) - -// Bad imports are sometimes causing attempts to pull that code. -// This makes the error more explicit. -replace go.etcd.io/etcd => ./FORBIDDEN_DEPENDENCY - -replace go.etcd.io/tests/v3 => ./FORBIDDEN_DEPENDENCY diff --git a/tools/.golangci.yaml b/tools/.golangci.yaml index 994d9afb3610..98717facf616 100644 --- a/tools/.golangci.yaml +++ b/tools/.golangci.yaml @@ -3,6 +3,7 @@ version: "2" linters: default: none enable: # please keep this alphabetized + - depguard # Implement forbidden dependencies - errorlint - ineffassign - nakedret @@ -17,6 +18,67 @@ linters: - usetesting - whitespace settings: + depguard: + rules: + api: + list-mode: lax + files: + # Check files inside the api module/directory, but skip the server/etcdserver/api + # directory. Note that this is configured this way as depguard doesn't support relative + # paths. + # > Should always prefix a file glob with **/ as files are matched against absolute + # > paths. + # Refer to: https://github.com/OpenPeeDeeP/depguard?tab=readme-ov-file#config + # Could be simplified if they resolve issue: https://github.com/OpenPeeDeeP/depguard/issues/54 + - '**/api/**/*.go' + - '!**/server/etcdserver/api/**/*.go' + deny: + - pkg: go.etcd.io/etcd/api/v3$ + - pkg: go.etcd.io/etcd/pkg/v3 + - pkg: go.etcd.io/etcd/v3 + - pkg: go.etcd.io/tests/v3 + client: + list-mode: lax + files: + - "**/client/v3/**/*.go" + deny: + - pkg: go.etcd.io/etcd/pkg/v3 + - pkg: go.etcd.io/etcd/v3 + - pkg: go.etcd.io/tests/v3 + etcdctl: + list-mode: lax + files: + - "**/etcdctl/**/*.go" + deny: + - pkg: go.etcd.io/etcd/v3 + - pkg: go.etcd.io/tests/v3 + etcdutl: + list-mode: lax + files: + - "**/etcdutl/**/*.go" + deny: + - pkg: go.etcd.io/etcd/v3 + - pkg: go.etcd.io/tests/v3 + server: + list-mode: lax + files: + - "**/server/**/*.go" + deny: + - pkg: go.etcd.io/etcd/v3 + - pkg: go.etcd.io/tests/v3 + pkg: + list-mode: lax + files: + # Check files inside the pkg module/directory, but skip the pkg directories inside + # client and the tools/rw-heatmaps modules. Note that this is configured this way as + # depguard doesn't support relative paths. + - "**/pkg/**/*.go" + - "!**/client/pkg/**/*.go" + - "!**/tools/rw-heatmaps/pkg/**/*.go" + deny: + - pkg: go.etcd.io/etcd/api/v3 + - pkg: go.etcd.io/etcd/v3 + - pkg: go.etcd.io/tests/v3 nakedret: # Align with https://github.com/alexkohler/nakedret/blob/v1.0.2/cmd/nakedret/main.go#L10 max-func-lines: 5