Array formatting inconsistencies
See original GitHub issueIf 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:
- Created 9 years ago
- Comments:5 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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:
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.
@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: