Skip to content

Commit

Permalink
Add pre-commit hook for linting and formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
choidabom committed Aug 10, 2024
1 parent f2e1160 commit af36b92
Show file tree
Hide file tree
Showing 5 changed files with 13,605 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 && npm run lint && npm run format:check
EXIT_CODE=$?
cd ..
if [ $EXIT_CODE -ne 0 ]; then
echo "Frontend linting failed. Commit aborted."
exit 1
fi
fi

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

0 comments on commit af36b92

Please sign in to comment.