chore: fix pre-commit hook to enforce formatting and linting (#2297)

The pre-commit hook existed but was not executable and used raw
prettier instead of lint-staged. This fixes:

- Make .husky/pre-commit executable (was -rw-r--r--)
- Use `npx lint-staged` instead of raw prettier/eslint commands
- Remove deprecated husky v4 config from package.json (hooks key)
- Remove unnecessary `git add` from lint-staged (auto-staged in v15)
- Add eslint --fix to lint-staged for JS/TS files

All contributors now get automatic formatting + linting on commit.

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Logan Yang 2026-03-14 20:10:05 -07:00 committed by GitHub
parent 1f2539712d
commit 095a5f2011
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 5 additions and 13 deletions

7
.husky/pre-commit Normal file → Executable file
View file

@ -1,6 +1 @@
# .husky/pre-commit
prettier $(git diff --cached --name-only --diff-filter=ACMR | sed 's| |\\ |g') --write --ignore-unknown
git update-index --again
# Add linting
npm run lint
npx lint-staged

View file

@ -22,15 +22,12 @@
},
"keywords": [],
"author": "Logan Yang",
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.{js,jsx,ts,tsx,json,css,md}": [
"prettier --write",
"git add"
"prettier --write"
],
"*.{js,jsx,ts,tsx}": [
"eslint --fix --no-warn-ignored"
]
},
"license": "AGPL-3.0",