1
0
mirror of https://github.com/golang/go synced 2024-11-18 14:54:40 -07:00

go.tools/imports: go/format outbound code

Fixes golang/go#8035.

LGTM=bradfitz
R=bradfitz
CC=golang-codereviews, shurcool
https://golang.org/cl/120840044
This commit is contained in:
Josh Bleecher Snyder 2014-07-28 17:15:17 -07:00
parent 8aabc9a084
commit 3442faf3c1
2 changed files with 33 additions and 0 deletions

View File

@ -616,6 +616,33 @@ import (
func main() {
_, _, _, _, _ = fmt.Errorf, io.Copy, strings.Contains, renamed_bar.A, B
}
`,
},
// Non-idempotent comment formatting
// golang.org/issue/8035
{
name: "issue 8035",
in: `package main
import (
"fmt" // A
"go/ast" // B
_ "launchpad.net/gocheck" // C
)
func main() { _, _ = fmt.Print, ast.Walk }
`,
out: `package main
import (
"fmt" // A
"go/ast" // B
_ "launchpad.net/gocheck" // C
)
func main() { _, _ = fmt.Print, ast.Walk }
`,
},
}

View File

@ -11,6 +11,7 @@ import (
"bytes"
"fmt"
"go/ast"
"go/format"
"go/parser"
"go/printer"
"go/token"
@ -89,6 +90,11 @@ func Process(filename string, src []byte, opt *Options) ([]byte, error) {
if len(spacesBefore) > 0 {
out = addImportSpaces(bytes.NewReader(out), spacesBefore)
}
out, err = format.Source(out)
if err != nil {
return nil, err
}
return out, nil
}