Consider removing empty lines from empty attrset
Description
Originally requested by @mightyiam in https://github.com/NixOS/nixfmt/pull/297
Should we ensure that empty attrsets are always formatted the same way?
Small example input
{
a = {
};
b = {
};
c = {
};
}
Expected output
{
a = { };
b = { };
c = { };
}
Actual output
{
a = {
};
b = {
};
c = {
};
}
I believe the intention of being somewhat permissive here is to minimise patch differences where entries are frequently added/removed from a set or a list:
E.g.:
{
example = {
- hello = "world";
};
}
vs
{
- example = {
- hello = "world";
- };
+ example = { };
}
That said, I don't have a strong opinion on whether this is more important than producing a consistent output style.
Negative. Preserving line breaks and preserving newlines are two different things in Nixfmt.
The original issue for which things got implemented was #188, however I don't remember if the wording in the specification was added before that or due to that.
CC @infinisil you implemented this, I'd like to hear your position.
Discussed at today's team meeting. This behavior occurs for the same underlying reason as https://github.com/NixOS/nixfmt/issues/298.
We want to continue to preserve empty lines, but we're willing to debate a:
a = {
};
There's no empty line here, so we could reformat this to:
a = { };
Nobody at the meeting has a strong opinion. We'll leave this on our backlog, and if someone wants to make a PR with a strong case, we'll look at it!
This issue has been mentioned on NixOS Discourse. There might be relevant details there:
https://discourse.nixos.org/t/formatting-team-meeting-2025-05-13/64230/1