-
Notifications
You must be signed in to change notification settings - Fork 278
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: fmt emits invalid CUE when commenting struct references in lists #2274
Comments
I also observe this. It's annoying as the comma is appended every time A really minimal example still produces this. a: [
"a"
// b,
] |
Thanks @jpluscplusm. Here's a slight rework of your example to make it clearer what the output from
Just to clarify however, my script above will fail when this bug is fixed because the |
Another reproducer: foo: [
"bar" + 1 // some comment,,,,,,,
] I don't believe this happens with basic elements though? |
I took a look at the fmt implementation and managed to reproduce quite a few more cases where this breaks:
|
When list elements are formatted in cue/format, the algorithm prints each element followed by a comment. In case an element has associated comments, they are printed as part of the element. This causes an issue when the comments appear after the element, because the comma will be printed at the end of the comment, and will ulimately be considered part of the comment, causing syntax errors. For example, given the following valid example: list: [ a.b, // selector (a), // paren +1, // unary a[0], // index strings.Sort([1, 2]), // call a.b, // under selector a.b, // multiple // under // selector ] The current formatting logic will produce this: list: [ a.b // selector, (a // paren), +1 // unary, a[0 // index], strings.Sort([1, 2], // call), a.b // under selector, a.b // multiple // under // selector, ] To resolve this, all comments that appear after an element are temporarily disassociated from the element, so that the list formatting section can insert the comma in the correct location. The solution could be cleaner, but a larger refactor is avoided since an overhaul of cue/format is planned. Fixes #2274 Updates #2567 Signed-off-by: Noam Dolovich <noam.tzvi.dolovich@gmail.com> Change-Id: Icbbb10800ed3f04bd5adc658b883fa259844b7e9
When list elements are formatted in cue/format, the algorithm prints each element followed by a comment. In case an element has associated comments, they are printed as part of the element. This causes an issue when the comments appear after the element, because the comma will be printed at the end of the comment, and will ulimately be considered part of the comment, causing syntax errors. For example, given the following valid example: list: [ a.b, // selector (a), // paren +1, // unary a[0], // index strings.Sort([1, 2]), // call a.b, // under selector a.b, // multiple // under // selector ] The current formatting logic will produce this: list: [ a.b // selector, (a // paren), +1 // unary, a[0 // index], strings.Sort([1, 2], // call), a.b // under selector, a.b // multiple // under // selector, ] To resolve this, all comments that appear after an element are temporarily disassociated from the element, so that the list formatting section can insert the comma in the correct location. The solution could be cleaner, but a larger refactor is avoided since an overhaul of cue/format is planned. Fixes #2274 Updates #2567 Signed-off-by: Noam Dolovich <noam.tzvi.dolovich@gmail.com> Change-Id: Icbbb10800ed3f04bd5adc658b883fa259844b7e9
When list elements are formatted in cue/format, the algorithm prints each element followed by a comment. In case an element has associated comments, they are printed as part of the element. This causes an issue when the comments appear after the element, because the comma will be printed at the end of the comment, and will ulimately be considered part of the comment, causing syntax errors. For example, given the following valid example: list: [ a.b, // selector (a), // paren +1, // unary a[0], // index strings.Sort([1, 2]), // call a.b, // under selector a.b, // multiple // under // selector ] The current formatting logic will produce this: list: [ a.b // selector, (a // paren), +1 // unary, a[0 // index], strings.Sort([1, 2], // call), a.b // under selector, a.b // multiple // under // selector, ] To resolve this, all comments that appear after an element are temporarily disassociated from the element, so that the list formatting section can insert the comma in the correct location. The solution could be cleaner, but a larger refactor is avoided since an overhaul of cue/format is planned. Fixes #2274 Updates #2567 Signed-off-by: Noam Dolovich <noam.tzvi.dolovich@gmail.com> Change-Id: Icbbb10800ed3f04bd5adc658b883fa259844b7e9
When list elements are formatted in cue/format, the algorithm prints each element followed by a comment. In case an element has associated comments, they are printed as part of the element. This causes an issue when the comments appear after the element, because the comma will be printed at the end of the comment, and will ulimately be considered part of the comment, causing syntax errors. For example, given the following valid example: list: [ a.b, // selector (a), // paren +1, // unary a[0], // index strings.Sort([1, 2]), // call a.b, // under selector a.b, // multiple // under // selector ] The current formatting logic will produce this: list: [ a.b // selector, (a // paren), +1 // unary, a[0 // index], strings.Sort([1, 2], // call), a.b // under selector, a.b // multiple // under // selector, ] To resolve this, all comments that appear after an element are temporarily disassociated from the element, so that the list formatting section can insert the comma in the correct location. The solution could be cleaner, but a larger refactor is avoided since an overhaul of cue/format is planned. Fixes #2274 Updates #2567 Signed-off-by: Noam Dolovich <noam.tzvi.dolovich@gmail.com> Change-Id: Icbbb10800ed3f04bd5adc658b883fa259844b7e9
When list elements are formatted in cue/format, the algorithm prints each element followed by a comment. In case an element has associated comments, they are printed as part of the element. This causes an issue when the comments appear after the element, because the comma will be printed at the end of the comment, and will ulimately be considered part of the comment, causing syntax errors. For example, given the following valid example: list: [ a.b, // selector (a), // paren +1, // unary a[0], // index strings.Sort([1, 2]), // call a.b, // under selector a.b, // multiple // under // selector ] The current formatting logic will produce this: list: [ a.b // selector, (a // paren), +1 // unary, a[0 // index], strings.Sort([1, 2], // call), a.b // under selector, a.b // multiple // under // selector, ] To resolve this, all comments that appear after an element are temporarily disassociated from the element, so that the list formatting section can insert the comma in the correct location. The solution could be cleaner, but a larger refactor is avoided since an overhaul of cue/format is planned. Fixes #2274 Updates #2567 Signed-off-by: Noam Dolovich <noam.tzvi.dolovich@gmail.com> Change-Id: Icbbb10800ed3f04bd5adc658b883fa259844b7e9
When list elements are formatted in cue/format, the algorithm prints each element followed by a comment. In case an element has associated comments, they are printed as part of the element. This causes an issue when the comments appear after the element, because the comma will be printed at the end of the comment, and will ulimately be considered part of the comment, causing syntax errors. For example, given the following valid example: list: [ a.b, // selector (a), // paren +1, // unary a[0], // index strings.Sort([1, 2]), // call a.b, // under selector a.b, // multiple // under // selector ] The current formatting logic will produce this: list: [ a.b // selector, (a // paren), +1 // unary, a[0 // index], strings.Sort([1, 2], // call), a.b // under selector, a.b // multiple // under // selector, ] To resolve this, all comments that appear after an element are temporarily disassociated from the element, so that the list formatting section can insert the comma in the correct location. The solution could be cleaner, but a larger refactor is avoided since an overhaul of cue/format is planned. Fixes #2274 Updates #2567 Signed-off-by: Noam Dolovich <noam.tzvi.dolovich@gmail.com> Change-Id: Icbbb10800ed3f04bd5adc658b883fa259844b7e9
When list elements are formatted in cue/format, the algorithm prints each element followed by a comma. In case an element has associated comments, they are printed as part of the element. This causes an issue when the comments appear after the element, because the comma will be printed at the end of the comment, and will ulimately be considered part of the comment, causing syntax errors. For example, given the following valid example: list: [ a.b, // selector (a), // paren +1, // unary a[0], // index strings.Sort([1, 2]), // call a.b, // under selector a.b, // multiple // under // selector ] The current formatting logic will produce this: list: [ a.b // selector, (a // paren), +1 // unary, a[0 // index], strings.Sort([1, 2], // call), a.b // under selector, a.b // multiple // under // selector, ] To resolve this, all comments that appear after an element are temporarily disassociated from the element, so that the list formatting section can insert the comma in the correct location. The solution could be cleaner, but a larger refactor is avoided since an overhaul of cue/format is planned. Fixes #2274 Updates #2567 Signed-off-by: Noam Dolovich <noam.tzvi.dolovich@gmail.com> Change-Id: Icbbb10800ed3f04bd5adc658b883fa259844b7e9
What version of CUE are you using (
cue version
)?Does this issue reproduce with the latest stable release?
Yes.
What did you do?
My editor runs
cue fmt
when it saves a .cue file.Just occasionally I was being confused by
cue
command failures -- happening later on in the development process where I pointed the CUE CLI at a .cue file -- where I was /sure/ I'd not hadcue fmt
failures when saving the file and exiting ... but then I discovered syntax errors in the file.Eventually I realised: I wasn't introducing the errors -
cue fmt
was.Sometimes
cue fmt
gets confused about trailing comments, and moves required list item separators inside the comment. Here's a txtar repro wherecue fmt
emits invalidate CUE:The bug seems to be picky about the lists it infects, and there's a slightly different list/comment scenario I've seen it fail in. Here, the blank line after the comment seems important: removing it stops the bug ocurring.
Both /seem/ to be related to that struct usage, and I've not managed to get the bug to affect a simpler list form.
What did you expect to see?
I expected to be able to put comments wherever I like; and for
cue fmt
either to tell me their form is not acceptable, or to emit valid CUE.What did you see instead?
cue fmt
emits invalid CUE.The text was updated successfully, but these errors were encountered: