We use Prettier to format our code. Prettier is an opinionated code formatter that enforces a consistent style by parsing your code and re-printing it with its own rules that take the maximum line length into account, wrapping code when necessary.
Note: We also have a Github Action that runs Prettier on every pull request and commits the new formats if necessary. Still, it's a good practice to run Prettier locally before pushing your changes or even having it running automatically in your IDE.
You should have Prettier installed as a development dependency in your project. If you don't, you can install it by running
npm i
# or
npm install prettier --save-devYou can run Prettier on your entire project by running
npm run prettierPrettier has integrations with most of the popular IDEs. You can find the instructions to install it in your
IDE here. Make sure to choose our configuration in the node_modules /
our .prettierrc file.
We also use Husky to run Prettier on every commit (pre-commit hook). This way, we ensure that every commit is formatted correctly. If you don't have Husky installed, you can install it by running
npm iIf you want to commit without running Husky, you can use the --no-verify flag. For example:
git commit -m "Your commit message" --no-verifyNote: We don't recommend using this flag. It's better to have your code validated and formatted before committing.