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

cue/fmt: Lists are indented too much #2314

Closed
uhthomas opened this issue Mar 25, 2023 · 4 comments
Closed

cue/fmt: Lists are indented too much #2314

uhthomas opened this issue Mar 25, 2023 · 4 comments
Labels
fmt Related to formatting functionality. NeedsInvestigation

Comments

@uhthomas
Copy link
Contributor

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

$ cue version
0.4.3-1

Does this issue reproduce with the latest stable release?

Yes.

What did you do?

import "list"

#List: items: list.Concat([
    a,

    b
])

What did you expect to see?

import "list"

#List: items: list.Concat([
    a,

    b
])

What did you see instead?

import "list"

#List: items: list.Concat([
        a,

    b
])
@uhthomas uhthomas added NeedsInvestigation Triage Requires triage/attention labels Mar 25, 2023
@uhthomas
Copy link
Contributor Author

FWIW, this is fine:

import "list"

items: list.Concat([
    a,

    b
])

Looks like a problem with shorthand notation and depth calculation. The formatter should understand that just because it's of depth: 2 does not mean that's how much it should be indented. Clearly the logic for this already exists as successive items are indented correctly.

@mvdan
Copy link
Member

mvdan commented Mar 28, 2023

Thank you, this does look like a formatting bug.

@mvdan mvdan added fmt Related to formatting functionality. and removed Triage Requires triage/attention labels Mar 28, 2023
@uhthomas
Copy link
Contributor Author

Looks like it's related to the length of the line.

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: list.Concat([
                                                ["a"],

        ["b"],
])

@Nemo157
Copy link

Nemo157 commented Apr 4, 2023

It seems to only trigger when the list is not the top-level value, i.e. this is fine:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: [
        ["a"],

        ["b"],
]

but these fail:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: _ | [
                                                ["a"],

        ["b"],
]

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: *[
                                                ["a"],

        ["b"],
]

if the subsequent lines don't change indentation then it continues using the incorrect indentation for them:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: *[
                                                ["a"],
                                                ["b"],
]

@myitcv myitcv added this to the fmt-redesign milestone Apr 27, 2023
@myitcv myitcv added zGarden and removed zGarden labels Jun 13, 2023
uhthomas added a commit to uhthomas/cue that referenced this issue Oct 11, 2023
Vertical tabs are not inserted when the next expression needs a form feed, but
are erroneously inserted for expressions which hide the underlying type. This is
fixed by recursively checking if expressions need a form feed.

Fixes: cue-lang#2314

Signed-off-by: Thomas Way <[email protected]>
uhthomas added a commit to uhthomas/cue that referenced this issue Oct 11, 2023
Vertical tabs are not inserted when the next expression needs a form feed, but
are erroneously inserted for expressions which hide the underlying type. This is
fixed by recursively checking if expressions need a form feed.

Fixes: cue-lang#2314

Signed-off-by: Thomas Way <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fmt Related to formatting functionality. NeedsInvestigation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants