aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/github.com/hashicorp/hcl2/hclwrite/format.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/hashicorp/hcl2/hclwrite/format.go')
-rw-r--r--vendor/github.com/hashicorp/hcl2/hclwrite/format.go35
1 files changed, 3 insertions, 32 deletions
diff --git a/vendor/github.com/hashicorp/hcl2/hclwrite/format.go b/vendor/github.com/hashicorp/hcl2/hclwrite/format.go
index f20ae23..ded7fb4 100644
--- a/vendor/github.com/hashicorp/hcl2/hclwrite/format.go
+++ b/vendor/github.com/hashicorp/hcl2/hclwrite/format.go
@@ -54,22 +54,12 @@ func formatIndent(lines []formatLine) {
54 // which should be more than enough for reasonable HCL uses. 54 // which should be more than enough for reasonable HCL uses.
55 indents := make([]int, 0, 10) 55 indents := make([]int, 0, 10)
56 56
57 inHeredoc := false
58 for i := range lines { 57 for i := range lines {
59 line := &lines[i] 58 line := &lines[i]
60 if len(line.lead) == 0 { 59 if len(line.lead) == 0 {
61 continue 60 continue
62 } 61 }
63 62
64 if inHeredoc {
65 for _, token := range line.lead {
66 if token.Type == hclsyntax.TokenCHeredoc {
67 inHeredoc = false
68 }
69 }
70 continue // don't touch indentation inside heredocs
71 }
72
73 if line.lead[0].Type == hclsyntax.TokenNewline { 63 if line.lead[0].Type == hclsyntax.TokenNewline {
74 // Never place spaces before a newline 64 // Never place spaces before a newline
75 line.lead[0].SpacesBefore = 0 65 line.lead[0].SpacesBefore = 0
@@ -80,9 +70,10 @@ func formatIndent(lines []formatLine) {
80 for _, token := range line.lead { 70 for _, token := range line.lead {
81 netBrackets += tokenBracketChange(token) 71 netBrackets += tokenBracketChange(token)
82 if token.Type == hclsyntax.TokenOHeredoc { 72 if token.Type == hclsyntax.TokenOHeredoc {
83 inHeredoc = true 73 break
84 } 74 }
85 } 75 }
76
86 for _, token := range line.assign { 77 for _, token := range line.assign {
87 netBrackets += tokenBracketChange(token) 78 netBrackets += tokenBracketChange(token)
88 } 79 }
@@ -391,9 +382,9 @@ func linesForFormat(tokens Tokens) []formatLine {
391 382
392 // Now we'll pick off any trailing comments and attribute assignments 383 // Now we'll pick off any trailing comments and attribute assignments
393 // to shuffle off into the "comment" and "assign" cells. 384 // to shuffle off into the "comment" and "assign" cells.
394 inHeredoc := false
395 for i := range lines { 385 for i := range lines {
396 line := &lines[i] 386 line := &lines[i]
387
397 if len(line.lead) == 0 { 388 if len(line.lead) == 0 {
398 // if the line is empty then there's nothing for us to do 389 // if the line is empty then there's nothing for us to do
399 // (this should happen only for the final line, because all other 390 // (this should happen only for the final line, because all other
@@ -401,26 +392,6 @@ func linesForFormat(tokens Tokens) []formatLine {
401 continue 392 continue
402 } 393 }
403 394
404 if inHeredoc {
405 for _, tok := range line.lead {
406 if tok.Type == hclsyntax.TokenCHeredoc {
407 inHeredoc = false
408 break
409 }
410 }
411 // Inside a heredoc everything is "lead", even if there's a
412 // template interpolation embedded in there that might otherwise
413 // confuse our logic below.
414 continue
415 }
416
417 for _, tok := range line.lead {
418 if tok.Type == hclsyntax.TokenOHeredoc {
419 inHeredoc = true
420 break
421 }
422 }
423
424 if len(line.lead) > 1 && line.lead[len(line.lead)-1].Type == hclsyntax.TokenComment { 395 if len(line.lead) > 1 && line.lead[len(line.lead)-1].Type == hclsyntax.TokenComment {
425 line.comment = line.lead[len(line.lead)-1:] 396 line.comment = line.lead[len(line.lead)-1:]
426 line.lead = line.lead[:len(line.lead)-1] 397 line.lead = line.lead[:len(line.lead)-1]