-
Notifications
You must be signed in to change notification settings - Fork 1k
Ignore dot-prefixed files and subdirs when scanning packages #551
Changes from 3 commits
536add9
2ff0643
474fb3e
78ecf7b
27fbbf2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -199,10 +199,17 @@ 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] == '_' { | ||
// Skip underscore-led or dot-led files, in keeping with the rest of the toolchain. | ||
bPrefix := filepath.Base(file)[0] | ||
if bPrefix == '_' || bPrefix == '.' { | ||
continue | ||
} | ||
|
||
// Skip any directories that happened to get caught by glob | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. delete this code, its not needed now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it still is - in the event of e.g. a directory named There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It still is. My comment about "NOTE: this doesn't handle directories" no longer applies, as demonstrated by the attached test case. |
||
if stat, err := os.Stat(file); err == nil && stat.IsDir() { | ||
continue | ||
} | ||
|
||
pf, err := parser.ParseFile(token.NewFileSet(), file, nil, parser.ImportsOnly|parser.ParseComments) | ||
if err != nil { | ||
if os.IsPermission(err) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1280,6 +1280,11 @@ func TestListPackages(t *testing.T) { | |
}, | ||
}, | ||
}, | ||
"skip directories starting with '.'": { | ||
fileRoot: j("dotgodir"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's also add e.g. a |
||
importRoot: "dotgodir", | ||
err: nil, | ||
}, | ||
} | ||
|
||
for name, fix := range table { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any file that starts with
.
,_
or calledtestdata
should be ignored when scanning source directories. Rather than this check, extend the check on line 203 to check for `== '.'.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good! Is this documented somewhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, that still leaves us open to the case where somebody names a directory "foo.go" inside their project. Perhaps we should handle that case separately, or at least give them a more helpful error message?