mirror of
https://github.com/matt-fidd/stratos.git
synced 2026-01-01 18:39:32 +00:00
Added husky pre-commit hook
This commit is contained in:
32
.husky/pre-commit
Executable file
32
.husky/pre-commit
Executable file
@@ -0,0 +1,32 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
cd "$(git rev-parse --show-toplevel)"
|
||||||
|
ESLINT="node_modules/.bin/eslint"
|
||||||
|
pwd
|
||||||
|
|
||||||
|
if [[ ! -x "$ESLINT" ]]; then
|
||||||
|
printf "\t\033[41mPlease install ESlint\033[0m (npm i --save-dev eslint)\n"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
STAGED_FILES=($(git diff --cached --name-only --diff-filter=ACM | grep "\.js$"))
|
||||||
|
|
||||||
|
echo "Linting ${#STAGED_FILES[@]} files"
|
||||||
|
|
||||||
|
if [[ "$STAGED_FILES" = "" ]]; then
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
$ESLINT "${STAGED_FILES[@]}"
|
||||||
|
|
||||||
|
ESLINT_EXIT="$?"
|
||||||
|
|
||||||
|
#ESLINT_EXIT=0
|
||||||
|
|
||||||
|
if [[ "${ESLINT_EXIT}" == 0 ]]; then
|
||||||
|
printf "\n\033[42mCOMMIT SUCCEEDED\033[0m\n"
|
||||||
|
else
|
||||||
|
printf "\n\033[41mCOMMIT FAILED:\033[0m Fix eslint errors and try again\n"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
exit $?
|
||||||
Reference in New Issue
Block a user