diff options
| author | David Smith <smithdc@gmail.com> | 2025-08-28 10:22:21 -0300 |
|---|---|---|
| committer | nessita <124304+nessita@users.noreply.github.com> | 2025-08-28 13:48:32 -0300 |
| commit | c93dddf65910eb94bb33d1895ff133cef74a308e (patch) | |
| tree | 9ef564217c512bec4b3906ab1b1467ced9295c74 /docs | |
| parent | 56955636e66505b7ac0246f97883f979d1b1f6a1 (diff) | |
Added sphinxlint checker to flag relative targets in :doc: roles.
Co-authored-by: Adam Johnson <me@adamj.eu>
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/lint.py | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/docs/lint.py b/docs/lint.py index 5c7a168c97..2358fec78e 100644 --- a/docs/lint.py +++ b/docs/lint.py @@ -14,7 +14,7 @@ from sphinxlint.checkers import ( from sphinxlint.checkers import checker as sphinxlint_checker from sphinxlint.rst import SIMPLENAME from sphinxlint.sphinxlint import check_text -from sphinxlint.utils import PER_FILE_CACHES, hide_non_rst_blocks +from sphinxlint.utils import PER_FILE_CACHES, hide_non_rst_blocks, paragraphs def django_check_file(filename, checkers, options=None): @@ -136,6 +136,22 @@ def check_python_domain_in_roles(file, lines, options=None): yield lno, f":py domain is the default and can be omitted {role.group(0)!r}" +_DOC_CAPTURE_TARGET_RE = re.compile(r":doc:`(?:[^<`]+<)?([^>`]+)>?`") + + +@sphinxlint_checker(".rst", rst_only=True) +def check_absolute_targets_doc_role(file, lines, options=None): + for paragraph_lno, paragraph in paragraphs(lines): + for error in _DOC_CAPTURE_TARGET_RE.finditer(paragraph): + target = error.group(1) + # Skip absolute or intersphinx refs like "python:using/windows". + if target.startswith("/") or ":" in target.split("/", 1)[0]: + continue + # Relative target, report as a violation. + error_offset = paragraph[: error.start()].count("\n") + yield (paragraph_lno + error_offset, target) + + import sphinxlint # noqa: E402 sphinxlint.check_file = django_check_file |
