Skip to content

Commit c3d5c3c

Browse files
committed
address review
1 parent e558a6f commit c3d5c3c

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

sphinxlint/checkers.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ def check_unbalanced_inline_literals_delimiters(file, lines, options=None):
109109
)
110110

111111

112+
_ends_with_role_tag = re.compile(rst.ROLE_TAG + "$").search
113+
_starts_with_role_tag = re.compile("^" + rst.ROLE_TAG).search
114+
115+
112116
@checker(".rst", ".po", enabled=False)
113117
def check_default_role(file, lines, options=None):
114118
"""Search for default roles (but they are allowed in many projects).
@@ -127,10 +131,10 @@ def check_default_role(file, lines, options=None):
127131
if (stripped_line.startswith("|") and stripped_line.endswith("|") and
128132
stripped_line.count("|") >= 4 and "|" in match.group(0)):
129133
return # we don't handle tables yet.
130-
if rst.ROLE_TAG_ENDING_LINE_RE.search(before_match):
134+
if _ends_with_role_tag(before_match):
131135
# It's not a default role: it ends with a tag.
132136
continue
133-
if rst.ROLE_TAG_STARTING_LINE_RE.search(after_match):
137+
if _starts_with_role_tag(after_match):
134138
# It's not a default role: it starts with a tag.
135139
continue
136140
if match.group(0).startswith("``") and match.group(0).endswith("``"):
@@ -280,7 +284,7 @@ def check_role_with_double_backticks(file, lines, options=None):
280284
if inline_literal is None:
281285
break
282286
before = paragraph[: inline_literal.start()]
283-
if rst.ROLE_TAG_ENDING_LINE_RE.search(before):
287+
if _ends_with_role_tag(before):
284288
error_offset = paragraph[: inline_literal.start()].count("\n")
285289
yield paragraph_lno + error_offset, "role use a single backtick, double backtick found."
286290
paragraph = (

sphinxlint/rst.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,6 @@
144144

145145
BEFORE_ROLE = r"(^|(?<=[\s(/'{\[*-]))"
146146
ROLE_TAG = rf":{SIMPLENAME}:"
147-
ROLE_TAG_ENDING_LINE_RE = re.compile(ROLE_TAG + "$")
148-
ROLE_TAG_STARTING_LINE_RE = re.compile("^" + ROLE_TAG)
149147
ROLE_HEAD = rf"({BEFORE_ROLE}:{SIMPLENAME}:)" # A role, with a clean start
150148

151149
ASCII_ALLOWED_BEFORE_INLINE_MARKUP = r"""-:/'"<(\[{"""

0 commit comments

Comments
 (0)