Skip to content

cue/format: formatv2 shouldn't split long field lines after a colon #4395

Description

@mvdan
env CUE_EXPERIMENT=formatterv2=0
exec cue def in.cue
exec cue export --out cue in.cue

env CUE_EXPERIMENT=formatterv2=1
exec cue def in.cue
exec cue export --out cue in.cue

-- in.cue --
aVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongLine: "someVeryVeryVeryVeryLongValue"
> env CUE_EXPERIMENT=formatterv2=0
> exec cue def in.cue
[stdout]
aVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongLine: "someVeryVeryVeryVeryLongValue"
> exec cue export --out cue in.cue
[stdout]
aVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongLine: "someVeryVeryVeryVeryLongValue"
> env CUE_EXPERIMENT=formatterv2=1
> exec cue def in.cue
[stdout]
aVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongLine:
	"someVeryVeryVeryVeryLongValue"
> exec cue export --out cue in.cue
[stdout]
aVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongLine:
	"someVeryVeryVeryVeryLongValue"

Note how the new formatter seems fine with the style below:

foo:
    "bar"

This is perfectly valid CUE, and if a user writes CUE like this, the formatter shouldn't necessarily remove the newline. That said, I don't think we should encourage it by adding this newline on long lines.

For example, see #4172, where a user spent hours trying to figure out why this didn't work:

#RDLClass: {
    RDLClassDefinition: 
        id: string
        IMFType: #IMFType

To the trained CUE user, they can easily spot the problem; we can adjust the indentation to make it clearer:

#RDLClass: {
    RDLClassDefinition: 
        id: string
    IMFType: #IMFType

However, this mistake is very easy to make for users coming from languages such as YAML or Python, where indentation carries meaning.

In the original issue I argued that cue/format should always collapse a newline after a colon. We should keep that issue open for that idea. But here I'm asking for something much less aggressive; we should not introduce such a newline when splitting long lines.

Metadata

Metadata

Assignees

No one assigned

    Labels

    fmtRelated to formatting functionality.

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions