vscode settings - How do you format code on save in VS Code

ID : 10111

viewed : 52

Tags : visual-studio-codevscode-settingscode-formattingvisual-studio-code

Top 5 Answer for vscode settings - How do you format code on save in VS Code

vote vote

94

As of September 2016 (VSCode 1.6), this is now officially supported.

Add the following to your settings.json file:

"editor.formatOnSave": true 
vote vote

82

No need to add commands anymore. For those who are new to Visual Studio Code and searching for an easy way to format code on saving, kindly follow the below steps.

  1. Open Settings by pressing [Cmd+,] in Mac or using the below screenshot.

VS Code - Open Settings Command Image

  1. Type 'format' in the search box and enable the option 'Format On Save'.

enter image description here

You are done. Thank you.

vote vote

77

If you would like to auto format on save just with Javascript source, add this one into Users Setting (press CmdShiftP or CtrlShiftP then type Open Settings (JSON) to open settings.json file)

"[javascript]": { "editor.formatOnSave": true } 
vote vote

62

For eslint:

"editor.codeActionsOnSave": { "source.fixAll.eslint": true } 
vote vote

60

For MAC user, add this line into your Default Settings

File path is: /Users/USER_NAME/Library/Application Support/Code/User/settings.json

"tslint.autoFixOnSave": true

Sample of the file would be:

{     "window.zoomLevel": 0,     "workbench.iconTheme": "vscode-icons",     "typescript.check.tscVersion": false,     "vsicons.projectDetection.disableDetect": true,     "typescript.updateImportsOnFileMove.enabled": "always",     "eslint.autoFixOnSave": true,     "tslint.autoFixOnSave": true } 

Top 3 video Explaining vscode settings - How do you format code on save in VS Code

Related QUESTION?