skip ignoreable directories

This commit is contained in:
Mark Bates 2019-11-04 11:48:06 -05:00
parent 3cbd07f98b
commit 20292c885b
1 changed files with 10 additions and 1 deletions

View File

@ -6,11 +6,12 @@ import (
"go/token" "go/token"
"os" "os"
"path/filepath" "path/filepath"
"strings"
"github.com/markbates/pkger/here" "github.com/markbates/pkger/here"
) )
// var DefaultIgnoredFolders = []string{".", "_", "vendor", "node_modules", "_fixtures", "testdata"} var defaultIgnoredFolders = []string{".", "_", "vendor", "node_modules", "testdata"}
func Parse(her here.Info) (Decls, error) { func Parse(her here.Info) (Decls, error) {
src, err := fromSource(her) src, err := fromSource(her)
@ -43,6 +44,14 @@ func fromSource(her here.Info) (Decls, error) {
if !info.IsDir() { if !info.IsDir() {
return nil return nil
} }
base := filepath.Base(path)
for _, x := range defaultIgnoredFolders {
if strings.HasPrefix(base, x) {
return filepath.SkipDir
}
}
pkgs, err := parser.ParseDir(fset, path, nil, 0) pkgs, err := parser.ParseDir(fset, path, nil, 0)
if err != nil { if err != nil {
return err return err