mirror of
https://github.com/django/django.git
synced 2025-09-10 02:59:34 +00:00
Added sphinxlint checker to flag relative targets in :doc: roles.
Co-authored-by: Adam Johnson <me@adamj.eu>
This commit is contained in:
parent
56955636e6
commit
c93dddf659
18
docs/lint.py
18
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user