nixfmt
nixfmt copied to clipboard
`f x.a or b` should be formatted to `f (x.a or b)`
Description
This is a ferociously confusing parse, as precedent from Nix and Haskell would have you expect that no operator binds tighter than function calls, and the spaced keyword especially makes it strongly look like (f x.a) or b
.
Note that this also applies to e.g. [ x.a or b ]
and even x.a or f b
. I think the rule should be something like “any non‐parenthesized x.a or b
expression that is a direct child of a function call or list should have parentheses added”.
See https://github.com/NixOS/nixpkgs/pull/339006#pullrequestreview-2276246040 for a real‐world example where this came up and could avoid future readability nit‐picking.
Small example input
{ a ? x.a or f b }: {
glurk = x.a or 1 + 2;
zorpy = f x.a or b;
yammo = [ x.a or b x.y or c (x.a or f x.y or b) ];
}
Expected output
{
a ? x.a or f b,
}:
{
glurk = x.a or 1 + 2;
zorpy = f (x.a or b);
yammo = [
(x.a or b)
(x.y or c)
((x.a or f) (x.y or b))
];
}
Actual output
{
a ? x.a or f b,
}:
{
glurk = x.a or 1 + 2;
zorpy = f x.a or b;
yammo = [
x.a or b
x.y or c
(x.a or f x.y or b)
];
}