|
1 <!DOCTYPE html> |
|
2 <html><head> |
|
3 <title>eric7.Plugins.CheckerPlugins.CodeStyleChecker.Complexity.ComplexityChecker</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> |
|
22 <a NAME="top" ID="top"></a> |
|
23 <h1>eric7.Plugins.CheckerPlugins.CodeStyleChecker.Complexity.ComplexityChecker</h1> |
|
24 |
|
25 <p> |
|
26 Module implementing a checker for code complexity. |
|
27 </p> |
|
28 <h3>Global Attributes</h3> |
|
29 |
|
30 <table> |
|
31 <tr><td>None</td></tr> |
|
32 </table> |
|
33 <h3>Classes</h3> |
|
34 |
|
35 <table> |
|
36 |
|
37 <tr> |
|
38 <td><a href="#ComplexityChecker">ComplexityChecker</a></td> |
|
39 <td>Class implementing a checker for code complexity.</td> |
|
40 </tr> |
|
41 <tr> |
|
42 <td><a href="#LineComplexityVisitor">LineComplexityVisitor</a></td> |
|
43 <td>Class calculating the number of AST nodes per line of code and the median nodes/line score.</td> |
|
44 </tr> |
|
45 </table> |
|
46 <h3>Functions</h3> |
|
47 |
|
48 <table> |
|
49 <tr><td>None</td></tr> |
|
50 </table> |
|
51 <hr /> |
|
52 <hr /> |
|
53 <a NAME="ComplexityChecker" ID="ComplexityChecker"></a> |
|
54 <h2>ComplexityChecker</h2> |
|
55 |
|
56 <p> |
|
57 Class implementing a checker for code complexity. |
|
58 </p> |
|
59 <h3>Derived from</h3> |
|
60 None |
|
61 <h3>Class Attributes</h3> |
|
62 |
|
63 <table> |
|
64 <tr><td>Codes</td></tr> |
|
65 </table> |
|
66 <h3>Class Methods</h3> |
|
67 |
|
68 <table> |
|
69 <tr><td>None</td></tr> |
|
70 </table> |
|
71 <h3>Methods</h3> |
|
72 |
|
73 <table> |
|
74 |
|
75 <tr> |
|
76 <td><a href="#ComplexityChecker.__init__">ComplexityChecker</a></td> |
|
77 <td>Constructor</td> |
|
78 </tr> |
|
79 <tr> |
|
80 <td><a href="#ComplexityChecker.__checkLineComplexity">__checkLineComplexity</a></td> |
|
81 <td>Private method to check the complexity of a single line of code and the median line complexity of the source code.</td> |
|
82 </tr> |
|
83 <tr> |
|
84 <td><a href="#ComplexityChecker.__checkMcCabeComplexity">__checkMcCabeComplexity</a></td> |
|
85 <td>Private method to check the McCabe code complexity.</td> |
|
86 </tr> |
|
87 <tr> |
|
88 <td><a href="#ComplexityChecker.__error">__error</a></td> |
|
89 <td>Private method to record an issue.</td> |
|
90 </tr> |
|
91 <tr> |
|
92 <td><a href="#ComplexityChecker.__ignoreCode">__ignoreCode</a></td> |
|
93 <td>Private method to check if the message code should be ignored.</td> |
|
94 </tr> |
|
95 <tr> |
|
96 <td><a href="#ComplexityChecker.run">run</a></td> |
|
97 <td>Public method to check the given source for code complexity.</td> |
|
98 </tr> |
|
99 </table> |
|
100 <h3>Static Methods</h3> |
|
101 |
|
102 <table> |
|
103 <tr><td>None</td></tr> |
|
104 </table> |
|
105 |
|
106 <a NAME="ComplexityChecker.__init__" ID="ComplexityChecker.__init__"></a> |
|
107 <h4>ComplexityChecker (Constructor)</h4> |
|
108 <b>ComplexityChecker</b>(<i>source, filename, tree, select, ignore, args</i>) |
|
109 |
|
110 <p> |
|
111 Constructor |
|
112 </p> |
|
113 <dl> |
|
114 |
|
115 <dt><i>source</i> (list of str)</dt> |
|
116 <dd> |
|
117 source code to be checked |
|
118 </dd> |
|
119 <dt><i>filename</i> (str)</dt> |
|
120 <dd> |
|
121 name of the source file |
|
122 </dd> |
|
123 <dt><i>tree</i> (ast.Module)</dt> |
|
124 <dd> |
|
125 AST tree of the source code |
|
126 </dd> |
|
127 <dt><i>select</i> (list of str)</dt> |
|
128 <dd> |
|
129 list of selected codes |
|
130 </dd> |
|
131 <dt><i>ignore</i> (list of str)</dt> |
|
132 <dd> |
|
133 list of codes to be ignored |
|
134 </dd> |
|
135 <dt><i>args</i> (dict)</dt> |
|
136 <dd> |
|
137 dictionary of arguments for the miscellaneous checks |
|
138 </dd> |
|
139 </dl> |
|
140 <a NAME="ComplexityChecker.__checkLineComplexity" ID="ComplexityChecker.__checkLineComplexity"></a> |
|
141 <h4>ComplexityChecker.__checkLineComplexity</h4> |
|
142 <b>__checkLineComplexity</b>(<i></i>) |
|
143 |
|
144 <p> |
|
145 Private method to check the complexity of a single line of code and |
|
146 the median line complexity of the source code. |
|
147 </p> |
|
148 <p> |
|
149 Complexity is defined as the number of AST nodes produced by a line |
|
150 of code. |
|
151 </p> |
|
152 <a NAME="ComplexityChecker.__checkMcCabeComplexity" ID="ComplexityChecker.__checkMcCabeComplexity"></a> |
|
153 <h4>ComplexityChecker.__checkMcCabeComplexity</h4> |
|
154 <b>__checkMcCabeComplexity</b>(<i></i>) |
|
155 |
|
156 <p> |
|
157 Private method to check the McCabe code complexity. |
|
158 </p> |
|
159 <a NAME="ComplexityChecker.__error" ID="ComplexityChecker.__error"></a> |
|
160 <h4>ComplexityChecker.__error</h4> |
|
161 <b>__error</b>(<i>lineNumber, offset, code, *args</i>) |
|
162 |
|
163 <p> |
|
164 Private method to record an issue. |
|
165 </p> |
|
166 <dl> |
|
167 |
|
168 <dt><i>lineNumber</i> (int)</dt> |
|
169 <dd> |
|
170 line number of the issue |
|
171 </dd> |
|
172 <dt><i>offset</i> (int)</dt> |
|
173 <dd> |
|
174 position within line of the issue |
|
175 </dd> |
|
176 <dt><i>code</i> (str)</dt> |
|
177 <dd> |
|
178 message code |
|
179 </dd> |
|
180 <dt><i>args</i> (list)</dt> |
|
181 <dd> |
|
182 arguments for the message |
|
183 </dd> |
|
184 </dl> |
|
185 <a NAME="ComplexityChecker.__ignoreCode" ID="ComplexityChecker.__ignoreCode"></a> |
|
186 <h4>ComplexityChecker.__ignoreCode</h4> |
|
187 <b>__ignoreCode</b>(<i>code</i>) |
|
188 |
|
189 <p> |
|
190 Private method to check if the message code should be ignored. |
|
191 </p> |
|
192 <dl> |
|
193 |
|
194 <dt><i>code</i> (str)</dt> |
|
195 <dd> |
|
196 message code to check for |
|
197 </dd> |
|
198 </dl> |
|
199 <dl> |
|
200 <dt>Return:</dt> |
|
201 <dd> |
|
202 flag indicating to ignore the given code |
|
203 </dd> |
|
204 </dl> |
|
205 <dl> |
|
206 <dt>Return Type:</dt> |
|
207 <dd> |
|
208 bool |
|
209 </dd> |
|
210 </dl> |
|
211 <a NAME="ComplexityChecker.run" ID="ComplexityChecker.run"></a> |
|
212 <h4>ComplexityChecker.run</h4> |
|
213 <b>run</b>(<i></i>) |
|
214 |
|
215 <p> |
|
216 Public method to check the given source for code complexity. |
|
217 </p> |
|
218 <div align="right"><a href="#top">Up</a></div> |
|
219 <hr /> |
|
220 <hr /> |
|
221 <a NAME="LineComplexityVisitor" ID="LineComplexityVisitor"></a> |
|
222 <h2>LineComplexityVisitor</h2> |
|
223 |
|
224 <p> |
|
225 Class calculating the number of AST nodes per line of code |
|
226 and the median nodes/line score. |
|
227 </p> |
|
228 <h3>Derived from</h3> |
|
229 ast.NodeVisitor |
|
230 <h3>Class Attributes</h3> |
|
231 |
|
232 <table> |
|
233 <tr><td>None</td></tr> |
|
234 </table> |
|
235 <h3>Class Methods</h3> |
|
236 |
|
237 <table> |
|
238 <tr><td>None</td></tr> |
|
239 </table> |
|
240 <h3>Methods</h3> |
|
241 |
|
242 <table> |
|
243 |
|
244 <tr> |
|
245 <td><a href="#LineComplexityVisitor.__init__">LineComplexityVisitor</a></td> |
|
246 <td>Constructor</td> |
|
247 </tr> |
|
248 <tr> |
|
249 <td><a href="#LineComplexityVisitor.score">score</a></td> |
|
250 <td>Public method to calculate the median.</td> |
|
251 </tr> |
|
252 <tr> |
|
253 <td><a href="#LineComplexityVisitor.sortedList">sortedList</a></td> |
|
254 <td>Public method to get a sorted list of (line, nodes) tuples.</td> |
|
255 </tr> |
|
256 <tr> |
|
257 <td><a href="#LineComplexityVisitor.visit">visit</a></td> |
|
258 <td>Public method to recursively visit all the nodes and add up the instructions.</td> |
|
259 </tr> |
|
260 </table> |
|
261 <h3>Static Methods</h3> |
|
262 |
|
263 <table> |
|
264 <tr><td>None</td></tr> |
|
265 </table> |
|
266 |
|
267 <a NAME="LineComplexityVisitor.__init__" ID="LineComplexityVisitor.__init__"></a> |
|
268 <h4>LineComplexityVisitor (Constructor)</h4> |
|
269 <b>LineComplexityVisitor</b>(<i></i>) |
|
270 |
|
271 <p> |
|
272 Constructor |
|
273 </p> |
|
274 <a NAME="LineComplexityVisitor.score" ID="LineComplexityVisitor.score"></a> |
|
275 <h4>LineComplexityVisitor.score</h4> |
|
276 <b>score</b>(<i></i>) |
|
277 |
|
278 <p> |
|
279 Public method to calculate the median. |
|
280 </p> |
|
281 <dl> |
|
282 <dt>Return:</dt> |
|
283 <dd> |
|
284 median line complexity value |
|
285 </dd> |
|
286 </dl> |
|
287 <dl> |
|
288 <dt>Return Type:</dt> |
|
289 <dd> |
|
290 float |
|
291 </dd> |
|
292 </dl> |
|
293 <a NAME="LineComplexityVisitor.sortedList" ID="LineComplexityVisitor.sortedList"></a> |
|
294 <h4>LineComplexityVisitor.sortedList</h4> |
|
295 <b>sortedList</b>(<i></i>) |
|
296 |
|
297 <p> |
|
298 Public method to get a sorted list of (line, nodes) tuples. |
|
299 </p> |
|
300 <dl> |
|
301 <dt>Return:</dt> |
|
302 <dd> |
|
303 sorted list of (line, nodes) tuples |
|
304 </dd> |
|
305 </dl> |
|
306 <dl> |
|
307 <dt>Return Type:</dt> |
|
308 <dd> |
|
309 list of tuple of (int,int) |
|
310 </dd> |
|
311 </dl> |
|
312 <a NAME="LineComplexityVisitor.visit" ID="LineComplexityVisitor.visit"></a> |
|
313 <h4>LineComplexityVisitor.visit</h4> |
|
314 <b>visit</b>(<i>node</i>) |
|
315 |
|
316 <p> |
|
317 Public method to recursively visit all the nodes and add up the |
|
318 instructions. |
|
319 </p> |
|
320 <dl> |
|
321 |
|
322 <dt><i>node</i> (ast.AST)</dt> |
|
323 <dd> |
|
324 reference to the node |
|
325 </dd> |
|
326 </dl> |
|
327 <div align="right"><a href="#top">Up</a></div> |
|
328 <hr /> |
|
329 </body></html> |