You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This does indeed generate ugly output. The thing is, your suggested expected output changes the contents of the string (it removes the leading spaces). In fact, this string is impossible to format as indented strings without those leading tabs. Those tabs are a bit of a hack and I don't want to generate code like that. The proper solution could be to use concatStringsSep or concatMap to add the spaces to a list of lines or it could be to remove the leading spaces, but that's a decision that the programmer should make. Nixfmt should never change the semantics of the code on its own. Generating function calls is also tricky because we can't be sure whether lib or builtins is bound to what we expect. In the end it's best to leave it to the user to detect these cases and manually choose a solution.
PS. If you lost access to the unformatted indented string and feel it's a lot of work to recover the indented string, you could remove the indentation of any single line in the string and reformat again and nixfmt will turn it back into an indented string since it now has a valid representation as indented string.
I just checked nix repl and it seems Nix also includes the tabs as part of the string which means nixfmt is still changing semantics in this case. I'm considering making tabs in indentation a parse error.
Input (note that every line starts with a single tab character):
Expected output:
Actual output:
" foo\n bar\n"
This can be disastrous: https://gitlab.com/Fuzen-py/configsreborn/-/blob/2a6b5aa5c8bee37cc13ab35d186b8fa604f62b2c/Snow/homeManager/programs/waybar/default.nix#L93-96
The text was updated successfully, but these errors were encountered: