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

Inconsistent splitting with long lines #279

Open
jtojnar opened this issue Jan 24, 2025 · 2 comments
Open

Inconsistent splitting with long lines #279

jtojnar opened this issue Jan 24, 2025 · 2 comments

Comments

@jtojnar
Copy link
Member

jtojnar commented Jan 24, 2025

Description

The second optionals will get split onto two extra lines, probably since the line spans 110 columns but splitting it vertically only reduces it down three columns – not a very good trade in my opinion.

Small example input

{
  patches =
    attrs.patches or [ ]
    ++ lib.optionals (lib.versionOlder prev.php.version "7.4") [
      ./foo.patch
    ]
    ++ lib.optionals (lib.versionAtLeast prev.php.version "8.0" && lib.versionOlder prev.php.version "8.1") [
      ./bar.patch
    ];
}

Expected output

{
  patches =
    attrs.patches or [ ]
    ++ lib.optionals (lib.versionOlder prev.php.version "7.4") [
      ./foo.patch
    ]
    ++ lib.optionals (lib.versionAtLeast prev.php.version "8.0" && lib.versionOlder prev.php.version "8.1") [
      ./bar.patch
    ];
}

Actual output

{
  patches =
    attrs.patches or [ ]
    ++ lib.optionals (lib.versionOlder prev.php.version "7.4") [
      ./foo.patch
    ]
    ++
      lib.optionals (lib.versionAtLeast prev.php.version "8.0" && lib.versionOlder prev.php.version "8.1")
        [
          ./bar.patch
        ];
}
@piegamesde
Copy link
Member

piegamesde commented Jan 24, 2025

This is an artifact of the line length limit, your expected output exceeds it. If you increase the limit you will get the desired formatting again

@jtojnar
Copy link
Member Author

jtojnar commented Jan 24, 2025

Right. I am arguing for the line length limit to be a bit more fuzzy.

For example, nixfmt could prefer more compact vertical layout when splitting a line would also overflow the line limit and the reduction of width would be insignificant (it is less than 3% here).

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

2 participants