Skip to content

Instantly share code, notes, and snippets.

@bultas
Forked from jhartikainen/commit-msg
Last active March 4, 2016 08:22
Show Gist options
  • Save bultas/688ef4d04ae8783dbd3a to your computer and use it in GitHub Desktop.
Save bultas/688ef4d04ae8783dbd3a to your computer and use it in GitHub Desktop.
Pre-commit to check tracked/commited js/jsx files with ESlint (node_modules)
#!/bin/bash
files=$(git diff --diff-filter=ACMRT --cached --name-only | grep '\.jsx\|\.js\?$')
# Prevent ESLint help message if no files matched
if [[ $files = "" ]] ; then
exit 0
fi
failed=0
for file in ${files}; do
git show :$file | node_modules/eslint/bin/eslint.js --stdin --stdin-filename $file
if [[ $? != 0 ]] ; then
failed=1
fi
done;
if [[ $failed != 0 ]] ; then
echo "ESLint check failed, commit denied"
exit $failed
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment