Pre-commit hook runs for all files rather than only for those that are staged
See original GitHub issueI am using simple configuration via package.json:
"lint-staged": {
"*.js": ["prettier --write", "eslint", "git add"]
}
During commit of one file, prettier is run for all files (matching *.js
) in my project rather then only for the file(s) being committed.
After execution of pre-commit hook, I see that hook did modifications in some files which are marked as unstaged by git. (Those files weren’t modified before commit)
Using:
husky 0.14.3
lint-staged 6.0.0
prettier 1.8.2
I didn’t hit this issue on different projects where we are using older version of lint-stage (v 5.0.0).
Console log:
Issue Analytics
- State:
- Created 6 years ago
- Comments:5
Top Results From Across the Web
Run eslint "ONLY" on the staged files - Stack Overflow
I am using husky and lint-staged. But it runs the lint command for all the files in src and not on staged files...
Read more >Pre-commit Hook - Prettier
You can use Prettier with a pre-commit tool. This can re-format your files that are marked as “staged” via git add before you...
Read more >pre-commit
We built pre-commit to solve our hook issues. It is a multi-language package manager for pre-commit hooks. You specify a list of hooks...
Read more >How to use git pre-commit hooks, the hard way and the easy ...
You can also run pre-commit run --all-files at any time to run your pre-commit hooks against all files in your repository. I highly...
Read more >pre-commit: Various Ways to Run Hooks - Adam Johnson
pre-commit's main mode of operation is to run hooks against changed files when you commit. But you can also run hooks without committing, ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The problem is here:
You have a script named
prettier
which takes priority. You can also see this in the logs:This gets executed using
npm
:On the other hand,
eslint
andgit
are resolved correctly:So just rename your script to something like
format
and you should be good.No problem. This behavior seems to trip quite a few people. We have been considering removing support for npm scripts or at least de-prioritizing it over installed binaries.