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:
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.
Note how the new formatter seems fine with the style below:
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:
To the trained CUE user, they can easily spot the problem; we can adjust the indentation to make it clearer:
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/formatshould 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.