From 8ae8ca008ba26ab258597ac5b8bea0478f0f4875 Mon Sep 17 00:00:00 2001 From: Guillem Bonet Date: Fri, 28 Jul 2023 13:11:20 +0200 Subject: [PATCH] exclude files too Signed-off-by: Guillem Bonet --- parser.go | 6 ++++++ parser_test.go | 14 ++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/parser.go b/parser.go index 6bf991e92..eb2b16b83 100644 --- a/parser.go +++ b/parser.go @@ -1673,6 +1673,12 @@ func (parser *Parser) getAllGoFileInfo(packageDir, searchDir string) error { return err } + if parser.excludes != nil { + if _, ok := parser.excludes[relPath]; ok { + return nil + } + } + return parser.parseFile(filepath.ToSlash(filepath.Dir(filepath.Clean(filepath.Join(packageDir, relPath)))), path, nil, ParseAll) }) } diff --git a/parser_test.go b/parser_test.go index d818f705c..1f7c5c521 100644 --- a/parser_test.go +++ b/parser_test.go @@ -3772,6 +3772,20 @@ func TestParser_Skip(t *testing.T) { assert.Error(t, parser.Skip(filepath.Clean("admin/release"), &mockFS{IsDirectory: true})) } +func TestParser_ExcludeFilesAndFolders(t *testing.T) { + t.Parallel() + + searchDir := "testdata/conflict_name" + + p := New(SetExcludedDirsAndFiles("api/api1.go,model")) + err := p.getAllGoFileInfo("testdata", searchDir) + + assert.NoError(t, err) + assert.Equal(t, 4, len(p.packages.files)) + + assert.Error(t, p.Skip("model", &mockFS{IsDirectory: true})) +} + func TestGetFieldType(t *testing.T) { t.Parallel()