Skip to content

Instantly share code, notes, and snippets.

@quangnd
Forked from jhartikainen/commit-msg
Created March 27, 2018 08:15
Show Gist options
  • Save quangnd/0e7d8ffdd589992e8cbd94d2f8cfb4ec to your computer and use it in GitHub Desktop.
Save quangnd/0e7d8ffdd589992e8cbd94d2f8cfb4ec to your computer and use it in GitHub Desktop.
ESLint git commit hook
#!/bin/bash
files=$(git diff --cached --name-only | grep '\.js$')
# Prevent ESLint help message if no files matched
if [[ $files = "" ]] ; then
exit 0
fi
echo $files | xargs eslint
rc=$?
if [[ $rc != 0 ]] ; then
echo "ESLint check failed, commit denied"
exit $rc
fi
@quangnd
Copy link
Author

quangnd commented Mar 27, 2018

I recommend automating ESLint to your git commits. This way you will never commit in code that doesn't pass a check.

I've created an example git hook that you can use.

Download the git hook
Place the file into .git/hooks/commit-msg. This should be where you created or cloned your git repository
Now whenever you commit, ESLint will run and check any .js files for issues. If ESLint finds any issues, it will block the commit.

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