JavaScript formatting - array of objects, have opening brace on same line as bracket
I'm trying to get the formatting right for an array of objects. The format I'm looking for is this:
var arr = [{
test: 1,
test2: 2
}];
But what I get is this:
var arr = [
{
test: 1,
test2: 2
}
];
This takes up way too much space for me, and causes more indenting than I'd like. Is there a property in the Editor > Code Style > JavaScript area that I'm missing?
Please sign in to leave a comment.
can't recreate. do you have 'New line after '{'' enabled in Settings | Editor | Code Style | JavaScript | Wrapping and Braces | Array initializer?
I don't see one for "New line after '{'", but I do see one for "New line after '['" which I do have checked... because I want a newline for a normal array, like:
var a = [
1,
2
];
>I don't see one for "New line after '{'", but I do see one for "New line after '['" which I do have checked
Yes, it should have been "New line after '['", sorry. As you have it enabled, a new line is inserted after '[', as expected.
There are no special settings for objects inside arrays, so there is no way to add a new line in one case and not add it in another.
Related feature request: https://youtrack.jetbrains.com/issue/WEB-7226
Thank you very much for the help and link, Elena!