【发布时间】:2021-02-03 07:41:40
【问题描述】:
我想用pre-commit 编写一个pygrep 钩子,它可以找到以下情况,例如
.. warning:
(应该是.. warning::)。
如果我写
- repo: local
- id: incorrect-sphinx-directives
name: Check for incorrect Sphinx directives
language: pygrep
entry: \.\. (autosummary|contents|currentmodule|deprecated|function|image|important|include|ipython|literalinclude|math|module|note|raw|seealso|toctree|versionadded|versionchanged|warning):[^:]
files: \.(py|pyx|rst)$
然后这行得通 - 但是,字符串太长了。有没有办法把它分成多行?
我试过了
entry: "\
.. (autosummary|contents|currentmodule|deprecated\
|function|image|important|include|ipython\
|literalinclude|math|module|note|raw|seealso\
|toctree|versionadded|versionchanged|warning\
):[^:]"
但这不起作用(生成的正则表达式不同)。
有什么建议吗?
【问题讨论】:
-
我没有使用正则表达式来修改yaml,不知道你的意思
标签: python regex yaml pre-commit pre-commit.com