hclwrite: Fix improper indent calculation inside heredocs (#107)
This commit is contained in:
parent
7fc56095bc
commit
984d1e8201
@ -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)
|
||||
}
|
||||
|
@ -548,6 +548,36 @@ EOT
|
||||
baz {
|
||||
default = "string"
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
`
|
||||
foo {
|
||||
bar = <<EOT
|
||||
Foo bar baz
|
||||
EOT
|
||||
baz = <<EOT
|
||||
Foo bar baz
|
||||
EOT
|
||||
}
|
||||
|
||||
bar {
|
||||
foo = "bar"
|
||||
}
|
||||
`,
|
||||
`
|
||||
foo {
|
||||
bar = <<EOT
|
||||
Foo bar baz
|
||||
EOT
|
||||
baz = <<EOT
|
||||
Foo bar baz
|
||||
EOT
|
||||
}
|
||||
|
||||
bar {
|
||||
foo = "bar"
|
||||
}
|
||||
`,
|
||||
},
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user