Skip to content

Commit e558a6f

Browse files
committed
fix 'n' cleanup
1 parent 8df071e commit e558a6f

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

sphinxlint/checkers.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,12 @@ def check_default_role(file, lines, options=None):
127127
if (stripped_line.startswith("|") and stripped_line.endswith("|") and
128128
stripped_line.count("|") >= 4 and "|" in match.group(0)):
129129
return # we don't handle tables yet.
130-
if rst.ROLE_TAG_STARTING_LINE_RE.search(before_match):
131-
# It's not a default role: it starts with a tag.
132-
continue
133-
if rst.ROLE_TAG_ENDING_LINE_RE.search(after_match):
130+
if rst.ROLE_TAG_ENDING_LINE_RE.search(before_match):
134131
# It's not a default role: it ends with a tag.
135132
continue
133+
if rst.ROLE_TAG_STARTING_LINE_RE.search(after_match):
134+
# It's not a default role: it starts with a tag.
135+
continue
136136
if match.group(0).startswith("``") and match.group(0).endswith("``"):
137137
# It's not a default role: it's an inline literal.
138138
continue
@@ -453,7 +453,7 @@ def check_triple_backticks(file, lines, options=None):
453453
yield lno + 1, "There's no rst syntax using triple backticks"
454454

455455

456-
_BAD_DEDENT_RE = re.compile(" [^ ].*::$")
456+
_contains_bad_dedent = re.compile(" [^ ].*::$").match
457457

458458

459459
@checker(".rst", ".po", rst_only=False)
@@ -473,19 +473,20 @@ def check_bad_dedent(file, lines, options=None):
473473

474474
def check_block(block_lineno, block):
475475
for lineno, line in enumerate(block.splitlines()):
476-
if _BAD_DEDENT_RE.match(line):
476+
if _contains_bad_dedent(line):
477477
errors.append((block_lineno + lineno, "Bad dedent in block"))
478478

479479
list(hide_non_rst_blocks(lines, hidden_block_cb=check_block))
480480
yield from errors
481481

482482

483-
_DANGLING_HYPHEN_RE = re.compile(r".*[a-z]-$")
483+
_contains_dangling_hyphen = re.compile(r".*[a-z]-$").match
484+
484485

485486
@checker(".rst", rst_only=True)
486487
def check_dangling_hyphen(file, lines, options):
487488
"""Check for lines ending in a hyphen."""
488489
for lno, line in enumerate(lines):
489490
stripped_line = line.rstrip("\n")
490-
if _DANGLING_HYPHEN_RE.match(stripped_line):
491+
if _contains_dangling_hyphen(stripped_line):
491492
yield lno + 1, f"Line ends with dangling hyphen"

tests/test_sphinxlint.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def test_sphinxlint_shall_not_pass(file, expected_errors, capsys):
6464
assert expected_error in out
6565
number_of_expected_errors = len(expected_errors)
6666
number_of_reported_errors = len(out.splitlines())
67-
assert number_of_expected_errors == number_of_reported_errors
67+
assert number_of_expected_errors == number_of_reported_errors, f"{number_of_reported_errors=}, {out=}"
6868

6969

7070
@pytest.mark.parametrize("file", [str(FIXTURE_DIR / "paragraphs.rst")])

0 commit comments

Comments
 (0)