I created a new project with create-react-app. I have configured prettier tool. Unfortunately, formatting on save doesn't work on this project. Works fine on other projects. What could have happened?
My VSCode setting is:
{
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSaveMode": "modifications",
}
Since this is a new project, I presume that means it is not in source control. The setting "modifications" will not work in that situation, as described on the site (https://code.visualstudio.com/docs/getstarted/settings):
// Controls if format on save formats the whole file or only modifications. Only applies when `editor.formatOnSave` is enabled.
// - file: Format the whole file.
// - modifications: Format modifications (requires source control).
// - modificationsIfAvailable: Will attempt to format modifications only (requires source control). If source control can't be used, then the whole file will be formatted.
Try using "modificationsIfAvailable" instead:
{
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSaveMode": "modificationsIfAvailable",
}