question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for prepush as well

See original GitHub issue

Firstly, 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:closed
  • Created 6 years ago
  • Reactions:50
  • Comments:23 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
rubengmurraycommented, Oct 13, 2021

I was looking for support for the same functionality within lint-staged on pre-push, but after doing some reading it appears that what I’m after is nothing to do with staged 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 to eslint 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$)")

2reactions
turadgcommented, Apr 8, 2018

This needs more validation

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.

I want this tool to be focused on a single task rather than trying to do everything.

@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)

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found