|
10 | 10 |
|
11 | 11 | """Sphinx rst linter."""
|
12 | 12 |
|
13 |
| -__version__ = "0.6.5" |
| 13 | +__version__ = "0.6.6" |
14 | 14 |
|
15 | 15 | import argparse
|
16 | 16 | import multiprocessing
|
@@ -239,6 +239,8 @@ def clean_paragraph(paragraph):
|
239 | 239 | paragraph = escape2null(paragraph)
|
240 | 240 | paragraph = _clean_heuristic(paragraph, inline_literal_re)
|
241 | 241 | paragraph = _clean_heuristic(paragraph, inline_internal_target_re)
|
| 242 | + paragraph = _clean_heuristic(paragraph, hyperlink_references_re) |
| 243 | + paragraph = _clean_heuristic(paragraph, anonymous_hyperlink_references_re) |
242 | 244 | paragraph = normal_role_re.sub("", paragraph)
|
243 | 245 | return paragraph.replace("\x00", "\\")
|
244 | 246 |
|
@@ -418,6 +420,8 @@ def inline_markup_gen(start_string, end_string, extra_allowed_before=""):
|
418 | 420 | # https://docutils.sourceforge.io/docs/ref/rst/restructuredtext.html#inline-markup-recognition-rules
|
419 | 421 | interpreted_text_re = inline_markup_gen("`", "`")
|
420 | 422 | inline_internal_target_re = inline_markup_gen("_`", "`")
|
| 423 | +hyperlink_references_re = inline_markup_gen("`", "`_") |
| 424 | +anonymous_hyperlink_references_re = inline_markup_gen("`", "`__") |
421 | 425 | inline_literal_re = inline_markup_gen("``", "``")
|
422 | 426 | normal_role_re = re.compile(
|
423 | 427 | f":{SIMPLENAME}:{interpreted_text_re.pattern}", flags=re.VERBOSE | re.DOTALL
|
@@ -627,6 +631,27 @@ def check_missing_space_before_default_role(file, lines, options=None):
|
627 | 631 | )
|
628 | 632 |
|
629 | 633 |
|
| 634 | +@checker(".rst") |
| 635 | +def check_hyperlink_reference_missing_backtick(file, lines, options=None): |
| 636 | + """Search for missing backticks in front of hyperlink references. |
| 637 | +
|
| 638 | + Bad: Misc/NEWS <https://github.com/python/cpython/blob/v3.2.6/Misc/NEWS>`_ |
| 639 | + Good: `Misc/NEWS <https://github.com/python/cpython/blob/v3.2.6/Misc/NEWS>`_ |
| 640 | + """ |
| 641 | + for paragraph_lno, paragraph in paragraphs(lines): |
| 642 | + if paragraph.count("|") > 4: |
| 643 | + return # we don't handle tables yet. |
| 644 | + paragraph = clean_paragraph(paragraph) |
| 645 | + paragraph = interpreted_text_re.sub("", paragraph) |
| 646 | + for hyperlink_reference in re.finditer(r"\S* <https?://[^ ]+>`_", paragraph): |
| 647 | + error_offset = paragraph[: hyperlink_reference.start()].count("\n") |
| 648 | + context = hyperlink_reference.group(0) |
| 649 | + yield ( |
| 650 | + paragraph_lno + error_offset, |
| 651 | + f"missing backtick before hyperlink reference: {context!r}.", |
| 652 | + ) |
| 653 | + |
| 654 | + |
630 | 655 | @checker(".rst")
|
631 | 656 | def check_missing_colon_in_role(file, lines, options=None):
|
632 | 657 | """Search for missing colons in roles.
|
|
0 commit comments