mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
Go: Only log one line for stray .go files
This commit is contained in:
@@ -2,6 +2,7 @@ package util
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"log"
|
||||
"net/url"
|
||||
@@ -185,12 +186,39 @@ func GoFilesOutsideDirs(root string, dirsToSkip ...string) []string {
|
||||
return filepath.SkipDir
|
||||
}
|
||||
if filepath.Ext(d.Name()) == ".go" {
|
||||
log.Printf("Found stray Go source file in %s.\n", path)
|
||||
result = append(result, path)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
if len(result) > 0 {
|
||||
log.Printf(
|
||||
"Found %d stray Go source file(s) in %s\n",
|
||||
len(result),
|
||||
JoinTruncatedList(result, ", ", 5),
|
||||
)
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// Joins the `elements` into one string, up to `maxElements`, separated by `sep`.
|
||||
// If the length of `elements` exceeds `maxElements`, the string "and %d more" is
|
||||
// appended where `%d` is the number of `elements` that were omitted.
|
||||
func JoinTruncatedList(elements []string, sep string, maxElements int) string {
|
||||
num := len(elements)
|
||||
numIncluded := num
|
||||
truncated := false
|
||||
if num > maxElements {
|
||||
numIncluded = maxElements
|
||||
truncated = true
|
||||
}
|
||||
|
||||
result := strings.Join(elements[0:numIncluded], sep)
|
||||
if truncated {
|
||||
result += fmt.Sprintf(", and %d more", num-maxElements)
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user