lefthook
lefthook copied to clipboard
pre-commit hook command doesn't work with prettier
I have this in my lefthook.yml:
pre-commit:
commands:
prettier:
run: npx prettier -w {staged_files}
Then I edit my .js file and stage it:
git add .
After it I am testing lefthook to run pre-commit commands with lefthook run pre-commit and I get:
RUNNING HOOKS GROUP: pre-commit
⠦ waiting [error] No files matching the pattern were found: "'src/pages/news/[id]/index.js'".
EXECUTE > prettier
lefthook.yml 34ms
SUMMARY: (done in 0.83 seconds)
🥊 prettier
What I do wrong and how to fix this behavior?
I think the problem here is Prettier's exit code. I was able to fix this problem with a workaround by using pretty-quick:
lefthook.yml
pre-commit:
parallel: true
commands:
prettier:
run: yarn pretty-quick --staged --ignore-path .gitignore