1
0
mirror of https://github.com/golang/go synced 2024-11-26 18:06:55 -07:00

go/parser: ignore subdirectories in ParseDir

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>
This commit is contained in:
Carlos Alexandro Becker 2020-11-13 10:47:15 -03:00
parent 30ba798093
commit be59d85fe2
3 changed files with 10 additions and 1 deletions

View File

@ -140,7 +140,7 @@ func ParseDir(fset *token.FileSet, path string, filter func(fs.FileInfo) bool, m
pkgs = make(map[string]*ast.Package)
for _, d := range list {
if strings.HasSuffix(d.Name(), ".go") && (filter == nil || filter(d)) {
if !d.IsDir() && strings.HasSuffix(d.Name(), ".go") && (filter == nil || filter(d)) {
filename := filepath.Join(path, d.Name())
if src, err := ParseFile(fset, filename, nil, mode); err == nil {
name := src.Name.Name

View File

@ -82,6 +82,14 @@ func TestParseDir(t *testing.T) {
}
}
func TestIssue42951(t *testing.T) {
path := "./testdata/issue42951"
_, err := ParseDir(token.NewFileSet(), path, nil, 0)
if err != nil {
t.Errorf("ParseDir(%s): %v", path, err)
}
}
func TestParseExpr(t *testing.T) {
// just kicking the tires:
// a valid arithmetic expression

View File

@ -0,0 +1 @@
This file should not be parsed by ParseDir.