Skip to content

Commit

Permalink
Go: Only log one line for stray .go files
Browse files Browse the repository at this point in the history
  • Loading branch information
mbg committed Jun 7, 2024
1 parent e7a60b7 commit 5c1f68c
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion go/extractor/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package util

import (
"errors"
"fmt"
"io/fs"
"log"
"net/url"
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 5c1f68c

Please sign in to comment.