Skip to content

Commit

Permalink
hclwrite: Formatter to put spaces before colons
Browse files Browse the repository at this point in the history
The symmetrical spaces around colons in conditionals are important for
familiarity with C-like languages, so we'll instead accept spaces around
colons in our HCL2-unique "for expression" construct.
  • Loading branch information
apparentlymart committed Dec 14, 2018
1 parent 4c4fdbd commit dac4796
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
4 changes: 0 additions & 4 deletions hclwrite/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,6 @@ func spaceAfterToken(subject, before, after *Token) bool {
}
return true

case after.Type == hclsyntax.TokenColon:
// Never spaces before colons
return false

// In the unlikely event that an interpolation expression is just
// a single object constructor, we'll put a space between the ${ and
// the following { to make this more obvious, and then the same
Expand Down
12 changes: 8 additions & 4 deletions hclwrite/format_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,21 @@ foo(
)
`,
},
{
`a?b:c`,
`a ? b : c`,
},
{
`[ [ ] ]`,
`[[]]`,
},
{
`[for x in y: x]`,
`[for x in y: x]`,
`[for x in y : x]`,
`[for x in y : x]`,
},
{
`[for x in [y]: x]`,
`[for x in [y]: x]`,
`[for x in [y] : x]`,
`[for x in [y] : x]`,
},
{
`
Expand Down

0 comments on commit dac4796

Please sign in to comment.