Merge pull request #165 from hashicorp/b-string-fmt

hcl/printer: multiline strings don't indent lines 2+
This commit is contained in:
Mitchell Hashimoto 2016-11-03 18:42:59 -07:00 committed by GitHub
commit f74cf82815
4 changed files with 23 additions and 1 deletions

View File

@ -195,7 +195,8 @@ func (p *printer) output(n interface{}) []byte {
func (p *printer) literalType(lit *ast.LiteralType) []byte {
result := []byte(lit.Token.Text)
if lit.Token.Type == token.HEREDOC {
switch lit.Token.Type {
case token.HEREDOC:
// Clear the trailing newline from heredocs
if result[len(result)-1] == '\n' {
result = result[:len(result)-1]
@ -203,6 +204,12 @@ func (p *printer) literalType(lit *ast.LiteralType) []byte {
// Poison lines 2+ so that we don't indent them
result = p.heredocIndent(result)
case token.STRING:
// If this is a multiline string, poison lines 2+ so we don't
// indent them.
if bytes.ContainsRune(result, '\n') {
result = p.heredocIndent(result)
}
}
return result

View File

@ -40,6 +40,7 @@ var data = []entry{
{"comment_standalone.input", "comment_standalone.golden"},
{"empty_block.input", "empty_block.golden"},
{"list_of_objects.input", "list_of_objects.golden"},
{"multiline_string.input", "multiline_string.golden"},
}
func TestFiles(t *testing.T) {

View File

@ -0,0 +1,7 @@
resource "null_resource" "some_command" {
provisioner "local-exec" {
command = "echo '
some newlines
and additonal output'"
}
}

View File

@ -0,0 +1,7 @@
resource "null_resource" "some_command" {
provisioner "local-exec" {
command = "echo '
some newlines
and additonal output'"
}
}