Skip to content

Commit 5968bfc

Browse files
committed
Fix false positive: role inside inline literal.
1 parent 0294f52 commit 5968bfc

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

sphinxlint.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,8 @@ def check_paragraph(paragraph_lno, paragraph):
208208
if error and not "|" in paragraph:
209209
error_offset = paragraph[: error.start()].count("\n")
210210
yield paragraph_lno + error_offset, f"role missing closing backtick: {error.group(0)!r}"
211-
for role in re.finditer("``[^`]+``.", paragraph, flags=re.DOTALL):
211+
paragraph_without_roles = re.sub(normal_role, "", paragraph).replace("````", "")
212+
for role in re.finditer("``.+?``(?!`).", paragraph_without_roles, flags=re.DOTALL):
212213
if not re.match(end_string_suffix, role.group(0)[-1]):
213214
error_offset = paragraph[: role.start()].count("\n")
214215
yield paragraph_lno + error_offset, f"code sample missing surrogate space before plural: {role.group(0)!r}"
@@ -231,6 +232,7 @@ def check_suspicious_constructs_in_paragraphs(file, lines):
231232

232233

233234
role_body = r"([^`]|\s`+|\\`)+"
235+
normal_role = f":{simplename}:`{role_body}`"
234236
backtick_in_front_of_role = re.compile(rf"(^|\s)`:{simplename}:`{role_body}`")
235237

236238

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Alone:
2+
3+
For these, use ``:obj:`~.acos()```.
4+
5+
Or not alone:
6+
7+
For these, use ``:obj:`~.acos()```. The ``~`` makes it so that the
8+
text in the rendered HTML only shows ``acos`` instead of the fully
9+
qualified name.

0 commit comments

Comments
 (0)