1

我想写一个pygrep钩子pre-commit来查找案例,例如

    .. 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\
            ):[^:]"

但这不起作用(生成的正则表达式不同)。

有什么建议么?

4

2 回答 2

2

文档所述,您可以使用详细的表达式:

        entry: |
            (?x)^(
                thing|
                other_thing|
                other_other_thing
            )$
于 2020-10-20T15:02:22.157 回答
1

解决方案是做

        entry: "\
            \\.\\. (autosummary|contents|currentmodule|deprecated\
            |function|image|important|include|ipython\
            |literalinclude|math|module|note|raw|seealso\
            |toctree|versionadded|versionchanged|warning\
            ):[^:]"
于 2020-10-20T13:20:30.283 回答