DEV Community

Bimochan Shrestha
Bimochan Shrestha

Posted on

Integration of ESlint, Prettier and Husky

To integrate ESlint, Prettier, and husky into your project, you will need to follow these steps:

Install the necessary dependencies:

npm install --save-dev eslint prettier husky

Set up ESlint by creating an .eslintrc configuration file. You can do this either manually or by using the eslint --init command, which will guide you through the process of creating the configuration file.

Set up Prettier by creating a .prettierrc configuration file. This file should contain the Prettier configuration options that you want to use.

Add the following script to your package.json file:

"scripts": {
"precommit": "eslint --fix && prettier --write"
}

This script will run ESlint and Prettier on your code whenever you try to commit changes using git commit.

Configure husky to run the precommit script by adding the following block to your package.json file:

"husky": {
"hooks": {
"pre-commit": "npm run precommit"
}
}

You can now run git commit as usual and ESlint and Prettier will automatically run and fix any issues before the commit is finalized.

Note: If you want to run ESlint and Prettier on all files in your project, you can use the --find-related-files flag, like this:

"scripts": {
"precommit": "eslint --fix --find-related-files && prettier --write --find-related-files"
}

This will scan your project for all files that match the patterns specified in your ESlint and Prettier configuration files and lint and format them.

Top comments (0)