hcl/printer: newline after heredoc items in lists
This commit is contained in:
parent
e930f8e5fe
commit
4f76b0e04a
@ -503,7 +503,16 @@ func (p *printer) list(l *ast.ListType) []byte {
|
|||||||
val := p.output(item)
|
val := p.output(item)
|
||||||
curLen := len(val)
|
curLen := len(val)
|
||||||
buf.Write(p.indent(val))
|
buf.Write(p.indent(val))
|
||||||
buf.WriteString(",")
|
|
||||||
|
// if this item is a heredoc, then we output the comma on
|
||||||
|
// the next line. This is the only case this happens.
|
||||||
|
comma := []byte{','}
|
||||||
|
if lit, ok := item.(*ast.LiteralType); ok && lit.Token.Type == token.HEREDOC {
|
||||||
|
buf.WriteByte(newline)
|
||||||
|
comma = p.indent(comma)
|
||||||
|
}
|
||||||
|
|
||||||
|
buf.Write(comma)
|
||||||
|
|
||||||
if lit, ok := item.(*ast.LiteralType); ok && lit.LineComment != nil {
|
if lit, ok := item.(*ast.LiteralType); ok && lit.LineComment != nil {
|
||||||
// if the next item doesn't have any comments, do not align
|
// if the next item doesn't have any comments, do not align
|
||||||
|
@ -132,7 +132,7 @@ func format(src []byte) ([]byte, error) {
|
|||||||
|
|
||||||
// make sure formatted output is syntactically correct
|
// make sure formatted output is syntactically correct
|
||||||
if _, err := parser.Parse(formatted); err != nil {
|
if _, err := parser.Parse(formatted); err != nil {
|
||||||
return nil, fmt.Errorf("parse: %s\n%s", err, src)
|
return nil, fmt.Errorf("parse: %s\n%s", err, formatted)
|
||||||
}
|
}
|
||||||
|
|
||||||
return formatted, nil
|
return formatted, nil
|
||||||
|
11
hcl/printer/testdata/list.golden
vendored
11
hcl/printer/testdata/list.golden
vendored
@ -25,3 +25,14 @@ foo = [
|
|||||||
"ethiopia",
|
"ethiopia",
|
||||||
"columbia",
|
"columbia",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
foo = [
|
||||||
|
<<EOS
|
||||||
|
one
|
||||||
|
EOS
|
||||||
|
,
|
||||||
|
<<EOS
|
||||||
|
two
|
||||||
|
EOS
|
||||||
|
,
|
||||||
|
]
|
||||||
|
11
hcl/printer/testdata/list.input
vendored
11
hcl/printer/testdata/list.input
vendored
@ -19,3 +19,14 @@ foo = [1, 2,3, 4]
|
|||||||
foo = [
|
foo = [
|
||||||
"kenya", "ethiopia",
|
"kenya", "ethiopia",
|
||||||
"columbia"]
|
"columbia"]
|
||||||
|
|
||||||
|
foo = [
|
||||||
|
<<EOS
|
||||||
|
one
|
||||||
|
EOS
|
||||||
|
,
|
||||||
|
<<EOS
|
||||||
|
two
|
||||||
|
EOS
|
||||||
|
,
|
||||||
|
]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user