-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add pre-commit hook using husky for linting and formatting (#281)
* 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
Showing
5 changed files
with
13,617 additions
and
13,535 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.