From 984d1e820160faeb0eb73f5145aac18d0d65019c Mon Sep 17 00:00:00 2001 From: nozaq Date: Tue, 23 Jul 2019 04:57:18 +0900 Subject: [PATCH] hclwrite: Fix improper indent calculation inside heredocs (#107) --- hclwrite/format.go | 13 ++----------- hclwrite/format_test.go | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 11 deletions(-) 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 = <