diff --git a/hclwrite/format.go b/hclwrite/format.go index f20ae23..0cb0bac 100644 --- a/hclwrite/format.go +++ b/hclwrite/format.go @@ -54,22 +54,12 @@ func formatIndent(lines []formatLine) { // which should be more than enough for reasonable HCL uses. indents := make([]int, 0, 10) - inHeredoc := false for i := range lines { line := &lines[i] if len(line.lead) == 0 { continue } - if inHeredoc { - for _, token := range line.lead { - if token.Type == hclsyntax.TokenCHeredoc { - inHeredoc = false - } - } - continue // don't touch indentation inside heredocs - } - if line.lead[0].Type == hclsyntax.TokenNewline { // Never place spaces before a newline line.lead[0].SpacesBefore = 0 @@ -80,9 +70,10 @@ func formatIndent(lines []formatLine) { for _, token := range line.lead { netBrackets += tokenBracketChange(token) if token.Type == hclsyntax.TokenOHeredoc { - inHeredoc = true + break } } + for _, token := range line.assign { netBrackets += tokenBracketChange(token) } diff --git a/hclwrite/format_test.go b/hclwrite/format_test.go index 6f64b07..5445494 100644 --- a/hclwrite/format_test.go +++ b/hclwrite/format_test.go @@ -548,6 +548,36 @@ EOT baz { default = "string" } +`, + }, + { + ` +foo { +bar = <