1

EDIT: I don't want to put opening curly brackets on a separate line, in general. I simply want to do so in this case where two opening brackets are on the same line. ESLint does it correctly but Beautify does not, but ESLint is only for inline Javascript.

I'm using the Beautify extension in VSCode to try to format this chunk of inline javascript as follows:

    const dogs = [
        {
            name: 'Snickers',
            age: 2,
        },
        {
            name: 'Hugo',
            age: 2,
        },
        {
            name: 'Sunny',
            age: 2,
        },
    ];

Instead, it does this:

    const dogs = [{
            name: 'Snickers',
            age: 2,
        },
        {
            name: 'Hugo',
            age: 2,
        },
        {
            name: 'Sunny',
            age: 2,
        },
    ];

As you can see, it puts the opening square and curly brackets on the same line. Is there a rule (in .jsbeautifyrc) to force the desired behavior or is this a bug in js-beautify?

Bluebird45
  • 147
  • 2
  • 10
  • 2
    Possible duplicate of [How do I set up VSCode to put curly braces on a new line?](https://stackoverflow.com/questions/32900921/how-do-i-set-up-vscode-to-put-curly-braces-on-a-new-line) – Code Maniac May 28 '19 at 04:41
  • See my EDIT. I only want these nested opening brackets such as this separated onto separate lines. – Bluebird45 May 28 '19 at 13:39

2 Answers2

1
  1. Try paste this rule in your .jsbeautifyrc

    {
        "js": {
            "brace_style": "expand"
        }
    }


Also you can try this extension too: Visual Studio Code Format

1

Prettier is also used for formatting the code in VS code. This extension does not have this problem. You can try installing this extension and try once. I have checked this and did not see this issue.

Extension name: Prettier - Code formatter

yaswanth
  • 159
  • 9
  • Prettier doesn't have that problem but it breaks other things and uses a different configuration file with different conventions. I'd rather just fix this one thing. – Bluebird45 May 28 '19 at 14:56