Support for prepush as well
See original GitHub issueFirstly, thanks - this is an awesome library!
As the name of this lib implies, it passes the names of the files - that are currently staged for git commit - to the configured linters
. This it works really well to this effect, and is best employed in a git precommit
hook.
However, I feel that this lib can be useful beyond this use case, and work quite well to power a git prepush
hook as well. In order for it to power this use case, the list of files to pass to the configured linters
should be different: Instead of staged files, have all the files that have been added since between the current branch and its parent branch.
What are your thoughts on this?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:50
- Comments:23 (8 by maintainers)
Top Results From Across the Web
Use pre-commit, commit-msg, and pre-push git hooks to fix ...
This hook checks the commit message entered by the author. There are some well-established and well-accepted rules for writing good Git commit ...
Read more >How to create a pre-push git hook to detect hardcoded secrets ...
Secrets like API keys and credentials can create a huge security risk when they get leaked into remote git repositories.
Read more >In pre-push hook, get "git push" command full content?
Example, when I run: git push origin master , pre-push hooks executed. I want to get origin & master in this hook. How...
Read more >Git Hooks - Git SCM
The pre-push hook runs during git push , after the remote refs have been updated but before any objects have been transferred.
Read more >Hooks | Dev Cheatsheets - Michael Currin
Well, in my experience is actually uses the commit message hook when you commit ... Git: Support editing the commit message in a...
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
I was looking for support for the same functionality within
lint-staged
onpre-push
, but after doing some reading it appears that what I’m after is nothing to do withstaged
files, as staging is pre-commit…I think I’ve found a solution though, perhaps this will solve the OP & others requirements in terms of functionality:
Add a
.husky/pre-push
file and make this the runnable line:npx eslint $(git diff --name-only origin/$(git rev-parse --abbrev-ref HEAD)..$(git rev-parse --abbrev-ref) HEAD | grep -E "(.ts$)")
This will take the branch you’re working on and run a diff between the local version and the version on the remote.
Seems to do the trick for me (I’m looking for .ts files).
Credit to these for the steers:
https://gist.github.com/seeliang/0f0de424d1cdc4541c338f4ee93b7e6a https://stackoverflow.com/a/6245587/10732370
EDIT:
I just found out the above hook throws on deleted files… passing
--no-error-on-unmatched-pattern
toeslint
removes that issue (but could mask others in your general linting pattern I guess - though I’m not bothered, this error feels a bit overkill to me by default)npx eslint --no-error-on-unmatched-pattern $(git diff --name-only origin/$(git rev-parse --abbrev-ref HEAD)..$(git rev-parse --abbrev-ref) HEAD | grep -E "(.ts$)")
I share @bguiz 's wish to lint on prepush instead of precommit. My hook does a lot now and takes some time to run, time that slows down each commit. And when there’s an error it’s awkward in Github Desktop I sometimes use for patches.
The purpose of what I run in the hooks is to catch problems sooner than the CI, so all I really need is to check what I’m pushing.
@okonet would you be comfortable with someone forking this to handle the prepush use case? E.g. like https://github.com/clakech/lint-committed
(@cakeinpanic , your polite-linter does not allow for the other lint logic I have)