mirror of https://github.com/python/cpython.git
bpo-42238: rstlint: Add two new checks. (GH-26966)
This commit is contained in:
parent
4bcef2bb48
commit
01331f1a3c
|
@ -42,10 +42,89 @@
|
||||||
'versionchanged'
|
'versionchanged'
|
||||||
]
|
]
|
||||||
|
|
||||||
all_directives = '(' + '|'.join(directives) + ')'
|
roles = [
|
||||||
seems_directive_re = re.compile(r'(?<!\.)\.\. %s([^a-z:]|:(?!:))' % all_directives)
|
":class:",
|
||||||
default_role_re = re.compile(r'(^| )`\w([^`]*?\w)?`($| )')
|
":func:",
|
||||||
leaked_markup_re = re.compile(r'[a-z]::\s|`|\.\.\s*\w+:')
|
":meth:",
|
||||||
|
":mod:",
|
||||||
|
":exc:",
|
||||||
|
":issue:",
|
||||||
|
":attr:",
|
||||||
|
":c:func:",
|
||||||
|
":ref:",
|
||||||
|
":const:",
|
||||||
|
":term:",
|
||||||
|
":data:",
|
||||||
|
":keyword:",
|
||||||
|
":file:",
|
||||||
|
":pep:",
|
||||||
|
":c:type:",
|
||||||
|
":c:member:",
|
||||||
|
":option:",
|
||||||
|
":rfc:",
|
||||||
|
":envvar:",
|
||||||
|
":c:data:",
|
||||||
|
":source:",
|
||||||
|
":mailheader:",
|
||||||
|
":program:",
|
||||||
|
":c:macro:",
|
||||||
|
":dfn:",
|
||||||
|
":kbd:",
|
||||||
|
":command:",
|
||||||
|
":mimetype:",
|
||||||
|
":opcode:",
|
||||||
|
":manpage:",
|
||||||
|
":py:data:",
|
||||||
|
":RFC:",
|
||||||
|
":pdbcmd:",
|
||||||
|
":abbr:",
|
||||||
|
":samp:",
|
||||||
|
":token:",
|
||||||
|
":PEP:",
|
||||||
|
":sup:",
|
||||||
|
":py:class:",
|
||||||
|
":menuselection:",
|
||||||
|
":doc:",
|
||||||
|
":sub:",
|
||||||
|
":py:meth:",
|
||||||
|
":newsgroup:",
|
||||||
|
":code:",
|
||||||
|
":py:func:",
|
||||||
|
":memory:",
|
||||||
|
":makevar:",
|
||||||
|
":guilabel:",
|
||||||
|
":title-reference:",
|
||||||
|
":py:mod:",
|
||||||
|
":download:",
|
||||||
|
":2to3fixer:",
|
||||||
|
]
|
||||||
|
|
||||||
|
all_directives = "(" + "|".join(directives) + ")"
|
||||||
|
all_roles = "(" + "|".join(roles) + ")"
|
||||||
|
|
||||||
|
# Find comments that looks like a directive, like:
|
||||||
|
# .. versionchanged 3.6
|
||||||
|
# or
|
||||||
|
# .. versionchanged: 3.6
|
||||||
|
# as it should be:
|
||||||
|
# .. versionchanged:: 3.6
|
||||||
|
seems_directive_re = re.compile(r"(?<!\.)\.\. %s([^a-z:]|:(?!:))" % all_directives)
|
||||||
|
|
||||||
|
# Find directive prefixed with three dots instead of two, like:
|
||||||
|
# ... versionchanged:: 3.6
|
||||||
|
# instead of:
|
||||||
|
# .. versionchanged:: 3.6
|
||||||
|
three_dot_directive_re = re.compile(r"\.\.\. %s::" % all_directives)
|
||||||
|
|
||||||
|
# Find role used with double backticks instead of simple backticks like:
|
||||||
|
# :const:``None``
|
||||||
|
# instead of:
|
||||||
|
# :const:`None`
|
||||||
|
double_backtick_role = re.compile(r"(?<!``)%s``" % all_roles)
|
||||||
|
|
||||||
|
|
||||||
|
default_role_re = re.compile(r"(^| )`\w([^`]*?\w)?`($| )")
|
||||||
|
leaked_markup_re = re.compile(r"[a-z]::\s|`|\.\.\s*\w+:")
|
||||||
|
|
||||||
|
|
||||||
checkers = {}
|
checkers = {}
|
||||||
|
@ -82,13 +161,17 @@ def check_syntax(fn, lines):
|
||||||
def check_suspicious_constructs(fn, lines):
|
def check_suspicious_constructs(fn, lines):
|
||||||
"""Check for suspicious reST constructs."""
|
"""Check for suspicious reST constructs."""
|
||||||
inprod = False
|
inprod = False
|
||||||
for lno, line in enumerate(lines):
|
for lno, line in enumerate(lines, start=1):
|
||||||
if seems_directive_re.search(line):
|
if seems_directive_re.search(line):
|
||||||
yield lno+1, 'comment seems to be intended as a directive'
|
yield lno, "comment seems to be intended as a directive"
|
||||||
if '.. productionlist::' in line:
|
if three_dot_directive_re.search(line):
|
||||||
|
yield lno, "directive should start with two dots, not three."
|
||||||
|
if double_backtick_role.search(line):
|
||||||
|
yield lno, "role use a single backtick, double backtick found."
|
||||||
|
if ".. productionlist::" in line:
|
||||||
inprod = True
|
inprod = True
|
||||||
elif not inprod and default_role_re.search(line):
|
elif not inprod and default_role_re.search(line):
|
||||||
yield lno+1, 'default role used'
|
yield lno, "default role used"
|
||||||
elif inprod and not line.strip():
|
elif inprod and not line.strip():
|
||||||
inprod = False
|
inprod = False
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue