mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
gofmt: more consistent formatting of const/var decls
- gofmt -w src misc - only manually modified file: src/pkg/go/printer/nodes.go R=rsc CC=golang-dev, r https://golang.org/cl/606041
This commit is contained in:
parent
74fac99d05
commit
53f3d0733c
16 changed files with 138 additions and 88 deletions
|
|
@ -1105,11 +1105,6 @@ const (
|
||||||
// multiLine to true if the spec spans multiple lines.
|
// multiLine to true if the spec spans multiple lines.
|
||||||
//
|
//
|
||||||
func (p *printer) spec(spec ast.Spec, n int, context declContext, indent bool, multiLine *bool) {
|
func (p *printer) spec(spec ast.Spec, n int, context declContext, indent bool, multiLine *bool) {
|
||||||
var (
|
|
||||||
comment *ast.CommentGroup // a line comment, if any
|
|
||||||
extraTabs int // number of extra tabs before comment, if any
|
|
||||||
)
|
|
||||||
|
|
||||||
switch s := spec.(type) {
|
switch s := spec.(type) {
|
||||||
case *ast.ImportSpec:
|
case *ast.ImportSpec:
|
||||||
p.setComment(s.Doc)
|
p.setComment(s.Doc)
|
||||||
|
|
@ -1118,7 +1113,7 @@ func (p *printer) spec(spec ast.Spec, n int, context declContext, indent bool, m
|
||||||
p.print(blank)
|
p.print(blank)
|
||||||
}
|
}
|
||||||
p.expr(s.Path, multiLine)
|
p.expr(s.Path, multiLine)
|
||||||
comment = s.Comment
|
p.setComment(s.Comment)
|
||||||
|
|
||||||
case *ast.ValueSpec:
|
case *ast.ValueSpec:
|
||||||
p.setComment(s.Doc)
|
p.setComment(s.Doc)
|
||||||
|
|
@ -1132,23 +1127,27 @@ func (p *printer) spec(spec ast.Spec, n int, context declContext, indent bool, m
|
||||||
p.print(blank, token.ASSIGN)
|
p.print(blank, token.ASSIGN)
|
||||||
p.exprList(noPos, s.Values, 1, blankStart|commaSep, multiLine, noPos)
|
p.exprList(noPos, s.Values, 1, blankStart|commaSep, multiLine, noPos)
|
||||||
}
|
}
|
||||||
|
p.setComment(s.Comment)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
extraTabs = 2
|
extraTabs := 3
|
||||||
if s.Type != nil || s.Values != nil {
|
|
||||||
p.print(vtab)
|
|
||||||
}
|
|
||||||
if s.Type != nil {
|
if s.Type != nil {
|
||||||
|
p.print(vtab)
|
||||||
p.expr(s.Type, multiLine)
|
p.expr(s.Type, multiLine)
|
||||||
extraTabs = 1
|
extraTabs--
|
||||||
}
|
}
|
||||||
if s.Values != nil {
|
if s.Values != nil {
|
||||||
p.print(vtab)
|
p.print(vtab, token.ASSIGN)
|
||||||
p.print(token.ASSIGN)
|
|
||||||
p.exprList(noPos, s.Values, 1, blankStart|commaSep, multiLine, noPos)
|
p.exprList(noPos, s.Values, 1, blankStart|commaSep, multiLine, noPos)
|
||||||
extraTabs = 0
|
extraTabs--
|
||||||
|
}
|
||||||
|
if s.Comment != nil {
|
||||||
|
for ; extraTabs > 0; extraTabs-- {
|
||||||
|
p.print(vtab)
|
||||||
|
}
|
||||||
|
p.setComment(s.Comment)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
comment = s.Comment
|
|
||||||
|
|
||||||
case *ast.TypeSpec:
|
case *ast.TypeSpec:
|
||||||
p.setComment(s.Doc)
|
p.setComment(s.Doc)
|
||||||
|
|
@ -1159,18 +1158,11 @@ func (p *printer) spec(spec ast.Spec, n int, context declContext, indent bool, m
|
||||||
p.print(vtab)
|
p.print(vtab)
|
||||||
}
|
}
|
||||||
p.expr(s.Type, multiLine)
|
p.expr(s.Type, multiLine)
|
||||||
comment = s.Comment
|
p.setComment(s.Comment)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
panic("unreachable")
|
panic("unreachable")
|
||||||
}
|
}
|
||||||
|
|
||||||
if comment != nil {
|
|
||||||
for ; extraTabs > 0; extraTabs-- {
|
|
||||||
p.print(vtab)
|
|
||||||
}
|
|
||||||
p.setComment(comment)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
29
src/pkg/go/printer/testdata/comments.golden
vendored
29
src/pkg/go/printer/testdata/comments.golden
vendored
|
|
@ -14,6 +14,35 @@ const (
|
||||||
c2 // c2
|
c2 // c2
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Alignment of comments in declarations>
|
||||||
|
const (
|
||||||
|
_ T = iota // comment
|
||||||
|
_ // comment
|
||||||
|
_ // comment
|
||||||
|
_ = iota + 10
|
||||||
|
_ // comments
|
||||||
|
|
||||||
|
_ = 10 // comment
|
||||||
|
_ T = 20 // comment
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
_____ = iota // foo
|
||||||
|
_ // bar
|
||||||
|
_ = 0 // bal
|
||||||
|
_ // bat
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
_ T = iota // comment
|
||||||
|
_ // comment
|
||||||
|
_ // comment
|
||||||
|
_ = iota + 10
|
||||||
|
_ // comment
|
||||||
|
_ = 10
|
||||||
|
_ = 20 // comment
|
||||||
|
_ T = 0 // comment
|
||||||
|
)
|
||||||
|
|
||||||
// The SZ struct; it is empty.
|
// The SZ struct; it is empty.
|
||||||
type SZ struct{}
|
type SZ struct{}
|
||||||
|
|
|
||||||
29
src/pkg/go/printer/testdata/comments.input
vendored
29
src/pkg/go/printer/testdata/comments.input
vendored
|
|
@ -14,6 +14,35 @@ const (
|
||||||
c2 // c2
|
c2 // c2
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Alignment of comments in declarations>
|
||||||
|
const (
|
||||||
|
_ T = iota // comment
|
||||||
|
_ // comment
|
||||||
|
_ // comment
|
||||||
|
_ = iota+10
|
||||||
|
_ // comments
|
||||||
|
|
||||||
|
_ = 10 // comment
|
||||||
|
_ T = 20 // comment
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
_____ = iota // foo
|
||||||
|
_ // bar
|
||||||
|
_ = 0 // bal
|
||||||
|
_ // bat
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
_ T = iota // comment
|
||||||
|
_ // comment
|
||||||
|
_ // comment
|
||||||
|
_ = iota + 10
|
||||||
|
_ // comment
|
||||||
|
_ = 10
|
||||||
|
_ = 20 // comment
|
||||||
|
_ T = 0 // comment
|
||||||
|
)
|
||||||
|
|
||||||
// The SZ struct; it is empty.
|
// The SZ struct; it is empty.
|
||||||
type SZ struct {}
|
type SZ struct {}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue