Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prettier disable on certain languages not working

On VS Code, I installed the prettier extensions, and since it doesn't support EJS, I added"prettier.disableLanguages": [ "ejs", ".ejs" ] to the setting.json file. This also shows up in the regular settings under Prettier: Disable Languages. Despite this, prettier keeps on re-formatting my EJS, which is super frustrating. How do I stop prettier from modifying a certain language besides this method?

like image 335
ansgup Avatar asked Jun 24 '20 06:06

ansgup


People also ask

How do I disable prettier on a specific file?

To disable Prettier checks for a single file, we can add the path of the file we want Prettier to ignore into the . prettierignore file. We follow the . gitignore file syntax to add it.

How do I ignore prettier error?

Use . prettierignore to ignore (i.e. not reformat) certain files and folders completely. Use “prettier-ignore” comments to ignore parts of files.

How do I fix prettier in VSCode?

Open up VSCode settings in UI mode by selecting File > Preferences > Settings or press Ctrl + ,. Input “formatter” in the search box. Once you see Editor: Default Formatter section, select . This setting allows you to define a default formatter which takes precedence over all other formatter settings.


1 Answers

Since Prettier knows nothing about EJS, it doesn't understand what you wrote in prettier.disableLanguages. Also VS Code considers .ejs files HTML. This not exactly accurate conclusion is passed to the Prettier extension, which in turn passes it to Prettier, so Prettier tries to format your files as pure HTML.

Try adding *.ejs to the .prettierignore file. You can read more about it here: https://prettier.io/docs/en/ignore.html

like image 157
thorn0 Avatar answered Sep 23 '22 20:09

thorn0