Sphinx Lint
Sphinx Lint is a lightweight Python linter designed to check for stylistic and formal issues in `.rst` (reStructuredText) and `.py` (Python) files primarily used in Sphinx documentation. It complements other linters by focusing on Sphinx-specific field list conventions and semantic consistency checks. The current version is 1.0.2, and the library maintains an active release cadence with regular updates and improvements.
Warnings
- breaking Python 3.8 and 3.9 support was officially dropped in version 1.0.1. Users on older Python versions must upgrade their environment to Python 3.10 or newer to use sphinx-lint >= 1.0.1.
- breaking Version 1.0.2 introduced new linting rules for hyperlinks (flagging unnecessary underscores) and roles starting with `!~`. Existing documentation that previously passed linting might now fail due to these newly enforced stylistic and formal checks.
- breaking As of v0.9.0, Sphinx Lint prints error messages to `stderr` instead of `stdout`. Scripts or CI/CD pipelines that parsed `stdout` for linting failures will need to be updated to capture `stderr` instead.
- gotcha Sphinx Lint has known limitations with tables. Due to its line-by-line parsing, it may incorrectly flag roles within complex table structures as unclosed or malformed. To mitigate false positives, some rules are skipped when content is detected within a table.
- gotcha When using `sphinx-lint` with `pre-commit`, it is recommended to set `require_serial: true` for the hook to prevent potential issues with parallel execution, especially on Windows or when dealing with file locking. This became the default in v0.8.1, but custom or older configurations might need adjustment.
Install
-
pip install sphinx-lint
Quickstart
pip install sphinx-lint pre-commit pre-commit install # .pre-commit-config.yaml example # In your project's root: # git init # pre-commit install # vim .pre-commit-config.yaml # Add the following content: # # repos: # - repo: https://github.com/sphinx-contrib/sphinx-lint # rev: v1.0.2 # Use the latest release tag # hooks: # - id: sphinx-lint # types: [rst, python] # Command line usage sphinx-lint # Check a specific file sphinx-lint docs/index.rst # Check a directory sphinx-lint docs # Ignore a directory sphinx-lint -i venv # Show help sphinx-lint -h