printer: fix leadcomments for multiple comments
This commit is contained in:
parent
bbc2d19923
commit
3ee0cb44fa
@ -42,20 +42,14 @@ func (p *printer) output(n interface{}) []byte {
|
|||||||
return buf.Bytes()
|
return buf.Bytes()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *printer) comment(c *ast.CommentGroup) []byte {
|
|
||||||
var buf bytes.Buffer
|
|
||||||
for _, comment := range c.List {
|
|
||||||
buf.WriteString(comment.Text)
|
|
||||||
}
|
|
||||||
return buf.Bytes()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *printer) objectItem(o *ast.ObjectItem) []byte {
|
func (p *printer) objectItem(o *ast.ObjectItem) []byte {
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
|
|
||||||
if o.LeadComment != nil {
|
if o.LeadComment != nil {
|
||||||
buf.Write(p.comment(o.LeadComment))
|
for _, comment := range o.LeadComment.List {
|
||||||
buf.WriteByte(newline)
|
buf.WriteString(comment.Text)
|
||||||
|
buf.WriteByte(newline)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, k := range o.Keys {
|
for i, k := range o.Keys {
|
||||||
@ -73,7 +67,9 @@ func (p *printer) objectItem(o *ast.ObjectItem) []byte {
|
|||||||
|
|
||||||
if o.Val.Pos().Line == o.Keys[0].Pos().Line && o.LineComment != nil {
|
if o.Val.Pos().Line == o.Keys[0].Pos().Line && o.LineComment != nil {
|
||||||
buf.WriteByte(blank)
|
buf.WriteByte(blank)
|
||||||
buf.Write(p.comment(o.LineComment))
|
for _, comment := range o.LineComment.List {
|
||||||
|
buf.WriteString(comment.Text)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return buf.Bytes()
|
return buf.Bytes()
|
||||||
|
7
printer/testdata/comment.golden
vendored
7
printer/testdata/comment.golden
vendored
@ -4,6 +4,13 @@ variable "foo" {
|
|||||||
description = "bar" # yooo
|
description = "bar" # yooo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
aligned = {
|
||||||
|
a = "bar" # yoo1
|
||||||
|
default = "bar" #yoo2
|
||||||
|
bar = "bar" # yoo3
|
||||||
|
}
|
||||||
|
|
||||||
|
// fatih arslan
|
||||||
/* This is a developer test
|
/* This is a developer test
|
||||||
account and a multine comment */
|
account and a multine comment */
|
||||||
developer = ["fatih", "arslan"] // fatih arslan
|
developer = ["fatih", "arslan"] // fatih arslan
|
||||||
|
13
printer/testdata/comment.input
vendored
13
printer/testdata/comment.input
vendored
@ -4,6 +4,13 @@ variable "foo" {
|
|||||||
description = "bar" # yooo
|
description = "bar" # yooo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
aligned {
|
||||||
|
a = "bar" # yoo1
|
||||||
|
default = "bar" #yoo2
|
||||||
|
bar = "bar" # yoo3
|
||||||
|
}
|
||||||
|
|
||||||
|
// fatih arslan
|
||||||
/* This is a developer test
|
/* This is a developer test
|
||||||
account and a multine comment */
|
account and a multine comment */
|
||||||
developer = [ "fatih", "arslan"] // fatih arslan
|
developer = [ "fatih", "arslan"] // fatih arslan
|
||||||
@ -17,8 +24,8 @@ variable = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// lead comment
|
// lead comment
|
||||||
foo {
|
foo {
|
||||||
bar = "fatih" // line comment 2
|
bar = "fatih" // line comment 2
|
||||||
} // line comment 3
|
} // line comment 3
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user