I would like to run some of the built-in hooks available from the pre-commit package from the command line, not as hooks but just from the command line to spot clean files as necessary.
For example, if I want to run black on an arbitrary file in my project, I can just run it with black [directory]
command.
I don't see in the documentation what the entry commands for built-in hooks such as trailing-whitespace
are.
For example, I would like to clean up trailing whitespace in foo.py
by just typing trailing-whitespace foo.py
. This does not work, however.
How would one go about doing this?
As a side note, this should also be possible if running hooks as local
with pre-commit installed in a local env.
Depending on which repository you're installing you'd need to pip
install that externally and then run the command. You probably don't want to do that since that defeats the purpose of the framework (it manages the installs for you so you don't have to). You probably want to pre-commit run trailing-whitespace --files ...
instead
that said, you still can if you want. For the trailing-whitespace hook you mention -- that comes from pre-commit/pre-commit-hooks
. If you look at the alternate installation instructions, you can pip install pre-commit-hooks
and then run the executable for that (you can find the exact executable name from the entry
field in the repository manifest, in that case: entry: trailing-whitespace-fixer
)
disclaimer: I created pre-commit and pre-commit/pre-commit-hooks