nixfmt icon indicating copy to clipboard operation
nixfmt copied to clipboard

Expansion of `\t` in strings

Open rycee opened this issue 5 years ago • 2 comments

Description

The \t form of tab characters in strings are expanded to a literal tab character. The result could be confused for space characters.

Small example input

"a\tb"

Expected output

"a\tb"

Actual output

"a	b"

rycee avatar Mar 05 '20 23:03 rycee

Nixfmt intentionally throws the choice between literal tab characters and escape codes away because it ensures semantically identical strings get formatted the same way. It uses heuristics in order to determine how they should be printed. In this case, I think an acceptable thing to do is to format only indentation as tabs and anything in the middle or end of a line as escape codes. I will try this out sometime soon.

Lucus16 avatar Mar 06 '20 13:03 Lucus16

Yeah, I think normalizing the formatting of tabs is a good idea. I don't have a very strong opinion in this instance since I so rarely encounter tabs in Nix strings.

Instead of different behavior depending on where the tab is in the string I think it would be best to have a very simple rule saying that \t is always expanded (i.e. to keep the existing behavior) or tabs are always contracted to \t. I'm slightly in favor of always contracting to \t for legibility reasons but I would not protest keeping the existing behavor.

rycee avatar Mar 07 '20 11:03 rycee

The RFC format states that string content should be preserved without doing any normalization. This is implemented as part of #118

piegamesde avatar Mar 14 '24 20:03 piegamesde