summaryrefslogtreecommitdiff
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
commitec964dc3b0a761f832631bc47f4853751a5a4c47 (patch)
tree6422c7efdb1b56add32cd1863d06298c7fa7f580 /src/cmd/fix
parent1fa1c89bdf78b29293f9c090a12fe388110d7d97 (diff)
downloadgo-ec964dc3b0a761f832631bc47f4853751a5a4c47.tar.gz
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 http://codereview.appspot.com/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 b151408d7..dc10d6beb 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()