Skip to content

Instantly share code, notes, and snippets.

@renesansz
Last active March 1, 2022 03:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save renesansz/1a8338d9643cabd99898a659a28dd726 to your computer and use it in GitHub Desktop.
Save renesansz/1a8338d9643cabd99898a659a28dd726 to your computer and use it in GitHub Desktop.
Pre-commit lint checking. This will run eslint command for every diff (except deleted, unmerged files)
#!/usr/bin/env bash
lint_check() {
changes="$(git diff -r --exit-code --name-only --staged --diff-filter=duxb -C packages/$1 | grep -E '.*\.(js|jsx|ts|tsx)$')"
# Only execute lint check if response code from git diff is 0 (has changes)
if [ "$?" -eq 0 ]; then
echo -e "🔎 Running lint check for \033[1;34m$1\033[0m"
npm --prefix ./packages/$1 run es ${changes//packages\/$1\//.\/}
fi
# Cancel commit if the last npm run command raised an error code (non-zero)
if [ "$?" -gt 0 ]; then
echo -e "🚨 \033[1;31mCommit cancelled, please fix the error(s) and/or warning(s)\033[0m"
exit 255
fi
}
# Run lint checks
lint_check "site-admin"
lint_check "backend-api"
lint_check "backend-api-tests"
lint_check "nextpay-ui"
echo -e "✅ \033[1;32mAll good!\033[0m"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment