Skip to content

Instantly share code, notes, and snippets.

@johngrimes
Created February 14, 2018 22:15
Show Gist options
  • Save johngrimes/843b435def6cfb59ce826b009a7e9894 to your computer and use it in GitHub Desktop.
Save johngrimes/843b435def6cfb59ce826b009a7e9894 to your computer and use it in GitHub Desktop.
Format staged files with Prettier before commit
#!/bin/bash
STAGED=$(git diff --name-only --cached --diff-filter=AM | egrep '^(.*).(js|json|css)$')
yarn prettier --write $STAGED
git add $STAGED
{
"name": "my-app",
"version": "0.1.0",
"dependencies": {},
"devDependencies": {
"pre-commit": "^1.2.2",
"prettier": "^1.10.2"
},
"scripts": {
"format-staged": "bash scripts/formatStagedFiles.sh"
},
"pre-commit": ["lint", "format-staged", "test"]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment