nixfmt
nixfmt copied to clipboard
Expansion of `\t` in strings
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"
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.
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.
The RFC format states that string content should be preserved without doing any normalization. This is implemented as part of #118