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

Every time format, a comma is added. #1553

Closed
Coordinate-Cat opened this issue Feb 27, 2022 · 2 comments
Closed

Every time format, a comma is added. #1553

Coordinate-Cat opened this issue Feb 27, 2022 · 2 comments
Labels
fmt Related to formatting functionality. NeedsFix

Comments

@Coordinate-Cat
Copy link

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

$ cue version v0.4.2 darwin/amd64

Does this issue reproduce with the latest release?

yes

What did you do?

At first I thought it was a formatting bug in the vscode extension, but it seems to be reproduced in cue fmt, so I'm reporting it.
johnallen3d/vscode-cue-fmt#8

What did you expect to see?

What did you see instead?

I don't want commas to be added after formatting.

❯ cat test.cue
test: {
	test_list: {
		test_list_arr: [
			{
				name: "hoge"
			},
			{
				name: "fuga"
			},
		]
		// list: [
		//   {
		//     name: "hoge"
		//   }
		// ]
	}
	test_list2: {
		create: [
			{}
			// {
			//   name: "hoge"
			// },
			// {
			//   name: "fuga"
			// },
		]
	}
}

❯ cue fmt test.cue 

❯ cat test.cue
test: {
	test_list: {
		test_list_arr: [
			{
				name: "hoge"
			},
			{
				name: "fuga"
			},
		]
		// list: [
		//   {
		//     name: "hoge"
		//   }
		// ]
	}
	test_list2: {
		create: [
			{}                        <-------- Removing this object will fix it, but I don't want to remove it.
			// {
			//   name: "hoge"
			// },
			// {
			//   name: "fuga"
			// },,,,,,                <------- this
		]
	}
}
@Coordinate-Cat Coordinate-Cat added NeedsInvestigation Triage Requires triage/attention labels Feb 27, 2022
@mpvl mpvl added the fmt Related to formatting functionality. label Mar 4, 2022
@rogpeppe rogpeppe removed the Triage Requires triage/attention label Apr 19, 2022
@rogpeppe
Copy link
Member

Here's a simple testscript reproducer:

exec cue fmt x.cue
cp x.cue x1.cue
exec cue fmt x.cue
cmp x.cue x1.cue

-- x.cue --
[
	{} //
]

This fails for me as follows:

> exec cue fmt x.cue
> cp x.cue x1.cue
> exec cue fmt x.cue
> cmp x.cue x1.cue
--- x.cue
+++ x1.cue
@@ -1,3 +1,3 @@
 [
-	{} //,,
+	{} //,
 ]

FAIL: /tmp/testscript108976944/x.txtar/script.txt:4: x.cue and x1.cue differ
error running /tmp/x.txtar in /tmp/testscript108976944/x.txtar

testscript: exit 1

@mvdan
Copy link
Member

mvdan commented Jun 25, 2022

I am pretty sure that this is a duplicate of #1478, which is a bit older and has been correctly labelled for some time as well.

@mvdan mvdan closed this as not planned Won't fix, can't repro, duplicate, stale Jun 25, 2022
cueckoo pushed a commit that referenced this issue Jul 22, 2022
`cue fmt` unexpectedly adds trailing comma not before but after comment
if `StructLit` satisfies the following conditions:

* is an element of list
* has no element
* is before `Comment`

This CL:

* fix this issue
* add a new test data
* fix an existing test data

Close #1553
Signed-off-by: satotake <doublequotation@gmail.com>
Change-Id: Icd181b6c8bee651ff98cf17ca706d453f960b7b4
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/539255
Reviewed-by: Marcel van Lohuizen <mpvl@gmail.com>
Unity-Result: CUEcueckoo <cueckoo@cuelang.org>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
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

4 participants