Skip to content

Commit 01331f1

Browse files
authored
bpo-42238: rstlint: Add two new checks. (GH-26966)
1 parent 4bcef2b commit 01331f1

File tree

1 file changed

+91
-8
lines changed

1 file changed

+91
-8
lines changed

Doc/tools/rstlint.py

+91-8
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,89 @@
4242
'versionchanged'
4343
]
4444

45-
all_directives = '(' + '|'.join(directives) + ')'
46-
seems_directive_re = re.compile(r'(?<!\.)\.\. %s([^a-z:]|:(?!:))' % all_directives)
47-
default_role_re = re.compile(r'(^| )`\w([^`]*?\w)?`($| )')
48-
leaked_markup_re = re.compile(r'[a-z]::\s|`|\.\.\s*\w+:')
45+
roles = [
46+
":class:",
47+
":func:",
48+
":meth:",
49+
":mod:",
50+
":exc:",
51+
":issue:",
52+
":attr:",
53+
":c:func:",
54+
":ref:",
55+
":const:",
56+
":term:",
57+
":data:",
58+
":keyword:",
59+
":file:",
60+
":pep:",
61+
":c:type:",
62+
":c:member:",
63+
":option:",
64+
":rfc:",
65+
":envvar:",
66+
":c:data:",
67+
":source:",
68+
":mailheader:",
69+
":program:",
70+
":c:macro:",
71+
":dfn:",
72+
":kbd:",
73+
":command:",
74+
":mimetype:",
75+
":opcode:",
76+
":manpage:",
77+
":py:data:",
78+
":RFC:",
79+
":pdbcmd:",
80+
":abbr:",
81+
":samp:",
82+
":token:",
83+
":PEP:",
84+
":sup:",
85+
":py:class:",
86+
":menuselection:",
87+
":doc:",
88+
":sub:",
89+
":py:meth:",
90+
":newsgroup:",
91+
":code:",
92+
":py:func:",
93+
":memory:",
94+
":makevar:",
95+
":guilabel:",
96+
":title-reference:",
97+
":py:mod:",
98+
":download:",
99+
":2to3fixer:",
100+
]
101+
102+
all_directives = "(" + "|".join(directives) + ")"
103+
all_roles = "(" + "|".join(roles) + ")"
104+
105+
# Find comments that looks like a directive, like:
106+
# .. versionchanged 3.6
107+
# or
108+
# .. versionchanged: 3.6
109+
# as it should be:
110+
# .. versionchanged:: 3.6
111+
seems_directive_re = re.compile(r"(?<!\.)\.\. %s([^a-z:]|:(?!:))" % all_directives)
112+
113+
# Find directive prefixed with three dots instead of two, like:
114+
# ... versionchanged:: 3.6
115+
# instead of:
116+
# .. versionchanged:: 3.6
117+
three_dot_directive_re = re.compile(r"\.\.\. %s::" % all_directives)
118+
119+
# Find role used with double backticks instead of simple backticks like:
120+
# :const:``None``
121+
# instead of:
122+
# :const:`None`
123+
double_backtick_role = re.compile(r"(?<!``)%s``" % all_roles)
124+
125+
126+
default_role_re = re.compile(r"(^| )`\w([^`]*?\w)?`($| )")
127+
leaked_markup_re = re.compile(r"[a-z]::\s|`|\.\.\s*\w+:")
49128

50129

51130
checkers = {}
@@ -82,13 +161,17 @@ def check_syntax(fn, lines):
82161
def check_suspicious_constructs(fn, lines):
83162
"""Check for suspicious reST constructs."""
84163
inprod = False
85-
for lno, line in enumerate(lines):
164+
for lno, line in enumerate(lines, start=1):
86165
if seems_directive_re.search(line):
87-
yield lno+1, 'comment seems to be intended as a directive'
88-
if '.. productionlist::' in line:
166+
yield lno, "comment seems to be intended as a directive"
167+
if three_dot_directive_re.search(line):
168+
yield lno, "directive should start with two dots, not three."
169+
if double_backtick_role.search(line):
170+
yield lno, "role use a single backtick, double backtick found."
171+
if ".. productionlist::" in line:
89172
inprod = True
90173
elif not inprod and default_role_re.search(line):
91-
yield lno+1, 'default role used'
174+
yield lno, "default role used"
92175
elif inprod and not line.strip():
93176
inprod = False
94177

0 commit comments

Comments
 (0)