Skip to content

Commit

Permalink
Use format.Node() instead printer.Fprint()
Browse files Browse the repository at this point in the history
printer.Fprint() does strange formatting (indention) whereas format.Node() formats according to gofmt
  • Loading branch information
AntonStoeckl committed Feb 28, 2020
1 parent 219c9a9 commit d2d8eab
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
3 changes: 1 addition & 2 deletions cmd/go-mutesting/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"go/ast"
"go/format"
"go/printer"
"go/token"
"go/types"
"io"
Expand Down Expand Up @@ -505,7 +504,7 @@ func saveAST(mutationBlackList map[string]struct{}, file string, fset *token.Fil

h := md5.New()

err := printer.Fprint(io.MultiWriter(h, &buf), fset, node)
err := format.Node(io.MultiWriter(h, &buf), fset, node)
if err != nil {
return "", false, err
}
Expand Down
7 changes: 4 additions & 3 deletions test/mutator.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package test
import (
"bytes"
"fmt"
"go/printer"
"go/format"
"io/ioutil"
"testing"

Expand Down Expand Up @@ -40,7 +40,8 @@ func Mutator(t *testing.T, m mutator.Mutator, testFile string, count int) {
assert.True(t, <-changed)

buf := new(bytes.Buffer)
err = printer.Fprint(buf, fset, src)
err = format.Node(buf, fset, src)

assert.Nil(t, err)

changedFilename := fmt.Sprintf("%s.%d.go", testFile, i)
Expand All @@ -57,7 +58,7 @@ func Mutator(t *testing.T, m mutator.Mutator, testFile string, count int) {
assert.True(t, <-changed)

buf = new(bytes.Buffer)
err = printer.Fprint(buf, fset, src)
err = format.Node(buf, fset, src)
assert.Nil(t, err)

assert.Equal(t, string(data), buf.String())
Expand Down
8 changes: 4 additions & 4 deletions testdata/structinit/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
package example

type Some struct {
a string
B int
a string
B int
}

func removeFieldsFromStructInit() Some {
some := Some{
a: "a value",
B: 5,
a: "a value",
B: 5,
}

return some
Expand Down
4 changes: 2 additions & 2 deletions testdata/structinit/remove.go.0.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
package example

type Some struct {
a string
B int
a string
B int
}

func removeFieldsFromStructInit() Some {
Expand Down
4 changes: 2 additions & 2 deletions testdata/structinit/remove.go.1.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
package example

type Some struct {
a string
B int
a string
B int
}

func removeFieldsFromStructInit() Some {
Expand Down

0 comments on commit d2d8eab

Please sign in to comment.