Checks syntax of reStructuredText and code blocks nested within it
npx @tessl/cli install tessl/pypi-rstcheck@6.2.0A comprehensive Python CLI tool for checking the syntax of reStructuredText files and code blocks nested within them. rstcheck validates both the RST document structure and the syntax of embedded code blocks in multiple programming languages, making it essential for documentation quality assurance in Python projects and technical writing workflows.
pip install rstcheckOptional extras:
pip install rstcheck[toml] - TOML configuration supportpip install rstcheck[sphinx] - Sphinx directive/role supportThe primary interface is the command-line tool, but programmatic access is available:
from rstcheck import _cliBasic syntax checking:
# Check a single RST file
rstcheck document.rst
# Check multiple files
rstcheck doc1.rst doc2.rst src/readme.rst
# Check all RST files in a directory recursively
rstcheck --recursive docs/
# Read from stdin
cat document.rst | rstcheck -Using command-line options:
# Ignore specific code block languages
rstcheck --ignore-languages cpp,javascript document.rst
# Set report level
rstcheck --report-level ERROR --log-level INFO document.rst
# Use custom config file
rstcheck --config myproject.cfg document.rst
# Ignore custom directives and roles
rstcheck --ignore-directives custom-directive --ignore-roles custom-role document.rstUsing configuration file (.rstcheck.cfg or pyproject.toml):
[rstcheck]
ignore_directives = custom-directive,foobar
ignore_roles = custom-role
ignore_messages = (Title underline too short\.$)
ignore_languages = cpp,javascript
report_level = warningCore file processing functionality for RST syntax validation.
# Command: rstcheck [OPTIONS] FILES...
# FILES: One or more RST file paths, directories (with --recursive), or "-" for stdinFile Input Options:
--recursive: Recursively find and check all .rst files"-": Read RST content from standard input (exclusive with other files)Configuration system supporting multiple file formats and sources.
# Configuration options
--config PATH # Config file or directory path
--warn-unknown-settings # Log warnings for unknown config settingsConfiguration File Resolution:
--config option.rstcheck.cfg in current or parent directoriespyproject.toml with [tool.rstcheck] section (requires toml extra)setup.cfg with [rstcheck] sectionSupported Configuration Formats:
.cfg, .ini files): [rstcheck] sectionpyproject.toml): [tool.rstcheck] sectionControl the severity level of issues reported.
--report-level LEVEL # Report level: INFO|WARNING|ERROR|SEVERE|NONE
--log-level LEVEL # Application log level: DEBUG|INFO|WARNING|ERROR|CRITICALReport Levels:
INFO: Report all issues including informational messagesWARNING: Report warnings and above (default)ERROR: Report errors and severe issues onlySEVERE: Report only severe structural issuesNONE: Suppress all issue reporting (exit code still reflects status)Flexible filtering system to ignore specific RST elements and code blocks.
--ignore-directives TEXT # Comma-separated directives to ignore
--ignore-roles TEXT # Comma-separated roles to ignore
--ignore-substitutions TEXT # Comma-separated substitutions to ignore
--ignore-languages TEXT # Comma-separated code block languages to ignore
--ignore-messages REGEX # Regular expression for messages to ignoreIgnore Options:
Recursive directory processing with flexible file discovery.
--recursive, -r # Recursively search directories for RST filesDirectory Processing Features:
.rst file discovery in directory treesComprehensive syntax validation for embedded code blocks in multiple languages.
Supported Languages:
Version reporting for rstcheck and its dependencies.
--version # Print version information and exitVersion Output:
While primarily a CLI tool, programmatic access is available for integration.
from rstcheck._cli import main, setup_logger, cli
def main() -> None:
"""Run the CLI application."""
# Entry point for programmatic execution
def setup_logger(loglevel: str) -> None:
"""Set up logging configuration.
Args:
loglevel (str): Logging level (DEBUG|INFO|WARNING|ERROR|CRITICAL)
Raises:
TypeError: On invalid logging levels
"""
def cli(
files: list[pathlib.Path],
config: pathlib.Path | None = None,
warn_unknown_settings: bool | None = None,
recursive: bool | None = None,
report_level: str | None = None,
log_level: str = "WARNING",
ignore_directives: str | None = None,
ignore_roles: str | None = None,
ignore_substitutions: str | None = None,
ignore_languages: str | None = None,
ignore_messages: str | None = None,
version: bool | None = None,
) -> None:
"""Main CLI function with full parameter control.
Args:
files: List of RST file paths to check
config: Path to configuration file or directory
warn_unknown_settings: Log warnings for unknown config settings
recursive: Recursively search directories for RST files
report_level: Issue report level (INFO|WARNING|ERROR|SEVERE|NONE)
log_level: Application logging level
ignore_directives: Comma-separated directives to ignore
ignore_roles: Comma-separated roles to ignore
ignore_substitutions: Comma-separated substitutions to ignore
ignore_languages: Comma-separated languages to ignore in code blocks
ignore_messages: Regular expression for messages to ignore
version: Print version information and exit
Raises:
typer.Exit: On completion (with appropriate exit code)
FileNotFoundError: When specified config path is not found
"""rstcheck provides comprehensive error reporting with structured output.
Exit Codes:
0: Success, no issues detected1: Issues detected or execution errorError Message Format:
filename.rst:line: (SEVERITY/level) message contextCommon Error Categories:
Error Suppression:
--report-level NONE--ignore-messagesrstcheck includes pre-commit hook configuration:
repos:
- repo: https://github.com/rstcheck/rstcheck
rev: v6.2.5
hooks:
- id: rstcheck
additional_dependencies: [rstcheck[sphinx,toml]]Command-line interface enables easy CI/CD integration:
# Fail build on any RST issues
rstcheck --report-level ERROR docs/
# Check all documentation with custom config
rstcheck --recursive --config .rstcheck.cfg docs/Integration with development tools and workflows:
Required Dependencies:
rstcheck-core >=1.1: Core RST checking functionalitytyper >=0.12.0: Modern CLI frameworkOptional Dependencies:
sphinx >=6.0: Sphinx directive and role supporttomli >=2.0 (Python ≤3.10): TOML configuration file supportConfigure rstcheck to recognize project-specific RST extensions:
[rstcheck]
ignore_directives =
custom-directive,
project-specific-directive,
legacy-directive
ignore_roles =
custom-role,
domain-specific-roleFine-tune code block validation for your project's needs:
[rstcheck]
# Skip validation for languages not relevant to your project
ignore_languages = cpp,rust,go
# Focus on critical languages
report_level = ERRORUse regular expressions to suppress specific known issues:
[rstcheck]
# Suppress title underline warnings for specific patterns
ignore_messages = (Title underline too short for title.*\.$)|(Unknown directive type.*\.$)