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