mirror of
https://github.com/golang/go
synced 2024-11-20 01:04:40 -07:00
go/printer, gofmt: use blank to separate import rename from import path
Note that declarations.golden is not using spaces for alignment (so that the alignment tabs are visible) which is why this change affects the test cases significantly. gofmt uses spaces for alignment (by default) and only tabs for indentation. gofmt -w src misc (no changes) Fixes #1673. R=iant CC=golang-dev https://golang.org/cl/4388044
This commit is contained in:
parent
8fc6703391
commit
ebaf01f052
@ -1200,7 +1200,7 @@ func (p *printer) spec(spec ast.Spec, n int, doIndent bool, multiLine *bool) {
|
|||||||
p.setComment(s.Doc)
|
p.setComment(s.Doc)
|
||||||
if s.Name != nil {
|
if s.Name != nil {
|
||||||
p.expr(s.Name, multiLine)
|
p.expr(s.Name, multiLine)
|
||||||
p.print(vtab)
|
p.print(blank)
|
||||||
}
|
}
|
||||||
p.expr(s.Path, multiLine)
|
p.expr(s.Path, multiLine)
|
||||||
p.setComment(s.Comment)
|
p.setComment(s.Comment)
|
||||||
|
77
src/pkg/go/printer/testdata/declarations.golden
vendored
77
src/pkg/go/printer/testdata/declarations.golden
vendored
@ -7,10 +7,10 @@ package imports
|
|||||||
import "io"
|
import "io"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
_ "io"
|
_ "io"
|
||||||
)
|
)
|
||||||
|
|
||||||
import _ "io"
|
import _ "io"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
@ -20,40 +20,40 @@ import (
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
aLongRename "io"
|
aLongRename "io"
|
||||||
|
|
||||||
b "io"
|
b "io"
|
||||||
)
|
)
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"unrenamed"
|
"unrenamed"
|
||||||
renamed "renameMe"
|
renamed "renameMe"
|
||||||
. "io"
|
. "io"
|
||||||
_ "io"
|
_ "io"
|
||||||
"io"
|
"io"
|
||||||
. "os"
|
. "os"
|
||||||
)
|
)
|
||||||
|
|
||||||
// no newlines between consecutive single imports, but
|
// no newlines between consecutive single imports, but
|
||||||
// respect extra line breaks in the source (at most one empty line)
|
// respect extra line breaks in the source (at most one empty line)
|
||||||
import _ "io"
|
import _ "io"
|
||||||
import _ "io"
|
import _ "io"
|
||||||
import _ "io"
|
import _ "io"
|
||||||
|
|
||||||
import _ "os"
|
import _ "os"
|
||||||
import _ "os"
|
import _ "os"
|
||||||
import _ "os"
|
import _ "os"
|
||||||
|
|
||||||
|
|
||||||
import _ "fmt"
|
import _ "fmt"
|
||||||
import _ "fmt"
|
import _ "fmt"
|
||||||
import _ "fmt"
|
import _ "fmt"
|
||||||
|
|
||||||
import "foo" // a comment
|
import "foo" // a comment
|
||||||
import "bar" // a comment
|
import "bar" // a comment
|
||||||
|
|
||||||
import (
|
import (
|
||||||
_ "foo"
|
_ "foo"
|
||||||
// a comment
|
// a comment
|
||||||
"bar"
|
"bar"
|
||||||
"foo" // a comment
|
"foo" // a comment
|
||||||
@ -63,17 +63,17 @@ import (
|
|||||||
// comments + renames
|
// comments + renames
|
||||||
import (
|
import (
|
||||||
"unrenamed" // a comment
|
"unrenamed" // a comment
|
||||||
renamed "renameMe"
|
renamed "renameMe"
|
||||||
. "io" /* a comment */
|
. "io" /* a comment */
|
||||||
_ "io/ioutil" // a comment
|
_ "io/ioutil" // a comment
|
||||||
"io" // testing alignment
|
"io" // testing alignment
|
||||||
. "os"
|
. "os"
|
||||||
// a comment
|
// a comment
|
||||||
)
|
)
|
||||||
|
|
||||||
// a case that caused problems in the past (comment placement)
|
// a case that caused problems in the past (comment placement)
|
||||||
import (
|
import (
|
||||||
. "fmt"
|
. "fmt"
|
||||||
"io"
|
"io"
|
||||||
"malloc" // for the malloc count test only
|
"malloc" // for the malloc count test only
|
||||||
"math"
|
"math"
|
||||||
@ -81,9 +81,38 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// more import examples
|
||||||
|
import (
|
||||||
|
"xxx"
|
||||||
|
"much longer name" // comment
|
||||||
|
"short name" // comment
|
||||||
|
)
|
||||||
|
|
||||||
|
import (
|
||||||
|
_ "xxx"
|
||||||
|
"much longer name" // comment
|
||||||
|
)
|
||||||
|
|
||||||
|
import (
|
||||||
|
mymath "math"
|
||||||
|
"/foo/bar/long_package_path" // a comment
|
||||||
|
)
|
||||||
|
|
||||||
|
import (
|
||||||
|
"package_a" // comment
|
||||||
|
"package_b"
|
||||||
|
my_better_c "package_c" // comment
|
||||||
|
"package_d" // comment
|
||||||
|
my_e "package_e" // comment
|
||||||
|
|
||||||
|
"package_a" // comment
|
||||||
|
"package_bb"
|
||||||
|
"package_ccc" // comment
|
||||||
|
"package_dddd" // comment
|
||||||
|
)
|
||||||
|
|
||||||
// at least one empty line between declarations of different kind
|
// at least one empty line between declarations of different kind
|
||||||
import _ "io"
|
import _ "io"
|
||||||
|
|
||||||
var _ int
|
var _ int
|
||||||
|
|
||||||
|
29
src/pkg/go/printer/testdata/declarations.input
vendored
29
src/pkg/go/printer/testdata/declarations.input
vendored
@ -81,6 +81,35 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// more import examples
|
||||||
|
import (
|
||||||
|
"xxx"
|
||||||
|
"much longer name" // comment
|
||||||
|
"short name" // comment
|
||||||
|
)
|
||||||
|
|
||||||
|
import (
|
||||||
|
_ "xxx"
|
||||||
|
"much longer name" // comment
|
||||||
|
)
|
||||||
|
|
||||||
|
import (
|
||||||
|
mymath "math"
|
||||||
|
"/foo/bar/long_package_path" // a comment
|
||||||
|
)
|
||||||
|
|
||||||
|
import (
|
||||||
|
"package_a" // comment
|
||||||
|
"package_b"
|
||||||
|
my_better_c "package_c" // comment
|
||||||
|
"package_d" // comment
|
||||||
|
my_e "package_e" // comment
|
||||||
|
|
||||||
|
"package_a" // comment
|
||||||
|
"package_bb"
|
||||||
|
"package_ccc" // comment
|
||||||
|
"package_dddd" // comment
|
||||||
|
)
|
||||||
|
|
||||||
// at least one empty line between declarations of different kind
|
// at least one empty line between declarations of different kind
|
||||||
import _ "io"
|
import _ "io"
|
||||||
|
Loading…
Reference in New Issue
Block a user