Skip to content

Commit

Permalink
Merge pull request #32 from hashicorp/b-vet-vendor-pkg-names
Browse files Browse the repository at this point in the history
vet: account for vendored package names
  • Loading branch information
evanphx authored Jan 9, 2019
2 parents 332dc5f + 27de0b2 commit 4783cae
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion hclogvet/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"go/importer"
"go/token"
"go/types"
"strings"
)

// stdImporter is the importer we use to import packages.
Expand Down Expand Up @@ -42,7 +43,18 @@ func isNamedType(t types.Type, path, name string) bool {
return false
}
obj := n.Obj()
return obj.Name() == name && obj.Pkg() != nil && obj.Pkg().Path() == path
return obj.Name() == name && isPackage(obj.Pkg(), path)
}

// isPackage reports whether pkg has path as the canonical path,
// taking into account vendoring effects
func isPackage(pkg *types.Package, path string) bool {
if pkg == nil {
return false
}

return pkg.Path() == path ||
strings.HasSuffix(pkg.Path(), "/vendor/"+path)
}

// importType returns the type denoted by the qualified identifier
Expand Down

0 comments on commit 4783cae

Please sign in to comment.