ent/entc: no need to pass options to imports.Process

Summary: default options produce the same formatted output

Reviewed By: a8m

Differential Revision: D17760716

fbshipit-source-id: 556dc11e4c48c480e704f28ec779ec721137a9ba
This commit is contained in:
Alex Snast
2019-10-04 04:09:48 -07:00
committed by Facebook Github Bot
parent 6a1c9e73fe
commit 2a6060a3ab

View File

@@ -87,7 +87,7 @@ func (g *Graph) Gen() (err error) {
b := bytes.NewBuffer(nil)
check(templates.ExecuteTemplate(b, tmpl.Name, n), "execute template %q", tmpl.Name)
target := filepath.Join(g.Config.Target, tmpl.Format(n))
check(writefmt(target, b.Bytes()), "write file %s", target)
check(writeFile(target, b.Bytes()), "write file %s", target)
}
}
for _, tmpl := range append(GraphTemplates[:], external...) {
@@ -101,7 +101,7 @@ func (g *Graph) Gen() (err error) {
b := bytes.NewBuffer(nil)
check(templates.ExecuteTemplate(b, tmpl.Name, g), "execute template %q", tmpl.Name)
target := filepath.Join(g.Config.Target, tmpl.Format)
check(writefmt(target, b.Bytes()), "write file %s", target)
check(writeFile(target, b.Bytes()), "write file %s", target)
}
return
}
@@ -440,15 +440,10 @@ func catch(err *error) {
}
}
func writefmt(target string, src []byte) error {
source, err := imports.Process(target, src, &imports.Options{
TabWidth: 8,
TabIndent: true,
Comments: true,
Fragment: true,
})
func writeFile(target string, src []byte) error {
source, err := imports.Process(target, src, nil)
if err != nil {
return fmt.Errorf("running goimports %s", string(src))
return fmt.Errorf("formatting source: %v", err)
}
return ioutil.WriteFile(target, source, 0644)
}