From d6eb4cbdfaf42e42b25b8046e7f86cb263df1443 Mon Sep 17 00:00:00 2001 From: Varun Sivapalan <5470233+sivapalan@users.noreply.github.com> Date: Mon, 21 Sep 2020 21:21:56 +0200 Subject: [PATCH] hclwrite: do not add space after a bang --- hclwrite/format.go | 4 ++++ hclwrite/format_test.go | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/hclwrite/format.go b/hclwrite/format.go index b94bee38..2b4ba323 100644 --- a/hclwrite/format.go +++ b/hclwrite/format.go @@ -263,6 +263,10 @@ func spaceAfterToken(subject, before, after *Token) bool { case after.Type == hclsyntax.TokenOBrack && (subject.Type == hclsyntax.TokenIdent || subject.Type == hclsyntax.TokenNumberLit || tokenBracketChange(subject) < 0): return false + case subject.Type == hclsyntax.TokenBang: + // No space after a bang + return false + case subject.Type == hclsyntax.TokenMinus: // Since a minus can either be subtraction or negation, and the latter // should _not_ have a space after it, we need to use some heuristics diff --git a/hclwrite/format_test.go b/hclwrite/format_test.go index 241cc7a5..037157a9 100644 --- a/hclwrite/format_test.go +++ b/hclwrite/format_test.go @@ -67,6 +67,10 @@ func TestFormat(t *testing.T) { `foo(a,b...)`, `foo(a, b...)`, }, + { + `! true`, + `!true`, + }, { `a="hello ${ name }"`, `a = "hello ${name}"`,