Skip to content

Commit

Permalink
hclwrite: fix space being added between interpolated items
Browse files Browse the repository at this point in the history
closes hashicorp#65
- add missing edge case for two interpolated items next to each other
- add tests for both quote and heredoc cases
  • Loading branch information
acburdine authored and apparentlymart committed Jan 16, 2019
1 parent 40e962e commit 7b147fb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions hclwrite/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,10 @@ func spaceAfterToken(subject, before, after *Token) bool {
case subject.Type == hclsyntax.TokenCBrace && after.Type == hclsyntax.TokenTemplateSeqEnd:
return true

// Don't add spaces between interpolated items
case subject.Type == hclsyntax.TokenTemplateSeqEnd && after.Type == hclsyntax.TokenTemplateInterp:
return false

case tokenBracketChange(subject) > 0:
// No spaces after open brackets
return false
Expand Down
20 changes: 20 additions & 0 deletions hclwrite/format_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ func TestFormat(t *testing.T) {
`a="hello ${~ name ~}"`,
`a = "hello ${~name~}"`,
},
{
`a="${b}${c}${ d } ${e}"`,
`a = "${b}${c}${d} ${e}"`,
},
{
`b{}`,
`b {}`,
Expand Down Expand Up @@ -500,6 +504,22 @@ foo {
${ { blahblahblah = x } }
EOT
}
`,
},
{
`
foo {
bar = <<-EOT
${a}${b}${ c } ${d}
EOT
}
`,
`
foo {
bar = <<-EOT
${a}${b}${c} ${d}
EOT
}
`,
},
}
Expand Down

0 comments on commit 7b147fb

Please sign in to comment.