Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pre-commit hook using husky for linting and formatting #281

Merged
merged 4 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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