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

Add the following to your settings.json file:

"editor.formatOnSave": true

Here is the menu to access the settings

Answer from Tomas Nikodym on Stack Overflow
🌐
DigitalOcean
digitalocean.com › community › tutorials › how-to-format-code-with-prettier-in-visual-studio-code
Format Code with Prettier in Visual Studio Code: Setup Guide | DigitalOcean
August 1, 2025 - Prettier Can Be Run Manually or Automatically on Save: With the Format Document command or by enabling Format On Save, you can ensure that your code is always formatted cleanly with minimal effort. You Can Customize Prettier to Match Your Preferences: Settings such as quote style, semicolon ...
Discussions

Format on Save (prettier) stopped working with latest update
Format on Save (prettier) stopped working with the latest update Multiple time reinstalled Prettier, and checked the settings, it happened right after the update of VSCode. https://gyazo.com/f07a3b... More on github.com
🌐 github.com
86
October 10, 2020
To The Developer Who Decided Format-On-Save On By Default was a Good Idea
The default value of editor.formatOnSave is false. More on reddit.com
🌐 r/vscode
25
0
April 12, 2024
Setting up Auto Format on Save easily in VS Code (Visual Studio Code) for Expo React-Native - Stack Overflow
I have tried simply downloading ... and auto-format on save did not work. I really just needed a basic setup which would automatically become the default and work for all my projects and any new projects I created. Then, perhaps a simple guide to adding a bit more customization, etc. ... Please provide enough code so others can better understand or reproduce the problem. ... I'm more of the "edit the JSON" type of user of VSCode, and the answer ... More on stackoverflow.com
🌐 stackoverflow.com
Sorting lines alphabetically on save

This may help you:
https://marketplace.visualstudio.com/items?itemName=richie5um2.vscode-sort-json
Try searching for "Sort JSON" or similar, and perhaps you may find what you're looking for.

More on reddit.com
🌐 r/vscode
6
1
December 17, 2019
🌐
YouTube
youtube.com › code 2020
VS Code tips — Format on save - YouTube
Today's VS Code tip: Format on saveAutomatically format your code when you save it. No more worrying about checking in unformatted codeUse the "editor.format...
Published   December 12, 2020
Views   23K
🌐
Visual Studio Code
code.visualstudio.com › docs › python › formatting
Formatting Python in VS Code
November 3, 2021 - You can also add the following setting to your User settings.json file to enable formatting on save for your code:
🌐
Visual Studio Marketplace
marketplace.visualstudio.com › items
Prettier - Code formatter - Visual Studio Marketplace
January 21, 2026 - Extension for Visual Studio Code - Code formatter using prettier
🌐
GitHub
github.com › microsoft › vscode › issues › 108447
Format on Save (prettier) stopped working with latest update · Issue #108447 · microsoft/vscode
October 10, 2020 - You switched accounts on another tab or window. Reload to refresh your session. ... *questionIssue represents a question, should be posted to StackOverflow (VS Code)Issue represents a question, should be posted to StackOverflow (VS Code)formattingSource formatter issuesSource formatter issues ... Multiple time reinstalled Prettier, and checked the settings, it happened right after the update of VSCode.
Author   ivanjeremic
Find elsewhere
🌐
Visual Studio Code
code.visualstudio.com › docs › editing › codebasics
Basic editing
November 3, 2021 - editor.formatOnSave Open in VS Code Open in VS Code Insiders - Format a file on save.
🌐
Medium
medium.com › @kiran.jasvanee › prettier-auto-formatting-in-visual-studio-code-beab1c026b13
Prettier Auto Formatting in Visual Studio Code. | by Kiran Jasvanee | Medium
March 22, 2020 - In the Workspace section, select Text Editor and select Formatting. Check Format on Save, the second option in Formatting and we are done here.
🌐
Boot.dev
blog.boot.dev › golang › format-on-save-vs-code-golang
Format on Save in Go With vs Code [2023]
3 weeks ago - { // format all files on save if a formatter is available "editor.formatOnSave": true, // I use "goimports" instead of "gofmt" // because it does the same thing but also formats imports "go.formatTool": "goimports", // go-specific settings "[go]": { "editor.formatOnSave": true, "editor.codeActionsOnSave": { "source.organizeImports": true } }, "[go.mod]": { "editor.formatOnSave": true, "editor.codeActionsOnSave": { "source.organizeImports": true } } }
🌐
It's FOSS
itsfoss.com › vs-code-auto-format-code
Automatically Format Code On File Save in Visual Studio Code
May 18, 2025 - Select “Prettier - Code formatter” from the list. Now try saving your file again. If Prettier is correctly selected, it should instantly reformat the code on save.
🌐
Aleksandr Hovhannisyan
aleksandrhovhannisyan.com › blog › eslint-format-on-save
How to Format on Save with ESlint | Aleksandr Hovhannisyan
August 22, 2024 - Now, open up a JavaScript file and introduce formatting errors on purpose; you should see squiggly red lines if the violation is treated as an error and orange if it’s a warning. VS Code will auto-format your code when you save the file.
🌐
Reddit
reddit.com › r/vscode › to the developer who decided format-on-save on by default was a good idea
r/vscode on Reddit: To The Developer Who Decided Format-On-Save On By Default was a Good Idea
April 12, 2024 -

... you've helped me bring my code to the next level.

Thankyou everyone for your valuable advice, I remain in awe of all this community offers. I lost a bit of formatting I wanted to keep, but I'm sure I came out ahead in the end.

Top answer
1 of 3
7

I'm more of the "edit the JSON" type of user of VSCode, and the answer from Masud was confusing to me because of that. It did push me in the right direction and I want to share for other like myself, more familiar with the .vscode/settings.json(s) than with that graphical Settings Editor.

settings.json edits - add these:

{
  "editor.defaultFormatter": "esbenp.prettier-vscode",
  "editor.formatOnSave": true
}

.prettierrc edit or add a file by that name at the root of your project for any custom settings. Here are some of my favs:

{
  "singleQuote": true,
  "tabWidth": 2,
  "trailingComma": "none"
}

Then, you can sanity check against those rules. I just added a trailing comma in an object block (in a Styles block in the sample Expo tsx component, in my case - brand new project) and see it removed on save... Then, remove the trailingComma rule, save, and try the comma again and see that the comma stays.

2 of 3
4

Regarding Auto Code Formatting:

For anyone starting out with VSCode - Expo, React-Native devs or having some issues with code formatting, please find below the simplest solution I could find (ESLint is a bit confusing / complex unless you are fairly familiar) - link to Expo guide is here if you would really like to do this (https://docs.expo.dev/guides/using-eslint/) - It is a bit complicated if you are just starting out and I find ESLint to cause too much bloat messaging on my code editor screen, especially now that there are things such as copilot etc.


[Instructions] Simply set up Prettier (no ESLint):

  1. Add 'Prettier - Code Formatter' extension in VSCode and enable it
  2. Go to the VSCode settings to set both the User and Workspace fields for a) Editor: Default Formatter to "Prettier - Code formatter", then b) check to enable Format on Save (I also checked Notebook > Format on Save).

Now get to Coding!!!


Some Next Steps:

You can check out the Expo Guide (or similar) for further best practices but it will take some time to get it all setup.

Prettier should already auto-format on save and you can further configure it by adding a .prettierrc file at the root of your project and following https://github.com/expo/expo/tree/main/packages/eslint-config-universe#customizing-prettier which should override the default settings you have set up for all your projects.

You can later setup linting as well which is generally more useful down the line for when working with remote/shared repositories (ie: they contain explanations for the correction, etc.). Causes a bit of bloat but it's quite helpful for navigating a new team / codebase (ex Amazon SDE) to understand the style guidelines being used, fixing an entire project programmatically via a script etc. with ESLint.

🌐
Visual Studio Marketplace
marketplace.visualstudio.com › items
Format document on Save - Visual Studio Marketplace
June 5, 2025 - Extension for Visual Studio - Enables auto formatting of the code when you save a file. Visual Studio supports auto formatting of the code with the CTRL+E,D or CTRL+E,F key shortcuts but with this extension the VS command 'Format Document' is ...
🌐
C# Corner
c-sharpcorner.com › blogs › its-time-to-tidy-up-your-code-how-to-use-vs-code-autoformat
It’s Time To Tidy Up Your Code: How To Use VS Code Autoformat
March 19, 2022 - By default, you can use VS code ... file, let’s check both: Open the menu File->Preferences->Settings and under Text Editor look for Formating and enable the option Format On Save choosing which option is better on ...
🌐
Oreate AI
oreateai.com › blog › taming-your-code-vs-codes-autosave-and-autoformat-magic › 4b6198c06f8e90ba75c1a6e3f9801411
Taming Your Code: VS Code's Auto-Save and Auto-Format Magic - Oreate AI Blog
3 weeks ago - When you enable this, VS Code will automatically run a formatter every time you save a file. But here's the crucial part: VS Code needs to know which formatter to use. It's not enough to just install a formatter like Prettier or Black; you need to tell VS Code to use it. This is done by specifying the editor.defaultFormatter for specific languages. So, for JavaScript, you might set it to esbenp.prettier-vscode, and for Python, perhaps ms-python.black-formatter.
🌐
Visual Studio Code
code.visualstudio.com › docs › configure › settings
User and workspace settings
November 3, 2021 - For example, when modifying the user-scope diffEditor.codeLens Open in VS Code Open in VS Code Insiders setting while there is a @lang:css filter in the search widget, the Settings editor saves the new value to the CSS-specific section of the user settings file. ... If you enter more than one language filter in the search widget, the current behavior is that only the first language filter will be used.