I have been using prettier with visual studio code now for a while. But recently I started thinking about how do you enforce prettiers formatting if you have developers that don't use it?
So I started looking around on prettiers website and learned that you can use it with git hooks. Having never used git hooks before I was interested and started diging more.
Run the following commands in your project.
npm install prettier --save-dev --save-exact
npm install pretty-quick husky --save-dev
Then add the below to the scripts section in your package.json
file and thats it. Now every time you commit prettier will be run against your staged files before they are committed.
{
"scripts": {
"precommit": "pretty-quick --staged"
}
}
Visit Prettier website to learn even more about this amazing tool.