I'm using VsCode with Prettied Extension. Prettier in some cases is formatting inside the HTML element (I.g. Class value), which is annoying, because its breaking the property in multiple lines unnecessarily, Hence:
I don't want to use “prettier-ignore” comments for every line in code because its tedious and
I don't want to use .prettierignore file in root, because in my understanding it ignores the HTML files and also turn off vscode's default HTML formatter.
I want to allow prettier for all the languages except for HTML, so I put a file with the extension .prettierrc in project root with the content as following:
{
"editor.defaultFormatter": "esbenp.prettier-vscode",
"[html]": {
"editor.defaultFormatter": null
}
}
Now my question is:
Can I use .prettierignore file in root, if so, will it disable vscode's HTML default formatter?
Check my .prettierrc config file and let me know if its the right (or another) way.
A good workaround for your desired result would be to switch HTML formatting to the default vscode formatter and then leave everything else for Prettier. We can do that just by changing a value in our settings.json
You can press Ctrl + Shift + P
in vscode to open the command pallete and search for open settings
, you will find a setting called Preferences: Open Settings (JSON)
or you can straight up go to C: -> Users -> UserName -> Roaming -> Code -> User
and then open settings.json
.
Then make sure to change/fill in these values:
"editor.defaultFormatter": "esbenp.prettier-vscode",
"[html]": {
"editor.defaultFormatter": "vscode.html-language-features"
},
That way you don't need any prettier configuration files. I hope I helped.