Skip to content

Instantly share code, notes, and snippets.

@luuuis luuuis/ forked from dahjelle/
Last active May 15, 2019

What would you like to do?
Pre-commit hook for eslint, linting *only* staged changes.
#!/usr/bin/env bash
set -uo pipefail
# Improvements from dahjelle/
# - does not lint deleted files,
# - lints all staged files before exiting with an error code,
# - handles spaces and other unusual chars in file names.
# Based also on @jancimajek's one liner in that Gist.
# ESLint staged changes only
git diff --diff-filter=d --cached --name-only -z -- '*.js' '*.jsx' \
| xargs -0 -I % sh -c 'git show ":%" | ./node_modules/.bin/eslint --stdin --stdin-filename "%";'
if [ ${eslint_exit} -eq 0 ]; then
echo "✓ ESLint passed"
echo "✘ ESLint failed!" 1>&2
exit ${eslint_exit}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.