[style] automate reformatting with pre-commit hooks
See original GitHub issueš Feature request
I was just reading how make style
can be automated with pre-commit hooks. Noticing how often I run and even more often forget to run make style
before committing, perhaps others are in the same boat - and therefore I thought to propose to the dev community to (mostly) automate this process. The only cons is that each dev will still have to run pre-commit install
once after cloning the project. This is a security feature of git, so it wonāt run anything automatically unless you take action to enable such thing.
If I understand it correctly, if an individual dev doesnāt run pre-commit install
inside the repo, things are just as normal as they are now. That dev will just run make style
manually. i.e. the proposed feature is optional for those who want it.
I read about it here, please scroll down to the section: āBlack as a Git pre-commit hookā. And it links to the whole detailed website: https://pre-commit.com/
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (5 by maintainers)
I personally wouldnāt like having a pre-commit hook change all my commits without me being able to see the end result. On my setup, I have a pre-push hook that aborts a push if make quality fails. I think if we had an install script, we could handle both options?
Even though I originally created this thread 1.5 years later I now agree with @sgugger, that I donāt want format changes done while pushing - I need to see what has been changed since sometimes the autoformatter messes things up badly and I need to rewrite things to make the end result readable.
If this can be done as an option and not a requirement then Iām not against it, but there needs to be a way to validate/reformat files before git is involved.
BTW,
precommit
can be run manually as well and not via git, which doesnāt requirepre-commit install
:And we have 2 ways to reformat files:
fixup
(fast - only modified files) -style
(slow)