Go: Add comment to AnyGoFilesOutsideDirs and use slices.Contains

This commit is contained in:
Michael B. Gale
2024-02-12 15:17:03 +00:00
parent 843f7694fd
commit d4ea45bdaf

View File

@@ -10,6 +10,7 @@ import (
"os/exec"
"path/filepath"
"runtime"
"slices"
"strings"
)
@@ -319,18 +320,16 @@ func FindAllFilesWithName(root string, name string, dirsToSkip ...string) []stri
return paths
}
// Determines whether there are any Go source files in locations which do not have a Go.mod
// file in the same directory or higher up in the file hierarchy, relative to the `root`.
func AnyGoFilesOutsideDirs(root string, dirsToSkip ...string) bool {
found := false
filepath.WalkDir(root, func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
if d.IsDir() {
for _, dirToSkip := range dirsToSkip {
if path == dirToSkip {
return filepath.SkipDir
}
}
if d.IsDir() && slices.Contains(dirsToSkip, path) {
return filepath.SkipDir
}
if filepath.Ext(d.Name()) == ".go" {
found = true