aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/fix
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2012-11-27 10:29:49 -0800
committerRobert Griesemer <gri@golang.org>2012-11-27 10:29:49 -0800
commite781b20ac9c0d5ec7658f4f6a2b8041b3706e1c0 (patch)
treee349c73a4430ed447856fa5a89894632fe7448fd /src/cmd/fix
parent51b8edcb37e7f20859b69623f69e9032e9601add (diff)
downloadgo-e781b20ac9c0d5ec7658f4f6a2b8041b3706e1c0.tar.gz
go-e781b20ac9c0d5ec7658f4f6a2b8041b3706e1c0.zip
go/format: Package format implements standard formatting of Go source.
Package format is a utility package that takes care of parsing, sorting of imports, and formatting of .go source using the canonical gofmt formatting parameters. Use go/format in various clients instead of the lower-level components. R=r, bradfitz, dave, rogpeppe, rsc CC=golang-dev https://golang.org/cl/6852075
Diffstat (limited to 'src/cmd/fix')
-rw-r--r--src/cmd/fix/main.go21
1 files changed, 4 insertions, 17 deletions
diff --git a/src/cmd/fix/main.go b/src/cmd/fix/main.go
index b151408d74..dc10d6beb5 100644
--- a/src/cmd/fix/main.go
+++ b/src/cmd/fix/main.go
@@ -9,8 +9,8 @@ import (
"flag"
"fmt"
"go/ast"
+ "go/format"
"go/parser"
- "go/printer"
"go/scanner"
"go/token"
"io/ioutil"
@@ -97,23 +97,11 @@ func main() {
os.Exit(exitCode)
}
-const (
- tabWidth = 8
- parserMode = parser.ParseComments
- printerMode = printer.TabIndent | printer.UseSpaces
-)
-
-var printConfig = &printer.Config{
- Mode: printerMode,
- Tabwidth: tabWidth,
-}
+const parserMode = parser.ParseComments
func gofmtFile(f *ast.File) ([]byte, error) {
var buf bytes.Buffer
-
- ast.SortImports(fset, f)
- err := printConfig.Fprint(&buf, fset, f)
- if err != nil {
+ if err := format.Node(&buf, fset, f); err != nil {
return nil, err
}
return buf.Bytes(), nil
@@ -211,8 +199,7 @@ var gofmtBuf bytes.Buffer
func gofmt(n interface{}) string {
gofmtBuf.Reset()
- err := printConfig.Fprint(&gofmtBuf, fset, n)
- if err != nil {
+ if err := format.Node(&gofmtBuf, fset, n); err != nil {
return "<" + err.Error() + ">"
}
return gofmtBuf.String()