Skip to content

Instantly share code, notes, and snippets.

@aalin
Created August 9, 2017 09:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aalin/68167bada0f90e9a2175a23b985dc31b to your computer and use it in GitHub Desktop.
Save aalin/68167bada0f90e9a2175a23b985dc31b to your computer and use it in GitHub Desktop.
Run prettier on staged files
#!/bin/bash
prettier=$(npm bin)/prettier
git diff --cached --name-status src/ | while read -r status filename; do
# skip deleted files
if [[ "$status" == "D" ]]; then continue; fi
if [[ "$filename" =~ \.jsx?$ ]]; then
"$prettier" --single-quote --no-bracket-spacing --write "$filename" || exit 1
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment