refactor: remove regex code generated
parent
27a82681f1
commit
5a08a1bc47
|
@ -2,12 +2,9 @@ package imports
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"go/ast"
|
"go/ast"
|
||||||
"regexp"
|
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
var reGoGenerated = regexp.MustCompile(`^// Code generated .* DO NOT EDIT\.$`)
|
|
||||||
|
|
||||||
// Copy from https://github.com/mvdan/gofumpt
|
// Copy from https://github.com/mvdan/gofumpt
|
||||||
func isGoFile(name string) bool {
|
func isGoFile(name string) bool {
|
||||||
// Hidden files are ignored
|
// Hidden files are ignored
|
||||||
|
@ -19,6 +16,7 @@ func isGoFile(name string) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy from https://github.com/mvdan/gofumpt
|
// Copy from https://github.com/mvdan/gofumpt
|
||||||
|
// Copy from https://github.com/incu6us/goimports-reviser
|
||||||
func isGoGenerated(file *ast.File) bool {
|
func isGoGenerated(file *ast.File) bool {
|
||||||
for _, cg := range file.Comments {
|
for _, cg := range file.Comments {
|
||||||
// Ignore if package ... is on top
|
// Ignore if package ... is on top
|
||||||
|
@ -27,7 +25,7 @@ func isGoGenerated(file *ast.File) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, line := range cg.List {
|
for _, line := range cg.List {
|
||||||
if reGoGenerated.MatchString(line.Text) {
|
if strings.Contains(line.Text, "// Code generated") {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue