diff --git a/printer/nodes.go b/printer/nodes.go index bba5acb..6dc8e7f 100644 --- a/printer/nodes.go +++ b/printer/nodes.go @@ -42,20 +42,14 @@ 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)) - buf.WriteByte(newline) + for _, comment := range o.LeadComment.List { + buf.WriteString(comment.Text) + buf.WriteByte(newline) + } } 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 { buf.WriteByte(blank) - buf.Write(p.comment(o.LineComment)) + for _, comment := range o.LineComment.List { + buf.WriteString(comment.Text) + } } return buf.Bytes() diff --git a/printer/testdata/comment.golden b/printer/testdata/comment.golden index f14d003..6587adb 100644 --- a/printer/testdata/comment.golden +++ b/printer/testdata/comment.golden @@ -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 diff --git a/printer/testdata/comment.input b/printer/testdata/comment.input index 7f0615c..725017b 100644 --- a/printer/testdata/comment.input +++ b/printer/testdata/comment.input @@ -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,8 +24,8 @@ variable = { } -// lead comment + // lead comment foo { - bar = "fatih" // line comment 2 -} // line comment 3 + bar = "fatih" // line comment 2 +} // line comment 3