2022-11-24 18:17:35 +00:00
|
|
|
package imports
|
|
|
|
|
|
|
|
import (
|
|
|
|
"go/ast"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Copy from https://github.com/mvdan/gofumpt
|
|
|
|
func isGoFile(name string) bool {
|
|
|
|
// Hidden files are ignored
|
|
|
|
if strings.HasPrefix(name, ".") {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
return strings.HasSuffix(name, ".go")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy from https://github.com/mvdan/gofumpt
|
2022-11-24 18:21:57 +00:00
|
|
|
// Copy from https://github.com/incu6us/goimports-reviser
|
2022-11-24 18:17:35 +00:00
|
|
|
func isGoGenerated(file *ast.File) bool {
|
|
|
|
for _, cg := range file.Comments {
|
|
|
|
// Ignore if package ... is on top
|
|
|
|
if cg.Pos() > file.Package {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, line := range cg.List {
|
2022-11-24 18:21:57 +00:00
|
|
|
if strings.Contains(line.Text, "// Code generated") {
|
2022-11-24 18:17:35 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|