Documentation/Source/eric5.Plugins.CheckerPlugins.CodeStyleChecker.NamingStyleChecker.html

changeset 2985
177b1858245f
child 3209
c5432abceb25
equal deleted inserted replaced
2984:031cceaa8b01 2985:177b1858245f
1 <!DOCTYPE html>
2 <html><head>
3 <title>eric5.Plugins.CheckerPlugins.CodeStyleChecker.NamingStyleChecker</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>eric5.Plugins.CheckerPlugins.CodeStyleChecker.NamingStyleChecker</h1>
23 <p>
24 Module implementing a checker for naming conventions.
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="#NamingStyleChecker">NamingStyleChecker</a></td>
34 <td>Class implementing a checker for naming conventions.</td>
35 </tr>
36 </table>
37 <h3>Functions</h3>
38 <table>
39 <tr><td>None</td></tr>
40 </table>
41 <hr /><hr />
42 <a NAME="NamingStyleChecker" ID="NamingStyleChecker"></a>
43 <h2>NamingStyleChecker</h2>
44 <p>
45 Class implementing a checker for naming conventions.
46 </p>
47 <h3>Derived from</h3>
48 object
49 <h3>Class Attributes</h3>
50 <table>
51 <tr><td>CamelcaseRegexp</td></tr><tr><td>Codes</td></tr><tr><td>LowercaseRegex</td></tr><tr><td>Messages</td></tr><tr><td>MixedcaseRegexp</td></tr><tr><td>UppercaseRegexp</td></tr>
52 </table>
53 <h3>Class Methods</h3>
54 <table>
55 <tr>
56 <td><a href="#NamingStyleChecker.getMessage">getMessage</a></td>
57 <td>Class method to get a translated and formatted message for a given code.</td>
58 </tr>
59 </table>
60 <h3>Methods</h3>
61 <table>
62 <tr>
63 <td><a href="#NamingStyleChecker.__init__">NamingStyleChecker</a></td>
64 <td>Constructor (according to 'extended' pep8.py API)</td>
65 </tr><tr>
66 <td><a href="#NamingStyleChecker.__checkClassName">__checkClassName</a></td>
67 <td>Private class to check the given node for class name conventions (N801).</td>
68 </tr><tr>
69 <td><a href="#NamingStyleChecker.__checkFunctionArgumentNames">__checkFunctionArgumentNames</a></td>
70 <td>Private class to check the argument names of functions (N803, N804, N805, N806).</td>
71 </tr><tr>
72 <td><a href="#NamingStyleChecker.__checkFuntionName">__checkFuntionName</a></td>
73 <td>Private class to check the given node for function name conventions (N802).</td>
74 </tr><tr>
75 <td><a href="#NamingStyleChecker.__checkImportAs">__checkImportAs</a></td>
76 <td>Private method to check that imports don't change the naming convention (N811, N812, N813, N814).</td>
77 </tr><tr>
78 <td><a href="#NamingStyleChecker.__checkModule">__checkModule</a></td>
79 <td>Private method to check module naming conventions (N807, N808).</td>
80 </tr><tr>
81 <td><a href="#NamingStyleChecker.__checkNameToBeAvoided">__checkNameToBeAvoided</a></td>
82 <td>Private class to check the given node for a name to be avoided (N831).</td>
83 </tr><tr>
84 <td><a href="#NamingStyleChecker.__checkVariablesInFunction">__checkVariablesInFunction</a></td>
85 <td>Private method to check local variables in functions (N821).</td>
86 </tr><tr>
87 <td><a href="#NamingStyleChecker.__error">__error</a></td>
88 <td>Private method to build the error information.</td>
89 </tr><tr>
90 <td><a href="#NamingStyleChecker.__findGlobalDefs">__findGlobalDefs</a></td>
91 <td>Private method amend a node with global definitions information.</td>
92 </tr><tr>
93 <td><a href="#NamingStyleChecker.__getArgNames">__getArgNames</a></td>
94 <td>Private method to get the argument names of a function node.</td>
95 </tr><tr>
96 <td><a href="#NamingStyleChecker.__isNameToBeAvoided">__isNameToBeAvoided</a></td>
97 <td>Private method to check, if the given name should be avoided.</td>
98 </tr><tr>
99 <td><a href="#NamingStyleChecker.__tagClassFunctions">__tagClassFunctions</a></td>
100 <td>Private method to tag functions if they are methods, class methods or static methods.</td>
101 </tr><tr>
102 <td><a href="#NamingStyleChecker.__visitNode">__visitNode</a></td>
103 <td>Private method to inspect the given AST node.</td>
104 </tr><tr>
105 <td><a href="#NamingStyleChecker.__visitTree">__visitTree</a></td>
106 <td>Private method to scan the given AST tree.</td>
107 </tr><tr>
108 <td><a href="#NamingStyleChecker.run">run</a></td>
109 <td>Public method run by the pep8.py checker.</td>
110 </tr>
111 </table>
112 <h3>Static Methods</h3>
113 <table>
114 <tr><td>None</td></tr>
115 </table>
116 <a NAME="NamingStyleChecker.getMessage" ID="NamingStyleChecker.getMessage"></a>
117 <h4>NamingStyleChecker.getMessage (class method)</h4>
118 <b>getMessage</b>(<i>code, *args</i>)
119 <p>
120 Class method to get a translated and formatted message for a
121 given code.
122 </p><dl>
123 <dt><i>code</i></dt>
124 <dd>
125 message code (string)
126 </dd><dt><i>args</i></dt>
127 <dd>
128 arguments for a formatted message (list)
129 </dd>
130 </dl><dl>
131 <dt>Returns:</dt>
132 <dd>
133 translated and formatted message (string)
134 </dd>
135 </dl><a NAME="NamingStyleChecker.__init__" ID="NamingStyleChecker.__init__"></a>
136 <h4>NamingStyleChecker (Constructor)</h4>
137 <b>NamingStyleChecker</b>(<i>tree, filename, options</i>)
138 <p>
139 Constructor (according to 'extended' pep8.py API)
140 </p><dl>
141 <dt><i>tree</i></dt>
142 <dd>
143 AST tree of the source file
144 </dd><dt><i>filename</i></dt>
145 <dd>
146 name of the source file (string)
147 </dd><dt><i>options</i></dt>
148 <dd>
149 options as parsed by pep8.StyleGuide
150 </dd>
151 </dl><a NAME="NamingStyleChecker.__checkClassName" ID="NamingStyleChecker.__checkClassName"></a>
152 <h4>NamingStyleChecker.__checkClassName</h4>
153 <b>__checkClassName</b>(<i>node, parents</i>)
154 <p>
155 Private class to check the given node for class name
156 conventions (N801).
157 </p><p>
158 Almost without exception, class names use the CapWords convention.
159 Classes for internal use have a leading underscore in addition.
160 </p><dl>
161 <dt><i>node</i></dt>
162 <dd>
163 AST note to check
164 </dd><dt><i>parents</i></dt>
165 <dd>
166 list of parent nodes
167 </dd>
168 </dl><dl>
169 <dt>Returns:</dt>
170 <dd>
171 tuple giving line number, offset within line and error code
172 (integer, integer, string)
173 </dd>
174 </dl><a NAME="NamingStyleChecker.__checkFunctionArgumentNames" ID="NamingStyleChecker.__checkFunctionArgumentNames"></a>
175 <h4>NamingStyleChecker.__checkFunctionArgumentNames</h4>
176 <b>__checkFunctionArgumentNames</b>(<i>node, parents</i>)
177 <p>
178 Private class to check the argument names of functions
179 (N803, N804, N805, N806).
180 </p><p>
181 The argument names of a function should be lowercase, with words
182 separated by underscores. A class method should have 'cls' as the
183 first argument. A method should have 'self' as the first argument.
184 </p><dl>
185 <dt><i>node</i></dt>
186 <dd>
187 AST note to check
188 </dd><dt><i>parents</i></dt>
189 <dd>
190 list of parent nodes
191 </dd>
192 </dl><dl>
193 <dt>Returns:</dt>
194 <dd>
195 tuple giving line number, offset within line and error code
196 (integer, integer, string)
197 </dd>
198 </dl><a NAME="NamingStyleChecker.__checkFuntionName" ID="NamingStyleChecker.__checkFuntionName"></a>
199 <h4>NamingStyleChecker.__checkFuntionName</h4>
200 <b>__checkFuntionName</b>(<i>node, parents</i>)
201 <p>
202 Private class to check the given node for function name
203 conventions (N802).
204 </p><p>
205 Function names should be lowercase, with words separated by underscores
206 as necessary to improve readability. Functions <b>not</b> being
207 methods '__' in front and back are not allowed. Mixed case is allowed
208 only in contexts where that's already the prevailing style
209 (e.g. threading.py), to retain backwards compatibility.
210 </p><dl>
211 <dt><i>node</i></dt>
212 <dd>
213 AST note to check
214 </dd><dt><i>parents</i></dt>
215 <dd>
216 list of parent nodes
217 </dd>
218 </dl><dl>
219 <dt>Returns:</dt>
220 <dd>
221 tuple giving line number, offset within line and error code
222 (integer, integer, string)
223 </dd>
224 </dl><a NAME="NamingStyleChecker.__checkImportAs" ID="NamingStyleChecker.__checkImportAs"></a>
225 <h4>NamingStyleChecker.__checkImportAs</h4>
226 <b>__checkImportAs</b>(<i>node, parents</i>)
227 <p>
228 Private method to check that imports don't change the
229 naming convention (N811, N812, N813, N814).
230 </p><dl>
231 <dt><i>node</i></dt>
232 <dd>
233 AST note to check
234 </dd><dt><i>parents</i></dt>
235 <dd>
236 list of parent nodes
237 </dd>
238 </dl><dl>
239 <dt>Returns:</dt>
240 <dd>
241 tuple giving line number, offset within line and error code
242 (integer, integer, string)
243 </dd>
244 </dl><a NAME="NamingStyleChecker.__checkModule" ID="NamingStyleChecker.__checkModule"></a>
245 <h4>NamingStyleChecker.__checkModule</h4>
246 <b>__checkModule</b>(<i>node, parents</i>)
247 <p>
248 Private method to check module naming conventions (N807, N808).
249 </p><p>
250 Module and package names should be lowercase.
251 </p><dl>
252 <dt><i>node</i></dt>
253 <dd>
254 AST note to check
255 </dd><dt><i>parents</i></dt>
256 <dd>
257 list of parent nodes
258 </dd>
259 </dl><dl>
260 <dt>Returns:</dt>
261 <dd>
262 tuple giving line number, offset within line and error code
263 (integer, integer, string)
264 </dd>
265 </dl><a NAME="NamingStyleChecker.__checkNameToBeAvoided" ID="NamingStyleChecker.__checkNameToBeAvoided"></a>
266 <h4>NamingStyleChecker.__checkNameToBeAvoided</h4>
267 <b>__checkNameToBeAvoided</b>(<i>node, parents</i>)
268 <p>
269 Private class to check the given node for a name to be avoided (N831).
270 </p><dl>
271 <dt><i>node</i></dt>
272 <dd>
273 AST note to check
274 </dd><dt><i>parents</i></dt>
275 <dd>
276 list of parent nodes
277 </dd>
278 </dl><dl>
279 <dt>Returns:</dt>
280 <dd>
281 tuple giving line number, offset within line and error code
282 (integer, integer, string)
283 </dd>
284 </dl><a NAME="NamingStyleChecker.__checkVariablesInFunction" ID="NamingStyleChecker.__checkVariablesInFunction"></a>
285 <h4>NamingStyleChecker.__checkVariablesInFunction</h4>
286 <b>__checkVariablesInFunction</b>(<i>node, parents</i>)
287 <p>
288 Private method to check local variables in functions (N821).
289 </p><p>
290 Local variables in functions should be lowercase.
291 </p><dl>
292 <dt><i>node</i></dt>
293 <dd>
294 AST note to check
295 </dd><dt><i>parents</i></dt>
296 <dd>
297 list of parent nodes
298 </dd>
299 </dl><dl>
300 <dt>Returns:</dt>
301 <dd>
302 tuple giving line number, offset within line and error code
303 (integer, integer, string)
304 </dd>
305 </dl><a NAME="NamingStyleChecker.__error" ID="NamingStyleChecker.__error"></a>
306 <h4>NamingStyleChecker.__error</h4>
307 <b>__error</b>(<i>node, code</i>)
308 <p>
309 Private method to build the error information.
310 </p><dl>
311 <dt><i>node</i></dt>
312 <dd>
313 AST node to report an error for
314 </dd><dt><i>code</i></dt>
315 <dd>
316 error code to report (string)
317 </dd>
318 </dl><dl>
319 <dt>Returns:</dt>
320 <dd>
321 tuple giving line number, offset within line and error code
322 (integer, integer, string)
323 </dd>
324 </dl><a NAME="NamingStyleChecker.__findGlobalDefs" ID="NamingStyleChecker.__findGlobalDefs"></a>
325 <h4>NamingStyleChecker.__findGlobalDefs</h4>
326 <b>__findGlobalDefs</b>(<i>functionNode</i>)
327 <p>
328 Private method amend a node with global definitions information.
329 </p><dl>
330 <dt><i>functionNode</i></dt>
331 <dd>
332 AST tree node to amend
333 </dd>
334 </dl><a NAME="NamingStyleChecker.__getArgNames" ID="NamingStyleChecker.__getArgNames"></a>
335 <h4>NamingStyleChecker.__getArgNames</h4>
336 <b>__getArgNames</b>(<i>node</i>)
337 <p>
338 Private method to get the argument names of a function node.
339 </p><dl>
340 <dt><i>node</i></dt>
341 <dd>
342 AST node to extract arguments names from
343 </dd>
344 </dl><dl>
345 <dt>Returns:</dt>
346 <dd>
347 list of argument names (list of string)
348 </dd>
349 </dl><a NAME="NamingStyleChecker.__isNameToBeAvoided" ID="NamingStyleChecker.__isNameToBeAvoided"></a>
350 <h4>NamingStyleChecker.__isNameToBeAvoided</h4>
351 <b>__isNameToBeAvoided</b>(<i>name</i>)
352 <p>
353 Private method to check, if the given name should be avoided.
354 </p><dl>
355 <dt><i>name</i></dt>
356 <dd>
357 name to be checked (string)
358 </dd>
359 </dl><dl>
360 <dt>Returns:</dt>
361 <dd>
362 flag indicating to avoid it (boolen)
363 </dd>
364 </dl><a NAME="NamingStyleChecker.__tagClassFunctions" ID="NamingStyleChecker.__tagClassFunctions"></a>
365 <h4>NamingStyleChecker.__tagClassFunctions</h4>
366 <b>__tagClassFunctions</b>(<i>classNode</i>)
367 <p>
368 Private method to tag functions if they are methods, class methods or
369 static methods.
370 </p><dl>
371 <dt><i>classNode</i></dt>
372 <dd>
373 AST tree node to tag
374 </dd>
375 </dl><a NAME="NamingStyleChecker.__visitNode" ID="NamingStyleChecker.__visitNode"></a>
376 <h4>NamingStyleChecker.__visitNode</h4>
377 <b>__visitNode</b>(<i>node</i>)
378 <p>
379 Private method to inspect the given AST node.
380 </p><dl>
381 <dt><i>node</i></dt>
382 <dd>
383 AST tree node to inspect
384 </dd>
385 </dl><dl>
386 <dt>Returns:</dt>
387 <dd>
388 tuple giving line number, offset within line, code and
389 checker function
390 </dd>
391 </dl><a NAME="NamingStyleChecker.__visitTree" ID="NamingStyleChecker.__visitTree"></a>
392 <h4>NamingStyleChecker.__visitTree</h4>
393 <b>__visitTree</b>(<i>node</i>)
394 <p>
395 Private method to scan the given AST tree.
396 </p><dl>
397 <dt><i>node</i></dt>
398 <dd>
399 AST tree node to scan
400 </dd>
401 </dl><dl>
402 <dt>Returns:</dt>
403 <dd>
404 tuple giving line number, offset within line, code and
405 checker function
406 </dd>
407 </dl><a NAME="NamingStyleChecker.run" ID="NamingStyleChecker.run"></a>
408 <h4>NamingStyleChecker.run</h4>
409 <b>run</b>(<i></i>)
410 <p>
411 Public method run by the pep8.py checker.
412 </p><dl>
413 <dt>Returns:</dt>
414 <dd>
415 tuple giving line number, offset within line, code and
416 checker function
417 </dd>
418 </dl>
419 <div align="right"><a href="#top">Up</a></div>
420 <hr />
421 </body></html>

eric ide

mercurial