Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jdkaplan opened this issue Jan 17, 2022 · 4 comments
Closed

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

jdkaplan opened this issue Jan 17, 2022 · 4 comments
Labels
fmt Related to formatting functionality. NeedsFix

Comments

@jdkaplan
Copy link

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 jdkaplan added NeedsInvestigation Triage Requires triage/attention labels Jan 17, 2022
@mpvl mpvl added fmt Related to formatting functionality. NeedsFix and removed NeedsInvestigation Triage Requires triage/attention labels Jan 17, 2022
@danielpcox
Copy link

Also still exists on v0.4.3 darwin/arm64

@myitcv myitcv added this to the fmt-redesign milestone Apr 27, 2023
@myitcv myitcv added the zGarden label Jun 13, 2023
@mvdan mvdan added the good first issue Good for newcomers label Oct 23, 2023
@mvdan
Copy link
Member

mvdan commented Nov 8, 2023

Note that this issue is extremely similar to #2274, although that issue has an example where fmt's output CUE is invalid.

@rudifa
Copy link
Contributor

rudifa commented Nov 17, 2023

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
]

@mvdan
Copy link
Member

mvdan commented Nov 17, 2023

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

@mvdan mvdan closed this as completed Nov 17, 2023
@mvdan mvdan removed the good first issue Good for newcomers label Nov 17, 2023
@mvdan mvdan removed the zGarden label Jan 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fmt Related to formatting functionality. NeedsFix
Projects
None yet
Development

No branches or pull requests

6 participants