cue icon indicating copy to clipboard operation
cue copied to clipboard

cue/syntax: error for mismatched white space in multiline strings could be improved

Open dave08 opened this issue 2 years ago • 3 comments

In the docs it says:

The whitespace directly preceding the closing quote must match the preceding whitespace on all other lines and is removed from these lines.

It uses the word "whitespace" which implies including tabs... but when tabs are used there's an error. Is using tabs disallowed? Or is this a bug that was overlooked?

dave08 avatar May 18 '22 09:05 dave08

Tabs are certainly allowed (and cue fmt will rewrite the indentation to use tabs), so perhaps you could provide a specific example that fails for you?

As an example, this CUE code in the playground uses tabs and works fine: https://cuelang.org/play/?id=MURHPZfKSdg#cue@export@cue

Note that the whitespace must match exactly - perhaps there was a space character hiding next to one of your tabs?

rogpeppe avatar May 18 '22 12:05 rogpeppe

That was the problem --- since I pasted from a ConfigMap yaml file (which has spaces), and Intellij cue plugin uses real tabs by default (which I can't set to be spaces for some reason)... but when I looked at the docs, the word "whitespace" doesn't mention that it needs to be one type, but rather seems to imply ANY type/combination of whitespace...

I'm starting to understand the sense of tabs not being able to replace the spaces with tabs since three spaces don't visually align with three tabs, so how would cue know when they're aligned... but the current situation is maybe worse, because in larger configs that come already indenting with a combination of the two (that's being pasted from somewhere else), it would be VERY difficult to find the error...

Maybe only enforce the same whitespace type on the line just before the closing """? It seems like even that returns an error... https://cuelang.org/play/?id=byJ-4Kf8fa3#cue@export@cue

dave08 avatar May 18 '22 13:05 dave08

Maybe only enforce the same whitespace type on the line just before the closing """?

It's that very white space that defines the white space that must appear before each line of the string, so that doesn't really make sense AFAICS.

in larger configs that come already indenting with a combination of the two (that's being pasted from somewhere else), it would be VERY difficult to find the error...

I think the latter assertion is the crux of the matter. The error message could use improvement to be more explicit about the source of the issue, and perhaps how it might be fixed. For example, it could point to the first location where the white space is inconsistent and the place where the indent is defined, and also say what the clash is.

Accordingly, since this issue isn't actually a bug, I'll retitle it to make it about improving the diagnostics in this kind of situation.

rogpeppe avatar May 18 '22 15:05 rogpeppe