-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow tab usage in indented strings #2911
base: master
Are you sure you want to change the base?
Conversation
I think it's better to be opinionated and discourage/disallow the use of tabs. If there are places in Nixpkgs that use tabs, they should be fixed. |
I think it's better to be opinionated and discourage/disallow the use of tabs. If there are places in Nixpkgs that use tabs, they should be fixed.
What's the benefit of discouraging tabs?
|
To ensure consistency. |
I know a number of languages that recommend using spaces to indent, but none that outright require it. As far as I'm aware, this is the only place where the nix language cares about whitespace. I personally like to (ab)use elastic tabstops, so having to switch only when writing indented strings in personal derivations is a bit annoying. It isn't breaking anything, but it does make writing .nix feel a little awkward compared to other languages. Maybe some sort of opinionated Plus, since this would make the behavior of indented strings work consistently with tabs, a formatter would be able to replace tabs with spaces in indented strings without changing behavior. |
Somehow my cursor hit the close button when I closed my laptop. Reopened |
@edolstra could you please expand a bit? Because in another place, you opposed the simplest available way to ensure syntactic consistency… |
@7c6f434c On the contrary, I'm all in favor of consistent use of URLs. |
Well, at least with spaces and tabs we hopefully won't get a limitation that makes the encouraged option inevitably suboptimal for the most frequent use case. |
If tabs aren't stripped, I suggest updating nix/doc/manual/expressions/language-values.xml Lines 113 to 115 in 6924bdf
, since tabs are indentation, but multiline literals in tab-formatted file don't work as I would expect from reading that. Maybe even make tabs a syntax error, if using them is going to subtly change the meaning of expressions. (I just spent a few minutes figuring out why two identical-looking pieces of code had different outputs...) |
Nix is also used in user configurations, that don't need to adhere to nixpkgs guidelines. So for a better user experience, I would kindly request that this gets merged. For consistency in nixpkgs, the CI tools can check that edited files contain only spaces for indentation. |
This has been confusing me for years because I was wondering why the docs said that indentation would be stripped however I was still seeing indentation in my output. This should definitely fixed. Enforcing an indentation style on nixpkgs can be done with a simple linter (and be more effective) however there is no reason to prevent tabs for personal nix configs especially when it is a source of confusion. |
I marked this as stale due to inactivity. → More info |
How about outputting a warning that tabs should not be used in nix definition files, for consistency? |
I marked this as stale due to inactivity. → More info |
still relevant AFAIK
|
For reference, issue #3759 is also about this topic. Note that other line terminators (i.e. CRLF) also seem to “break” indented strings. |
Is this discussion still active? I do not understand why only spaces would be stripped when there is a well understood concept of "Whitespace" (see every regex dialect), I don't want nixpkgs strict style guidelines to be forced onto me in my own personal repos where I choose to use tabs for my own reasons, I should be able to do that. Furthermore if it is to be arbitrarily limited to spaces only, the doco should be updated because stating that "whitespace" is removed is misleading. |
I marked this as stale due to inactivity. → More info |
Not stale AFAIK |
This comment was marked as off-topic.
This comment was marked as off-topic.
@@ -41,8 +41,9 @@ let | |||
''; | |||
|
|||
s6 = '' | |||
Tabs are not interpreted as whitespace (since we can't guess | |||
what tab settings are intended), so don't use them. | |||
Tabs are only interpreted as whitespace when they are |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whitespace when
should be whitespace when
. No need for two spaces.
|
If we do add a warning we need to find a way to make it relatively subtle. Probably would need to be dismissable. The last thing I want is some log noise during every Nix evaluation. I do agree that if a versioning system is likely to land it would be a good way to roll this out. |
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/2023-07-14-nix-team-meeting-minutes-71/30472/1 |
And please also add a warning on CRLF (and CR), since they cause the same problem. While it is probably less common to use CRLF than tabs in the Linux ecosystem, I guess adding this check in addition to the check for tabs shouldn't be that complicated. [EDIT: Also, if you somehow end up with CRLF, it is often less visible than tabs. Many editors will just start using CRLF for each line termination if they find one occurrence in the file. Some editors1 will not even show you an indication which line termination they are using.] FYI, I don't know why CRLF breaks indented string since the CR (\r) is at the end of the line, not at the beginning, but it does. Footnotes
|
It's probably a good thing to eliminate "surprising behavior" where possible, rather than warn about it IMO. If RFC 137 succeeds, that sounds like the better route to me. I don't think this will threaten ecosystem consistency, given that nixpkgs and every nix formatter I have seen uses spaces. |
Marked as draft because this is either blocked on RFC 137 for supporting breaking language changes, or this could be converted to a change that warn appropriately when such tabs are encountered. |
RFC 137 did not pass. |
There are a fair number of derivations in nixpkgs that seem to unintentionally use tabs in their expressions instead of spaces (evilwm, gitit, animbar, ocaml-expat), and right now spaces are the only indentation recognized. This change allows tabs to be used by having whatever whitespace character appears first at the start of lines as the character used for indentation. No assumptions need to be made about tab configuration because this does not support mixed tabs and spaces. This would also allow people who prefer tabs in their local derivations to use that instead.
The only place where mixing is acceptable is with the final ignored line, as some of the packages specified above have spaces indenting their final lines, which seem to be intended to be ignored.
This is my first PR, so feel free to modify or critique it however you want.