Welcome to rstcheck’s documentation!
General |
|
CI |
|
PyPI |
|
Github |
|
This a the documentation of rstcheck
. A CLI application for checking
the syntax of reStructuredText and code blocks nested within it.
Installation
This part of the documentation covers how to install the package. It is recommended to install the package in a virtual environment.
Create virtual environment
There are several packages/modules for creating python virtual environments. Here is a manual by the PyPA.
Installation from PyPI
You can simply install the package from PyPI:
$ pip install rstcheck
Extras
rstcheck
has extras which can be installed to activate optional functionality:
sphinx
- To activate support for rst documents using the sphinx builder.toml
- To activate support for TOML files as configuration files.
To install an extra simply add it in brackets like so:
$ pip install rstcheck[sphinx,toml]
Installation from source
You can install rstcheck
directly from a Git repository clone.
This can be done either by cloning the repository and installing from the local clone:
$ git clone https://github.com/rstcheck/rstcheck.git
$ cd rstcheck
$ pip install .
Or installing directly via git:
$ pip install git+https://github.com/rstcheck/rstcheck
You can also download the current version as tar.gz or zip file, extract it and install it with pip like above.
Usage
rstcheck
is a CLI application which uses the rstcheck-core
library.
CLI
This part of the documentation covers the CLI interface and is auto-generated by sphinx-click extension.
Warning
The CLI interface differs depending on the available opt-in extensions:
Sphinx
Toml
The documentation shown here uses all opt-in features.
Note
More information about the single configuration options can be found in the Configuration section
rstcheck
CLI of rstcheck.
Enabled features: [‘Sphinx’]
Pass one ore more rst FILES to check. Can be files or directories if –recursive is passed too. Pass “-” if you want to read from stdin.
rstcheck [OPTIONS] FILES...
Options
- --config <config>
Config file to load. Can be a INI file or directory. If a directory is passed it will be searched for .rstcheck.cfg | setup.cfg. If ‘NONE’ is passed no config file is loaded at all.
- --warn-unknown-settings
Log a WARNING for unknown settings in config files. Can be hidden via –log-level.
- -r, --recursive
Recursively search passed directories for RST files to check.
- --report-level <LEVEL>
The report level of the linting issues found. Valid levels are: INFO | WARNING | ERROR | SEVERE | NONE. Defaults to INFO. Can be set in config file.
- --log-level <LEVEL>
The log level of the application for information that is not a linting issue. Valid levels are: DEBUG | INFO | WARNING | ERROR | CRITICAL. Defaults to WARNING.
- Default:
WARNING
- --ignore-directives <ignore_directives>
Comma-separated-list of directives to add to the ignore list. Can be set in config file.
- --ignore-roles <ignore_roles>
Comma-separated-list of roles to add to the ignore list. Can be set in config file.
- --ignore-substitutions <ignore_substitutions>
Comma-separated-list of substitutions to add to the ignore list. Can be set in config file.
- --ignore-languages <ignore_languages>
Comma-separated-list of languages for code-blocks to add to the ignore list. The code in ignored code-blocks will not be checked for errors. Can be set in config file.
- --ignore-messages <REGEX>
A regular expression to match linting issue messages against to ignore. Can be set in config file.
- --version
- --install-completion
Install completion for the current shell.
- --show-completion
Show completion for the current shell, to copy it or customize the installation.
Arguments
- FILES
Required argument(s)
Configuration
rstcheck
’s config system knows three sources:
Inline comments (for config and flow control instructions)
CLI options
Config files (INI and TOML)
Order of application
The config sources apply according to a set of rules:
Flow control instructions from inline comments:
always apply regardless of other config.
are expressive and say for themselves what they apply to.
Config from inline comments:
always apply regardless of other config.
always apply for the whole file regardless where they are placed.
is added to the remaining config and does not overwrite it.
CLI options always overwrite config coming from a file.
File config has the lowest priority.
Configuration sources
Now let’s take a deeper look at the different sources of config.
Inline comments
Inline comments are simply rst comments starting with rstcheck:
.
There are two types of inline comments:
Simple inline config e.g.
ignore-languages=python
which follows the syntax ofkey=value
.Flow control instructions e.g.
ignore-next-code-block
which follows the syntax ofwords-divided-by-dashes
.
Here is an example with both of them:
Example
=======
.. rstcheck: ignore-next-code-block
.. code-block:: python
print("Hello World")
.. rstcheck: ignore-languages=python
CLI options
For information on the CLI options please see the CLI section.
Configuration files
rstcheck
has an automatic config file detection mechanic. This mechanic includes
the following config files sorted by priority:
.rstcheck.cfg
pyproject.toml
setup.cfg
When a directory is searched for a config file, the first found config section is taken and the search is not aborted on the first file found. This means that if you for example have a pyproject.toml file without a matching config section and an setup.cfg file with a matching section, the section from setup.cfg would be used. pyproject.toml would be searched first, but nothing would be found and so the search would continue.
For each rst source file that is linted, its parent directory is searched for a config file. If the parent directory has no config file with a matching config section the parent’s parent directory is searched next. This continues up the directory tree until the root directory. If no config file is found, the default values for each setting apply.
This whole mechanic is deactivated, when a config file or directory is explicitly set. See the Configuration file section for more information on setting a config file/directory.
rstcheck
supports two types of config formats: INI and TOML.
They are written pretty similar, but have some differences.
The two following sections explain both formats.
Files ending on .toml
are parsed as TOML files.
Every other file is parsed as an INI file.
If .rstcheck.cfg
does not contain a valid section a warning is printed.
INI format
In INI format all config related to rstcheck
must go into a [rstcheck]
section.
The default INI format applies: key = value
.
Lists are comma-separated strings, which can be multiline.
Whitespace before and after a key or value is ignored.
Trailing commas are optional.
Here is an example:
[rstcheck]
report_level=WARNING
ignore_directives =
one,
two,
three,
ignore_roles=src, RFC
ignore_substitutions=
image_link
ignore_languages=
python,
cpp
ignore_messages=(Document or section may not begin with a transition\.$)
TOML format
Note
TOML format is only supported when the python library tomli
is importable.
See the Installation section for more information.
In TOML format all config related to rstcheck
must go into the [tool.rstcheck]
dictionary. This is due to the python convention for the pyproject.toml
file, which
rstcheck
uses for all TOML files.
The official TOML syntax applies here, so strings are strings and lists are lists for example.
Here is an example:
[tool.rstcheck]
report_level = "WARNING"
ignore_directives = [
"one",
"two",
"three",
]
ignore_roles = ["src", "RFC"]
ignore_substitutions = [
"image_link"
]
ignore_languages = [
"python",
"cpp"
]
ignore_messages = "(Document or section may not begin with a transition\.$)"
Configuration options
Now it’s time for all the available settings you can set.
Configuration file
Supported sources:
CLI (
--config PATH
)
With the --config
CLI option you can set a config file or directory.
The path may be relative or absolute.
If the passed path does not exist the runner exits with an error, which is logged.
If the path is a literal NONE
, no file is loaded or directory searched, this includes
the automatic config file detection mechanic.
When the path points to a file, this concrete file is read and searched for a matching config section. If no section is found a warning is logged and no file config is used.
When the path is a directory, this directory is search for a config file, like described in the earlier Configuration files section, except that only this directory is search and not the directory tree.
Recursive resolution
Supported sources:
CLI (
--recursive
or-r
)
By default only files passed to the CLI runner are checked and directories are ignored. When this config is set, passed directories are searched recursively for rst source files.
Report level
Supported sources:
CLI (
--report-level LEVEL
)Config-File (key:
report_level
, value: LEVEL)
The level at which linting issues should be printed. The following levels are supported:
INFO (default)
WARNING
ERROR
SEVERE
NONE
This currently only applies to issues with rst source. Issues in code blocks are on ERROR level and always printed, even if the level is set to SEVERE or NONE.
The level can be set case insensitive.
Logging level
Supported sources:
CLI (
--log-level LEVEL
)
The level at which additional information besides linting issues should be printed. The following levels are supported:
DEBUG
INFO
WARNING (default)
ERROR
CRITICAL
The level can be set case insensitive.
Ignore directives
Supported sources:
Inline comments (key:
ignore-directives
, value: list of directives)CLI (
--ignore-directives D1,D2,...
)Config-File (key:
ignore_directives
, value: list of directives)
A list of directives to ignore while checking rst source.
Ignore roles
Supported sources:
Inline comments (key:
ignore-roles
, value: list of roles)CLI (
--ignore-roles R1,R2,...
)Config-File (key:
ignore_roles
, value: list of roles)
A list of roles to ignore while checking rst source.
Ignore substitutions
Supported sources:
Inline comments (key:
ignore-substitutions
, value: list of substitutions)CLI (
--ignore-substitutions S1,S2,...
)Config-File (key:
ignore_substitutions
, value: list of substitutions)
A list of substitutions to ignore while checking rst source.
Ignore specific code-block languages
Supported sources:
Inline comments (key:
ignore-languages
, value: list of languages)CLI (
--ignore-languages L1,L2,...
)Config-File (key:
ignore_languages
, value: list of languages)
A list of languages to ignore for code blocks in rst source. Unsupported languages are ignored automatically.
Supported languages are:
Bash
Doctest
C (C99)
C++ (C++11)
JSON
XML
Python
reStructuredText
Ignore specific error messages
Supported sources:
CLI (
--ignore-messages REGEX_STRING
)Config-File (key:
ignore_messages
, value: regular expression string)
A list of linting issue messages to ignore while checking rst source and code blocks.
Note
In TOML format a list of strings is also valid. The list’s entries will be concatenated with the OR operator “|” between each entry.
Control Flow instructions
There are also control flow instructions which are only available as inline comments. They change the flow of checking the rst source, hence the name.
Skipping code blocks
With the ignore-next-code-block
flow control instruction you can skip single code blocks.
This way you don’t have to use the heavy tools like ignoring a whole language or directive.
The instruction must be placed in the line directly above the code block directive like so:
.. rstcheck: ignore-next-code-block
.. code-block:: python
print("Hello world")
Examples with explanation
These examples are cases to show concepts of configuration in rstcheck
.
They don’t always follow best practices.
Only inline comments
Example
=======
.. rstcheck: ignore-next-code-block
.. code-block:: python
print("Here is an error."
.. rstcheck: ignore-languages=python
In this example the code-block would be ignored/skipped due to the flow control instruction. But the code-block’s language is python which is on the ignore list for languages, because of the config at the bottom. This means if you remove the flow control instruction, the code-block would still be skipped and the error inside would ignored.
Integration
rstcheck
can be integrated and used with other tools.
Usage in Vim
Using with Syntastic:
let g:syntastic_rst_checkers = ['rstcheck']
Using with ALE:
Just install rstcheck
and make sure is on your path.
Use as a pre-commit hook
Add this to your .pre-commit-config.yaml
:
- repo: https://github.com/rstcheck/rstcheck
rev: '' # Use the sha / tag you want to point at
hooks:
- id: rstcheck
additional_dependencies: [] # can be omitted if empty
You may want to specify a rstcheck-core
version or range, if you depend on a feature which was
added after the current minimal version of rstcheck-core
.
Simply add e.g. "rstcheck-core==v1.0.0"
to the list for additional_dependencies
.
Use with Mega-Linter
Just install Mega-Linter in your repository, rstcheck is part of the 70 linters activated out of the box.
Workflows
Here is the documentation about different workflows for rstcheck
.
Development
rstcheck
uses Semantic Versioning.
rstcheck
uses main
as its single development branch. Therefore releases are
made from this branch. Only the current release is supported and bugfixes are released
with a patch release for the current minor release.
Tooling
For development the following tools are used:
poetry
for dependency management, package metadata, building and publishing.tox
for automated and isolated testing.pre-commit
for automated QA checks via different linters and formatters.
Set up Local Development Environment
The setup of a local development environment is pretty easy. The only tool you need is the
poetry. You can install it via the recommended way, which installs it globally on your
system or you can install it via pip
in a self-created virtualenv (virtualenv manual).
With poetry
set up and ready we can create our development environment in just one
step:
$ poetry install
This will install rstcheck
along its main and development dependencies.
Working with the Local Development Environment
Dependency management and more with poetry
is used for dependency management, building and publishing rstcheck
.
Testing with tox
To run all available tests and check simply run:
$ tox
This will run:
formatters and linters via
pre-commit
.the full test suite with
pytest
.a test coverage report.
tests for the documentation.
Different environment lists are available and can be selected with tox -n <ENVLIST>
:
test: run full test suite with
pytest
and report coverage.py3.7 - py3.10 run full test suite with specific python version and report coverage.
docs: run all documentation tests.
Linting and formatting pre-commit
can be used directly from within the development environment or you can use
tox
to run it pre-configured.
There are 3 available tox
envs with all use the same virtualenv:
pre-commit
: For running anypre-commit
command liketox -e pre-commit -- autoupdate --freeze
.pre-commit-run
: For running all hooks against the code base. A single hook’s id can be passed as argument to run this hook only liketox -e pre-commit-run -- black
.pre-commit-install
: For installing pre-commit hooks as git hooks, to automatically run them before every commit.
IDE integration
The development environment has flakeheaven
(a flake8
wrapper), pylint
and mypy
installed to allow IDEs to use them for inline error messages. Their config is in
pyproject.toml
. To run them actively use pre-commit
and/or tox
.
Releases
Release workflow
When enough changes and additions or time important fixes have accumulated on the
main
branch its time for a new release. The exact time is subject to the
judgment of the maintainer(s).
Note
Before starting the process of creating a new release make sure that all CI pipelines are green for the current commit.
Check if the
CHANGELOG.md
is up-to-date and all changes are noted.Run
prep_release.py
script to bump version, finalizeCHANGELOG.md
, commit the changes and create a new git tag:$ python3 prep_release.py <TYPE>
For the increase type there are three options:
patch
/bugfix
: for changes that do not add new functionality and are backwards compatibleminor
/feature
: for changes that do add new functionality and are backwards compatiblemajor
/breaking
: for changes that are not backwards compatible
Build the sdist and wheel:
$ poetry build
Publish package:
$ poetry publish
Push the commit and tag to github:
$ git push --follow-tags
FAQ / Known limitations / Known issues
You may also take a look at the same section for rstcheck-core.
Known limitations
There are inherent limitations to what rstcheck
can and cannot do. The reason for this is that
rstcheck
itself relies on external tools for parsing and error reporting.
The rst source e.g. is given to docutils
which then parses it and returns the errors.
Therefore rstcheck is more like an error accumulation tool. The same goes for the source
code in supported code blocks.
Note
Windows support is not stable!
Reason: Tests are failing with wrong positives and wrong negatives out of unknown reasons. See issue #107.
Known issues
ImportError: cannot import name ‘get_terminal_size’ from ‘click.termui’
Affected rstcheck version(s): All 6.0 releases
This issue is caused by an incompatibility of the dependency typer
in version 0.4.0
and its
subdependency click
with version >=8.1.0
.
The issue was fixed in typer
version 0.4.1
.
If you encounter this issue you can either:
update
rstcheck
to a non affected version.manually limit
click
’s upper version-bound to<8.1
if you need to rely ontyper
<0.4.1
.manually limit
typer
’s lower version-bound to>=0.4.1
.manually limit
typer
’s upper version-bound to<0.4
which results intyper
version0.3.2
andclick
version<7.2
.
See #138 for reference.
Migration-Guides
Only breaking changes are mentioned here. New features or fixes are only mentioned if they somehow correspond to a breaking change.
Version 5 to 6
With version 6 the whole code base was restructured. The core library was moved into its own
repository at rstcheck/rstcheck-core
.
rstcheck
moved from myint/rstcheck
to rstcheck/rstcheck
so you may want to update
links you have pointing to the old repository’s location.
The master
branch was renamed to main
. If you use git dependencies you may need to update
your reference.
The new logging system may help you find issues while migrating to v6.
You may then want to turn it on on the lowest level --log-level DEBUG
.
Configuration file
CLI options now overwrite settings in configuration files. Update your setup accordingly.
The following configuration keys changed:
report
renamed toreport_level
ignore_language
renamed toignore_languages
Set the
--warn-unknown-settings
CLI flag for warnings on unknown settings in configuration files.Numbers are no longer supported for
report_level
(old:report
)
CLI
CLI options now overwrite settings in configuration files. Update your setup accordingly.
Non existing files are ignored, but a warning is logged and the exit code is non-zero.
-The following CLI options changed:
--report
renamed to--report-level
and no longer accepts integers
--ignore-language
renamed to--ignore-languages
--ignore
dropped -> use--ignore-languages
--debug
replaced with new--log-level
-> use--log-level DEBUG
for verbose output
Numbers are no longer supported for
--report-level
(old:--report
)A non-existing path passed with
--config
results in a non-zero exit code.
Sphinx features
Support for sphinx prior version 2.0 was dropped.
Hard-coded default values for roles and directives coming from sphinx
were dropped.
If you encounter a lot of unknown roles and directives this may be the reason
(Example issue).
To fix this simply add sphinx to the environment from where you run rstcheck
:
$ pip install sphinx # directly
$ pip install rstcheck[sphinx] # or via extra
To check if sphinx support is activate run:
$ rstcheck --help | grep Sphinx
Version 4 to 5
Nothing to do if you don’t need the test suit of rstcheck
.
Use tox
to run test suite.
Version 3 to 4
Use python 3.7 or newer to run rstcheck
.
Changelog
This is the changelog of rstcheck
. Releases and their respective
changes are listed here. The order of releases is time and not version based!
For a list of all available releases see the
tags section on Github.
Links on the versions point to PyPI.
Unreleased
Miscellaneous
6.1.2 (2023-03-12)
Miscellaneous
6.1.1 (2022-11-12)
Documentation
Add link to rstcheck-core for FAQ
Remove unused pydantic related stuff from docs (#149)
Miscellaneous
Remove unused dependencies (docutils & its stubs, pydantic) (#149)
Add python 3.11 to CI
6.1.0 (2022-08-14)
Documentation
Miscellaneous
Fix release script’s changelog insertion
Add pre-commit-ci badge to README
Update development tooling dependencies
Bump lower version constraint on typer from 0.3.2 to 0.4.1 (#138)
6.0.0.post1 (2022-06-05)
Miscellaneous
Move release date into version headline link
Don’t include failing test example in sdist (#128)
6.0.0 (2022-06-04)
New features
Add a
--version
flag back. This flag gets its information from the metadata in the virtualenv.
Documentation
Finalize v6 migration guide.
Add notice to fix
rstcheck-core
version for needed features.
Miscellaneous
Add tox envs to test with sphinx v5.
Update
sphinx
extlinks
config for v5.Bump min version of
rstcheck-core
to v1.0.2.
v6.0.0rc3 (2022-05-28)
BREAKING CHANGES
New features
Add
NONE
as a special config file path, to disable config file loading (#125)
Documentation
Update config documentation (#126)
v6.0.0rc2 (2022-05-26)
New features
Documentation
Update links to new repository home at rstcheck/rstcheck
Update config documentation
Miscellaneous
Fix release date in changelog for v6.0.0rc1 release
Set the rstcheck pre-commit hook to run in serial to avoid overhead of doubling parallel runs with pre-commit
Little improvements to logging messages
Rename master branch to main
v6.0.0rc1 (2022-05-21)
BREAKING CHANGES
find_ignored_languages
no longer throws exception but logs warning (#108)
New features
v6.0.0a2 (2022-05-20)
BREAKING CHANGES
String lists for
ignore_*
configs are white-space cleaned at string start and end. Restores behavior of pre v6. (#116)
New features
Add support for INI multi-line string back (#116)
Bugfixes
Fix bug #113 - sphinx print warnings for overwriting registered nodes (#117)
v6.0.0a1 (2022-05-13)
BREAKING CHANGES
Full restructuring of the code base (#100)
Rewrite of CLI with
typer
(#100)Renamed config
report
toreport_level
(#100)Renamed config
ignore_language
toignore_languages
(#100)Renamed CLI option
--report
to--report-level
(#100)Renamed CLI option
--ignore-language
to--ignore-languages
(#100)Drop CLI option
--ignore
as alias to--ignore-languages
(#100)Drop CLI option
--debug
(#100)Drop CLI option
--version
; may be added back later (#100)Don’t support multi-line strings in INI files (#100)
Prohibit numbers as report level (#100)
Non-existing files are skipped;
rstcheck non-existing-file.rst
exits 0; may be changed later (#100)Drop support for sphinx < 2.0
Drop default values for directives and roles for sphinx (#65)
CLI options now take precedence over config file options (#96)
New features
Bugfixes
v5.0.0 (2022-04-17)
Add examples/ to sdist
Add
Development
section to README and updateTesting
sectionAdd
Mega-Linter
section to READMEAdd
BREAKING CHANGES
sections to changelog
BREAKING CHANGES
Rewrite test.bash script in pytest test cases and run them on Linux in CI
Rewrite old test suite in pytest and AAA style
v4.1.0 (2022-04-16)
v4.0.0 (2022-04-15)
Add inline type annotations
Add
sphinx
as extraUpdate build process and set up
poetry
Add
pre-commit
andtox
for automated testing, linting and formattingMove from travis to github actions
Activate dependabot
BREAKING CHANGES
Drop support for python versions prior 3.7
v3.5.0 (2022-04-14)
Deprecate python versions prior 3.7
v3.4.0 (2022-04-12)
Add
--config
option to change the location of the config file.Add
pre-commit
hooks config.
v3.3.1 (2018-11-09)
Make compatible with Sphinx >= 1.8.
v3.3 (2018-03-17)
Parse more options from configuration file (thanks to Santos Gallegos).
Allow ignoring specific (info/warning/error) messages via
--ignore-messages
(thanks to Santos Gallegos).
v3.2 (2018-02-17)
Check for invalid Markdown-style links (thanks to biscuitsnake).
Allow configuration to be stored in
setup.cfg
(thanks to Maël Pedretti).Add
--recursive
option to recursively drill down directories to check for all*.rst
files.
v3.1 (2017-03-08)
Add support for checking XML code blocks (thanks to Sameer Singh).
v3.0.1 (2017-03-02)
Support UTF-8 byte order marks (BOM). Previously,
docutils
would interpret the BOM as a visible character, which would lead to false positives about underlines being too short.
v3.0 (2016-12-19)
Optionally support Sphinx 1.5. Sphinx support will be enabled if Sphinx is installed.
v2.2 (2016-10-11)
Unknown
v2.1 (2016-10-11)
Unknown
v2.0 (2016-07-27)
Support loading settings from configuration files.
v1.5.1 (2016-05-29)
Unknown
v1.5 (2016-02-03)
Unknown
v1.4.2 (2015-12-16)
Unknown
v1.4.1 (2015-08-16)
Unknown
v1.4 (2015-06-26)
Unknown
v1.3.1 (2015-04-14)
Unknown
v1.3 (2015-04-11)
Unknown
v1.2.1 (2015-04-11)
Unknown
v1.2 (2015-04-11)
Unknown
v1.1.1 (2015-04-05)
Unknown
v1.1 (2015-04-03)
Unknown
v1.0 (2015-03-14)
Add Sphinx support.
v0.6 (2014-09-25)
Unknown
v0.5.1 (2014-08-23)
Unknown
v0.5 (2014-06-01)
Unknown
v0.4.1 (2014-05-31)
Unknown
v0.4 (2014-05-24)
Unknown
v0.3.6 (2014-04-12)
Unknown
v0.3.5 (2014-01-25)
Unknown
v0.3.4 (2013-12-29)
Unknown
v0.3.3 (2013-12-28)
Unknown
v0.3.2 (2013-12-27)
Unknown
v0.3.1
Unknown
v0.2
Unknown
v0.1.1
Unknown
v0.1 (2013-12-02)
Initial version.
License
Copyright (C) 2013-2022 Steven Myint
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.