I am using VS Code and would like to exclude a specific json file data.json
from being formatted by Prettier on save. Say it's in the root, then I create a file .prettierignore
and add a line data.json
(according to the docs).
This works fine with other types of files, but not with json files. In fact, even writing *.json
will still format the json files.
There is a setting in VS Code
JSON > Format:Enable
Enable/disabled default JSON formatter
which is enabled. When I disabled it, however, no json file will be formatted on save. This is not what I want. I only want to exclude a specific json file. How can I achieve this?
I have already seen the related question 46409892.
I think your VS Code formatter is not Prettier by default for JSON (or maybe not your default formatter for all documents ?)
To define a formatter by default, according to Prettier doc, you have to set your VS Code settings file like this :
{
// For all files
"editor.defaultFormatter": "esbenp.prettier-vscode",
// For JSON specifically
"[json]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
}
Then, you can define ignored files in your .prettierignore
using same syntax as .gitignore
.