lefthook icon indicating copy to clipboard operation
lefthook copied to clipboard

pre-commit hook command doesn't work with prettier

Open yurkimus opened this issue 4 years ago • 1 comments

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?

yurkimus avatar May 29 '21 22:05 yurkimus

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

bennycode avatar May 21 '22 22:05 bennycode