Skip to content

Instantly share code, notes, and snippets.

@edasque
Last active December 22, 2020 15:10
Show Gist options
  • Select an option

  • Save edasque/ab826eb94aae97239132 to your computer and use it in GitHub Desktop.

Select an option

Save edasque/ab826eb94aae97239132 to your computer and use it in GitHub Desktop.
pre-commit Git hook to JSONlint - place it in .git/hooks
#!/bin/sh
git diff-index -z --cached HEAD --name-only --diff-filter=ACMRTUXB |
xargs -0 -t -L1 /usr/local/bin/jsonlint -c;
if [ "$?" != "0" ]; then
echo "\nOne or more JSON file didn't pass jsonlint'ing.";
echo "Fix them before committing. If it is not possible to fix them all commit with the option --no-verify.";
exit 1;
fi
@edasque

edasque commented Feb 19, 2016

Copy link
Copy Markdown
Author

This works on a mac. xargs is a little bit different on linux where it probably should be changed to xargs --null --no-run-if-empty /usr/local/bin/jsonlint -c;.
This assumes jsonlint 1.6.x is installed in /usr/local/bin

@v6

v6 commented May 8, 2017

Copy link
Copy Markdown

// , Nice work. This was the third result in my search for jsonlint hook.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment