chore: make generate organize imports (#13337)
This commit is contained in:
parent
d32ee8a86a
commit
9dc218f2b1
2 changed files with 10 additions and 2 deletions
|
|
@ -14,6 +14,7 @@ import (
|
|||
|
||||
combinations "github.com/mxschmitt/golang-combinations"
|
||||
"github.com/spf13/pflag"
|
||||
"golang.org/x/tools/imports"
|
||||
)
|
||||
|
||||
//go:embed decorate.tpl
|
||||
|
|
@ -177,8 +178,9 @@ func main() {
|
|||
target = &gofile
|
||||
}
|
||||
|
||||
var name string
|
||||
if target != nil {
|
||||
name := *target
|
||||
name = *target
|
||||
if !strings.HasSuffix(name, ".go") {
|
||||
name += ".go"
|
||||
}
|
||||
|
|
@ -198,6 +200,12 @@ func main() {
|
|||
formatted = []byte(generated)
|
||||
}
|
||||
|
||||
formatted, err = imports.Process(name, formatted, nil)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(3)
|
||||
}
|
||||
|
||||
if _, err := out.Write(formatted); err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(2)
|
||||
|
|
|
|||
2
go.mod
2
go.mod
|
|
@ -188,7 +188,7 @@ require (
|
|||
golang.org/x/mod v0.16.0 // indirect
|
||||
golang.org/x/sys v0.18.0 // indirect
|
||||
golang.org/x/term v0.18.0 // indirect
|
||||
golang.org/x/tools v0.19.0 // indirect
|
||||
golang.org/x/tools v0.19.0
|
||||
google.golang.org/appengine v1.6.8 // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237 // indirect
|
||||
gopkg.in/go-playground/validator.v9 v9.31.0 // indirect
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue