2020
2121directives = [
2222 # standard docutils ones
23- 'admonition' , 'attention' , 'caution' , 'class' , 'compound' , 'container' ,
24- 'contents' , 'csv-table' , 'danger' , 'date' , 'default-role' , 'epigraph' ,
25- 'error' , 'figure' , 'footer' , 'header' , 'highlights' , 'hint' , 'image' ,
26- 'important' , 'include' , 'line-block' , 'list-table' , 'meta' , 'note' ,
27- 'parsed-literal' , 'pull-quote' , 'raw' , 'replace' ,
28- 'restructuredtext-test-directive' , 'role' , 'rubric' , 'sectnum' , 'sidebar' ,
29- 'table' , 'target-notes' , 'tip' , 'title' , 'topic' , 'unicode' , 'warning' ,
23+ 'admonition' ,
24+ 'attention' ,
25+ 'caution' ,
26+ 'class' ,
27+ 'compound' ,
28+ 'container' ,
29+ 'contents' ,
30+ 'csv-table' ,
31+ 'danger' ,
32+ 'date' ,
33+ 'default-role' ,
34+ 'epigraph' ,
35+ 'error' ,
36+ 'figure' ,
37+ 'footer' ,
38+ 'header' ,
39+ 'highlights' ,
40+ 'hint' ,
41+ 'image' ,
42+ 'important' ,
43+ 'include' ,
44+ 'line-block' ,
45+ 'list-table' ,
46+ 'meta' ,
47+ 'note' ,
48+ 'parsed-literal' ,
49+ 'pull-quote' ,
50+ 'raw' ,
51+ 'replace' ,
52+ 'restructuredtext-test-directive' ,
53+ 'role' ,
54+ 'rubric' ,
55+ 'sectnum' ,
56+ 'sidebar' ,
57+ 'table' ,
58+ 'target-notes' ,
59+ 'tip' ,
60+ 'title' ,
61+ 'topic' ,
62+ 'unicode' ,
63+ 'warning' ,
3064 # Sphinx and Python docs custom ones
31- 'acks' , 'attribute' , 'autoattribute' , 'autoclass' , 'autodata' ,
32- 'autoexception' , 'autofunction' , 'automethod' , 'automodule' , 'centered' ,
33- 'cfunction' , 'class' , 'classmethod' , 'cmacro' , 'cmdoption' , 'cmember' ,
34- 'code-block' , 'confval' , 'cssclass' , 'ctype' , 'currentmodule' , 'cvar' ,
35- 'data' , 'decorator' , 'decoratormethod' , 'deprecated-removed' ,
36- 'deprecated(?!-removed)' , 'describe' , 'directive' , 'doctest' , 'envvar' ,
37- 'event' , 'exception' , 'function' , 'glossary' , 'highlight' , 'highlightlang' ,
38- 'impl-detail' , 'index' , 'literalinclude' , 'method' , 'miscnews' , 'module' ,
39- 'moduleauthor' , 'opcode' , 'pdbcommand' , 'productionlist' ,
40- 'program' , 'role' , 'sectionauthor' , 'seealso' , 'sourcecode' , 'staticmethod' ,
41- 'tabularcolumns' , 'testcode' , 'testoutput' , 'testsetup' , 'toctree' , 'todo' ,
42- 'todolist' , 'versionadded' , 'versionchanged'
65+ 'acks' ,
66+ 'attribute' ,
67+ 'autoattribute' ,
68+ 'autoclass' ,
69+ 'autodata' ,
70+ 'autoexception' ,
71+ 'autofunction' ,
72+ 'automethod' ,
73+ 'automodule' ,
74+ 'centered' ,
75+ 'cfunction' ,
76+ 'class' ,
77+ 'classmethod' ,
78+ 'cmacro' ,
79+ 'cmdoption' ,
80+ 'cmember' ,
81+ 'code-block' ,
82+ 'confval' ,
83+ 'cssclass' ,
84+ 'ctype' ,
85+ 'currentmodule' ,
86+ 'cvar' ,
87+ 'data' ,
88+ 'decorator' ,
89+ 'decoratormethod' ,
90+ 'deprecated-removed' ,
91+ 'deprecated(?!-removed)' ,
92+ 'describe' ,
93+ 'directive' ,
94+ 'doctest' ,
95+ 'envvar' ,
96+ 'event' ,
97+ 'exception' ,
98+ 'function' ,
99+ 'glossary' ,
100+ 'highlight' ,
101+ 'highlightlang' ,
102+ 'impl-detail' ,
103+ 'index' ,
104+ 'literalinclude' ,
105+ 'method' ,
106+ 'miscnews' ,
107+ 'module' ,
108+ 'moduleauthor' ,
109+ 'opcode' ,
110+ 'pdbcommand' ,
111+ 'productionlist' ,
112+ 'program' ,
113+ 'role' ,
114+ 'sectionauthor' ,
115+ 'seealso' ,
116+ 'sourcecode' ,
117+ 'staticmethod' ,
118+ 'tabularcolumns' ,
119+ 'testcode' ,
120+ 'testoutput' ,
121+ 'testsetup' ,
122+ 'toctree' ,
123+ 'todo' ,
124+ 'todolist' ,
125+ 'versionadded' ,
126+ 'versionchanged' ,
43127]
44128
45129all_directives = '(' + '|' .join (directives ) + ')'
55139
56140def checker (* suffixes , ** kwds ):
57141 """Decorator to register a function as a checker."""
142+
58143 def deco (func ):
59144 for suffix in suffixes :
60145 checkers .setdefault (suffix , []).append (func )
61146 for prop in checker_props :
62147 setattr (func , prop , kwds .get (prop , checker_props [prop ]))
63148 return func
149+
64150 return deco
65151
66152
@@ -84,11 +170,11 @@ def check_suspicious_constructs(fn, lines):
84170 inprod = False
85171 for lno , line in enumerate (lines ):
86172 if seems_directive_re .search (line ):
87- yield lno + 1 , 'comment seems to be intended as a directive'
173+ yield lno + 1 , 'comment seems to be intended as a directive'
88174 if '.. productionlist::' in line :
89175 inprod = True
90176 elif not inprod and default_role_re .search (line ):
91- yield lno + 1 , 'default role used'
177+ yield lno + 1 , 'default role used'
92178 elif inprod and not line .strip ():
93179 inprod = False
94180
@@ -98,11 +184,11 @@ def check_whitespace(fn, lines):
98184 """Check for whitespace and line length issues."""
99185 for lno , line in enumerate (lines ):
100186 if '\r ' in line :
101- yield lno + 1 , '\\ r in line'
187+ yield lno + 1 , '\\ r in line'
102188 if '\t ' in line :
103- yield lno + 1 , 'OMG TABS!!!1'
189+ yield lno + 1 , 'OMG TABS!!!1'
104190 if line [:- 1 ].rstrip (' \t ' ) != line [:- 1 ]:
105- yield lno + 1 , 'trailing whitespace'
191+ yield lno + 1 , 'trailing whitespace'
106192
107193
108194@checker ('.rst' , severity = 0 )
@@ -111,12 +197,14 @@ def check_line_length(fn, lines):
111197 for lno , line in enumerate (lines ):
112198 if len (line ) > 81 :
113199 # don't complain about tables, links and function signatures
114- if line .lstrip ()[0 ] not in '+|' and \
115- 'http://' not in line and \
116- not line .lstrip ().startswith (('.. function' ,
117- '.. method' ,
118- '.. cfunction' )):
119- yield lno + 1 , "line too long"
200+ if (
201+ line .lstrip ()[0 ] not in '+|'
202+ and 'http://' not in line
203+ and not line .lstrip ().startswith (
204+ ('.. function' , '.. method' , '.. cfunction' )
205+ )
206+ ):
207+ yield lno + 1 , "line too long"
120208
121209
122210@checker ('.html' , severity = 2 , falsepositives = True )
@@ -126,7 +214,7 @@ def check_leaked_markup(fn, lines):
126214 """
127215 for lno , line in enumerate (lines ):
128216 if leaked_markup_re .search (line ):
129- yield lno + 1 , 'possibly leaked markup: %r' % line
217+ yield lno + 1 , 'possibly leaked markup: %r' % line
130218
131219
132220def main (argv ):
@@ -137,7 +225,8 @@ def main(argv):
137225 -f enable checkers that yield many false positives
138226 -s sev only show problems with severity >= sev
139227 -i path ignore subdir or file path
140- ''' % argv [0 ]
228+ ''' % argv [0 ]
229+
141230 try :
142231 gopts , args = getopt .getopt (argv [1 :], 'vfs:i:' )
143232 except getopt .GetoptError :
@@ -222,7 +311,7 @@ def main(argv):
222311 for severity in sorted (count ):
223312 number = count [severity ]
224313 print ('%d problem%s with severity %d found.' %
225- (number , number > 1 and 's' or '' , severity ))
314+ (number , 's' if number > 1 else '' , severity ))
226315 return int (bool (count ))
227316
228317
0 commit comments