feature: Skip some hooks when using `--all-files`
See original GitHub issueI realize this may be a pretty far-fetched request, but I figured it couldn’t hurt to start a discussion.
We’d like a configurable way to disable some hooks from running when using pre-commit run --all-files
. However, the hook should still run when --all-files
is not supplied or when it is explicitly specified as an arg.
Use Case
We have a monorepo and some hooks (like terraform) have special dependencies that aren’t always managed or installed by pre-commit. The files that the hooks run on are isolated to a specific folder. Most teams never interact with these files, but if they do, the hooks should trigger.
Occasionally, we like to run pre-commit run --all-files
as hooks (or their dependencies) are upgraded to ensure everything is still passing. A recent example of why this may be needed was when we upgraded black
and had files that were reformatted after the upgrade.
We periodically run into issues where engineers don’t have the correct setup and those special hooks fail, resulting in confusion and blocked progress.
Workarounds
I realize that we could use SKIP
for this. The issue is that SKIP
is opt-in and not configurable via .pre-commit-config.yaml
. This means that the whole engineering team needs to set the variable and then unset it when they want to run the team-specific hooks. What we’d like to is sort of the opposite, have hooks that are skipped by default but can be opted-into.
Risks
I realize this is a slippery slope and may not even be possible with the current architecture (I’m guilty of not taking a deeper look into the codebase yet). There’s definitely a chance files get committed that should have been linted. We hope that by limiting the skipping to just the bare pre-commit run --all-files
that this chance is sufficiently small that it is an acceptable trade off.
Issue Analytics
- State:
- Created 2 years ago
- Comments:13 (7 by maintainers)
Top GitHub Comments
Yup. Was hoping to keep it contained within the workflow of
pre-commit
(to avoid the inevitable person who doesn’t search internal docs first), but I completely understand it not being worth implementing.I think this is where the issue lies. We want to not run something in that case and run that same something in all other cases.
Yes, it’s a conscious decision, but that doesn’t mean an entire engineering organization is aware that they should set
SKIP
in their local environment.Ultimately, it seems like the workaround is a script that sets
SKIP
and trying to educate users to use that script instead ofpre-commit run --all-files
.Thank you for the help.