yaml 多行正则表达式
yaml multiline regex
我想用 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\
):[^:]"
但这不起作用(生成的正则表达式不同)。
有什么建议吗?
解决方法是
entry: "\
\.\. (autosummary|contents|currentmodule|deprecated\
|function|image|important|include|ipython\
|literalinclude|math|module|note|raw|seealso\
|toctree|versionadded|versionchanged|warning\
):[^:]"
与documented一样,您可以使用详细表达式:
entry: |
(?x)^(
thing|
other_thing|
other_other_thing
)$
我想用 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\
):[^:]"
但这不起作用(生成的正则表达式不同)。
有什么建议吗?
解决方法是
entry: "\
\.\. (autosummary|contents|currentmodule|deprecated\
|function|image|important|include|ipython\
|literalinclude|math|module|note|raw|seealso\
|toctree|versionadded|versionchanged|warning\
):[^:]"
与documented一样,您可以使用详细表达式:
entry: |
(?x)^(
thing|
other_thing|
other_other_thing
)$