summaryrefslogtreecommitdiff
path: root/hclwrite/format.go
diff options
context:
space:
mode:
Diffstat (limited to 'hclwrite/format.go')
-rw-r--r--hclwrite/format.go22
1 files changed, 9 insertions, 13 deletions
diff --git a/hclwrite/format.go b/hclwrite/format.go
index dc7bc73..dca247e 100644
--- a/hclwrite/format.go
+++ b/hclwrite/format.go
@@ -4,16 +4,6 @@ import (
"github.com/hashicorp/hcl/v2/hclsyntax"
)
-var inKeyword = hclsyntax.Keyword([]byte{'i', 'n'})
-
-// placeholder token used when we don't have a token but we don't want
-// to pass a real "nil" and complicate things with nil pointer checks
-var nilToken = &Token{
- Type: hclsyntax.TokenNil,
- Bytes: []byte{},
- SpacesBefore: 0,
-}
-
// format rewrites tokens within the given sequence, in-place, to adjust the
// whitespace around their content to achieve canonical formatting.
func format(tokens Tokens) {
@@ -108,6 +98,14 @@ func formatIndent(lines []formatLine) {
}
func formatSpaces(lines []formatLine) {
+ // placeholder token used when we don't have a token but we don't want
+ // to pass a real "nil" and complicate things with nil pointer checks
+ nilToken := &Token{
+ Type: hclsyntax.TokenNil,
+ Bytes: []byte{},
+ SpacesBefore: 0,
+ }
+
for _, line := range lines {
for i, token := range line.lead {
var before, after *Token
@@ -156,7 +154,6 @@ func formatSpaces(lines []formatLine) {
}
func formatCells(lines []formatLine) {
-
chainStart := -1
maxColumns := 0
@@ -218,7 +215,6 @@ func formatCells(lines []formatLine) {
if chainStart != -1 {
closeCommentChain(len(lines))
}
-
}
// spaceAfterToken decides whether a particular subject token should have a
@@ -251,7 +247,7 @@ func spaceAfterToken(subject, before, after *Token) bool {
// No extra spaces within templates
return false
- case inKeyword.TokenMatches(subject.asHCLSyntax()) && before.Type == hclsyntax.TokenIdent:
+ case hclsyntax.Keyword([]byte{'i', 'n'}).TokenMatches(subject.asHCLSyntax()) && before.Type == hclsyntax.TokenIdent:
// This is a special case for inside for expressions where a user
// might want to use a literal tuple constructor:
// [for x in [foo]: x]