Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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).

like image 426
Max Waterman Avatar asked Jun 12 '17 13:06

Max Waterman


1 Answers

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, ...

like image 172
Alex Avatar answered Sep 29 '22 23:09

Alex