From dac4796ca1468257e064e5be7626198bbf85aa17 Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Fri, 14 Dec 2018 15:53:02 -0800 Subject: [PATCH] hclwrite: Formatter to put spaces before colons 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. --- hclwrite/format.go | 4 ---- hclwrite/format_test.go | 12 ++++++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/hclwrite/format.go b/hclwrite/format.go index ad17121..ef50e09 100644 --- a/hclwrite/format.go +++ b/hclwrite/format.go @@ -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 diff --git a/hclwrite/format_test.go b/hclwrite/format_test.go index 9106466..b4783c2 100644 --- a/hclwrite/format_test.go +++ b/hclwrite/format_test.go @@ -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]`, }, { `