Skip to content

Commit 1ebab9f

Browse files
committed
more
1 parent 33d1564 commit 1ebab9f

File tree

3 files changed

+20
-20
lines changed

3 files changed

+20
-20
lines changed

sphinxlint/checkers.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ def check_missing_backtick_after_role(file, lines, options=None):
6464

6565

6666
_RST_ROLE_RE = re.compile("``.+?``(?!`).", flags=re.DOTALL)
67+
_END_STRING_SUFFIX_RE = re.compile(rst.END_STRING_SUFFIX)
6768

6869

6970
@checker(".rst", ".po")
@@ -78,7 +79,7 @@ def check_missing_space_after_literal(file, lines, options=None):
7879
return # we don't handle tables yet.
7980
paragraph = clean_paragraph(paragraph)
8081
for role in _RST_ROLE_RE.finditer(paragraph):
81-
if not rst.END_STRING_SUFFIX_RE.match(role[0][-1]):
82+
if not _END_STRING_SUFFIX_RE.match(role[0][-1]):
8283
error_offset = paragraph[: role.start()].count("\n")
8384
yield (
8485
paragraph_lno + error_offset,
@@ -405,8 +406,8 @@ def check_missing_final_newline(file, lines, options=None):
405406

406407

407408
_is_long_interpreted_text = re.compile(r"^\s*\W*(:(\w+:)+)?`.*`\W*$").match
408-
_is_directive_or_hyperlink = re.compile(r"^\s*\.\. ").match
409-
_is_anonymous_hyperlink = re.compile(r"^\s*__ ").match
409+
_starts_with_directive_or_hyperlink = re.compile(r"^\s*\.\. ").match
410+
_starts_with_anonymous_hyperlink = re.compile(r"^\s*__ ").match
410411
_is_very_long_string_literal = re.compile(r"^\s*``[^`]+``$").match
411412

412413

@@ -420,9 +421,9 @@ def check_line_too_long(file, lines, options=None):
420421
continue # ignore wide tables
421422
if _is_long_interpreted_text(line):
422423
continue # ignore long interpreted text
423-
if _is_directive_or_hyperlink(line):
424+
if _starts_with_directive_or_hyperlink(line):
424425
continue # ignore directives and hyperlink targets
425-
if _is_anonymous_hyperlink(line):
426+
if _starts_with_anonymous_hyperlink(line):
426427
continue # ignore anonymous hyperlink targets
427428
if _is_very_long_string_literal(line):
428429
continue # ignore a very long literal string
@@ -457,7 +458,7 @@ def check_triple_backticks(file, lines, options=None):
457458
yield lno + 1, "There's no rst syntax using triple backticks"
458459

459460

460-
_contains_bad_dedent = re.compile(" [^ ].*::$").match
461+
_has_bad_dedent = re.compile(" [^ ].*::$").match
461462

462463

463464
@checker(".rst", ".po", rst_only=False)
@@ -477,20 +478,20 @@ def check_bad_dedent(file, lines, options=None):
477478

478479
def check_block(block_lineno, block):
479480
for lineno, line in enumerate(block.splitlines()):
480-
if _contains_bad_dedent(line):
481+
if _has_bad_dedent(line):
481482
errors.append((block_lineno + lineno, "Bad dedent in block"))
482483

483484
list(hide_non_rst_blocks(lines, hidden_block_cb=check_block))
484485
yield from errors
485486

486487

487-
_contains_dangling_hyphen = re.compile(r".*[a-z]-$").match
488+
_has_dangling_hyphen = re.compile(r".*[a-z]-$").match
488489

489490

490491
@checker(".rst", rst_only=True)
491492
def check_dangling_hyphen(file, lines, options):
492493
"""Check for lines ending in a hyphen."""
493494
for lno, line in enumerate(lines):
494495
stripped_line = line.rstrip("\n")
495-
if _contains_dangling_hyphen(stripped_line):
496+
if _has_dangling_hyphen(stripped_line):
496497
yield lno + 1, f"Line ends with dangling hyphen"

sphinxlint/rst.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,6 @@ def inline_markup_gen(start_string, end_string, extra_allowed_before=""):
250250

251251
START_STRING_PREFIX = f"(^|(?<=\\s|[{OPENERS}{DELIMITERS}|]))"
252252
END_STRING_SUFFIX = f"($|(?=\\s|[\x00{CLOSING_DELIMITERS}{DELIMITERS}{CLOSERS}|]))"
253-
END_STRING_SUFFIX_RE = re.compile(END_STRING_SUFFIX)
254253

255254
# Find role glued with another word like:
256255
# the:c:func:`PyThreadState_LeaveTracing` function.

sphinxlint/utils.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -200,26 +200,26 @@ def hide_non_rst_blocks(lines, hidden_block_cb=None):
200200
return output
201201

202202

203-
_contains_directive = re.compile(rf"\.\. {rst.ALL_DIRECTIVES}::").match
204-
_contains_footnote = re.compile(r"\.\. \[[0-9]+\] ").match
205-
_contains_citation = re.compile(r"\.\. \[[^\]]+\] ").match
206-
_contains_target = re.compile(r"\.\. _.*[^_]: ").match
207-
_contains_substitution = re.compile(r"\.\. \|[^\|]*\| ").match
203+
_starts_with_directive_marker = re.compile(rf"\.\. {rst.ALL_DIRECTIVES}::").match
204+
_starts_with_footnote_marker = re.compile(r"\.\. \[[0-9]+\] ").match
205+
_starts_with_citation_marker = re.compile(r"\.\. \[[^\]]+\] ").match
206+
_starts_with_target = re.compile(r"\.\. _.*[^_]: ").match
207+
_starts_with_substitution_definition = re.compile(r"\.\. \|[^\|]*\| ").match
208208

209209

210210
@lru_cache()
211211
def type_of_explicit_markup(line):
212212
"""Tell apart various explicit markup blocks."""
213213
line = line.lstrip()
214-
if _contains_directive(line):
214+
if _starts_with_directive_marker(line):
215215
return "directive"
216-
if _contains_footnote(line):
216+
if _starts_with_footnote_marker(line):
217217
return "footnote"
218-
if _contains_citation(line):
218+
if _starts_with_citation_marker(line):
219219
return "citation"
220-
if _contains_target(line):
220+
if _starts_with_target(line):
221221
return "target"
222-
if _contains_substitution(line):
222+
if _starts_with_substitution_definition(line):
223223
return "substitution_definition"
224224
return "comment"
225225

0 commit comments

Comments
 (0)