Description
I've noticed a pull requests where files show multiple line changes even though nothing was actually modified. This usually happens when someone saves a file and their local Prettier setup reformats it differently. It clutters the diff and makes PRs harder to review.
To fix this, we should add Husky and lint-staged so that Prettier runs automatically on staged files before commits. That way, everyone’s code is formatted the same way and we avoid unnecessary changes showing up in reviews.
Proposed Implementation
-
Add Husky and lint-staged as dev dependencies.
-
Add a prepare script in package.json to enable Husky after install.
-
Create a .husky/pre-commit file that runs:
-
Add the following lint-staged config to package.json:
{
"*.{js,jsx,ts,tsx,md,json,css}": "prettier --write"
}
-
(Optional) Include ESLint with eslint --fix if we want linting checks too.
Example Configuration
"scripts": {
"prepare": "husky"
},
"devDependencies": {
"husky": "^9.1.7",
"lint-staged": "^16.2.3",
"prettier": "^3.6.2"
},
"lint-staged": {
"*.{js,jsx,ts,tsx,md,json,css}": "prettier --write"
}
And in .husky/pre-commit:
Expected Result
- Prettier runs automatically before every commit.
- No more random formatting diffs in pull requests.
- Consistent and clean code style across the project.
Additional Notes
I'd like to take this issue and set up the configuration.
Description
I've noticed a pull requests where files show multiple line changes even though nothing was actually modified. This usually happens when someone saves a file and their local Prettier setup reformats it differently. It clutters the diff and makes PRs harder to review.
To fix this, we should add Husky and lint-staged so that Prettier runs automatically on staged files before commits. That way, everyone’s code is formatted the same way and we avoid unnecessary changes showing up in reviews.
Proposed Implementation
Add Husky and lint-staged as dev dependencies.
Add a
preparescript inpackage.jsonto enable Husky after install.Create a
.husky/pre-commitfile that runs:Add the following
lint-stagedconfig topackage.json:{ "*.{js,jsx,ts,tsx,md,json,css}": "prettier --write" }(Optional) Include ESLint with
eslint --fixif we want linting checks too.Example Configuration
And in
.husky/pre-commit:Expected Result
Additional Notes
I'd like to take this issue and set up the configuration.