summaryrefslogtreecommitdiff
path: root/caddyconfig/caddyfile
diff options
context:
space:
mode:
authorMatthew Penner <me@matthewp.io>2021-05-10 12:01:27 -0600
committerGitHub <noreply@github.com>2021-05-10 12:01:27 -0600
commitbc2210247861340c644d9825ac2b2860f8c6e12a (patch)
treeb17c0c3b702e635a2524904ae236cd1c4ccd4bc2 /caddyconfig/caddyfile
parentf5db41ce1d4bb5ac75489f11985ca46898fb642e (diff)
caddyfile: Fix `caddy fmt` nesting not decrementing (#4157)
* caddyfile(formatter): fix nesting not decrementing This is an extremely weird edge-case where if you had a environment variable {} on one line, a comment on the next line, and the closing of the block on the following line; the rest of the Caddyfile would be indented further than it should've been. ref; https://github.com/matthewpi/vscode-caddyfile-support/issues/13 * run gofmt * fmt: better way of handling edge case
Diffstat (limited to 'caddyconfig/caddyfile')
-rw-r--r--caddyconfig/caddyfile/formatter.go1
-rw-r--r--caddyconfig/caddyfile/formatter_test.go38
2 files changed, 39 insertions, 0 deletions
diff --git a/caddyconfig/caddyfile/formatter.go b/caddyconfig/caddyfile/formatter.go
index 8620219..cb0033f 100644
--- a/caddyconfig/caddyfile/formatter.go
+++ b/caddyconfig/caddyfile/formatter.go
@@ -78,6 +78,7 @@ func Format(input []byte) []byte {
if comment {
if ch == '\n' {
comment = false
+ space = true
nextLine()
continue
} else {
diff --git a/caddyconfig/caddyfile/formatter_test.go b/caddyconfig/caddyfile/formatter_test.go
index 6cae20d..64cf6d2 100644
--- a/caddyconfig/caddyfile/formatter_test.go
+++ b/caddyconfig/caddyfile/formatter_test.go
@@ -321,6 +321,44 @@ baz`,
foo
}`,
},
+ {
+ description: "matthewpi/vscode-caddyfile-support#13",
+ input: `{
+ email {$ACMEEMAIL}
+ #debug
+}
+
+block {
+}
+`,
+ expect: `{
+ email {$ACMEEMAIL}
+ #debug
+}
+
+block {
+}
+`,
+ },
+ {
+ description: "matthewpi/vscode-caddyfile-support#13 - bad formatting",
+ input: `{
+ email {$ACMEEMAIL}
+ #debug
+ }
+
+ block {
+ }
+`,
+ expect: `{
+ email {$ACMEEMAIL}
+ #debug
+}
+
+block {
+}
+`,
+ },
} {
// the formatter should output a trailing newline,
// even if the tests aren't written to expect that