Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix indent of list item comments #85

Merged
merged 1 commit into from
Feb 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix indent of list item comments
  • Loading branch information
VladRassokhin committed Feb 7, 2016
commit d8e433406ef054e85bf51dc701722bba2cec7afd
8 changes: 2 additions & 6 deletions hcl/printer/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,12 +432,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
]
}