Skip to content

Commit effa7a2

Browse files
committed
Add JS linting to pre-commit hook
Run lint:js on changed JS/JSX/TS/TSX files during pre-commit to catch lint errors before they're committed.
1 parent 70a2df6 commit effa7a2

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

.githooks/pre-commit

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@ if [ -n "$PHP_FILES" ]; then
5454
echo "$PHP_FILES" | xargs composer lint:fix > /dev/null 2>&1 || { echo "PHP formatting failed"; exit 1; }
5555
fi
5656

57+
# Get all changed JS/TS files.
58+
JS_FILES=$(git diff --cached --name-only --diff-filter=ACMR | grep -E "\.(js|jsx|ts|tsx)$" || true)
59+
60+
# Run JS linting on changed files.
61+
if [ -n "$JS_FILES" ]; then
62+
echo "$JS_FILES" | xargs npm run lint:js -- || { echo "JavaScript linting failed"; exit 1; }
63+
fi
64+
5765
# Run the WordPress formatter without showing all file output.
5866
npm run format > /dev/null 2>&1 || { echo "JavaScript formatting failed"; exit 1; }
5967

0 commit comments

Comments
 (0)