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:
parent
133ecf9210
commit
4744be3abc
|
@ -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 --------------------------------------------------------
|
||||||
|
|
|
@ -3,8 +3,8 @@
|
||||||
package A1
|
package A1
|
||||||
|
|
||||||
import (
|
import (
|
||||||
. "fmt"
|
|
||||||
"errors"
|
"errors"
|
||||||
|
. "fmt"
|
||||||
myfmt "fmt"
|
myfmt "fmt"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
|
@ -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) {
|
||||||
|
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue