Skip to content

Instantly share code, notes, and snippets.

@wpcarro
Created January 5, 2018 23:00
Show Gist options
  • Save wpcarro/8e8d06d51d2dd1161840ae79f1fa7bb7 to your computer and use it in GitHub Desktop.
Save wpcarro/8e8d06d51d2dd1161840ae79f1fa7bb7 to your computer and use it in GitHub Desktop.
Run Prettier and ESLint before committing code.
#!/usr/bin/env bash
# short-circuit script for any non-zero exit
set -e
################################################################################
# This script will run ESLint over all staged files with js or jsx extensions.
# Author: William Carroll
################################################################################
# we want to exclude files that were deleted, since prettier cannot do anything
# with these
files=$(git diff --name-only --cached --diff-filter=d | grep -E '\.jsx?$')
# there will be problems if your ESLint configuration disagrees with your
# Prettier configuration
npx prettier --write ${files} && git add ${files}
npx eslint ${files}
@wpcarro
Copy link
Author

wpcarro commented Jan 5, 2018

This is an MVP and only targets javascript files. This will need to be augmented if you intend on using Prettier to format any JSON or styles code, which it does quite well!

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