Feature Request: Allow Arrays To Be Expanded By Default
See original GitHub issuePlease add a configuration option to allow arrays to be formatted as expanded, regardless of the number of items or the length of the line.
Yay
const example = [
alpha,
beta,
charlie,
delta,
echo,
];
Nay
const example = [alpha, beta, charlie, delta, echo];
There are a number of reasons why this is beneficial:
-
Readability: an array of items is more readable when it can be scanned as a list. Yes we read left to right, but when it comes to lists we read top to bottom. Bullet points are the perfect example of this. This is particularly true of sequences where order is important.
-
Consistency: having all arrays behave the same regardless of content is much more consistent.
-
Ease of use: it is much easier to move up and down a vertical list with a keyboard. It is also easier to duplicated a line.
-
Reviewability: It is much easier to see what has changed in a diff if there is one item on every line.
These same arguments can also be applied to restructuring of imports and variables.
Yay
{
alpha,
beta,
charlie,
delta,
echo,
} = example;
Nay
{ alpha, beta, charlie, delta, echo } = example;
Issue Analytics
- State:
- Created 7 years ago
- Reactions:10
- Comments:11 (7 by maintainers)
Your points are more subjective than you think. Also, you run into collapsed arrays all the time for simple stuff like
foo(["x", "y", "z"])
. We certainly don’t want to expand that as I think it aligns more with all your points than not. If that is deep in an expression, expanding it will make the entire larger expression break which is very undesirable.It seems like you generally want anything that is list-like to always be expanded, and we are not going to do that because that affects the style far too much. It does make it harder to read and review in some cases. But like I said, nothing here is objective, it’s all subjective, and we have to make a call and I think the way it currently works is what we’re going to stick to.
@Undistraction Alright, this is a little weird even for me. But I created an option for it on https://github.com/arijs/prettier-with-tabs/commit/f6c12c62a6afcb64f997f2ea8d064df440f1b4fd - please check out if the result is what you expected 😉
@jlongster @vjeux and prettier team - when you get esoteric feature requests for unconventional options, please feel free to forward them to me 😃