@@ -31,30 +31,6 @@ const (
3131 dotCharacter = 46
3232)
3333
34- // shouldFilter decides whether a match should be included in the final
35- // pool of files for renaming.
36- func shouldFilter (conf * config.Config , match * file.Change ) bool {
37- if conf .ExcludeRegex != nil &&
38- conf .ExcludeRegex .MatchString (match .Source ) {
39- return true
40- }
41-
42- if ! conf .IncludeDir && match .IsDir {
43- return true
44- }
45-
46- if conf .OnlyDir && ! match .IsDir {
47- return true
48- }
49-
50- if conf .IncludeRegex != nil &&
51- ! conf .IncludeRegex .MatchString (match .Source ) {
52- return true
53- }
54-
55- return false
56- }
57-
5834// skipFileIfHidden checks if a file is hidden, and if so, returns a boolean
5935// confirming whether it should be skipped or not.
6036func skipFileIfHidden (
@@ -214,6 +190,7 @@ func checkIfMatch(
214190 conf * config.Config ,
215191 path string ,
216192 entry fs.DirEntry ,
193+ filters Filters ,
217194 sortVars * variables.Variables ,
218195) (* file.Change , bool , error ) {
219196 var err error
@@ -251,7 +228,7 @@ func checkIfMatch(
251228 slog .Any ("match" , match ),
252229 )
253230
254- if shouldFilter (conf , match ) {
231+ if filters . Skip (conf , match ) {
255232 slog .Debug (
256233 "excluding file based on filter criteria" ,
257234 slog .Any ("match" , match ),
@@ -275,6 +252,7 @@ func walkDirectory(
275252 conf * config.Config ,
276253 rootPath string ,
277254 processedPaths map [string ]bool ,
255+ filters Filters ,
278256 sortVars * variables.Variables ,
279257) (file.Changes , error ) {
280258 var matches file.Changes
@@ -339,6 +317,7 @@ func walkDirectory(
339317 conf ,
340318 currentPath ,
341319 entry ,
320+ filters ,
342321 sortVars ,
343322 )
344323 if err != nil {
@@ -369,6 +348,7 @@ func shouldSkipExcludedDir(conf *config.Config, entry fs.DirEntry) bool {
369348func searchPaths (
370349 ctx context.Context ,
371350 conf * config.Config ,
351+ filters Filters ,
372352 sortVars , searchVars * variables.Variables ,
373353) (file.Changes , error ) {
374354 processedPaths := make (map [string ]bool )
@@ -393,6 +373,7 @@ func searchPaths(
393373 conf ,
394374 rootPath ,
395375 fs .FileInfoToDirEntry (fileInfo ),
376+ filters ,
396377 sortVars ,
397378 )
398379 if matchErr != nil {
@@ -413,6 +394,7 @@ func searchPaths(
413394 conf ,
414395 rootPath ,
415396 processedPaths ,
397+ filters ,
416398 sortVars ,
417399 )
418400 if err != nil {
@@ -607,7 +589,7 @@ func Find(
607589 if conf .CSVFilename != "" {
608590 matches , err = handleCSV (conf )
609591 } else {
610- matches , err = searchPaths (ctx , conf , & sortVars , & searchVars )
592+ matches , err = searchPaths (ctx , conf , NewFilters ( conf ), & sortVars , & searchVars )
611593 if err != nil {
612594 return nil , err
613595 }
0 commit comments