Skip to content

Instantly share code, notes, and snippets.

@kyuwoo-choi
Forked from wesbos/commit-msg
Last active April 18, 2017 06:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kyuwoo-choi/071d3fdabb666a377afb088f484b7fa8 to your computer and use it in GitHub Desktop.
Save kyuwoo-choi/071d3fdabb666a377afb088f484b7fa8 to your computer and use it in GitHub Desktop.
ESLint 3.0 Git Pre Commit Hook
#!/bin/zsh
source ~/.zshrc #in case your tools do not export path
files=$(git diff --cached --name-only | grep '\.jsx\?$')
# Prevent ESLint help message if no files matched
if [[ $files = "" ]] ; then
exit 0
fi
failed=0
for file in ${files}; do
git show :$file | eslint $file
if [[ $? != 0 ]] ; then
failed=1
fi
done;
if [[ $failed != 0 ]] ; then
echo "🚫🚫🚫 ESLint failed, git commit denied!"
exit $failed
fi
@kyuwoo-choi
Copy link
Author

kyuwoo-choi commented Apr 18, 2017

  1. rename your pre-commit hook
mv .git/hooks/pre-commit.sample .git/hooks/pre-commit
  1. copy & paste above script to .git/hooks/pre-commit
  2. if you use bash, modify shebang and source
#!/bin/bash 
source ~/.bash_profile
  1. git automatically sets right permission for hooks if not give the hook execute
chmod a+x .git/hooks/pre-commit
  1. done

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