File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -340,6 +340,28 @@ func AnyGoFilesOutsideDirs(root string, dirsToSkip ...string) bool {
340
340
return found
341
341
}
342
342
343
+ // Returns an array of any Go source files in locations which do not have a Go.mod
344
+ // file in the same directory or higher up in the file hierarchy, relative to the `root`.
345
+ func GoFilesOutsideDirs (root string , dirsToSkip ... string ) []string {
346
+ result := []string {}
347
+
348
+ filepath .WalkDir (root , func (path string , d fs.DirEntry , err error ) error {
349
+ if err != nil {
350
+ return err
351
+ }
352
+ if d .IsDir () && slices .Contains (dirsToSkip , path ) {
353
+ return filepath .SkipDir
354
+ }
355
+ if filepath .Ext (d .Name ()) == ".go" {
356
+ log .Printf ("Found stray Go source file in %s.\n " , path )
357
+ result = append (result , path )
358
+ }
359
+ return nil
360
+ })
361
+
362
+ return result
363
+ }
364
+
343
365
// For every file path in the input array, return the parent directory.
344
366
func GetParentDirs (paths []string ) []string {
345
367
dirs := make ([]string , len (paths ))
You can’t perform that action at this time.
0 commit comments