Skip to content

Commit d4ea45b

Browse files
committed
Go: Add comment to AnyGoFilesOutsideDirs and use slices.Contains
1 parent 843f769 commit d4ea45b

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

go/extractor/util/util.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"os/exec"
1111
"path/filepath"
1212
"runtime"
13+
"slices"
1314
"strings"
1415
)
1516

@@ -319,18 +320,16 @@ func FindAllFilesWithName(root string, name string, dirsToSkip ...string) []stri
319320
return paths
320321
}
321322

323+
// Determines whether there are any Go source files in locations which do not have a Go.mod
324+
// file in the same directory or higher up in the file hierarchy, relative to the `root`.
322325
func AnyGoFilesOutsideDirs(root string, dirsToSkip ...string) bool {
323326
found := false
324327
filepath.WalkDir(root, func(path string, d fs.DirEntry, err error) error {
325328
if err != nil {
326329
return err
327330
}
328-
if d.IsDir() {
329-
for _, dirToSkip := range dirsToSkip {
330-
if path == dirToSkip {
331-
return filepath.SkipDir
332-
}
333-
}
331+
if d.IsDir() && slices.Contains(dirsToSkip, path) {
332+
return filepath.SkipDir
334333
}
335334
if filepath.Ext(d.Name()) == ".go" {
336335
found = true

0 commit comments

Comments
 (0)