diff --git a/.husky/pre-commit b/.husky/pre-commit index 6dba6785..d12cc0df 100644 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -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 \ No newline at end of file + npm run format + if [ $? -ne 0 ]; then + echo "Backend formatting failed. Commit aborted." + exit 1 + fi + cd .. +fi \ No newline at end of file