Skip to content

Commit d335867

Browse files
committed
fix 3rd pkgpath filter
1 parent e8d0ad2 commit d335867

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

contextcheck.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,25 @@ type runner struct {
9797
disableFact bool
9898
}
9999

100+
func getPkgRoot(pkg string) string {
101+
arr := strings.Split(pkg, "/")
102+
if len(arr) < 3 {
103+
return arr[0]
104+
}
105+
if strings.IndexByte(arr[0], '.') == -1 {
106+
return arr[0]
107+
}
108+
return strings.Join(arr[:3], "/")
109+
}
110+
100111
func NewRun(pkgs []*packages.Package, disableFact bool) func(pass *analysis.Pass) (interface{}, error) {
101112
m := make(map[string]bool)
102113
for _, pkg := range pkgs {
103-
m[strings.Split(pkg.PkgPath, "/")[0]] = true
114+
m[getPkgRoot(pkg.PkgPath)] = true
104115
}
105116
return func(pass *analysis.Pass) (interface{}, error) {
106117
// skip different repo
107-
if len(m) > 0 && !m[strings.Split(pass.Pkg.Path(), "/")[0]] {
118+
if len(m) > 0 && !m[getPkgRoot(pass.Pkg.Path())] {
108119
return nil, nil
109120
}
110121
if len(m) == 0 && pkgprefix != "" && !strings.HasPrefix(pass.Pkg.Path(), pkgprefix) {

0 commit comments

Comments
 (0)