Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cue/format: omit whitespace before the first clause
When printing clauses, we often want to print a whitespace before the token "let", "if", and "for". For example: for i, v in src if i > 1 { As opposed to omitting spaces, which breaks the syntax: for i, v in srcif i > 1 { However, we also printed a space before the first clause in the list. This could result in a CUE file beginning with a space if the first token is a clause: $ cue fmt . $ cat if.cue if foo { } First, we fix that bug for clauses by not having walkClauseList call f.print(blank) before the first clause. Second, we also fix it for "let" declarations by teaching mayCombine about the previous token being ILLEGAL - meaning that we're printing the first token in the entire file. It is worth noting that this also changes how we print the first clause inside another expression; for instance: cfgs: [ for crd in ["one", "two"] { }] Now formats without the leading space, just like at the beginning of a file: cfgs: [for crd in ["one", "two"] { }] Arguably that is more consistent, as there is no space after the "for" clause, following the "}" token. Fixes #1544. Signed-off-by: Daniel Martí <mvdan@mvdan.cc> Change-Id: I72e4618f2b1011005316c617a32e0c3a6ff3b706 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/538624 TryBot-Result: CUEcueckoo <cueckoo@cuelang.org> Reviewed-by: Marcel van Lohuizen <mpvl@gmail.com> Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
- Loading branch information