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

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

eric ide

mercurial