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

Avoid list absorbtion when appended by two more non-list-literal expressions #198

Open
ShamrockLee opened this issue Apr 25, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@ShamrockLee
Copy link

ShamrockLee commented Apr 25, 2024

Description

"Absorption" is an "an alternative layout" that reduces indentation level, according to NixOS/rfcs#166. That is, the specification allows such "alternative" alongside the indent-after-newline right-hand-side style.

Given a chain of evaluated-to-list expressions chained by list concatenation operators (++) consisting of at least one of which is a multi-line literal list and two adjacent non-list-literal expressions, if the multi-line list literal gets absorbed, the adjacent non-list-literal terms will be squashed into the same line, producing a long, hard-to-read, and git-diff-unfriendly line of code.

Current implementation of nixfmt sometimes perform the above-mentioned absoption. In my opinion, such behavior should be avoided.

Small example input

{
  buildInputs = [
    "ee"
    "fff"
    "gggggggg"
    "hhh"
    "iiiii"
    "jjjjj"
    "kkkkkkkkkkk"
  ]
  ++ lib.optional true "lllll-lllll"
  ++ lib.optional false "mmmmmmmm"
  ;
}

Expected output

{
  buildInputs =
    [
      "ee"
      "fff"
      "gggggggg"
      "hhh"
      "iiiii"
      "jjjjj"
      "kkkkkkkkkkk"
    ]
    ++ lib.optional true "lllll-lllll"
    ++ lib.optional false "mmmmmmmm";
}

Actual output

{
  buildInputs = [
    "ee" # To patch /bin/sh shebangs.
    "fff"
    "gggggggg"
    "hhh"
    "iiiii"
    "jjjjj"
    "kkkkkkkkkkk" # Required at build time by SingularityCE
  ] ++ lib.optional true "lllll-lllll" ++ lib.optional false "mmmmmmmm";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Todo
Development

No branches or pull requests

2 participants