aboutsummaryrefslogtreecommitdiff
path: root/internal/stdlib
diff options
context:
space:
mode:
authorJonathan Amsterdam <jba@google.com>2019-11-11 16:22:26 -0500
committerJulie Qiu <julie@golang.org>2020-03-27 16:46:47 -0400
commit355b026adf25658be4978470eb851cb27eb30a3f (patch)
tree1ad19c5761ed018700382de645017250716165d4 /internal/stdlib
parent8f7732c9ce43eafff92a3395e86ee9bf0264a1aa (diff)
downloadgo-x-pkgsite-355b026adf25658be4978470eb851cb27eb30a3f.tar.xz
internal/postgres: ignore self-imports in imported-by counts
Do not count package A as importing package B if they are in the same module. Change-Id: Ic0f98af8d72b8fff29e105779c6eb619214335e9 Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/596525 CI-Result: Cloud Build <devtools-proctor-result-processor@system.gserviceaccount.com> Reviewed-by: Julie Qiu <julieqiu@google.com>
Diffstat (limited to 'internal/stdlib')
-rw-r--r--internal/stdlib/stdlib.go8
-rw-r--r--internal/stdlib/stdlib_test.go18
2 files changed, 26 insertions, 0 deletions
diff --git a/internal/stdlib/stdlib.go b/internal/stdlib/stdlib.go
index 8a081cfc..adf1cf49 100644
--- a/internal/stdlib/stdlib.go
+++ b/internal/stdlib/stdlib.go
@@ -357,6 +357,14 @@ func subTree(r *git.Repository, t *object.Tree, name string) (*object.Tree, erro
return nil, os.ErrNotExist
}
+// Contains reports whether the given import path is part of the Go standard library.
+func Contains(path string) bool {
+ if i := strings.IndexByte(path, '/'); i != -1 {
+ path = path[:i]
+ }
+ return !strings.Contains(path, ".")
+}
+
// References used for Versions during testing.
var testRefs = []plumbing.ReferenceName{
"refs/changes/56/93156/13",
diff --git a/internal/stdlib/stdlib_test.go b/internal/stdlib/stdlib_test.go
index eca3760d..a0116100 100644
--- a/internal/stdlib/stdlib_test.go
+++ b/internal/stdlib/stdlib_test.go
@@ -189,3 +189,21 @@ func TestVersionForTag(t *testing.T) {
}
}
}
+
+func TestContains(t *testing.T) {
+ for _, test := range []struct {
+ in string
+ want bool
+ }{
+ {"fmt", true},
+ {"encoding/json", true},
+ {"something/with.dots", true},
+ {"example.com", false},
+ {"example.com/fmt", false},
+ } {
+ got := Contains(test.in)
+ if got != test.want {
+ t.Errorf("Contains(%q) = %t, want %t", test.in, got, test.want)
+ }
+ }
+}