Skip to content

Commit

Permalink
Ignore underscore-led files when parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
sdboyer committed Apr 7, 2017
1 parent 411118b commit a33a859
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
11 changes: 11 additions & 0 deletions _testdata/src/skip_/_a.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package skip

import (
"bytes"
"sort"
)

var (
_ = sort.Strings
_ = bytes.Buffer
)
12 changes: 12 additions & 0 deletions _testdata/src/skip_/a.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package skip

import (
"sort"

"github.com/sdboyer/gps"
)

var (
_ = sort.Strings
_ = gps.Solve
)
4 changes: 4 additions & 0 deletions pkgtree/pkgtree.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ func fillPackage(p *build.Package) error {
var testImports []string
var imports []string
for _, file := range gofiles {
// Skip underscore-led files, in keeping with the rest of the toolchain.
if filepath.Base(file)[0] == '_' {
continue
}
pf, err := parser.ParseFile(token.NewFileSet(), file, nil, parser.ImportsOnly|parser.ParseComments)
if err != nil {
if os.IsPermission(err) {
Expand Down
20 changes: 20 additions & 0 deletions pkgtree/pkgtree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1153,6 +1153,26 @@ func TestListPackages(t *testing.T) {
},
},
},
"skip underscore": {
fileRoot: j("skip_"),
importRoot: "skip_",
out: PackageTree{
ImportRoot: "skip_",
Packages: map[string]PackageOrErr{
"skip_": {
P: Package{
ImportPath: "skip_",
CommentPath: "",
Name: "skip",
Imports: []string{
"github.com/sdboyer/gps",
"sort",
},
},
},
},
},
},
// This case mostly exists for the PackageTree methods, but it does
// cover a bit of range
"varied": {
Expand Down

0 comments on commit a33a859

Please sign in to comment.