-
-
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
Appending an optional string / array causes the entire expression to be reformatted #228
Comments
Is this an issue with the RFC or with the implementation? It seems this thread is discussing a similar issue too: https://discourse.nixos.org/t/satisfaction-survey-from-the-new-rfc-166-formatting/49758 |
This issue has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/nix-formatting-team-treewide-nixpkgs-formatting/56666/2 |
This is not legal under RFC166 because the closing bracket before
If you're used to the RFC style, this property is extremely important to parsing operator chains (aswell as bindings in general) quickly mentally and encountering a non-indented line that is not the last line of the binding is confusing. I don't see a good way to solve this but, as mentioned in https://discourse.nixos.org/t/nix-formatting-team-treewide-nixpkgs-formatting/56666/3, you could pre-emptively force the non-compact form using a comment or a no-op expression if you anticipate that an operator will be used on your expression in the future. |
The current format is really bad for reviewing diffs, for If the operator chain indentation rule is considered vital, then I would prefer formatting every multi‐line list like this: buildInputs =
[
foo
bar
baz
]; which, while certainly chunkier, is consistent with (and therefore no chunkier than) what you get when you start adding Of course you’d either have to do the same for strings or establish a convention of using See NixOS/nixpkgs#370526 (comment) for an example of where the current style demands a contributor reformat a huge portion of a critical file when making a change, breaking |
I'm likewise running into this in NixOS/nixpkgs#371214 (but this time I'm removing a trailing |
Discussed this in todays meeting {
currentStyle =
[
"hello"
"beautiful"
]
++ lib.optionals true [
(x ++ [ bash ])
"wonderful"
"world"
];
proposal1 = [
"hello"
"beautiful"
] ++ lib.optionals true [
(x ++ [ bash ])
"wonderful"
"world"
];
proposal2 = [
"hello"
"beautiful"
]
++ lib.optionals true [
(x ++ [ bash ])
"wonderful"
"world"
];
}
|
FWIW Thanks for working on this issue. Between ] ++ lib.optionals a [ b ]
++ lib.optional c d
++ lib.optionals e [
f
g
] ++ lib.optional h i where the lines without the (Needless to say all of the considerations about this issue apply equally to |
I don't find that effect to be weak at all. As mentioned previously, the fact that nothing is on the first level of indent until the expression is "closed" is an extremely valuable property of the RFC style IMHO. I'd rather see it explored to limit or even disable absorption for multi-line constructs like @emilazy mentioned. This {
exampleArray = [
"hello"
"beautiful"
];
} would become this: {
exampleArray =
[
"hello"
"beautiful"
];
} which I don't like but it's much preferable to this: {
proposal2 = [
"hello"
"beautiful"
] # Nuh-oh, expression isn't actually over yet!
++ lib.optionals true [
(x ++ [ bash ])
"wonderful"
"world"
]
++ lib.optionals true [
(x ++ [ bash ])
"wonderful"
"world"
]
++ lib.optionals true [
(x ++ [ bash ])
"wonderful"
"world"
]
... # more such expressions. It's no longer possible tell when the expression is "closed" from indent alone.
} Btw., I did not know there was a high-bandwidth synchronous discussion for this. It'd be great if such meetings that meaningfully discuss an issue could be announced before-hand in those specific issues. |
The formatting team meetings are regular (not sure how public the schedule is, but in theory everyone can join), the agenda however is "whatever happens to be the topic" and is not really planned in advance. I recommend joining #nix-formatting:nixos.org if you are interested |
This issue has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/formatting-team-meeting-2024-12-10-and-2025-01-07/58466/1 |
I don't like how hard it is to discover, but our team page currently mentions:
And I always announce the meetings in the Matrix room, they're open to join for anybody :) |
I'm aware there are formatting team meetings and those who are part of the formatting team or just generally interested in the development will regularly be in such meetings of course but I, as someone not in the formatting team but interested in just this particular issue, wouldn't normally be. This perhaps doesn't need to happen for every issue but it would be good for at least high-impact issues such as this one where getting a broader opinion spectrum can be critical. |
Since the agenda is flexible, you can influence it by just joining the meeting and letting us know the issues you think are important so we can discuss them right then :D |
I think you're missing the point that most people interested in this particular issue won't be in your regular meetings, no matter how open they are. |
I agree that for lists this is a bullet you can bite, but I don’t know if you can stomach prePatch =
''
patchShebangs .
rm generated.c
''; I doubt the Nixpkgs contributor base can. (You can use Personally I think the “run‐on” nature of the expressions is the easiest thing to stomach given all the trade‐offs. To me it’s kinda like let x = if cond {
foo
} else {
bar
}; in Rust, which is the idiomatic formatting there (and of most expression‐oriented bracey languages, I think, few in number though those are.) |
I didn't realise this before but I actually quite like how the opening and closing quotes are on the same horizontal position here? This is also consistent with (and thereby reduces diff noise for!) expressions that go in front such as prePatch =
let
foo = "bar";
in
''
patchShebangs .
rm generated.c
''; It's a +3 diff rather than -1+5. I'm liking this more and more actually. I think the hardest to stomach would be attrsets but even there I think I could get used to it and the opening brace being on the same horizontal position as the closing one could be a very nice property for easing mental parsing.
Honestly now that I'm used to our RFC-style formatting for such a ternary, I prefer it over this. An absorbed |
I admire your commitment to principle, and I would personally have no objection to formatting Nixpkgs this way. But I do think that both |
It would have beaten it if you asked just me a year ago too, even if you brought objective arguments. If you're extremely used to something, it's natural to not want to let it go; even in the face of overwhelming evidence against the thing. This happens everywhere and one of the greatest issues facing society today if you ask me. For instance: I'm well aware of how bad and unethical eating meat is and yet I still do it because of how used I am to the taste of the meals I've come to like. That's why I think this decision should be made primarily objectively with little regard for the popular opinion; "technocratically" as you put it.
Right but it contains the closing
Same. There could very well be flaws to this that aren't worth the trade-off but I really can't think of any other than that it's not what we're used to. Perhaps I'll see piegames the next few days again and ask them to show me how to touch nixfmt in the right way to achieve this. |
Description
I don't really mind either way, but filing this in case someone might find the following useful.
I think this diff could have been less noisy:
NixOS/nixpkgs@eac5951
Small example input
Consider this initial expression:
Now, we want to add some optional things:
Expected output
No change - I think the above is close to the existing style.
Actual output
nixfmt-rfc-style
reformats the entire thing, creating a big diff:The text was updated successfully, but these errors were encountered: