question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature Request: Allow Arrays To Be Expanded By Default

See original GitHub issue

Please 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:

  1. 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.

  2. Consistency: having all arrays behave the same regardless of content is much more consistent.

  3. 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.

  4. 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:closed
  • Created 7 years ago
  • Reactions:10
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

6reactions
jlongstercommented, Feb 27, 2017

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.

3reactions
rhenglescommented, Feb 27, 2017

@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 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Expand on the default Array Functions - NI Community
I would expand default functions with handling arrays of more than 1D size. Say, GetNumElements() works just for 1D arrays, but I need...
Read more >
RFE. Expand Arrays functionality ease alike ICE. Community ...
Ok, I'm going to file a feature request so we can deal with arrays ... The longest one is shortened, this way there's...
Read more >
Expanding responses | Stripe Documentation
This guide describes how to request additional properties from the API. ... The API has an Expand feature that allows you to retrieve...
Read more >
Spread syntax (...) - JavaScript - MDN Web Docs - Mozilla
The spread ( ... ) syntax allows an iterable, such as an array or string, to be expanded in places where zero or...
Read more >
Is there a way to auto expand objects in Chrome Dev Tools?
By default the console on Chrome and Safari browsers will output objects which are collapsed, with sorted property keys, and include all inherited...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found