Skip to content

Commit 35bfb70

Browse files
authored
Merge pull request #9062 from Neon-White/precommit-linter
Add a pre-commit ESLint hook
2 parents a68f6ef + a19b220 commit 35bfb70

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

.githooks/pre-commit

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/sh
2+
3+
# Get list of staged files
4+
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACMR | grep -E '\.(js|jsx|ts|tsx)$' | sed 's| |\\ |g')
5+
6+
# If there are no staged files, exit successfully
7+
if [ -z "$STAGED_FILES" ]; then
8+
exit 0
9+
fi
10+
11+
# Run ESLint on staged files and capture both output and exit code
12+
echo "Running ESLint on staged files..."
13+
ESLINT_OUTPUT=$(npx eslint $STAGED_FILES 2>&1)
14+
ESLINT_EXIT_CODE=$?
15+
16+
# If ESLint found errors, show them and exit with error
17+
if [ $ESLINT_EXIT_CODE -ne 0 ]; then
18+
echo "❌ ESLint found errors in staged files:"
19+
echo "$ESLINT_OUTPUT"
20+
echo "Please fix the errors above before committing."
21+
exit 1
22+
fi
23+
24+
echo "✅ ESLint passed!"
25+
exit 0

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"main": "src/api/index.js",
1515
"bin": "src/cmd/index.js",
1616
"scripts": {
17+
"preinstall": "if [ -d .git ]; then git config core.hooksPath .githooks; fi",
1718
"install": "echo install hook override to avoid npm default hook calling node-gyp",
1819
"build": "npm run build:native",
1920
"build:native": "node-gyp configure && node-gyp build",

0 commit comments

Comments
 (0)