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 ma (ie including the final one).
I'm running vscode 1.13.0 on Windows 10 (outside WSL).
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 ma (ie including the final one).
I'm running vscode 1.13.0 on Windows 10 (outside WSL).
Share Improve this question edited Jun 12, 2017 at 13:23 T.J. Crowder 1.1m200 gold badges2k silver badges1.9k bronze badges asked Jun 12, 2017 at 13:17 Max WatermanMax Waterman 5296 silver badges14 bronze badges 10- have you figured it out? I have the same question but the only answer doesn't seem resolved it. – jtcloud Commented May 11, 2020 at 19:23
- No, sorry....I gave up on VSCode and Windows too, and went back to Ubuntu and gvim :) – Max Waterman Commented May 13, 2020 at 5:29
- that's sad. Can't imagine so many javascript developers are just manually moving cursors around to plete a sentence.. – jtcloud Commented May 13, 2020 at 19:00
- I'm am only one, and I've been using vi{,m} since 1986 - lots of muscle memory. It is a general frustration to me that vscode (et al) keep filling in things and displaying things unnecessarily. NB, I don't have to 'manually move a cursor around to plete a sentence' in vim - I just type it. On the contrary, it is with vscode that I have to manually move the cursor around in order to correct what it has unhelpfully done "for me". I don't know why you would be 'sad' because my tool works much better for me - you should be happy :) – Max Waterman Commented May 15, 2020 at 0:01
- I was using python/java in IntelliJ like editor. {} are just automatically added if I do keyboard short like ctrl+shift+enter, and it can also intelligently tell whether you are going to the next line from if (so to add {}) or from a plain statement (so to just add ; behind). VScode is so popular in the world for Javascript and I'm sad that nobody gives it a shout for missing such an intelligent mon feature that other IDE do. – jtcloud Commented May 15, 2020 at 2:07
2 Answers
Reset to default 2Automatically add JSON/JavaScript Object ma.
https://marketplace.visualstudio./items?itemName=LeonQin.auto-insert-ma
You can use ESLint with the ESLint extension.
ESLint is able to "Fix" some of the rules automatically. For this one — ma-dangle.
.eslintrc
or .eslintrc.json
or some other eslint config file:
{
//...
"rules": {
"ma-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, ...