refactor: remove regex code generated

main
sudo pacman -Syu 2022-11-25 01:21:57 +07:00
parent 27a82681f1
commit 5a08a1bc47
No known key found for this signature in database
GPG Key ID: D6CB5C6C567C47B0
1 changed files with 2 additions and 4 deletions

View File

@ -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
} }
} }