kamadorueda / alejandra

The Uncompromising Nix Code Formatter
https://kamadorueda.github.io/alejandra/
The Unlicense
859 stars 41 forks source link

Whitepace added around parentheses within string #399

Open n8henrie opened 1 year ago

n8henrie commented 1 year ago

I have a "line too long" error thrown by pkgs.writers.writePythonApplication that I'm working around by changing

''"${thisLongNixPath}"'' into

''(
        "${thisLongNixPath}"
)';'

as the newline break should put the long string under the line length limit.

Unfortunately, alejandra keeps adding a bunch of whitespace before the ( and the "${:

$ diff flake.nix <(alejandra -q <flake.nix )
35,37c35,37
<           ''(
<             "${chromium}/Chromium.app/Contents/MacOS/Chromium"
<             )
---
>           ''            (
>                         "${chromium}/Chromium.app/Contents/MacOS/Chromium"
>                         )

I think that's because this is surrounded in a square bracket, and it seems to want to align the inner parentheses to the outer square bracket, but this kind of alignment within a string perhaps shouldn't happen:

Pre:

        replacements = [
          "--replace"
          ''"./Chromium.app/Contents/MacOS/Chromium"''
          ''(
            "${chromium}/Chromium.app/Contents/MacOS/Chromium"
            )
          ''
        ];

Post:

        replacements = [
          "--replace"
          ''"./Chromium.app/Contents/MacOS/Chromium"''
          ''            (
                        "${chromium}/Chromium.app/Contents/MacOS/Chromium"
                        )
          ''
        ];