-
-
Notifications
You must be signed in to change notification settings - Fork 42
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
Preserve more newlines #201
Conversation
The argument was never used for anything else
2ed49bb
to
1b4093a
Compare
Previously, newlines after the last list/attrs/let-in item would not be preserved. So e.g. [ "foo" ] would wrongly turn into [ "foo" ] Subsequently it would turn into [ "foo" ] This commit fixes it, such that the original is preserved in this case. Whereas previously all the newlines were stripped already during parsing, in this new commit all newlines are preserved, which both fixes the above problem and simplifies the code. This does introduce one odd edge case due to interaction with another feature. That feature is that comments before a let-in's `in` part, get moved below it. The following: let x = 10; # X in x Gets reformatted into let x = 10; in # X x Due to how the new code preserves newlines, those newly also get moved further down. So whereas previously the following: let x = 10; in x Would wrongly remove the newline, turning it into: let x = 10; in x With this change it won't anymore, but it will move the newline down: let x = 10; in x While this could be handled with a special case, I'm not sure if that's worth it. It might be better to rethink this moving of comments further down idea, I'm not sure if that's necessary anymore.
1b4093a
to
7071b1a
Compare
This fixes the odd case introduced in the parent commit
7071b1a
to
84b3b6c
Compare
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/formatting-team-meeting-2024-05-14/45433/1 |
I am not really a fan of the diff and think that the format specification should be changed instead. The rule of not preserving trailing empty lines should be easy to formalize and IMO is a good heuristic for desired behavior. |
@piegamesde The diff is a bit confusing, because all the extra lines it "adds" are ones that were already there before. E.g. the newline in this section was previously removed, but is now preserved. So while this causes the result to have more lines, the diff is actually smaller!
Reasons for having this:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed live during fmt meeting.
This fixes #188 in a better way, as an alternative to #193
Previously, newlines after the last list/attrs/let-in item would not be preserved. So e.g.
would wrongly turn into
Subsequently it would turn into
This PR fixes it, such that the original is preserved in this case.
Whereas previously all the newlines were stripped already during parsing, in this new commit all newlines are preserved, which both fixes the above problem and simplifies the code.