42

I use Visual Studio Code with Vetur extension, when I right click on my .vue file and chose "Format Document" option Visual Studio Code automatically add the semicolons that intentionally removed them.

How do I stop this?

Gama11
  • 31,714
  • 9
  • 78
  • 100
Engr.MTH
  • 1,002
  • 1
  • 11
  • 23

12 Answers12

44

Put this in your user settings and it won't change your semis:

"vetur.format.defaultFormatter.js": "vscode-typescript",
wscourge
  • 10,657
  • 14
  • 59
  • 80
KM3
  • 474
  • 5
  • 2
25

Forget the earlier answer, gives me runtime issues.

Install Prettier- code formatter extension and disable the addition of semi colons by unchecking the Prettier:Semi as in the screenshot below

Note : Dont forget to reload your vs code after you install the extension and before u do the config changes

enter image description here

Chris Gong
  • 8,031
  • 4
  • 30
  • 51
Gurudutt Shenoy
  • 297
  • 4
  • 7
23

Adding .prettierrc file in project root worked for me with following settings:

{
  "semi": false,
  "singleQuote": true
}

Changing prettier settings in VSCode Workspace did not work in my case.

Sainath A
  • 610
  • 9
  • 10
12

You can go to VSCode settings and search for the prettier section.... there's an option for turning off adding semicolons....

Or, just add this line to your custom settings in VSCode:

     "prettier.semi": false

I was trying to find a way to do this in the eslint config, and have vs code pick up whatever settings are in the eslint settings... but haven't found it yet. In the meantime, the above works for me...

Sean Rasmussen
  • 313
  • 4
  • 15
  • 1
    Thank you for your answer, although when I add `"prettier.semi": false` to the custom settings it tells me `"Unknown configuration setting"` but what happening know is, it removes the currently added semicolons! and I don't want it to add the missing ones or remove the existing one. I want to disable this automatic behavior entirely. – Engr.MTH Feb 24 '18 at 15:06
  • 2
    I guess it depends on which extensions you have.... I have prettier installed so it works... You can search the settings for "semi" and see if you can find something... – Sean Rasmussen Feb 25 '18 at 03:39
  • I don't have a formatting extension installed, also when I search for "semi" in the settings cant find any result contains "semi" in it. – Engr.MTH Feb 25 '18 at 05:47
  • Was anyone able to fix this bug? – Developer Apr 27 '18 at 20:27
  • Can you make it more clear in your answer that you are suggesting the OP first install and use the Prettier add-on? – Michael Fulton Feb 21 '19 at 19:52
10
  1. go to settings

enter image description here

  1. Go to Text Editor's Settings enter image description here

    "javascript.format.semicolons": "remove",
    "typescript.format.semicolons": "remove",
    "typescriptHero.imports.insertSemicolons": false, 
    "typescript.preferences.quoteStyle": "single",
    "javascript.preferences.quoteStyle": "single",   
    
  2. Editor enter image description here

YouTube Video

Rashid Iqbal
  • 1,123
  • 13
  • 13
  • Hi could you help me here? I tried your solution and I still get missing semi colon warnings: https://stackoverflow.com/questions/72779221/how-to-add-prettier-config-into-eslint-config – Leon Gaban Jun 27 '22 at 23:49
7

You can add in your VSCode settings.json

"vetur.format.defaultFormatterOptions": {
    "prettier": {
        "semi": false
    }
},
jojo
  • 71
  • 2
  • 4
  • Hi could you help me here? I tried your solution and I still get missing semi colon warnings: https://stackoverflow.com/questions/72779221/how-to-add-prettier-config-into-eslint-config – Leon Gaban Jun 27 '22 at 23:49
2

May be, you have different extensions installed where the usage of semicolons (;) is defined. Try to go to VSCode settings and search for "semicolon". All settings regarding the usage of semicolon will be shown and you can configure it as you like.

Michael
  • 416
  • 3
  • 10
1

This is what worked for me:

"typescript.format.semicolons": "remove"
Joel Wenzel
  • 9
  • 1
  • 2
0

Add this line to your custom settings in VSCode (helps with js files):

"autoimport.useSemiColon": false

0

setting organizedimports to false worked for me

"editor.codeActionsOnSave": {
"source.organizeImports": false
},
PhillipMwaniki
  • 1,166
  • 9
  • 14
0

Seems many formatters can make this stupid work. Maybe the ideas in other question works, maybe they don't work. This depends additionaly on the fact, which formatter is in use.

So, make rightclick in the code and choose "Format document with.." and then choose "Configure default formatter..". In my case (bu I am not sure about my Code state because I already made some attempts mentioned on this Stackoverflow page): Prettier made the problem, while Vetur and Volar worked well (no semicolon change).

mirek
  • 1,140
  • 11
  • 10
-3

Easiest fix is go to "Settings" in vs code, Search for ";"

In the search result that follows, remove ";" as demonstrated in the below screenshots.

Before the change: Before the change

After the change: After the change

Majid Hajibaba
  • 3,105
  • 6
  • 23
  • 55
Gurudutt Shenoy
  • 297
  • 4
  • 7