rst-lint
restructuredtext-lint (rst-lint) is a reStructuredText linter that validates RST syntax and helps prevent frustrating errors when uploading documentation to PyPI. It checks for common reStructuredText issues and provides comprehensive validation for documentation workflows.
Key Features:
- Malformed directive detection catching invalid reStructuredText directives
- Invalid syntax validation ensuring proper RST document structure
- Title underline problem detection verifying consistent heading formatting
- Multiple formatting error checks covering common RST pitfalls
- Docutils integration leveraging the standard RST parsing library
- Detailed error messages with precise line numbers for quick fixes
- Multiple output formats supporting both text and JSON output
- Custom directive support extensible with custom directives and roles
- Sphinx documentation compatibility for specialized documentation workflows
- PyPI upload validation preventing documentation upload failures
- Command-line interface for easy integration into build processes
- Fast processing optimized for large documentation projects
rst-lint documentation
- Version in MegaLinter: 1.4.0
- Visit Official Web Site
- See How to configure rst-lint rules
- See How to disable rst-lint rules in files
Configuration in MegaLinter
- Enable rst-lint by adding
RST_RST_LINT
in ENABLE_LINTERS variable - Disable rst-lint by adding
RST_RST_LINT
in DISABLE_LINTERS variable
Variable | Description | Default value |
---|---|---|
RST_RST_LINT_ARGUMENTS | User custom arguments to add in linter CLI call Ex: -s --foo "bar" |
|
RST_RST_LINT_COMMAND_REMOVE_ARGUMENTS | User custom arguments to remove from command line before calling the linter Ex: -s --foo "bar" |
|
RST_RST_LINT_FILTER_REGEX_INCLUDE | Custom regex including filter Ex: (src\|lib) |
Include every file |
RST_RST_LINT_FILTER_REGEX_EXCLUDE | Custom regex excluding filter Ex: (test\|examples) |
Exclude no file |
RST_RST_LINT_CLI_LINT_MODE | Override default CLI lint mode - file : Calls the linter for each file- project : Call the linter from the root of the project |
file |
RST_RST_LINT_FILE_EXTENSIONS | Allowed file extensions. "*" matches any extension, "" matches empty extension. Empty list excludes all filesEx: [".py", ""] |
[".rst"] |
RST_RST_LINT_FILE_NAMES_REGEX | File name regex filters. Regular expression list for filtering files by their base names using regex full match. Empty list includes all files Ex: ["Dockerfile(-.+)?", "Jenkinsfile"] |
Include every file |
RST_RST_LINT_PRE_COMMANDS | List of bash commands to run before the linter | None |
RST_RST_LINT_POST_COMMANDS | List of bash commands to run after the linter | None |
RST_RST_LINT_UNSECURED_ENV_VARIABLES | List of env variables explicitly not filtered before calling RST_RST_LINT and its pre/post commands | None |
RST_RST_LINT_DISABLE_ERRORS | Run linter but consider errors as warnings | false |
RST_RST_LINT_DISABLE_ERRORS_IF_LESS_THAN | Maximum number of errors allowed | 0 |
RST_RST_LINT_CLI_EXECUTABLE | Override CLI executable | ['rst-lint'] |
MegaLinter Flavors
This linter is available in the following flavors
Flavor | Description | Embedded linters | Info | |
---|---|---|---|---|
![]() |
all | Default MegaLinter Flavor | 126 | |
cupcake | MegaLinter for the most commonly used languages | 87 | ||
python | Optimized for PYTHON based projects | 65 |
Behind the scenes
How are identified applicable files
- File extensions:
.rst
How the linting is performed
- rst-lint is called one time by identified file (
file
CLI lint mode)
Example calls
rst-lint myfile.rst
Help content
usage: rst-lint [-h] [--version] [--format {text,json}] [--encoding ENCODING]
[--level {debug,info,warning,error,severe}]
[--rst-prolog RST_PROLOG]
path [path ...]
Lint reStructuredText files. Returns 0 if all files pass linting, 1 for an
internal error, and 2 if linting failed.
positional arguments:
path File/folder to lint
options:
-h, --help show this help message and exit
--version show program's version number and exit
--format {text,json} Format of the output (default: "text")
--encoding ENCODING Encoding of the input file (e.g. "utf-8")
--level {debug,info,warning,error,severe}
Minimum error level to report (default: "warning")
--rst-prolog RST_PROLOG
reStructuredText content to prepend to all files
(useful for substitutions)
Installation on mega-linter Docker image
- Dockerfile commands :
# renovate: datasource=pypi depName=Pygments
ARG PIP_PYGMENTS_VERSION=2.19.2
# renovate: datasource=pypi depName=restructuredtext_lint
ARG PIP_RESTRUCTUREDTEXT_LINT_VERSION=1.4.0
- PIP packages (Python):