|
1 <!DOCTYPE html> |
|
2 <html><head> |
|
3 <title>eric6.Plugins.CheckerPlugins.CodeStyleChecker.MiscellaneousChecker</title> |
|
4 <meta charset="UTF-8"> |
|
5 <style> |
|
6 body { |
|
7 background: #EDECE6; |
|
8 margin: 0em 1em 10em 1em; |
|
9 color: black; |
|
10 } |
|
11 |
|
12 h1 { color: white; background: #85774A; } |
|
13 h2 { color: white; background: #85774A; } |
|
14 h3 { color: white; background: #9D936E; } |
|
15 h4 { color: white; background: #9D936E; } |
|
16 |
|
17 a { color: #BA6D36; } |
|
18 |
|
19 </style> |
|
20 </head> |
|
21 <body><a NAME="top" ID="top"></a> |
|
22 <h1>eric6.Plugins.CheckerPlugins.CodeStyleChecker.MiscellaneousChecker</h1> |
|
23 <p> |
|
24 Module implementing a checker for miscellaneous checks. |
|
25 </p> |
|
26 <h3>Global Attributes</h3> |
|
27 <table> |
|
28 <tr><td>None</td></tr> |
|
29 </table> |
|
30 <h3>Classes</h3> |
|
31 <table> |
|
32 <tr> |
|
33 <td><a href="#MiscellaneousChecker">MiscellaneousChecker</a></td> |
|
34 <td>Class implementing a checker for miscellaneous checks.</td> |
|
35 </tr><tr> |
|
36 <td><a href="#TextVisitor">TextVisitor</a></td> |
|
37 <td>Class implementing a node visitor for bytes and str instances.</td> |
|
38 </tr> |
|
39 </table> |
|
40 <h3>Functions</h3> |
|
41 <table> |
|
42 <tr><td>None</td></tr> |
|
43 </table> |
|
44 <hr /><hr /> |
|
45 <a NAME="MiscellaneousChecker" ID="MiscellaneousChecker"></a> |
|
46 <h2>MiscellaneousChecker</h2> |
|
47 <p> |
|
48 Class implementing a checker for miscellaneous checks. |
|
49 </p> |
|
50 <h3>Derived from</h3> |
|
51 object |
|
52 <h3>Class Attributes</h3> |
|
53 <table> |
|
54 <tr><td>Codes</td></tr><tr><td>FormatFieldRegex</td></tr><tr><td>Formatter</td></tr> |
|
55 </table> |
|
56 <h3>Class Methods</h3> |
|
57 <table> |
|
58 <tr><td>None</td></tr> |
|
59 </table> |
|
60 <h3>Methods</h3> |
|
61 <table> |
|
62 <tr> |
|
63 <td><a href="#MiscellaneousChecker.__init__">MiscellaneousChecker</a></td> |
|
64 <td>Constructor</td> |
|
65 </tr><tr> |
|
66 <td><a href="#MiscellaneousChecker.__checkBlindExcept">__checkBlindExcept</a></td> |
|
67 <td>Private method to check for blind except statements.</td> |
|
68 </tr><tr> |
|
69 <td><a href="#MiscellaneousChecker.__checkCoding">__checkCoding</a></td> |
|
70 <td>Private method to check the presence of a coding line and valid encodings.</td> |
|
71 </tr><tr> |
|
72 <td><a href="#MiscellaneousChecker.__checkCopyright">__checkCopyright</a></td> |
|
73 <td>Private method to check the presence of a copyright statement.</td> |
|
74 </tr><tr> |
|
75 <td><a href="#MiscellaneousChecker.__checkFormatString">__checkFormatString</a></td> |
|
76 <td>Private method to check string format strings.</td> |
|
77 </tr><tr> |
|
78 <td><a href="#MiscellaneousChecker.__checkFuture">__checkFuture</a></td> |
|
79 <td>Private method to check the __future__ imports.</td> |
|
80 </tr><tr> |
|
81 <td><a href="#MiscellaneousChecker.__checkPep3101">__checkPep3101</a></td> |
|
82 <td>Private method to check for old style string formatting.</td> |
|
83 </tr><tr> |
|
84 <td><a href="#MiscellaneousChecker.__checkPrintStatements">__checkPrintStatements</a></td> |
|
85 <td>Private method to check for print statements.</td> |
|
86 </tr><tr> |
|
87 <td><a href="#MiscellaneousChecker.__checkTuple">__checkTuple</a></td> |
|
88 <td>Private method to check for one element tuples.</td> |
|
89 </tr><tr> |
|
90 <td><a href="#MiscellaneousChecker.__error">__error</a></td> |
|
91 <td>Private method to record an issue.</td> |
|
92 </tr><tr> |
|
93 <td><a href="#MiscellaneousChecker.__getFields">__getFields</a></td> |
|
94 <td>Private method to extract the format field information.</td> |
|
95 </tr><tr> |
|
96 <td><a href="#MiscellaneousChecker.__ignoreCode">__ignoreCode</a></td> |
|
97 <td>Private method to check if the message code should be ignored.</td> |
|
98 </tr><tr> |
|
99 <td><a href="#MiscellaneousChecker.__reportInvalidSyntax">__reportInvalidSyntax</a></td> |
|
100 <td>Private method to report a syntax error.</td> |
|
101 </tr><tr> |
|
102 <td><a href="#MiscellaneousChecker.run">run</a></td> |
|
103 <td>Public method to check the given source against miscellaneous conditions.</td> |
|
104 </tr> |
|
105 </table> |
|
106 <h3>Static Methods</h3> |
|
107 <table> |
|
108 <tr><td>None</td></tr> |
|
109 </table> |
|
110 <a NAME="MiscellaneousChecker.__init__" ID="MiscellaneousChecker.__init__"></a> |
|
111 <h4>MiscellaneousChecker (Constructor)</h4> |
|
112 <b>MiscellaneousChecker</b>(<i>source, filename, select, ignore, expected, repeat, args</i>) |
|
113 <p> |
|
114 Constructor |
|
115 </p><dl> |
|
116 <dt><i>source</i> (list of str)</dt> |
|
117 <dd> |
|
118 source code to be checked |
|
119 </dd><dt><i>filename</i> (str)</dt> |
|
120 <dd> |
|
121 name of the source file |
|
122 </dd><dt><i>select</i> (list of str)</dt> |
|
123 <dd> |
|
124 list of selected codes |
|
125 </dd><dt><i>ignore</i> (list of str)</dt> |
|
126 <dd> |
|
127 list of codes to be ignored |
|
128 </dd><dt><i>expected</i> (list of str)</dt> |
|
129 <dd> |
|
130 list of expected codes |
|
131 </dd><dt><i>repeat</i> (bool)</dt> |
|
132 <dd> |
|
133 flag indicating to report each occurrence of a code |
|
134 </dd><dt><i>args</i> (dict)</dt> |
|
135 <dd> |
|
136 dictionary of arguments for the miscellaneous checks |
|
137 </dd> |
|
138 </dl><a NAME="MiscellaneousChecker.__checkBlindExcept" ID="MiscellaneousChecker.__checkBlindExcept"></a> |
|
139 <h4>MiscellaneousChecker.__checkBlindExcept</h4> |
|
140 <b>__checkBlindExcept</b>(<i></i>) |
|
141 <p> |
|
142 Private method to check for blind except statements. |
|
143 </p><a NAME="MiscellaneousChecker.__checkCoding" ID="MiscellaneousChecker.__checkCoding"></a> |
|
144 <h4>MiscellaneousChecker.__checkCoding</h4> |
|
145 <b>__checkCoding</b>(<i></i>) |
|
146 <p> |
|
147 Private method to check the presence of a coding line and valid |
|
148 encodings. |
|
149 </p><a NAME="MiscellaneousChecker.__checkCopyright" ID="MiscellaneousChecker.__checkCopyright"></a> |
|
150 <h4>MiscellaneousChecker.__checkCopyright</h4> |
|
151 <b>__checkCopyright</b>(<i></i>) |
|
152 <p> |
|
153 Private method to check the presence of a copyright statement. |
|
154 </p><a NAME="MiscellaneousChecker.__checkFormatString" ID="MiscellaneousChecker.__checkFormatString"></a> |
|
155 <h4>MiscellaneousChecker.__checkFormatString</h4> |
|
156 <b>__checkFormatString</b>(<i></i>) |
|
157 <p> |
|
158 Private method to check string format strings. |
|
159 </p><a NAME="MiscellaneousChecker.__checkFuture" ID="MiscellaneousChecker.__checkFuture"></a> |
|
160 <h4>MiscellaneousChecker.__checkFuture</h4> |
|
161 <b>__checkFuture</b>(<i></i>) |
|
162 <p> |
|
163 Private method to check the __future__ imports. |
|
164 </p><a NAME="MiscellaneousChecker.__checkPep3101" ID="MiscellaneousChecker.__checkPep3101"></a> |
|
165 <h4>MiscellaneousChecker.__checkPep3101</h4> |
|
166 <b>__checkPep3101</b>(<i></i>) |
|
167 <p> |
|
168 Private method to check for old style string formatting. |
|
169 </p><a NAME="MiscellaneousChecker.__checkPrintStatements" ID="MiscellaneousChecker.__checkPrintStatements"></a> |
|
170 <h4>MiscellaneousChecker.__checkPrintStatements</h4> |
|
171 <b>__checkPrintStatements</b>(<i></i>) |
|
172 <p> |
|
173 Private method to check for print statements. |
|
174 </p><a NAME="MiscellaneousChecker.__checkTuple" ID="MiscellaneousChecker.__checkTuple"></a> |
|
175 <h4>MiscellaneousChecker.__checkTuple</h4> |
|
176 <b>__checkTuple</b>(<i></i>) |
|
177 <p> |
|
178 Private method to check for one element tuples. |
|
179 </p><a NAME="MiscellaneousChecker.__error" ID="MiscellaneousChecker.__error"></a> |
|
180 <h4>MiscellaneousChecker.__error</h4> |
|
181 <b>__error</b>(<i>lineNumber, offset, code, *args</i>) |
|
182 <p> |
|
183 Private method to record an issue. |
|
184 </p><dl> |
|
185 <dt><i>lineNumber</i> (int)</dt> |
|
186 <dd> |
|
187 line number of the issue |
|
188 </dd><dt><i>offset</i> (int)</dt> |
|
189 <dd> |
|
190 position within line of the issue |
|
191 </dd><dt><i>code</i> (str)</dt> |
|
192 <dd> |
|
193 message code |
|
194 </dd><dt><i>args</i> (list)</dt> |
|
195 <dd> |
|
196 arguments for the message |
|
197 </dd> |
|
198 </dl><a NAME="MiscellaneousChecker.__getFields" ID="MiscellaneousChecker.__getFields"></a> |
|
199 <h4>MiscellaneousChecker.__getFields</h4> |
|
200 <b>__getFields</b>(<i>string</i>) |
|
201 <p> |
|
202 Private method to extract the format field information. |
|
203 </p><dl> |
|
204 <dt><i>string</i> (str)</dt> |
|
205 <dd> |
|
206 format string to be parsed |
|
207 </dd> |
|
208 </dl><dl> |
|
209 <dt>Returns:</dt> |
|
210 <dd> |
|
211 format field information as a tuple with fields, implicit |
|
212 field definitions present and explicit field definitions present |
|
213 </dd> |
|
214 </dl><dl> |
|
215 <dt>Return Type:</dt> |
|
216 <dd> |
|
217 tuple of set of str, bool, bool |
|
218 </dd> |
|
219 </dl><a NAME="MiscellaneousChecker.__ignoreCode" ID="MiscellaneousChecker.__ignoreCode"></a> |
|
220 <h4>MiscellaneousChecker.__ignoreCode</h4> |
|
221 <b>__ignoreCode</b>(<i>code</i>) |
|
222 <p> |
|
223 Private method to check if the message code should be ignored. |
|
224 </p><dl> |
|
225 <dt><i>code</i> (str)</dt> |
|
226 <dd> |
|
227 message code to check for |
|
228 </dd> |
|
229 </dl><dl> |
|
230 <dt>Returns:</dt> |
|
231 <dd> |
|
232 flag indicating to ignore the given code |
|
233 </dd> |
|
234 </dl><dl> |
|
235 <dt>Return Type:</dt> |
|
236 <dd> |
|
237 bool |
|
238 </dd> |
|
239 </dl><a NAME="MiscellaneousChecker.__reportInvalidSyntax" ID="MiscellaneousChecker.__reportInvalidSyntax"></a> |
|
240 <h4>MiscellaneousChecker.__reportInvalidSyntax</h4> |
|
241 <b>__reportInvalidSyntax</b>(<i></i>) |
|
242 <p> |
|
243 Private method to report a syntax error. |
|
244 </p><a NAME="MiscellaneousChecker.run" ID="MiscellaneousChecker.run"></a> |
|
245 <h4>MiscellaneousChecker.run</h4> |
|
246 <b>run</b>(<i></i>) |
|
247 <p> |
|
248 Public method to check the given source against miscellaneous |
|
249 conditions. |
|
250 </p> |
|
251 <div align="right"><a href="#top">Up</a></div> |
|
252 <hr /><hr /> |
|
253 <a NAME="TextVisitor" ID="TextVisitor"></a> |
|
254 <h2>TextVisitor</h2> |
|
255 <p> |
|
256 Class implementing a node visitor for bytes and str instances. |
|
257 </p><p> |
|
258 It tries to detect docstrings as string of the first expression of each |
|
259 module, class or function. |
|
260 </p> |
|
261 <h3>Derived from</h3> |
|
262 ast.NodeVisitor |
|
263 <h3>Class Attributes</h3> |
|
264 <table> |
|
265 <tr><td>None</td></tr> |
|
266 </table> |
|
267 <h3>Class Methods</h3> |
|
268 <table> |
|
269 <tr><td>None</td></tr> |
|
270 </table> |
|
271 <h3>Methods</h3> |
|
272 <table> |
|
273 <tr> |
|
274 <td><a href="#TextVisitor.__init__">TextVisitor</a></td> |
|
275 <td>Constructor</td> |
|
276 </tr><tr> |
|
277 <td><a href="#TextVisitor.__addNode">__addNode</a></td> |
|
278 <td>Private method to add a node to our list of nodes.</td> |
|
279 </tr><tr> |
|
280 <td><a href="#TextVisitor.__isBaseString">__isBaseString</a></td> |
|
281 <td>Private method to determine, if a node is a base string node.</td> |
|
282 </tr><tr> |
|
283 <td><a href="#TextVisitor.__visitBody">__visitBody</a></td> |
|
284 <td>Private method to traverse the body of the node manually.</td> |
|
285 </tr><tr> |
|
286 <td><a href="#TextVisitor.__visitDefinition">__visitDefinition</a></td> |
|
287 <td>Private method handling class and function definitions.</td> |
|
288 </tr><tr> |
|
289 <td><a href="#TextVisitor.visit_Bytes">visit_Bytes</a></td> |
|
290 <td>Public method to record a bytes node.</td> |
|
291 </tr><tr> |
|
292 <td><a href="#TextVisitor.visit_Call">visit_Call</a></td> |
|
293 <td>Public method to handle a function call.</td> |
|
294 </tr><tr> |
|
295 <td><a href="#TextVisitor.visit_ClassDef">visit_ClassDef</a></td> |
|
296 <td>Public method to handle a class definition.</td> |
|
297 </tr><tr> |
|
298 <td><a href="#TextVisitor.visit_FunctionDef">visit_FunctionDef</a></td> |
|
299 <td>Public method to handle a function definition.</td> |
|
300 </tr><tr> |
|
301 <td><a href="#TextVisitor.visit_Module">visit_Module</a></td> |
|
302 <td>Public method to handle a module.</td> |
|
303 </tr><tr> |
|
304 <td><a href="#TextVisitor.visit_Str">visit_Str</a></td> |
|
305 <td>Public method to record a string node.</td> |
|
306 </tr> |
|
307 </table> |
|
308 <h3>Static Methods</h3> |
|
309 <table> |
|
310 <tr><td>None</td></tr> |
|
311 </table> |
|
312 <a NAME="TextVisitor.__init__" ID="TextVisitor.__init__"></a> |
|
313 <h4>TextVisitor (Constructor)</h4> |
|
314 <b>TextVisitor</b>(<i></i>) |
|
315 <p> |
|
316 Constructor |
|
317 </p><a NAME="TextVisitor.__addNode" ID="TextVisitor.__addNode"></a> |
|
318 <h4>TextVisitor.__addNode</h4> |
|
319 <b>__addNode</b>(<i>node</i>) |
|
320 <p> |
|
321 Private method to add a node to our list of nodes. |
|
322 </p><dl> |
|
323 <dt><i>node</i> (ast.AST)</dt> |
|
324 <dd> |
|
325 reference to the node to add |
|
326 </dd> |
|
327 </dl><a NAME="TextVisitor.__isBaseString" ID="TextVisitor.__isBaseString"></a> |
|
328 <h4>TextVisitor.__isBaseString</h4> |
|
329 <b>__isBaseString</b>(<i>node</i>) |
|
330 <p> |
|
331 Private method to determine, if a node is a base string node. |
|
332 </p><dl> |
|
333 <dt><i>node</i> (ast.AST)</dt> |
|
334 <dd> |
|
335 reference to the node to check |
|
336 </dd> |
|
337 </dl><dl> |
|
338 <dt>Returns:</dt> |
|
339 <dd> |
|
340 flag indicating a base string |
|
341 </dd> |
|
342 </dl><dl> |
|
343 <dt>Return Type:</dt> |
|
344 <dd> |
|
345 bool |
|
346 </dd> |
|
347 </dl><a NAME="TextVisitor.__visitBody" ID="TextVisitor.__visitBody"></a> |
|
348 <h4>TextVisitor.__visitBody</h4> |
|
349 <b>__visitBody</b>(<i>node</i>) |
|
350 <p> |
|
351 Private method to traverse the body of the node manually. |
|
352 </p><p> |
|
353 If the first node is an expression which contains a string or bytes it |
|
354 marks that as a docstring. |
|
355 </p><dl> |
|
356 <dt><i>node</i> (ast.AST)</dt> |
|
357 <dd> |
|
358 reference to the node to traverse |
|
359 </dd> |
|
360 </dl><a NAME="TextVisitor.__visitDefinition" ID="TextVisitor.__visitDefinition"></a> |
|
361 <h4>TextVisitor.__visitDefinition</h4> |
|
362 <b>__visitDefinition</b>(<i>node</i>) |
|
363 <p> |
|
364 Private method handling class and function definitions. |
|
365 </p><dl> |
|
366 <dt><i>node</i> (ast.FunctionDef or ast.ClassDef)</dt> |
|
367 <dd> |
|
368 reference to the node to handle |
|
369 </dd> |
|
370 </dl><a NAME="TextVisitor.visit_Bytes" ID="TextVisitor.visit_Bytes"></a> |
|
371 <h4>TextVisitor.visit_Bytes</h4> |
|
372 <b>visit_Bytes</b>(<i>node</i>) |
|
373 <p> |
|
374 Public method to record a bytes node. |
|
375 </p><dl> |
|
376 <dt><i>node</i> (ast.Bytes)</dt> |
|
377 <dd> |
|
378 reference to the bytes node |
|
379 </dd> |
|
380 </dl><a NAME="TextVisitor.visit_Call" ID="TextVisitor.visit_Call"></a> |
|
381 <h4>TextVisitor.visit_Call</h4> |
|
382 <b>visit_Call</b>(<i>node</i>) |
|
383 <p> |
|
384 Public method to handle a function call. |
|
385 </p><dl> |
|
386 <dt><i>node</i> (ast.Call)</dt> |
|
387 <dd> |
|
388 reference to the node to handle |
|
389 </dd> |
|
390 </dl><a NAME="TextVisitor.visit_ClassDef" ID="TextVisitor.visit_ClassDef"></a> |
|
391 <h4>TextVisitor.visit_ClassDef</h4> |
|
392 <b>visit_ClassDef</b>(<i>node</i>) |
|
393 <p> |
|
394 Public method to handle a class definition. |
|
395 </p><dl> |
|
396 <dt><i>node</i> (ast.ClassDef)</dt> |
|
397 <dd> |
|
398 reference to the node to handle |
|
399 </dd> |
|
400 </dl><a NAME="TextVisitor.visit_FunctionDef" ID="TextVisitor.visit_FunctionDef"></a> |
|
401 <h4>TextVisitor.visit_FunctionDef</h4> |
|
402 <b>visit_FunctionDef</b>(<i>node</i>) |
|
403 <p> |
|
404 Public method to handle a function definition. |
|
405 </p><dl> |
|
406 <dt><i>node</i> (ast.FunctionDef)</dt> |
|
407 <dd> |
|
408 reference to the node to handle |
|
409 </dd> |
|
410 </dl><a NAME="TextVisitor.visit_Module" ID="TextVisitor.visit_Module"></a> |
|
411 <h4>TextVisitor.visit_Module</h4> |
|
412 <b>visit_Module</b>(<i>node</i>) |
|
413 <p> |
|
414 Public method to handle a module. |
|
415 </p><dl> |
|
416 <dt><i>node</i> (ast.Module)</dt> |
|
417 <dd> |
|
418 reference to the node to handle |
|
419 </dd> |
|
420 </dl><a NAME="TextVisitor.visit_Str" ID="TextVisitor.visit_Str"></a> |
|
421 <h4>TextVisitor.visit_Str</h4> |
|
422 <b>visit_Str</b>(<i>node</i>) |
|
423 <p> |
|
424 Public method to record a string node. |
|
425 </p><dl> |
|
426 <dt><i>node</i> (ast.Str)</dt> |
|
427 <dd> |
|
428 reference to the string node |
|
429 </dd> |
|
430 </dl> |
|
431 <div align="right"><a href="#top">Up</a></div> |
|
432 <hr /> |
|
433 </body></html> |