aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/gostaticanalysis/analysisutil/pkg.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2020-09-15 18:05:35 +0200
committerDmitry Vyukov <dvyukov@google.com>2020-09-15 19:34:30 +0200
commit712de1c63d9db97c81af68cd0dc4372c53d2e57a (patch)
treeae1761fec52c3ae4ddd003a4130ddbda8d0a2d69 /vendor/github.com/gostaticanalysis/analysisutil/pkg.go
parent298a69c38dd5c8a9bbd7a022e88f4ddbcf885e16 (diff)
vendor/github.com/golangci/golangci-lint: update to v1.31
Diffstat (limited to 'vendor/github.com/gostaticanalysis/analysisutil/pkg.go')
-rw-r--r--vendor/github.com/gostaticanalysis/analysisutil/pkg.go29
1 files changed, 26 insertions, 3 deletions
diff --git a/vendor/github.com/gostaticanalysis/analysisutil/pkg.go b/vendor/github.com/gostaticanalysis/analysisutil/pkg.go
index c98710d18..b64150d81 100644
--- a/vendor/github.com/gostaticanalysis/analysisutil/pkg.go
+++ b/vendor/github.com/gostaticanalysis/analysisutil/pkg.go
@@ -2,14 +2,17 @@ package analysisutil
import (
"go/types"
+ "strconv"
"strings"
+
+ "golang.org/x/tools/go/analysis"
)
-// RemoVendor removes vendoring infomation from import path.
+// RemoVendor removes vendoring information from import path.
func RemoveVendor(path string) string {
- i := strings.Index(path, "vendor")
+ i := strings.Index(path, "vendor/")
if i >= 0 {
- return path[i+len("vendor")+1:]
+ return path[i+len("vendor/"):]
}
return path
}
@@ -24,3 +27,23 @@ func LookupFromImports(imports []*types.Package, path, name string) types.Object
}
return nil
}
+
+// Imported returns true when the given pass imports the pkg.
+func Imported(pkgPath string, pass *analysis.Pass) bool {
+ fs := pass.Files
+ if len(fs) == 0 {
+ return false
+ }
+ for _, f := range fs {
+ for _, i := range f.Imports {
+ path, err := strconv.Unquote(i.Path.Value)
+ if err != nil {
+ continue
+ }
+ if RemoveVendor(path) == pkgPath {
+ return true
+ }
+ }
+ }
+ return false
+}