简体   繁体   中英

Entry command for pre-commit built-in hooks

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM