预提交内置钩子的入口命令

Entry command for pre-commit built-in hooks

我想 运行 命令行中 pre-commit 包中的一些内置挂钩,不是挂钩,而是仅从命令行根据需要发现干净的文件.

例如,如果我想 运行 黑我项目中的任意文件,我可以 运行 使用 black [directory] 命令。

我没有在文档中看到 trailing-whitespace 等内置钩子的入口命令是什么。

例如,我想通过键入 trailing-whitespace foo.py 来清除 foo.py 中的尾随空格。但是,这不起作用。

要怎么做才能做到这一点?

附带说明一下,如果 运行ning 挂钩 local 并在本地环境中安装预提交,这也应该是可能的。

根据您要安装的存储库,您需要 pip 在外部安装它,然后 运行 命令。 您可能不想这样做,因为这违背了框架的目的(它会为您管理安装,因此您不必这样做)。您可能想要 pre-commit run trailing-whitespace --files ... 而不是

也就是说,如果你愿意,你仍然可以。对于尾随空白挂钩 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)


免责声明:我创建了预提交和 pre-commit/pre-commit-hooks