@@ -23,7 +23,8 @@ func (r *ImportShadowingRule) Apply(file *lint.File, _ lint.Arguments) []lint.Fa
23
23
24
24
fileAst := file .AST
25
25
walker := importShadowing {
26
- importNames : importNames ,
26
+ packageNameIdent : fileAst .Name ,
27
+ importNames : importNames ,
27
28
onFailure : func (failure lint.Failure ) {
28
29
failures = append (failures , failure )
29
30
},
@@ -57,9 +58,10 @@ func getName(imp *ast.ImportSpec) string {
57
58
}
58
59
59
60
type importShadowing struct {
60
- importNames map [string ]struct {}
61
- onFailure func (lint.Failure )
62
- alreadySeen map [* ast.Object ]struct {}
61
+ packageNameIdent * ast.Ident
62
+ importNames map [string ]struct {}
63
+ onFailure func (lint.Failure )
64
+ alreadySeen map [* ast.Object ]struct {}
63
65
}
64
66
65
67
// Visit visits AST nodes and checks if id nodes (ast.Ident) shadow an import name
@@ -79,6 +81,10 @@ func (w importShadowing) Visit(n ast.Node) ast.Visitor {
79
81
* ast.StructType : // skip analysis of struct type because struct fields can not shadow an import name
80
82
return nil
81
83
case * ast.Ident :
84
+ if n == w .packageNameIdent {
85
+ return nil // skip the ident corresponding to the package name of this file
86
+ }
87
+
82
88
id := n .Name
83
89
if id == "_" {
84
90
return w // skip _ id
0 commit comments