Max Waterman
Max Waterman

Reputation: 529

How to get VSCode to add a comma after the `}` it has just autocompleted?

If I try to write a method inside an object initializer, for example by typing:

myFunction() {

then vscode adds a }, leaving me to manually add the ,.

Is there a way to get it to always add },?

I should note that in my coding standards, all object properties should end with a comma (ie including the final one).

I'm running vscode 1.13.0 on Windows 10 (outside WSL).

Upvotes: 10

Views: 9408

Answers (2)

Hassan Khademi
Hassan Khademi

Reputation: 1410

Automatically add JSON/JavaScript Object comma.

https://marketplace.visualstudio.com/items?itemName=LeonQin.auto-insert-comma

Upvotes: 2

Alex
Alex

Reputation: 67979

You can use ESLint with the ESLint extension.

ESLint is able to "Fix" some of the rules automatically. For this one — comma-dangle.

.eslintrc or .eslintrc.json or some other eslint config file:

{
    //...
    "rules": {
        "comma-dangle": [1, {
            "objects": "always",
            "arrays": "ignore",
            "imports": "ignore",
            "exports": "ignore",
            "functions": "ignore"
        }]
    }
}

settings.json:

"eslint.autoFixOnSave": true

P.S. ESLint can auto fix some other things like indentation, spacing, semicolons, parentheses, curly braces, ...

Upvotes: 1

Related Questions