Last active
November 10, 2022 13:01
-
-
Save cvzi/d86cebab1a3836ca9c0a32f0397ba5ec to your computer and use it in GitHub Desktop.
pre-commit hook for JavaScript Standard Style on Windows
This file contains hidden or 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 | |
# | |
# Check staged .js files with standard (https://standardjs.com) | |
# Run with --all/-A to check all tracked *.js files, not just staged | |
# | |
if [ "$1" != "--all" ] && [ "$1" != "-A" ]; then | |
fileList=$(git diff --cached --name-only --diff-filter=ACM | grep ".js$") | |
else | |
fileList=$(git ls-tree --full-tree -r --name-only HEAD | grep ".js$") | |
fi | |
readarray -t fileList <<<"$fileList" | |
if [ ${#fileList} -lt 1 ]; then | |
echo 'standardjs - No (staged) .js files to test' | |
exit 0 | |
fi | |
# Output command with quotes | |
echo -n standard --verbose | |
for arg in "${fileList[@]}"; do | |
if [[ $arg =~ \ ]]; then | |
arg=\"$arg\" | |
fi | |
echo -n " $arg" | |
done | |
echo " | snazzy" | |
git diff --cached --name-only --diff-filter=ACM | grep ".js$"| xargs -r -E '' -t standard --verbose | snazzy | |
if [[ $? -ne 0 ]]; then | |
echo -e "\nPlease fix JavaScript Standard Style errors! Aborting commit." | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment