检查structuredText的语法和嵌套在其中的代码块

rstcheck的Python项目详细描述


Build status

检查structuredText的语法和嵌套在其中的代码块。

Installation

来自PIP:

$ pip install rstcheck

Supported languages in code blocks

  • 猛击
  • 博士学位
  • C(C99)
  • C++(C++ 11)
  • json
  • XML
  • Python
  • 重构文本

Examples

使用错误的python语法:

====Test====..code:: python

    print(
$ rstcheck bad_python.rst
bad_python.rst:7: (ERROR/3) (python) unexpected EOF while parsing
<不良的C++语法:

====Test====..code::cppintmain(){returnx;}
$ rstcheck bad_cpp.rst
bad_cpp.rst:9: (ERROR/3) (cpp) error: 'x' was not declared in this scope

重构文本文档本身语法错误:

====
Test===
$ rstcheck bad_rst.rst
bad_rst.rst:1: (SEVERE/4) Title overline & underline mismatch.

Options

usage: rstcheck [-h] [-r] [--report level] [--ignore-language language]
                [--ignore-messages messages] [--ignore-directives directives]
                [--ignore-substitutions substitutions] [--ignore-roles roles]
                [--debug] [--version]
                files [files ...]

Checks code blocks in reStructuredText.

positional arguments:
  files                 files to check

optional arguments:
  -h, --help            show this help message and exit
  -r, --recursive       run recursively over directories
  --report level        report system messages at or higher than level; info,
                        warning, error, severe, none (default: info)
  --ignore-language language, --ignore language
                        comma-separated list of languages to ignore
  --ignore-messages messages
                        python regex that match the messages to ignore
  --ignore-directives directives
                        comma-separated list of directives to ignore
  --ignore-substitutions substitutions
                        comma-separated list of substitutions to ignore
  --ignore-roles roles  comma-separated list of roles to ignore
  --debug               show messages helpful for debugging
  --version             show program's version number and exit

Ignore specific languages

可以忽略按语言检查嵌套代码块。要么使用 命令行选项--ignore或在文档中添加注释:

.. rstcheck: ignore-language=cpp,python,rst

Ignore specific errors

因为docutils不会将错误消息分类到高层之外 类别:信息、警告、错误和严重;我们需要在 文本级别。这是通过传递python正则表达式来完成的。举个例子 这样的正则表达式可以忽略几个错误:

(Title underline too short.*|Duplicate implicit target.*')

Configuration file

您可以在命令行中使用与 项目的本地配置文件(只需将_替换为-)。 rstcheck在目录中查找文件.rstcheck.cfg,或者 它正在检查的文件的祖先目录。

例如,考虑一个具有以下目录结构的项目:

docs
├── foo
│   └── bar.rst
├── index.rst
└── .rstcheck.cfg

.rstcheck.cfg包含:

[rstcheck]ignore_directives=one,two,threeignore_roles=src,RFCignore_messages=(Document or section may not begin with a transition\.$)report=warning

bar.rst包含:

Bar===:src:`hello_world.py`:RFC:`793`..one::

   Hello

rstcheck将使用.rstcheck.cfg

$ rstcheck docs/foo/bar.rst

Sphinx

启用狮身人面像:

$ pip install sphinx

安装的Sphinx版本必须至少为1.5。

要检查是否启用了Sphinx支持:

$ rstcheck -h | grep 'Sphinx is enabled'

Usage in Vim

Syntastic

一起使用
letg:syntastic_rst_checkers = ['rstcheck']

ALE

一起使用

只要安装rstcheck并确保在您的路径上。

Use as a module

rstcheck.check()产生一系列元组。每个元组的第一个值 是行号(不是行号)。第二个值是错误消息。

>>> import rstcheck
>>> list(rstcheck.check('Example\n==='))
[(2, '(INFO/1) Possible title underline, too short for the title.')]

注意,这不会加载任何配置,因为这会使 docutils注册表。

Testing

要运行所有测试,请执行:

$ make test

单元测试在test_rstcheck.py中。

系统测试由示例好/坏输入组成。测试输入是 包含在examples目录中。对于基本测试,添加测试应该 只需将文件添加到examples/goodexamples/bad即可。

History

3.3.1 (2018-10-09)

  • 与狮身人面像兼容>;=1.8。

3.3 (2018-03-17)

  • 解析配置文件中的更多选项(感谢santos gallegos)。
  • 允许通过忽略特定(信息/警告/错误)消息 --ignore-messages(感谢santos gallegos)。

3.2 (2018-02-17)

  • 检查无效的标记样式链接(感谢饼干蛇)。
  • 允许配置存储在setup.cfg中(多亏了Ma_l Pedretti)。
  • 添加--recursive选项以递归地向下搜索要检查的目录 所有*.rst文件。

3.1 (2017-03-08)

  • 添加对检查XML代码块的支持(感谢Sameer Singh)。

3.0.1 (2017-03-01)

  • 支持utf-8字节顺序标记(bom)。上一个很显然,docutils会 将bom解释为可见字符,这将导致误报 关于下划线太短。

3.0 (2016-12-19)

  • 可选支撑狮身人面像1.5。如果Sphinx是 安装。

2.0 (2015-07-27)

  • 支持从配置文件加载设置。

1.0 (2015-03-14)

  • 添加狮身人面像支持。

0.1 (2013-12-02)

  • 初始版本。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java为什么@DELETE REST不起作用?   带有JPA2的java表值参数。1和Hibernate,Sql Server   如何将Java类添加到Xamarin VS2017项目   绘制多边形时出现java空指针异常   java Apache WebClient 303状态未重定向   java如何用一组字符串数组从数据库中获取数据   java是否可以使用Google Drive API向文件中添加脚本?   java组织。阿帕奇。贾斯珀。JspC jar文件下载   java在整个JSON映射中将单个值作为JSON流   通过命令行将文件输入到java   java rs.next()总是返回false   java标记异常,通知调用方利用异常消息   java Spring YML数组属性为空