Stop Visual Studio Code From Automatically Adding Semicolons In .vue Files - visual-studio-code

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?

Put this in your user settings and it won't change your semis:
"vetur.format.defaultFormatter.js": "vscode-typescript",

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

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.

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

You can add in your VSCode settings.json
"vetur.format.defaultFormatterOptions": {
"prettier": {
"semi": false
}
},

go to settings
Go to Text Editor's Settings
"javascript.format.semicolons": "remove",
"typescript.format.semicolons": "remove",
"typescriptHero.imports.insertSemicolons": false,
"typescript.preferences.quoteStyle": "single",
"javascript.preferences.quoteStyle": "single",
Editor
YouTube Video

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.

This is what worked for me:
"typescript.format.semicolons": "remove"

Add this line to your custom settings in VSCode (helps with js files):
"autoimport.useSemiColon": false

setting organizedimports to false worked for me
"editor.codeActionsOnSave": {
"source.organizeImports": false
},

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:
After the change:

Related

"Prettier - Code formatter" is not working in Visual Studio code

I have Visual Code Studio(1.41.1) Editor and I need Auto Formatter
I have installed this code format: Prettier - Code formatter Successfully installed but not working,
I also tried to use the command ext install esbenp.prettier-vscode
that too was successful installation but is not working.
I checked that the composer is installed properly and the environment variable path is given correctly in my system, Also, I added it to the settings.json file by looking in the document: "phpformatter.composer": true but not success in auto-formatting my code
Visual Studio Code and System Restart also tried but did not succeed
Why can't I Auto Formatter in my Visual Studio code use this "Prettier - Code Formatter"? No errors are received, but the auto formatter is not working
try this, it worked for me
File -> Preferences -> Settings (for Windows)
Code -> Preferences -> Settings (for Mac)
Search for "Default Formatter". In the dropdown, prettier will show as esbenp.prettier-vscode.
Maybe the prettier extension is not working for javascript file. Open your settings.json for vs code and paste
{ "editor.defaultFormatter": "esbenp.prettier-vscode", "[javascript]": { "editor.defaultFormatter": "esbenp.prettier-vscode" } }
This might work for you
You may have local .vscode directory in the root of your project with settings that prevent formatting. Try to edit or remove .vscode local configurations if you have. After close and reopen VS Code.
as #harkesh kumar said : press Ctrl+shift+p and type format document then select prettier format, it may work for you
Make sure you have a file in the root folder with this name .prettierrc.js
inside you should have something like:
module.exports = {
bracketSpacing: false,
jsxBracketSameLine: true,
singleQuote: true,
trailingComma: 'all',
arrowParens: 'avoid',
};
If you don't have and don't want a prettier config file for some reason, you can uncheck the option "Prettier: Require Config"
In settings.json it's "prettier.requireConfig": true
In the UI it looks like this:
For me it was failing silently because I was using await inside of a function that wasn't marked with async. That raises another question - why would it fail silently here. Regardless, once I fixed that error then prettier began working again.
I finally found the issue. I was trying to format code on a remote server.
In the extension page for Prettier, it says:
This extension is disabled in this workspace because it is defined to run in the Remote Extension Host
Then I clicked on the button "install on remote host ..." and it worked

VS-Code Prettier Format On Save doesn't work

For about a month now, my Prettier extension has stopped working as it normally does. Most notably - format on save does not work. Other notes:
Format on typing a ; works
I get this error type symbol in the status bar next to the Prettier button - I can't find any reference to this relating to Prettier on Google:
]
I have my format on save checked in Settings:
'Format Document,Format SelectionandFormat Document with` command palette options all do nothing
Timing of the break coincides with moving from Prettier 2-3
I've followed the migration steps and think all is in order. Some snippets of the configuration between eslint and prettier that I have:
As per the prettier documentation, my VS Code settings has:
"eslint.autoFixOnSave": true, // (even though VSCode has this as deprecated), have tried with and without this line
"editor.codeActionsOnSave": {
"source.organizeImports": true,
"source.fixAll.eslint": true
},
My Dev dependencies include:
"eslint-config-prettier": "^6.5.0",
"eslint-plugin-prettier": "^3.1.2",
"prettier-eslint": "^9.0.0",
I have a prettier.config.js file
My .eslintrc.js file includes:
extends: ['airbnb', 'prettier'],
plugins: ['react', 'jsx-a11y', 'import', 'react-hooks', 'plugin:prettier/recommended'],
Anyone have any idea on how to fix this or further debugging tests to do here? It's driving me nuts!
Follow these steps:
CTRL + SHIFT + P
Format Document (in pop-up bar)
Select Format Document
Select Configure Default Formatter...
Select Prettier - Code formatter
Done!
In VSCode settings, search for "Editor: Default Formatter" and set it to esbenp.prettier-vscode
Configuration has changed you need to add this into you vs-code settings:
According to the documentation: "You can enable Auto-Fix on Save for ESLint, TSLint or Stylelint and still have formatting and quick fixes"
"editor.codeActionsOnSave": {
// For ESLint
"source.fixAll.eslint": true,
// For TSLint
"source.fixAll.tslint": true,
// For Stylelint
"source.fixAll.stylelint": true
}
On VScode go to Settings > Text Editor > Formatting
Then check the Format On Save checkbox.
For me, using prettier+(svipas.prettier-plus) -- because the default prettier plugin is no good -- ONLY changing:
"editor.formatOnSaveMode": "modifications",
to
"editor.formatOnSaveMode": "file",
solved my problem.
Try to make your code prettier manually by pressing CTRL + SHIFT + P >>> Format Document. If your file is being formatted without any issues, it means that the issue lies in formatOnSave settings. Probably, you can try to make further debugging from there.
in my case the issue was that the default formatter setting was not being used for typescript files. Looking at my settings.json I saw
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[typescript]": {
"editor.defaultFormatter": "vscode.typescript-language-features"
},
"[typescriptreact]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
After adjusting the value for [typescript] the issue was resolved.
I couldn't find a place Settings UI where the default formatter can be changed for TS only, but it would be a nice feature though.
For formatonSave was already checked and the defaultFormatter was prettier ... when I switched into settings.json, it was like!!
"[javascript]": { "editor.formatOnSave": false }, "eslint.autoFixOnSave": true, "prettier.disableLanguages": [ "js" ],
After changing it to
"[javascript]": { "editor.formatOnSave": true }, "eslint.autoFixOnSave": true, "prettier.disableLanguages": [],
it did work...
I had to add a jsconfig.json file containing:
{
"exclude": ["node_modules"]
}
to my app directory, and reload Visual Code, in order for Prettier to work.
Also, I can't choose "Format Document With..." in the Visual Code command palette until I add this file.
Basically it tells Visual Code that the project is written in JavaScript (if I understand it correctly) and to exclude node_modules from intellisense.
This was after doing everything else people mentioned here.
First check if Prettier works fine. You can try to format a single file using Shift + Cmd + P and Format Document. If this doesn't work then it is most likely an issue with Prettier extension. Disable and Enable Prettier extension from Extensions.
If Formant Document works fine on single file then the best way to resolve these type of issues is going to settings.json and looking up the config. I had an issue where the first few lines in settings.json had issues and hence the other settings like format on save (editor.formatOnSave) and defaultFormatter which were below the ill-formatted line wasn't working.
I tried checking the "format on save" box but it didn't do it for me, even prettier selected as a default formatter.
Editing the settings' json file worked for me :
Open the command palette with ctrl + maj + p
Search 'open settings json'
Select the user option
enter image description here
In the file look for "editor.defaultFormatter" for html (line 16 in my case)
Set its value to "esbenp.prettier-vscode"
enter image description here
Done
I had one repo formatting on save and another not, in two different VSCode windows. The broken repo was using this filename:
// incorrect
.prettierrc.json
The functioning repo was using this filename:
// correct
.prettierrc
Dropping the .json extension corrected the problem.

Visual Studio Code Emmet not working

I am using VisualStudioCode 1.20.1 Version. Emmet is inbuilt according to VSC website.But when i am trying on VSC IDE and using anchor tag and referring to class dropdown-toggle the class is not auto suggested or recognized by vsc.
In your vscode user setting, add
"emmet.includeLanguages": {
"javascript": "html"
}
That way you can use emmmet in your js files.
in vs code user setting add these
"emmet.triggerExpansionOnTab": true,
"emmet.includeLanguages": {
"javascript": "javascriptreact",
"vue-html": "html",
"razor": "html",
"plaintext": "jade"
}
This following worked for me:
Open Command Palette (Ctrl + Shift + P)
Open Settings (JSON)
Add to the end:
"emmet.showSuggestionsAsSnippets": true,
"files.associations": {
"*html": "html",
"*njk": "html"
},
I'd like to add to the others posting about emmet.includeLanguages, you can also add "vue": "html", so like:
"emmet.includeLanguages": {
"vue-html": "html",
"vue": "html",
"javascript": "html"
}
Emmet does not work on js file by default. To solve that problem you have to enable emmet abbreviation in the vscode's settings.
First, open settings.json from any directory:
vim ~/.config/Code/User/settings.json
To be more specific, on windows, you need to go to File > Preferences > Settings > Type in "Launch" > click on "Edit in settings.json"
Now you have to declare in settings.json that you will use emmet at js files:
(Its very simple just copy and paste into code setting file the code highligted)
{
/*here are your existing settings*/
/*THE CODE BELOW*/
"emmet.triggerExpansionOnTab": true,
"emmet.includeLanguages": {
"javascript": "javascriptreact",
"vue-html": "html",
"razor": "html",
"plaintext": "jade"
}
/*^^^^THE CODE ABOVE^^^^*/
}
Now just save it. Not necessary restart vscode.
For more details see that post at vscode official webite.
The issue is that you need to include the language in your settings file.
With newer versions of VSCode, you can open up settings by selecting Code > Preferences > Settings and then search for "Emmet: Include Languages" and simply add your language there.
I just did this to get emmet working on my react code.
Something I ran into that was driving me crazy trying to figure out was that the setting "emmet.showExpandedAbbreviation" will affect emmet working in your javascript files too.
To solve, remove it from your settings.json or set it to:
"emmet.showExpandedAbbreviation": "always"
Check the file extension icon, does it show up as html5 or dj (which stands for django)?
If it shows as dj, then you have the Django VSCode extension. You can do 2 things:
Remove the Django extension
Add "django-html": "html" to emmet.includeLanguages (as per this issue), so mine now looks like this:
"emmet.includeLanguages": {
"vue-html": "html",
"javascript": "javascriptreact",
"django-html": "html",
},
This happened to me in HTML files because another extension (for Django, a Python web framework) was overriding .HTML file types without a way to turn it off. I removed the extension, restarted VSCode, and now it's working again.
find setting.json file and add this code
and save it and if you don't know how to do it then watch this video
https://www.youtube.com/watch?v=AUuP_hriEc4`
"files.associations": {"*html":"html"},
"emmet.triggerExpansionOnTab": true
`
With aspnetcorerazor and razor language selection add the below code in your setting.json file:
"emmet.includeLanguages": { "aspnetcorerazor" : "html", "razor" : "html" }
In your setting.json file add this line "emmet.triggerExpansionOnTab": true,. Then ! and tab will do the work.
Go to VS Code settings -> Search Emmet -> In section Emmet:Include Languages, add {item, value}
{javascript :javascriptreact}
Tried all above , didn't work.
Updated my VScode by reinstalling it from here and everything works like a charm now.
Simply uninstall the extension related to HTML or CSS
And it work for me nicely
"editor.defaultFormatter": "VisualStudioExptTeam.vscodeintellicode"
for me emmet auto-fill stopped to work on single html page ; turnout it was bcz i used "<" twice not on a tag ( like withen the text) ,
remove them or but \ before them or use them inside (prism cdn is recomended then) will solve the issue
I ran into this issue today and realized that the following setting wasn't checked. When I checked the box, I went back to a test HTML file and used "!" to bring up the boilerplate, and this time it worked.
"Emmet: Use inline Completions"
Step 1: Start your VS Code. Click on the Settings or press Ctrl+, to open the VS Code Settings.
Step 2: Click on the Extensions tab on the left side of the settings. Click on HTML.
Step 3: Click on the Edit in settings:json hyperlink to edit the settings in JSON format.
Step 4: Inside the curly braces, enter the following code under the already written JSON code:
“emmet.triggerExpansionOnTab”:true,
“files.associations”: {“*html”:“html”},
“emmet.useInlineCompletions”:true
Step 5: Save the file. Now if you try to apply Emmet in your code, it will work smoothly!!
You have to uninstall your VS code and Node.js by going into control panel → program & features.
After the uninstall is copmlete, go to C:\Users\your_user_name_folder.
After reaching there, delete the .vscode folder.
Go to AppData\Roaming\Code (delete this Code folder).
Go to C:\Users\<your_user>\AppData\Local\Programs and delete the Microsoft VS code folder.
Now go to C:\Users\rajat\AppData\Local and delete the npm_cache folder.
Now reinstall Node.js and VSCode.

How to disable ESlint parser error messages in VSCode?

I have ESlint configured with vscode using the plugin, now I'm wondering is there some way I can stop ESlint from showing me the parser/syntax errors, so I can instead view the syntax errors that the Salsa language service provides by default.
Update: please refer this updated answer
Open up settings.json and add the property:
"eslint.enable": false
Check:
https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint
The old:
"eslint.enable": false
Is deprecated, now you need to use the builtin VSCode mechanism for disabling extensions:
In order to disable ESLint only for a specific repo (instead of disabling it globally). Create .vscode folder in your project root and there create a settings.json then add the following config:
{
"eslint.enable": false
}
Maybe after this setting you should consider adding the .vscode/settings.json line to your .gitignore file too, but it is based on your dev team's preference.
}
Additionally if you'd like to ignore only some vendor/3PP .js files only then you should consider creating an .eslintignore file. Read more about this here.
go to File => Preferences => Settings
go to Extensions=>ESLint
Uncheck the EsLint:Enable
1-) npm install -g eslint
2-) Open up settings.json and add the property: "eslint.enable": false
In VSCode, go to
File >> preferences >> settings
Type 'eslint quiet' in the search bar and click
the check box for quiet mode.
In quiet mode, eslint would ignore basic errors.
This should work for many VSCode users as at March 4, 2022.
You're welcome!
Please open settings.json file and edit the configuration as below:
"eslint.enable": false
Hope this helps.
I don't understand why some answers states that eslint.enable is depracted. it works for me. in my WorkSpace settings (JSON), I add the following configuration and eslint errors disapears
{
...
"settings": {
"eslint.enable": false
},
}

How to add semicolon to the end of the line in visual studio code

I press Shift+Enter, but not working, Ctrl+Enter start a new line, but not add semicolon at the end of previous line. Is there a shortcut?
Now there is an extension called Colonize:
Shift+Enter Insert semicolon at the end of line and continue on the same line
Alt+Enter Insert semicolon at the end of line and continue on the new line
Ctrl+Alt+Enter Insert semicolon and stay at the same position
Visual Studio Code doesn't appear to directly support adding a semi-colon to the end of a line via a keyboard shortcut, meaning it'll need a custom extension to support it. Fortunately, Sergii Naumov has created one for us, named (appropriately) 'Trailing Semicolon'.
To install this extension:
Launch Visual Studio Code
Press "Ctrl+P" (or "Command+P" on the Mac)
type "ext install Trailing Semicolon" to search for the extension
With the extension visible below the search box, click the Install Extension icon in the bottom right of the extension. (It's a cloud with an arrow pointing down...)
You will need to restart Visual Studio Code to enable the extension (Visual Studio Code should prompt you to restart once the extension has been successfully downloaded.)
According to Sergii, the default keybinding for the extension is "cmd+;". On my Mac, this meant pressing "Command+;", which worked great.
On my Windows 10 PC, I tried several key combinations ("Window+;" "Ctrl+;" "Alt+;" etc.), and nothing worked. I opened the Keyboard Shortcut preferences (File > Preferences > Keyboard Shortcuts) and searched for the new extension. I found it listed at the end of the keybindings:
{ "key": "win+;", "command": "extension.trailing-semicolon",
"when": "editorTextFocus" }
The "win" key binding apparently doesn't work. I copied this binding to the keybindings.json file, changed "win+;" to "ctrl+;" and it worked like a charm!
Hope that helps.
I wrote an extension to mimic IntelliJ's complete statement.
Pressing ctrl+; (cmd+; on mac) appends ; to the line end,
and moves cursor to line end.
If the line already ends with ;, pressing ctrl+; just moves cursor to line end.
There is also experimental support for complete structures like class, interface, function, if, switch, for, and while. (Not understanding semantic of languages, so it may not work as you expected.)
You can install it as VSIX at GitHub.
The version vscode marketplace is outdated. (Unfortunately my M$ account has been suspended, thus I cannot update it.)
There is no way to do it by default that I could find. I just had to make do as best I could.
I ended up adding a binding via File>Preferences>Keyboard Shortcuts, and then pressing ; after the shortcut. Having the semicolon is part of the binding is as close as I could get... at least my finger is already over that key
// Place your key bindings in this file to overwrite the defaults
[
{
"key": "ctrl+;",
"command": "cursorEnd",
"when": "editorTextFocus"
}
]
This simply means that Ctrl+; brings you to the end of the line, and then tap ; again.
Update (May 2021)
Started using VSCode Vim keybindings extension a few months ago. Highly recommend it. Out of interest, semi-colon end of the line is A; with vim keys⌨️
at 2021
settings >search for colon
You will find a javascript option to insert the semi-colon.
Try install the following ext then use shortcut: Ctr+; (Cmd+;)
There is a way to have semicolon appended automatically by VSCode.
By default this property is disabled:
For Windows ctrl + ,
For Mac cmd + ,
Settings -> in Search bar type: 'semicolon' -> change values to 'insert' for both JS and TS, save and close.
Now every time on save, VSCode will look for missing semicolons inside the file you're in and append them.
I just started using Visual Studio Code and felt this requirement myself yesterday. After a quick google search I found this nice extension called "Prettier". Being a little new to VSCode it took me a few hours to get it all setup but it works like a charm now. Here are the steps and my setup. I hope it helps others.
My coding environment: VSCode running on a Windows 10 desktop environment connecting to my codebase SMB share hosted on my development machine which is running Ubuntu server 18.04.
Solution Steps
Install node on the Windows desktop
Run, npm install -g prettier
Install the Prettier extension in VSCode
Edit the settings.json file for VSCode and add the following
"editor.defaultFormatter": "esbenp.prettier-vscode",
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
// Set the default
"editor.formatOnSave": true
Add the .prettierrc file at the root of my codebase on the ubuntu host (e.g.: /var/www/html/tutorials) with the following basic styling configuration
{
"semi": true,
"trailingComma": "all",
"singleQuote": true,
"printWidth": 80
}
Restart VSCode and open the code file
Use the existing VSCode keyboard shortcuts to apply formatting to the entire file (Ctrl+K Ctrl+F) or to a selection (Shift+Alt+F)
Or simply saving the file Ctrl+S adds the formatting while saving the file with no additional work required
Viola!
(March 2022) Missing semi colons can be added automatically without the needing of an extension (*with a little catch ;) They are added every time your code is formatted.
Go to settings: Look for this settings if you are writing javascript:
And/or go to settings: Look for this settings if you are writing typescript:
Go to settings: Look for this settings if you are writing javascript:
Format your code and semi colons will be added \o/ Yeah
*The catch: As the settings says: Your workspace needs to have typescript 3.7 or newer.
I know this is a really old post but Prettier - code formatter for vs code adds the semi colon (amongst other formatting).
ext install esbenp.prettier-vscode
If you need semicolons on Javascript/Typescript using vscode do:
Settings
type "semicolon"
you will have options for Javascript & Tyepscript
select the "insert" option as desired
You can also select semicolons for css, less, or scss
/*******/
You can select the "Show matching extensions" and get some extra help with extensions that address the same issue.
Go to settings: Look for this settings if you are writing javascript: enter image description here
And/or go to settings: Look for this settings if you are writing typescript: enter image description hereGo to settings: Look for this settings if you are writing javascript:
Format your code and semi colons will be added \o/ Yeah
*The catch: As the settings says: Your workspace needs to have typescript 3.7 or newer.
This solution works for me
Add the following configuration in settings.json:
"css.completion.completePropertyWithSemicolon": true
or you can cancel by:
"css.completion.completePropertyWithSemicolon": false
other
"scss.completion.completePropertyWithSemicolon": true,
"less.completion.completePropertyWithSemicolon": true
Add semicolon to the end of the line and go to the next line
Shortcode: ctrl+;
Install plugin: multicomando
ext install ryuta46.multi-command
Edit file: keybindings.json
// Place your key bindings in this file to override the defaults
[
{
"key": "ctrl+;",
"command": "extension.multiCommand.execute",
"args": {
"sequence": [
"cursorEnd",
{ "command": "type", "args": { "text": ";" } },
"lineBreakInsert",
"cursorDown"
]
},
"when": "editorTextFocus"
}
]
This plugin promotes a sequence of commands. Infinite possibilities!
I hope it helps someone!
You can try Semicolon Insertion Shortcut.
It's in Visual Studio's Preferences. Solution from sbi's answer here:
Go to Tools/Options/Environment/Keyboard.
Switch the "Use new shortcut in:" dropdown to "Text Editor".
Pick the Edit.BreakLine command.
In the Press shortcut keys edit pane press Shift+Enter.
Worked for me!
Ctrl+Shift+P and open Preferences:Open keyboard shortcuts (JSON) in VS Code
and insert
{
"key": "tab",
"command":"cursorEnd",
"when":"editorTextFocus"
}
tab is optional, ofc.
Put whatever you want from the keys on the keyboard.