gofimports/internal/imports/check.go

36 lines
661 B
Go
Raw Normal View History

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
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") {
return true
}
}
}
return false
}