📎 Webclip
Automatically Format your code on Git Commit using Husky, ESLint, Prettier in 9 minutes
The page explains how to automate formatting on Git commit so a project keeps a consistent code style. It uses Husky, ESLint, Prettier, and lint-staged, with setup split into package installation, ESLint and Prettier config, lint-staged rules, and a Husky pre-commit hook.
Reading notes#
- Install Husky, ESLint, Prettier, and lint-staged as dev dependencies.
- Initialize ESLint with
npx eslint --initand use or copy the generated.eslintrc.json. - Add a
.prettierrc.jsonfile in the project root with formatting options such assingleQuote,semi,trailingComma,printWidth, andtabWidth. - Add a
.prettierignorefile to skip files and folders such aspackage-lock.json,yarn.lock, andnode_modules. - Add
lint-stagedsettings inpackage.jsonso staged.js,.jsx, and.jsonfiles runeslint . --fixandprettier --write .. - Add Husky scripts and a
pre-commithook inpackage.json, then run theconfigure-huskyscript. - After committing changes, the setup formats code automatically and keeps the style consistent.
