Description
🔧 Summary
This may be me misunderstanding lefthook's philosophy, but after reading through those issues and PRs:
- feature: Skip unstaged changes for pre-commit hook #402
- Runs on contents which aren't staged for commit #60
- run hook against changed content only #239
- Documentation/Feature request:
git stash
onpre-commit
andpre-push
#131 - fix: try ignoring empty patch files on pre commit hook #676
- Restoring unstaged changes fails with git < 2.35.0 #584
I was convinced that lefthook stashes the changes before running pre-commit hooks. It seems to me however that this does not include untracked files. This means that if I add new files to the project without staging them, then they will be a part of hook's evaluation unless I explicitly specify the files for the linting / formatting tool with {staged_files} placeholder.
This is an issue for me since in our projects we often prepare npm scripts, like:
"lint": "pnpm lint:prettier && pnpm lint:eslint && astro check && tsc",
"lint:eslint": "eslint --max-warnings=0 src",
"lint:prettier": "prettier 'src/**/*.{js,jsx,ts,tsx,astro,scss,css,json,mdx,md}' --check",
"fix": "pnpm fix:prettier && pnpm fix:eslint",
"fix:eslint": "eslint --fix src",
"fix:prettier": "prettier 'src/**/*.{js,jsx,ts,tsx,astro,scss,css,json,mdx,md}' --write",
Those are pretty elaborate and I'd like to avoid rewriting and duplicating them in lefthook config file. Ideally lefthook would just run the scripts and the scripts would only see staged files. This is achievable by simply stashing all the changes - including new, untracked files, like git stash -a
does.
I suspect that this may be in conflict with the {all_files} placeholder. If that's the case then is there an elegant way to achieve what I'm trying to do?
Lefthook version
1.7.18