mirror of
https://github.com/github/codeql.git
synced 2026-04-22 15:25:18 +02:00
Go: Add comment to AnyGoFilesOutsideDirs and use slices.Contains
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user