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