Skip to content

Instantly share code, notes, and snippets.

@r3nya
Forked from dahjelle/pre-commit.sh
Created November 18, 2016 14:22
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 r3nya/583b2aa85acc147da831281cf2d354e1 to your computer and use it in GitHub Desktop.
Save r3nya/583b2aa85acc147da831281cf2d354e1 to your computer and use it in GitHub Desktop.
Pre-commit hook for eslint, linting *only* staged changes.
#!/bin/bash
for file in $(git diff --cached --name-only | grep -E '\.(js|jsx)$')
do
git show ":$file" | node_modules/.bin/eslint --stdin --stdin-filename "$file" # we only want to lint the staged changes, not any un-staged changes
if [ $? -ne 0 ]; then
echo "ESLint failed on staged file '$file'. Please check your code and try again. You can run ESLint manually via npm run eslint."
exit 1 # exit with failure status
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment