Skip to content

Commit

Permalink
Separate checking command failures
Browse files Browse the repository at this point in the history
  • Loading branch information
choidabom committed Aug 11, 2024
1 parent af36b92 commit 8a3b0e5
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,41 @@ LINT_FRONTEND=false
LINT_BACKEND=false

for FILE in $CHANGED_FILES; do
if [[ $FILE =~ ^frontend/ ]]; then
if [[ "$FILE" =~ ^frontend/ ]]; then
LINT_FRONTEND=true
elif [[ $FILE =~ ^backend/ ]]; then
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
cd frontend
npm run lint
if [ $? -ne 0 ]; then
echo "Frontend linting failed. Commit aborted."
exit 1
fi
npm run format
if [ $? -ne 0 ]; then
echo "Frontend 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 && npm run lint && npm run format
EXIT_CODE=$?
cd ..
if [ $EXIT_CODE -ne 0 ]; then
echo "Changes detected in the backend. Linting & Formatting backend..."
cd backend
npm run lint
if [ $? -ne 0 ]; then
echo "Backend linting failed. Commit aborted."
exit 1
fi
fi
npm run format
if [ $? -ne 0 ]; then
echo "Backend formatting failed. Commit aborted."
exit 1
fi
cd ..
fi

0 comments on commit 8a3b0e5

Please sign in to comment.