style: autoformat codegen files
This commit is contained in:
12
.vscode/settings.json
vendored
12
.vscode/settings.json
vendored
@@ -1,15 +1,15 @@
|
|||||||
{
|
{
|
||||||
"go.formatTool": "default",
|
"go.formatTool": "default",
|
||||||
"[json]": {
|
|
||||||
"editor.formatOnSave": true,
|
|
||||||
},
|
|
||||||
"[jsonc]": {
|
|
||||||
"editor.formatOnSave": true,
|
|
||||||
},
|
|
||||||
"[go]": {
|
"[go]": {
|
||||||
"editor.formatOnSave": true,
|
"editor.formatOnSave": true,
|
||||||
"editor.codeActionsOnSave": {
|
"editor.codeActionsOnSave": {
|
||||||
"source.organizeImports": "always"
|
"source.organizeImports": "always"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"[json]": {
|
||||||
|
"editor.formatOnSave": true,
|
||||||
|
},
|
||||||
|
"[jsonc]": {
|
||||||
|
"editor.formatOnSave": true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"go/format"
|
||||||
"os"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -117,13 +118,21 @@ func generateFile(sourcePath, destinationPath, tpl string) error {
|
|||||||
|
|
||||||
t := template.Must(template.New("tpl").Funcs(funcMap).Parse(tpl))
|
t := template.Must(template.New("tpl").Funcs(funcMap).Parse(tpl))
|
||||||
|
|
||||||
file, err := os.Create(destinationPath)
|
var b bytes.Buffer
|
||||||
if err != nil {
|
if err := t.Execute(&b, fileContent); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer file.Close()
|
|
||||||
|
|
||||||
return t.Execute(file, fileContent)
|
output := b.Bytes()
|
||||||
|
if strings.HasSuffix(destinationPath, ".go") {
|
||||||
|
formatted, err := format.Source(output)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
output = formatted
|
||||||
|
}
|
||||||
|
|
||||||
|
return os.WriteFile(destinationPath, output, 0644)
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateItems() error {
|
func generateItems() error {
|
||||||
@@ -217,9 +226,9 @@ func generateItems() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
itemsFileContent += "}"
|
itemsFileContent += "}"
|
||||||
err = os.WriteFile("pkg/data/item/items.go", []byte(itemsFileContent), 0644)
|
formatted, err := format.Source([]byte(itemsFileContent))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return os.WriteFile("pkg/data/item/items.go", formatted, 0644)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user