Skip to content

Instantly share code, notes, and snippets.

@jonalvarezz
Last active October 11, 2017 13:46
Show Gist options
  • Save jonalvarezz/300ebf335d86c5dbd54e71c8b39aaec7 to your computer and use it in GitHub Desktop.
Save jonalvarezz/300ebf335d86c5dbd54e71c8b39aaec7 to your computer and use it in GitHub Desktop.
Run ESLint with JS/JSX in Git pre-commit hook

Run ESLint with JS/JSX in Git pre-commit hook

Get rid off Syntax fix commits enabling your linter everytime a git commit try to be done.

This example features local eslint with js and jsx validation

Enable this hook creating or modifying the file /your/project/path/.git/hooks/pre-commit

#!/bin/sh 
# Ensure all javascript files staged for commit pass standard code style 
ROOT_DIR=$(git rev-parse --show-toplevel)
LINT="${ROOT_DIR}/node_modules/eslint/bin/eslint.js --ext .js --ext .jsx"

git diff --name-only --cached --relative | grep '\.jsx\?$' | xargs node $LINT
if [ $? -ne 0 ]; then exit 1; fi

Based on StandardJS

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