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