Skip to content

Commit

Permalink
refactor + improve doc comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ayoisaiah committed Oct 9, 2023
1 parent f29aa03 commit f221f81
Showing 1 changed file with 37 additions and 29 deletions.
66 changes: 37 additions & 29 deletions find/find.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,38 +34,46 @@ func shouldFilter(conf *config.Config, match *file.Change) bool {
return false
}

func checkHidden(conf *config.Config, path string) (bool, error) {
if !conf.IncludeHidden {
isHidden, err := checkIfHidden(filepath.Base(path), "")
if err != nil {
return false, err
}
// skipFileIfHidden checks if a file is hidden, and if so, returns a boolean
// confirming whether it should be skipped or not.
func skipFileIfHidden(
path string,
filesAndDirPaths []string,
includeHidden bool,
) (bool, error) {
if includeHidden {
return false, nil
}

if isHidden {
// Ensure that explicitly included file arguments are not affected
entryAbsPath, err := filepath.Abs(path)
if err != nil {
return false, err
}
isHidden, err := checkIfHidden(filepath.Base(path), "")
if err != nil {
return false, err
}

shouldSkip := true
if !isHidden {
return false, nil
}

for _, pathArg := range conf.FilesAndDirPaths {
argAbsPath, err := filepath.Abs(pathArg)
if err != nil {
return false, err
}
entryAbsPath, err := filepath.Abs(path)
if err != nil {
return false, err
}

if strings.EqualFold(entryAbsPath, argAbsPath) {
shouldSkip = false
}
}
skipFile := true

return shouldSkip, nil
// Ensure that explicitly included file arguments are not affected
for _, pathArg := range filesAndDirPaths {
argAbsPath, err := filepath.Abs(pathArg)
if err != nil {
return false, err
}

if strings.EqualFold(entryAbsPath, argAbsPath) {
skipFile = false
}
}

return false, nil
return skipFile, nil
}

// isMaxDepth reports whether the configured max depth has been reached.
Expand Down Expand Up @@ -145,7 +153,11 @@ func searchPaths(conf *config.Config) ([]*file.Change, error) {
return nil
}

skipHidden, herr := checkHidden(conf, currentPath)
skipHidden, herr := skipFileIfHidden(
currentPath,
conf.FilesAndDirPaths,
conf.IncludeHidden,
)
if herr != nil {
return herr
}
Expand All @@ -158,10 +170,6 @@ func searchPaths(conf *config.Config) ([]*file.Change, error) {
return nil
}

if currentPath == ".git" {
return fs.SkipDir
}

if isMaxDepth(rootPath, currentPath, maxDepth) {
return fs.SkipDir
}
Expand Down

0 comments on commit f221f81

Please sign in to comment.