diff options
author | Robert Griesemer <gri@golang.org> | 2012-11-27 10:29:49 -0800 |
---|---|---|
committer | Robert Griesemer <gri@golang.org> | 2012-11-27 10:29:49 -0800 |
commit | e781b20ac9c0d5ec7658f4f6a2b8041b3706e1c0 (patch) | |
tree | e349c73a4430ed447856fa5a89894632fe7448fd /src/cmd/fix | |
parent | 51b8edcb37e7f20859b69623f69e9032e9601add (diff) | |
download | go-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.go | 21 |
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() |