-
-
Notifications
You must be signed in to change notification settings - Fork 14.9k
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
[Discussion] How to use linter (nixf
) to standardize the usage of with
?
#330563
Comments
I am still leaning towards banning escaping-with. Not only is the { foo, bar, someBuilder, pythonPackages }:
someBuilder {
# ...
someList = with pythonPackages; [ bar baz ];
}
If we still want { foo, bar, someBuilder, pythonPackages }:
someBuilder {
# ...
someList = (with pythonPackages; [ baz ]) ++ [ bar ];
} And of course if we instead want to get IMO we should not permit constructs that invite confusion and make the code harder to read (since the human reading it has to do the "eval", not just "parsing"). I'd rather make the computers do that work where we can. |
I saw this example yesterday and it's kinda reasonable: nixpkgs/pkgs/os-specific/linux/kernel/linux-rt-5.15.nix Lines 33 to 41 in b73c222
But as long as lib.mkForce is used inside, it will be escaping with, so not agreed by nixf. |
I think this specific example happens to be fine from a human point of view because most people won't expect However, if we talk about a generalisable rule, what would be the negative to disallowing escaping-with? (Especially if the checks only affect files that passed in the past or new files?) |
|
I don't feel strongly about how we reduce the use of |
Anecdotally, I let nixf-tidy loose on my nixos-config yesterday and refactored away all instances of ambiguous Compare this example before: vs. after: Not relying on I don't think strict Enabling strict linter rules generally feels like the sort of thing that would require an RFC to me but OTOH I also feel like, if there are very good reasons for the rules, we should just try them out. If a significant amount of people take significant issue with that and/or have strong opinions on it, we can always remove the check again and only then bother with an RFC. |
Yes, I'm refactoring the checker, and it should filter new type of messages and messages popping up on changed lines. Currently, if you turn it on, more files will skip checking, which is not conducive to our goal of removing unused variables. |
Overall, I believe that the Therefore, it might be beneficial to establish a set of rules that permit certain "acceptable" patterns. For instance, using |
(Even |
I mean |
As a with-hater myself, my opinions are a bit radical... My rule of thumb is to confine
Well, @\eclairevoyant found a wild example...
Arguments of "small files exception" are not compelling. Further, I believe we do not have "small files" in Nixpkgs. In a preliminary scripting, I found an average of more than 80 lines in Nix files at
It is not easy to reason when the code has a nested |
Currently nixf-tidy (and nixd, of course) has some limitations for
with
:with
expression (let foo = "foo" in with bar; [ foo sthInsideBar ]
).with
expression unused (with bar; []
with bar; [ sthOutsideBar ]
).The first one seemed a bit strict, and we already have a lot of "anti-patterns" in Nixpkgs, so I disabled it for now. @inclyc also wants to remove this check from nixf itself. The second one is also a bit problematic, because when people abandon packages, they write
maintainers = with lib.maintainers; [ ];
which won't go throughnixf-tidy
, but since this is not so obvious, I choose to leave it alone and wait for others' feedback.The question now is: can we come up with some better rules?
Some ideas, after discussing with @inclyc
meta = with lib;
, so if the linter seesmeta
, it forbids usingwith lib
to enclose the following expression. This is effective but a bit too non-universalwith
expression on "top level", e.g. at the top of expressions in a file, or directly behind function arguments. This is pretty good, but may not be very friendly to small files.with
expression at all, likewith a; with b;
, but it's also not very friendly.with
, where the second argument comes from the first, likewith a; with bFromA
, this can also be controversial and requires a bit of evaluation involved, not just parsingThis is what we have come up with so far, hope you can provide more ideas!
Related: #292468
CC @inclyc @AndersonTorres @lolbinarycat @eclairevoyant @infinisil @roberth
The text was updated successfully, but these errors were encountered: