@@ -48,23 +48,35 @@ func run(pass *analysis.Pass) (interface{}, error) {
4848func reportImported (pass * analysis.Pass , expr ast.Expr , checkRE * regexp.Regexp , prefix string ) {
4949 switch x := expr .(type ) {
5050 case * ast.SelectorExpr :
51- if ! checkRE .MatchString (x .Sel .Name ) {
52- return
53- }
54-
5551 selectIdent , ok := x .X .(* ast.Ident )
5652 if ! ok {
5753 return
5854 }
5955
56+ var pkgPath string
6057 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 {
6260 return
6361 }
62+ pkgPath = pkg .Imported ().Path ()
6463 }
6564
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+ }
6776
77+ if matches {
78+ pass .Reportf (expr .Pos (), "%s variable %s in other package %s" , prefix , x .Sel .Name , selectIdent .Name )
79+ }
6880 case * ast.Ident :
6981 use , ok := pass .TypesInfo .Uses [x ].(* types.Var )
7082 if ! ok {
0 commit comments