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