Skip to content
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

f x.a or b should be formatted to f (x.a or b) #251

Open
emilazy opened this issue Sep 3, 2024 · 1 comment
Open

f x.a or b should be formatted to f (x.a or b) #251

emilazy opened this issue Sep 3, 2024 · 1 comment

Comments

@emilazy
Copy link
Member

emilazy commented Sep 3, 2024

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 NixOS/nixpkgs#339006 (review) 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)
  ];
}
@emilazy
Copy link
Member Author

emilazy commented Sep 3, 2024

Note that I think x.a or [ ] ++ b is also confusing, but just the regular kind of confusing that operator precedence tends to be, so I wouldn’t include that here. (Though again the or keyword adds to the confusion vs. a symbolic operator.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Todo
Development

No branches or pull requests

1 participant