How to base .prettierignore file on .gitignore

Viewed 5876

Looking at the Prettier docs, there is a tip to base your .prettierignore file on your .gitignore file.

https://prettier.io/docs/en/install.html

Tip! Base your .prettierignore on .gitignore and .eslintignore (if you have one).

Can someone explain what this means and how to do this? Is there a way to automatically add everything to your .prettierignore included in your .gitignore?

4 Answers

You can actually pass a flag to your prettier command --ignore-path and then give it the path of your .gitignore file so it will use that instead of the .prettierignore file.

prettier --ignore-path .gitignore

They're not implying there's an automatic way to do this, but you could cp .gitignore .prettierignore (or copy it some other way, such as in your IDE). There is a proposal to include other ignore files as well as a node tool to automate this for you if you want to, though.

From what I can tell from reading the docs is they mean to have the same files in your .prettierignore as you do in your .gitignore, since anything in .gitignore won't be check into your repository anyway, not that you can point the .prettierignore to .gitignore and have it use that file, though that would be cool. There's a similar issue raised and close here that mentions using symlink since they use the same structure.

Don't copy the file, link it to your .gitignore so they keep in sync if you edit them in the future:

ln -s .gitignore .prettierignore
Related