Skip to content

Commit

Permalink
Add pre-commit hook using husky for linting and formatting (#281)
Browse files Browse the repository at this point in the history
* Add pre-commit hook for linting and formatting

* Separate checking command failures

* Change to lint-staged for pre-commit hook

* Clearly revise the error message
  • Loading branch information
choidabom authored Aug 12, 2024
1 parent f2e1160 commit 7df0fc0
Show file tree
Hide file tree
Showing 5 changed files with 13,617 additions and 13,535 deletions.
34 changes: 34 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
CHANGED_FILES=$(git diff --cached --name-only)

LINT_FRONTEND=false
LINT_BACKEND=false

for FILE in $CHANGED_FILES; do
if [[ "$FILE" =~ ^frontend/ ]]; then
LINT_FRONTEND=true
elif [[ "$FILE" =~ ^backend/ ]]; then
LINT_BACKEND=true
fi
done

if [ "$LINT_FRONTEND" = true ]; then
echo "Changes detected in the frontend. Linting & Formatting frontend..."
cd frontend
npx lint-staged
if [ $? -ne 0 ]; then
echo "Frontend Linting & Formatting failed. Commit aborted."
exit 1
fi
cd ..
fi

if [ "$LINT_BACKEND" = true ]; then
echo "Changes detected in the backend. Linting & Formatting backend..."
cd backend
npx lint-staged
if [ $? -ne 0 ]; then
echo "Backend Linting & Formatting failed. Commit aborted."
exit 1
fi
cd ..
fi
Loading

0 comments on commit 7df0fc0

Please sign in to comment.