cue icon indicating copy to clipboard operation
cue copied to clipboard

cmd/fmt: comma appended to comment instead of list element

Open jdkaplan opened this issue 3 years ago • 1 comments

What version of CUE are you using (cue version)?

$ cue version
cue version v0.4.1 linux/amd64

What did you do?

I ran cue fmt on a file with a list of inline structs that ends in a comment rather than a value.

bug.cue:

l: [
	{},
	// comment
]
$ cue fmt bug.cue && cat bug.cue

What did you expect to see?

The input file should not have been changed, as it is correctly formatted.

What did you see instead?

l: [
	{}
	// comment,
]

If I format that file again, it appends another trailing comma:

l: [
	{}
	// comment,,
]

I get a new comma each time unless I add a value after the comment.

I'm very new to CUE, but I think this might be related to #1447 based on how both issues seem to interpret the comment as a list element.

jdkaplan avatar Jan 17 '22 01:01 jdkaplan

Also still exists on v0.4.3 darwin/arm64

danielpcox avatar Sep 08 '22 19:09 danielpcox

Note that this issue is extremely similar to https://github.com/cue-lang/cue/issues/2274, although that issue has an example where fmt's output CUE is invalid.

mvdan avatar Nov 08 '23 09:11 mvdan

As of cue v0.6.0 I cannot reproduce this bug

# issue #1478 is not reproducible as of cue v0.6.0---------
exec cat 1478G.cue
exec cue fmt 1478G.cue    ### fmt works
exec cat 1478G.cue
exec cue vet 1478G.cue    ### vet passes
cmp expected/1478G.cue 1478G.cue

-- 1478G.cue --
l: [
	{},
	// comment
]
-- expected/1478G.cue --
l: [
	{},
	// comment
]

rudifa avatar Nov 17 '23 13:11 rudifa

Thanks @rudifa! I can confirm the issue appears solved for me as well.

mvdan avatar Nov 17 '23 13:11 mvdan