Skip to content

Instantly share code, notes, and snippets.

@aughban
Last active December 19, 2015 07:19
Show Gist options
  • Save aughban/5917474 to your computer and use it in GitHub Desktop.
Save aughban/5917474 to your computer and use it in GitHub Desktop.
pre-commit for git to check json files syntax are correct.
#!/bin/bash
if git-rev-parse --verify HEAD >/dev/null 2>&1; then
against=HEAD
else
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi
exec 1>&2
flag=0
for FILE in `git diff --name-only $against --` ; do
# Check if the file contains 'debugger'
if [ ${FILE: -4} == "json" ]; then
echo "Validating ${FILE}..."
ERROR=`/usr/local/share/npm/bin/jsonlint -c \`pwd\`/$FILE`
if [ $? -ne 0 ]; then
ERROR="$FILE: $ERROR"
flag=1
ERRORS="${ERRORS}\n${ERROR}" | sed s/^\n//g
fi
fi
done
if [ $flag -ne 0 ]; then
exit 1
fi
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment