DEV Community

Bimochan Shrestha
Bimochan Shrestha

Posted on

1

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.

AWS Q Developer image

Your AI Code Assistant

Automate your code reviews. Catch bugs before your coworkers. Fix security issues in your code. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay