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