Last active
August 18, 2020 09:22
-
-
Save westh/a07e7baa2ef717a5b6bbb1a01337f8bb to your computer and use it in GitHub Desktop.
Just a little non-husky pre-commit hook that checks non-ascii file names and runs eslint, put it into .git/hooks if you want to use it ✌️
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
#!/bin/sh | |
# heavily inspired by @broofa's script and the default pre-commit sample | |
if git rev-parse --verify HEAD >/dev/null 2>&1 | |
then | |
against=HEAD | |
else | |
against=$(git hash-object -t tree /dev/null) | |
fi | |
allownonascii=$(git config --bool hooks.allownonascii) | |
if [ "$allownonascii" != "true" ] && | |
test $(git diff --cached --name-only --diff-filter=A -z $against | | |
LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0 | |
then | |
echo "You tried to commit a non-ASCII file name, not cool bro ❌" | |
exit 1 | |
fi | |
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep ".jsx\{0,1\}$") | |
if [[ "$STAGED_FILES" = "" ]]; then | |
exit 0 | |
fi | |
PASS=TRUE | |
echo "Linting ⏳" | |
for FILE in $STAGED_FILES | |
do | |
LINT_OUTPUT=$(npx eslint $FILE) | |
if [[ $LINT_OUTPUT != "" ]]; then | |
echo "$LINT_OUTPUT" | |
PASS=false | |
fi | |
done | |
if ! $PASS; then | |
echo "Looks like you have some errors bud ❌" | |
exit 1 | |
else | |
echo "Everything looks goodie ✅" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment