feat(scanner): add a new option for excluding paths based on a regexp

* Exclude paths based on new exclude pattern option

* Add test for excluded paths

* Add exclude pattern option to docs

* Set exclude regexp only if given argument is set

* Update scanner/scanner.go

---------

Co-authored-by: Senan Kelly <senan@senan.xyz>
This commit is contained in:
Gregor Zurowski
2023-05-06 19:03:11 +02:00
committed by GitHub
parent 74de06430a
commit 1d3877668f
6 changed files with 74 additions and 22 deletions

View File

@@ -27,10 +27,13 @@ type MockFS struct {
db *db.DB
}
func New(t testing.TB) *MockFS { return new(t, []string{""}) }
func NewWithDirs(t testing.TB, dirs []string) *MockFS { return new(t, dirs) }
func New(t testing.TB) *MockFS { return new(t, []string{""}, "") }
func NewWithDirs(t testing.TB, dirs []string) *MockFS { return new(t, dirs, "") }
func NewWithExcludePattern(t testing.TB, excludePattern string) *MockFS {
return new(t, []string{""}, excludePattern)
}
func new(t testing.TB, dirs []string) *MockFS {
func new(t testing.TB, dirs []string, excludePattern string) *MockFS {
dbc, err := db.NewMock()
if err != nil {
t.Fatalf("create db: %v", err)
@@ -59,7 +62,7 @@ func new(t testing.TB, dirs []string) *MockFS {
}
tagReader := &tagReader{paths: map[string]*tagReaderResult{}}
scanner := scanner.New(absDirs, dbc, ";", tagReader)
scanner := scanner.New(absDirs, dbc, ";", tagReader, excludePattern)
return &MockFS{
t: t,