Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

schema/gen/go: apply gofmt automatically #163

Merged
merged 1 commit into from
Apr 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion node/gendemo/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,5 @@
// The code generation is triggered by `go:generate` comments in the `doc.go` file.

//go:generate go run gen.go
//go:generate gofmt -w .

package gendemo
1 change: 0 additions & 1 deletion schema/dmt/gen_trigger.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//go:generate go run gen.go
//go:generate gofmt -w .

package schemadmt
12 changes: 11 additions & 1 deletion schema/gen/go/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package gengo
import (
"bytes"
"fmt"
"go/format"
"io"
"io/ioutil"
"path/filepath"
Expand Down Expand Up @@ -150,7 +151,16 @@ func withFile(filename string, fn func(io.Writer)) {
// more atomicity via the single write.
buf := new(bytes.Buffer)
fn(buf)
if err := ioutil.WriteFile(filename, buf.Bytes(), 0666); err != nil {

src := buf.Bytes()
// Format the source before writing, just like gofmt would.
// This also prevents us from writing invalid syntax to disk.
src, err := format.Source(src)
if err != nil {
panic(err)
}

if err := ioutil.WriteFile(filename, src, 0666); err != nil {
panic(err)
}
}
Expand Down