@@ -48,23 +48,35 @@ func run(pass *analysis.Pass) (interface{}, error) {
48
48
func reportImported (pass * analysis.Pass , expr ast.Expr , checkRE * regexp.Regexp , prefix string ) {
49
49
switch x := expr .(type ) {
50
50
case * ast.SelectorExpr :
51
- if ! checkRE .MatchString (x .Sel .Name ) {
52
- return
53
- }
54
-
55
51
selectIdent , ok := x .X .(* ast.Ident )
56
52
if ! ok {
57
53
return
58
54
}
59
55
56
+ var pkgPath string
60
57
if selectObj , ok := pass .TypesInfo .Uses [selectIdent ]; ok {
61
- if pkg , ok := selectObj .(* types.PkgName ); ! ok || pkg .Imported () == pass .Pkg {
58
+ pkg , ok := selectObj .(* types.PkgName )
59
+ if ! ok || pkg .Imported () == pass .Pkg {
62
60
return
63
61
}
62
+ pkgPath = pkg .Imported ().Path ()
64
63
}
65
64
66
- pass .Reportf (expr .Pos (), "%s variable %s in other package %s" , prefix , x .Sel .Name , selectIdent .Name )
65
+ matches := false
66
+ if checkRE .MatchString (x .Sel .Name ) {
67
+ matches = true
68
+ }
69
+ if ! matches {
70
+ // Expression may include a package name, so check that too. Support was added later so we check
71
+ // just name and qualified name separately for compatibility.
72
+ if checkRE .MatchString (pkgPath + "." + x .Sel .Name ) {
73
+ matches = true
74
+ }
75
+ }
67
76
77
+ if matches {
78
+ pass .Reportf (expr .Pos (), "%s variable %s in other package %s" , prefix , x .Sel .Name , selectIdent .Name )
79
+ }
68
80
case * ast.Ident :
69
81
use , ok := pass .TypesInfo .Uses [x ].(* types.Var )
70
82
if ! ok {
0 commit comments