-
Notifications
You must be signed in to change notification settings - Fork 331
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pre-commit: run only on changed files instead of all the files #1188
base: main
Are you sure you want to change the base?
Conversation
Yeah, but you'd want to run the hooks against all of the files in a CI/test run. Hooks can fail to run ,or can be disabled and bypassed. This catches that. |
That makes sense, what about giving users an option to set the behavior of |
I'm not certain why you believe that to be a best practice. It certainly is not how companies with large code bases typically do things. Failing a CI pipeline because all existing or legacy code does not meet some new style or linting requirements that we want to begin introducing, doesn't really make sense. That would force many companies to spend months and years before they could successfully submit any code through their CI pipeline. Yes, we make certain that all code, existing and new, pass unit/integration/e2e testing (and even then it gets turned off for some instances there). But I've never heard of enforcing style enforcement on legacy code. After 10+ years the pre-commit maintainers still default the tool to only run against edited files, with the option to run against all files by using the |
In a CI environment,
For example, from their own docs:
And literally, a pre-commit dev: pre-commit-ci/issues#90 (comment)
This would be a huge red flag at a company. If you're going to introduce a new linter rule piece-meal, then you need to leverage file exclusions and configure the linter to only emit warnings until you get the codebase under control. Honestly, in modern times, you'd likely just run the formatter against the entire codebase and add auto-formatting in CI.
Trust? Decades of experience? Come on, you can't be serious. 😂 Is there a pre-commit cult I'm not privy too?
IMO I could see this being somewhat useful if you're running An option to toggle the |
That part about If you are like many companies, working with a large code base but don't have a dedicated team to oversee the rollout (and possible rollback) of a migration to your entire codebase, then you move incrementally. And you run linters/formatters on new code prior to it ever being merged. Maybe I'm just out of the loop and there are now easily automated answers for all of these concerns? I don't know, I'm more of a software engineer than a DevOps guru. I do know that the devenv pre-commit integration behaving differently from the official pre-commit makes it harder for me to use, which means that I'll have to continue to use the official pre-commit. |
Again, you have all the tools at your disposal to make this work. Enabling a repo-wide hook that fails if run on certain files, then glossing over the fact that you have a misconfigured hook by just hoping you don't touch those files as you work is frankly a little ridiculous. I would re-evaluate the motivation for enabling a hook like this in the first place.
We are not in any way "using a different default" to pre-commit. There is no default for this use-case. The only default there is for running hooks on staged files pre commit, which git-hooks.nix and devenv obviously do. Anyways, we're just derailing this PR at this point. This PR is about |
According to https://pre-commit.com , by default, the pre-commit hooks should only run on the edited files instead of all files. This PR addresses this and changes the default to the former.
Another thing we can provide is an option in devenv.nix to set the desired behavior.