How to add Prettier code formatter to your project?
28 July, 2022
2
2
0
Contributors
You can use Prettier to make your code more readable and consistent with your style guide. There are several ways to start Prettier automatically, these are the most popular:
- pretty-quick
- Use the library pretty-quick to format your changed or staged files.
- Shell script
- Save this script as
.git/hooks/pre-commit
and give it execute permission:
If git is reporting that your prettified files are still modified after committing, you may need to add a post-commit script to update git’s index.
Add something like the following to .git/hooks/post-commit
:
Configure rules
Create a *.prettierrc
file at the root of your project to configure your prettier rules.
Here's an example file containing some popular rules:
For everything you don't want to format, create a .prettierignore file:
Manual Run & Fix
To manual run via CLI, add a command to package.json and run npm run format
.
tutorial
css
javascript
cli