logginghandler/vendor/github.com/nishanths/exhaustive/generated.go
Marvin Preuss d095180eb4
All checks were successful
continuous-integration/drone/push Build is passing
build: uses go modules for tool handling
2022-01-14 13:51:56 +01:00

35 lines
685 B
Go

package exhaustive
import (
"go/ast"
"strings"
)
// Adapated from https://gotools.org/dmitri.shuralyov.com/go/generated
func isGeneratedFile(file *ast.File) bool {
for _, c := range file.Comments {
for _, cc := range c.List {
s := cc.Text // "\n" already removed (see doc comment)
if len(s) >= 1 && s[len(s)-1] == '\r' {
s = s[:len(s)-1] // Trim "\r".
}
if containsGeneratedComment(s) {
return true
}
}
}
return false
}
func containsGeneratedComment(s string) bool {
return strings.HasPrefix(s, genCommentPrefix) &&
strings.HasSuffix(s, genCommentSuffix)
}
const (
genCommentPrefix = "// Code generated "
genCommentSuffix = " DO NOT EDIT."
)