Lint-staged: [Feat] Disable hook during rebase

Created on 19 Mar 2018  路  4Comments  路  Source: okonet/lint-staged

Description

Our repo require fairly strict commit messages so the normal workflow is something like:

  1. Commit WIP using the --no-verify flag
  2. Do the above multiple more times while developing a feature
  3. Once finished, rebase all commits into something like feat: My new feature

The issue is that during a rebase, the lint hook is running for each rebase step. The git rebase --continue etc command does not allow a --no-verify flag so each rebase step errors out due to lint-staged.

Steps to reproduce

  1. Commit something that breaks your lint-staged rules using the --no-verify flag.
  2. Do this again.
  3. Do this one more time.
  4. Begin an interactive rebase git rebase -i HEAD~2
  5. Merge your two commits into a single commit.
  6. See lint-staged kill rebase due to error. Even if the error is fixed in the 3rd rebase commit, it stops the rebase from moving forward.

I'm a bit surprised it seems no one else has run into this. Am I thinking about this incorrectly? Or is everyone making all their WIP commits pass the linter each time?

I'm not sure if lint-staged can know it's being run in a rebase or if there are times where you do need it to run during a rebase. Possibly a way to enable/disable via a ENV flag?

Most helpful comment

馃毇馃挬 Lint-staged is design to run on precommit. In your case it seems you better be suited with a CI.

All 4 comments

馃毇馃挬 Lint-staged is design to run on precommit. In your case it seems you better be suited with a CI.

I think lint-staged should not run while rebasing. What if the linter (e.g. prettier) is upgraded during one of those commits? While rebasing, if it is stricter, it will fail on one of the older commits.

I think the scenario @benjamincharity describes is that, installing lint-staged as described in the README, it still gets called during an _interactive_ rebase.

EDIT: There's a possible workaround on the Husky side: https://github.com/typicode/husky/issues/447

EDIT 2: To clarify, that pre-commit is called only on certain git rebase commands (like reword or fixup)

lint-staged currently contains code to make it handle rebase cases and reverting of the commit state in case of errors. It would be possible to detect an ongoing rebase and instead skip running lint-staged. This would have to be a new cli option to not make it a breaking change, something like --no-rebase.

Was this page helpful?
0 / 5 - 0 ratings