Skip to content

formatv2 does not keep well-balanced multi-line index expressions #4406

Description

@mvdan
exec cue-v0.16.1 fmt --diff in.cue
exec cue-v0.17.0-alpha.3 fmt --diff in.cue
exec cue-master fmt --diff in.cue

-- in.cue --
idx: bar[
	"baz"
]

> exec cue-v0.16.1 fmt --diff in.cue
[stderr]
expected ']', found newline:
    ./in.cue:2:7
missing ',' in struct literal:
    ./in.cue:3:1
[exit status 1]
FAIL: repro.txtar:1: unexpected command failure
> exec cue-v0.17.0-alpha.3 fmt --diff in.cue
[stdout]
diff in.cue.orig in.cue
--- in.cue.orig
+++ in.cue
@@ -1,3 +1,3 @@
 idx: bar[
-	"baz"
-]
+		"baz"
+		]

> exec cue-master fmt --diff in.cue
[stdout]
diff in.cue.orig in.cue
--- in.cue.orig
+++ in.cue
@@ -1,3 +1,2 @@
 idx: bar[
-	"baz"
-]
+	"baz"]

Support for a comma was added in v0.17, so ignore the fact that v0.16.0 fails.

Also ignore the fact that v0.17 leads to bad indentation. That's just the old formatter being buggy.

Regardless, formatv2 should be a no-op here; it shouldn't force ] to be collapsed when it's on a new line and well balanced with [ being at the end of a line.

Metadata

Metadata

Assignees

No one assigned

    Labels

    fmtRelated to formatting functionality.

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions