cue/format: tweaks to support embeddings
allow:
Def :: {{
a: int
}}
Change-Id: I55dea1b45fb10515a9d358a4a40b021be420d86b
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/3240
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
diff --git a/cue/format/node.go b/cue/format/node.go
index ffd9eb4..196db20 100644
--- a/cue/format/node.go
+++ b/cue/format/node.go
@@ -265,7 +265,7 @@
f.print(formfeed)
}
f.expr(n.Expr)
- f.print(newline, newsection, nooverride) // force newline
+ f.print(newsection, noblank)
case *ast.Ellipsis:
f.ellipsis(n)
@@ -495,7 +495,10 @@
ws = noblank
if f.lineout != l {
- ws = newline | nooverride
+ ws |= newline
+ if f.lastTok != token.RBRACE && f.lastTok != token.RBRACK {
+ ws |= nooverride
+ }
}
f.print(ws, x.Rbrace, token.RBRACE)
diff --git a/cue/format/testdata/expressions.golden b/cue/format/testdata/expressions.golden
index 20a35a6..ae7d8bd 100644
--- a/cue/format/testdata/expressions.golden
+++ b/cue/format/testdata/expressions.golden
@@ -155,15 +155,13 @@
e: {for k, v in someObject if k > "a" {"\(k)": v}}
e: {for k, v in someObject if k > "a" {
"\(k)": v
- }
- }
+ }}
e: {
for k, v in someObject
if k > "a" {
"\(k)": v
- }
- }
+ }}
e: [{
a: 1, b: 2
diff --git a/doc/tutorial/kubernetes/README.md b/doc/tutorial/kubernetes/README.md
index ef7eeb1..d9d7a6c 100644
--- a/doc/tutorial/kubernetes/README.md
+++ b/doc/tutorial/kubernetes/README.md
@@ -500,7 +500,6 @@
} for c in v.spec.template.spec.containers
for p in c.ports
if p._export ]
-
}
}
EOF