refactor/eg: use format.Node not printer.Fprint for canonical output

Fixes golang/go#10038

Change-Id: If3243f0c68fc0442dcc1e2dd71cbdc629beff70c
Reviewed-on: https://go-review.googlesource.com/6481
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
This commit is contained in:
Alan Donovan 2015-03-02 14:23:59 -05:00
parent 133ecf9210
commit 4744be3abc
5 changed files with 10 additions and 9 deletions

View File

@ -6,6 +6,7 @@ import (
"bytes" "bytes"
"fmt" "fmt"
"go/ast" "go/ast"
"go/format"
"go/printer" "go/printer"
"go/token" "go/token"
"os" "os"
@ -288,7 +289,7 @@ func WriteAST(fset *token.FileSet, filename string, f *ast.File) (err error) {
err = err2 // prefer earlier error err = err2 // prefer earlier error
} }
}() }()
return printer.Fprint(fh, fset, f) return format.Node(fh, fset, f)
} }
// -- utilities -------------------------------------------------------- // -- utilities --------------------------------------------------------

View File

@ -3,8 +3,8 @@
package A1 package A1
import ( import (
. "fmt"
"errors" "errors"
. "fmt"
myfmt "fmt" myfmt "fmt"
"os" "os"
"strings" "strings"

View File

@ -6,8 +6,8 @@ package A2
// TODO(adonovan): fix: it should also remove "fmt". // TODO(adonovan): fix: it should also remove "fmt".
import ( import (
myfmt "fmt"
"errors" "errors"
myfmt "fmt"
) )
func example(n int) { func example(n int) {

View File

@ -5,8 +5,8 @@ package D1
import "fmt" import "fmt"
func example() { func example() {
fmt.Println(456, "!") // match fmt.Println(456, "!") // match
fmt.Println(456, "!") // match fmt.Println(456, "!") // match
fmt.Println(456, "!") // match fmt.Println(456, "!") // match
fmt.Println(100+20+3, "a"+"") // no match: constant expressions, but not basic literals fmt.Println(100+20+3, "a"+"") // no match: constant expressions, but not basic literals
} }

View File

@ -3,11 +3,11 @@
package E1 package E1
import ( import (
"fmt"
"log" "log"
"os" "os"
"fmt"
) )
func example() { func example() {
fmt.Fprintf(os.Stderr, "warning: %v", "oops") // match fmt.Fprintf(os.Stderr, "warning: %v", "oops") // match
} }