woodpecker/vendor/github.com/nishanths/exhaustive/generated.go
Lukas c28f7cb29f
Add golangci-lint (#502)
Initial part of #435
2021-11-14 21:01:54 +01:00

34 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."
)