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.

Array formatting inconsistencies

See original GitHub issue

If I have an array with object literals in this format:

var v = [
  {
    id: 1,
  }, {
    id: 2,
  },
];

When formatted it looks like this:

var v = [{
  id: 1,
}, {
  id: 2,
}, ];

But if the first item is anything but an object literal, the formatted output will match the input:

var v = [
  0, {
    id: 1,
  }, {
    id: 2,
  },
];

The two differences between the two formats are:

  • The open and close brackets of the array are on different lines than the array items.
  • The array items are indented one level more than the array brackets.

Changing one item in the array shouldn’t change the formatting of the entire array. Which means one format should be chosen, right? So I would suggest the latter format should be chosen for these two reason:

  • The code is easier to read and follow because of the extra indentation. (which people will probably argue against)
  • Sublime Text can properly code fold it. With the former format sublime only collapses the first object instead of the entire array. (which people can’t argue against:-)

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
aclscommented, May 16, 2014

I wrote up a long response on why the indents are not redundant and how an option could be added to solve the inconsistencies. But in the processing of finding stuff to back up my arguments I realized with two little slashes all my dreams could come true:

var v = [ //
  {
    id: 1
  }, {
    id: 2
  }
];

Which then means there’s an easy work around and puts this on your todo last list. But I do hope it gets changed in a future release. Thanks.

0reactions
aclscommented, Feb 26, 2018

@kdelmonte It looks like it may be resolved. On http://jsbeautifier.org/ I was able to get the example to work with these config changes:

  • Changed indentation select to: Indent with 2 spaces (only because the example uses 2 spaces)
  • Changed braces select to: Attempt to keep braces where they are
  • Checked: Keep array indentation?
Read more comments on GitHub >

github_iconTop Results From Across the Web

Python loading text with inconsistent format into an array
How do I get it to ignore the first chunk of whitespace and then break it down into three columns of numbers and...
Read more >
49678 – Code formatting of arrays does not follow ... - Bugs
I have found that setting the array initializer brace to "Next line indented" introduces the sort of indentation I am looking for on...
Read more >
Three ways to expose formatting inconsistencies in a Word ...
Whether you're sharing new documents or revamping old ones, these three tools can reveal troublesome formatting problems.
Read more >
Why are timestamps inconsistent between the array and alerts?
When the storage array sends alerts, it does not correct for the time zone of the target server or host that receives the...
Read more >
RangeError: invalid array length - JavaScript - MDN Web Docs
The JavaScript exception "Invalid array length" occurs when specifying an array length that is either negative, a floating number or exceeds ...
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