blob: 209a73f026faaea7aab588d9e674bb335728b4f3 [file] [log] [blame]
Serge Bazanski8bd2ab12021-12-17 17:32:16 +01001package lib
2
3import (
4 "go/ast"
5 "strings"
6)
7
8const (
9 genPrefix = "// Code generated"
10 genSuffix = "DO NOT EDIT."
11)
12
13// IsGeneratedFile returns true if the file is generated according to
14// https://golang.org/s/generatedcode and other heuristics.
15func IsGeneratedFile(file *ast.File) bool {
16 for _, c := range file.Comments {
17 for _, t := range c.List {
18 if strings.HasPrefix(t.Text, genPrefix) && strings.HasSuffix(t.Text, genSuffix) {
19 return true
20 }
21 // Generated testmain.go stubs from rules_go - for some reason, they don't
22 // contain the expected markers.
23 if strings.Contains(t.Text, "This package must be initialized before packages being tested.") {
24 return true
25 }
26 }
27 }
28 return false
29}