Created
January 5, 2018 23:00
-
-
Save wpcarro/8e8d06d51d2dd1161840ae79f1fa7bb7 to your computer and use it in GitHub Desktop.
Run Prettier and ESLint before committing code.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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!