Sitemap

Member-only story

Automatically Format your code on Git Commit using Husky, ESLint, Prettier in 9 minutes

3 min readMar 13, 2022

--

When collaborating on a project with several other developers, maintaining a consistent code style drastically improves the code readability and maintainability.

Luckily we can automate this crucial process using Husky, ESLint, Prettier to make sure the code is formatted, every time someone commits.

1. Install Packages

We need to install the following packages:

  • Husky: A tool that makes working with git hooks a piece of cake
  • ESLint: Linter for JavaScript
  • Prettier: Code formatter
  • Lint-staged: As the docs state: Run linters against staged git files and don't let 💩 slip into your codebase!

To install the packages, use:

npm install --save-dev eslint prettier lint-staged husky

2. Configure ESLint

Run the following command to initialize ESLint:

npx eslint --init

You will be prompted to answer a few questions, from which the configuration for your specific use case will be generated

--

--

Tapajyoti Bose
Tapajyoti Bose

Written by Tapajyoti Bose

Top Rated Freelancer || Blogger || Cross-Platform App Developer || Web Developer || Open Source Contributor || FIRE Enthusiast

Responses (4)