Skip to content

Commit

Permalink
Merge pull request #85 from VladRassokhin/fix-list-comments-indent
Browse files Browse the repository at this point in the history
Fix indent of list item comments
  • Loading branch information
mitchellh committed Feb 7, 2016
2 parents aa4dbbc + d8e4334 commit a01f759
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
8 changes: 2 additions & 6 deletions hcl/printer/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,12 +434,8 @@ func (p *printer) list(l *ast.ListType) []byte {
if lit, ok := item.(*ast.LiteralType); ok && lit.LineComment != nil {
// if the next item doesn't have any comments, do not align
buf.WriteByte(blank) // align one space
if i != len(l.List)-1 {
if lit, ok := l.List[i+1].(*ast.LiteralType); ok && lit.LineComment != nil {
for i := 0; i < longestLine-curLen; i++ {
buf.WriteByte(blank)
}
}
for i := 0; i < longestLine-curLen; i++ {
buf.WriteByte(blank)
}

for _, comment := range lit.LineComment.List {
Expand Down
7 changes: 7 additions & 0 deletions hcl/printer/testdata/comment_aligned.golden
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,11 @@ aligned {
"foo", # kenya 1
"${aws_security_group.firewall.foo}", # kenya 2
]

security_groups2 = [
"foo", # kenya 1
"bar", # kenya 1.5
"${aws_security_group.firewall.foo}", # kenya 2
"foobar", # kenya 3
]
}
7 changes: 7 additions & 0 deletions hcl/printer/testdata/comment_aligned.input
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,11 @@ security_groups = [
"foo", # kenya 1
"${aws_security_group.firewall.foo}", # kenya 2
]

security_groups2 = [
"foo", # kenya 1
"bar", # kenya 1.5
"${aws_security_group.firewall.foo}", # kenya 2
"foobar", # kenya 3
]
}

0 comments on commit a01f759

Please sign in to comment.