Description
Hello,
I've been using alejandra for a while with no major issues, but recently I stumbled across a case where it's formatting is, IMO, making readability worse by a long shot. The case in question is when formatting a "dense list of records", such as:
[
{ foo = "foo"; bar = "bar"; baz = "baz"; }
{ foo = "foo"; bar = "bar"; baz = "baz"; }
{ foo = "foo"; bar = "bar"; baz = "baz"; }
{ foo = "foo"; bar = "bar"; ba
6326
z = "baz"; }
{ foo = "foo"; bar = "bar"; baz = "baz"; }
{ foo = "foo"; bar = "bar"; baz = "baz"; }
{ foo = "foo"; bar = "bar"; baz = "baz"; }
]
alejandra formats it as
[
{
foo = "foo";
bar = "bar";
baz = "baz";
}
{
foo = "foo";
bar = "bar";
baz = "baz";
}
{
foo = "foo";
bar = "bar";
baz = "baz";
}
{
foo = "foo";
bar = "bar";
baz = "baz";
}
{
foo = "foo";
bar = "bar";
baz = "baz";
}
{
foo = "foo";
bar = "bar";
baz = "baz";
}
{
foo = "foo";
bar = "bar";
baz = "baz";
}
];
but I think this is so much harder to read, especially if the list is longer.
When attributes are missing, like in this case:
[
{ foo = "foo"; bar = "barrr"; baz = "baz"; }
{ bar = "bar"; baz = "baz"; }
{ foo = "foooo"; bar = "bar"; baz = "baz"; }
{ foo = "foo"; baz = "baz"; }
{ foo = "foo"; bar = "baar"; baz = "baz"; }
{ foo = "fooo"; bar = "bar"; }
{ foo = "foo"; baz = "bazzz"; }
]
I think the ideal (most readable) formatting would be columnar, like this:
[
{ foo = "foo"; bar = "barrr"; baz = "baz"; }
{ bar = "bar"; baz = "baz"; }
{ foo = "foooo"; bar = "bar"; baz = "baz"; }
{ foo = "foo"; baz = "baz"; }
{ foo = "foo"; bar = "baar"; baz = "baz"; }
{ foo = "fooo"; bar = "bar"; }
{ foo = "foo"; baz = "bazzz"; }
]
In this case, the formatter might even sort the attributes (#276) to keep things tidy.
Of course, this is a very specific behavior, so to be honest I think a directive like # alejandra:dense,columnar
could work.
If having such a directive is not desirable, then I'd like to have a directive to avoid formatting an entire block, such as:
# alejandra:skip
[
{ foo = "unformatted"; }
{ bar="code"; }
]
I couldn't find something similar, so maybe it's already there.
I hope it makes sense!