The GIT Base implements GIT helpers and hooks to automate tasks within your project.
This hook runs before the files are committed locally.
Example:
#!/bin/bash
#### Define globals
FILES=$(git diff --cached --name-only --diff-filter=ACMR "*.js" | sed 's| |\\ |g')
PRETTIER="$(git rev-parse --show-toplevel)/node_modules/.bin/prettier"
ESLINT="$(git rev-parse --show-toplevel)/node_modules/.bin/eslint"
# Check if JS files are being committed
[ -z "$FILES" ] && exit 0
# Check if node_modules are installed
if [[ ! -x "$PRETTIER" ]]; then
printf "Please install the node_modules before committing!!"
exit 1
fi
# Check if node_modules are installed
if [[ ! -x "$ESLINT" ]]; then
printf "Please install the node_modules before committing!!"
exit 1
fi
#### Prettier Begin ####
# Prettify all selected files
echo "$FILES" | xargs $PRETTIER --write
# Add back the modified/prettified files to staging
echo "$FILES" | xargs git add
#### Prettier End ####
#### ESLint Begin ####
PASS=true
for FILE in $FILES
do
"$ESLINT" "$FILE"
if [[ "$?" == 0 ]]; then
printf ""
else
PASS=false
fi
done
if ! $PASS; then
printf "COMMIT FAILED: Your commit contains files that should pass ESLint but do not. Please fix the ESLint errors and try again.\n"
exit 1
fi
exit $?
#### ESLint End ####
https://github.com/DPDK-NL/dpdk_npm_git
Last modified | Wednesday, March 24, 2021, 9:08:59 AM UTC |
Last author | Glenn de Haan |
Commit ID | 319f2b7 |