- Select
File -> Preferences -> Settings(Ctrl+comma) and search formformatter - Set Prettiers as Default formatter.

If above does not work:
ctrl+shift+p > Format Document With... > Configure Default Formatter... > Prettier - Code formatter
This also work with ctrl+shift+I
prettier - problems with code formatting on save in vscode - Stack Overflow
I have done all kinds of things but my prettier does not format on save.
Does Prettier work with autosave?
Setting up Auto Format on Save easily in VS Code (Visual Studio Code) for Expo React-Native - Stack Overflow
Videos
- Select
File -> Preferences -> Settings(Ctrl+comma) and search formformatter - Set Prettiers as Default formatter.

If above does not work:
ctrl+shift+p > Format Document With... > Configure Default Formatter... > Prettier - Code formatter
This also work with ctrl+shift+I
If doing what @Simin Maleki mentioned does not solve it for you, there is a chance that your default formatter is not set:
File > Preferences > Settings > Search for "default formatter"
Make sure your Editor: Default Formatter field is not null but rather Prettier - Code formatter (esbenp.prettier-vscode) and that all the languages below are ticked. This fixed my issue.
STEP BY STEP WALKTHROUGH

Also make sure that your format on save is enabled:

Update, i just find the solution if anyone is having the same problem i have to add the following lines to user setting json
"editor.defaultFormatter": "esbenp.prettier-vscode",
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
Press Ctrl+shift+p and type Preferences: Open User Settings (JSON). In that json file add the following line and save. This should enable so vscode formats the code each time you save.
{
"editor.formatOnSave": true
}
I have installed Prettier and changed the defaults to use Prettier as per the documentation. I have turned on auto-save in VS Code therefore Prettier should work every time I make a change but it doesn't. It only works when I manually save by pressing Ctrl + S. Is this the intended behavior or am I missing something?
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.
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):
- Add 'Prettier - Code Formatter' extension in VSCode and enable it
- 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.
Hello, I am banging my head against a wall.
For long I had no autoformatting enabled in Vscode, when eslint (or prettier - I use the eslint prettier package) complained about some styling formatting I hovered over the error and clicked "Fix all problems" in Vscode.
But then I thought I finally need to setup the fix/format on save thingy… I enabled format on save in vscode settings And added this in my settings json in my project:
"editor.formatOnSave": true, "editor.codeActionsOnSave": { "source.fixAll.eslint": true },
And it works!
But it seems I have some conflicting rules or stuff. Because I have something like this: some function => {} and when I hit save it formats to add a whitespace inside the curly braces: some function => { }
And here begins my problem. With the space I get an eslint error to remove the whitespace but when saving it adds it again. I am basically stuck lol
I tried to revert the settings in vscode but it keeps happening and I have no idea where to look for to fix this issue?
I will really appreciate any help or hints.