|
1 <!DOCTYPE html> |
|
2 <html><head> |
|
3 <title>Plugin_Metrics_Radon.RadonMetrics.radon.complexity</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>Plugin_Metrics_Radon.RadonMetrics.radon.complexity</h1> |
|
23 |
|
24 <h3>Global Attributes</h3> |
|
25 <table> |
|
26 <tr><td>ALPHA</td></tr><tr><td>LINES</td></tr><tr><td>SCORE</td></tr> |
|
27 </table> |
|
28 <h3>Classes</h3> |
|
29 <table> |
|
30 <tr> |
|
31 <td><a href="#Flake8Checker">Flake8Checker</a></td> |
|
32 <td>Entry point for the Flake8 tool.</td> |
|
33 </tr> |
|
34 </table> |
|
35 <h3>Functions</h3> |
|
36 <table> |
|
37 <tr> |
|
38 <td><a href="#add_closures">add_closures</a></td> |
|
39 <td>Process a list of blocks by adding all closures as top-level blocks.</td> |
|
40 </tr><tr> |
|
41 <td><a href="#average_complexity">average_complexity</a></td> |
|
42 <td>Compute the average Cyclomatic complexity from the given blocks.</td> |
|
43 </tr><tr> |
|
44 <td><a href="#cc_rank">cc_rank</a></td> |
|
45 <td>Rank the complexity score from A to F, where A stands for the simplest and best score and F the most complex and worst one:</td> |
|
46 </tr><tr> |
|
47 <td><a href="#cc_visit">cc_visit</a></td> |
|
48 <td>Visit the given code with :class:`~radon.visitors.ComplexityVisitor`.</td> |
|
49 </tr><tr> |
|
50 <td><a href="#cc_visit_ast">cc_visit_ast</a></td> |
|
51 <td>Visit the AST node with :class:`~radon.visitors.ComplexityVisitor`.</td> |
|
52 </tr><tr> |
|
53 <td><a href="#sorted_results">sorted_results</a></td> |
|
54 <td>Given a ComplexityVisitor instance, returns a list of sorted blocks with respect to complexity.</td> |
|
55 </tr> |
|
56 </table> |
|
57 <hr /><hr /> |
|
58 <a NAME="Flake8Checker" ID="Flake8Checker"></a> |
|
59 <h2>Flake8Checker</h2> |
|
60 <p> |
|
61 Entry point for the Flake8 tool. |
|
62 </p> |
|
63 <h3>Derived from</h3> |
|
64 object |
|
65 <h3>Class Attributes</h3> |
|
66 <table> |
|
67 <tr><td>_code</td></tr><tr><td>_error_tmpl</td></tr><tr><td>max_cc</td></tr><tr><td>name</td></tr><tr><td>no_assert</td></tr><tr><td>version</td></tr> |
|
68 </table> |
|
69 <h3>Class Methods</h3> |
|
70 <table> |
|
71 <tr> |
|
72 <td><a href="#Flake8Checker.add_options">add_options</a></td> |
|
73 <td></td> |
|
74 </tr><tr> |
|
75 <td><a href="#Flake8Checker.parse_options">parse_options</a></td> |
|
76 <td></td> |
|
77 </tr> |
|
78 </table> |
|
79 <h3>Methods</h3> |
|
80 <table> |
|
81 <tr> |
|
82 <td><a href="#Flake8Checker.__init__">Flake8Checker</a></td> |
|
83 <td>Accept the AST tree and a filename (unused).</td> |
|
84 </tr><tr> |
|
85 <td><a href="#Flake8Checker.run">run</a></td> |
|
86 <td>Run the ComplexityVisitor over the AST tree.</td> |
|
87 </tr> |
|
88 </table> |
|
89 <h3>Static Methods</h3> |
|
90 <table> |
|
91 <tr><td>None</td></tr> |
|
92 </table> |
|
93 <a NAME="Flake8Checker.add_options" ID="Flake8Checker.add_options"></a> |
|
94 <h4>Flake8Checker.add_options (class method)</h4> |
|
95 <b>add_options</b>(<i>parser</i>) |
|
96 <a NAME="Flake8Checker.parse_options" ID="Flake8Checker.parse_options"></a> |
|
97 <h4>Flake8Checker.parse_options (class method)</h4> |
|
98 <b>parse_options</b>(<i>options</i>) |
|
99 <a NAME="Flake8Checker.__init__" ID="Flake8Checker.__init__"></a> |
|
100 <h4>Flake8Checker (Constructor)</h4> |
|
101 <b>Flake8Checker</b>(<i>tree, filename</i>) |
|
102 <p> |
|
103 Accept the AST tree and a filename (unused). |
|
104 </p><a NAME="Flake8Checker.run" ID="Flake8Checker.run"></a> |
|
105 <h4>Flake8Checker.run</h4> |
|
106 <b>run</b>(<i></i>) |
|
107 <p> |
|
108 Run the ComplexityVisitor over the AST tree. |
|
109 </p> |
|
110 <div align="right"><a href="#top">Up</a></div> |
|
111 <hr /><hr /> |
|
112 <a NAME="add_closures" ID="add_closures"></a> |
|
113 <h2>add_closures</h2> |
|
114 <b>add_closures</b>(<i>blocks</i>) |
|
115 <p> |
|
116 Process a list of blocks by adding all closures as top-level blocks. |
|
117 </p> |
|
118 <div align="right"><a href="#top">Up</a></div> |
|
119 <hr /><hr /> |
|
120 <a NAME="average_complexity" ID="average_complexity"></a> |
|
121 <h2>average_complexity</h2> |
|
122 <b>average_complexity</b>(<i>blocks</i>) |
|
123 <p> |
|
124 Compute the average Cyclomatic complexity from the given blocks. |
|
125 Blocks must be either :class:`~radon.visitors.Function` or |
|
126 :class:`~radon.visitors.Class`. If the block list is empty, then 0 is |
|
127 returned. |
|
128 </p> |
|
129 <div align="right"><a href="#top">Up</a></div> |
|
130 <hr /><hr /> |
|
131 <a NAME="cc_rank" ID="cc_rank"></a> |
|
132 <h2>cc_rank</h2> |
|
133 <b>cc_rank</b>(<i>cc</i>) |
|
134 <p> |
|
135 Rank the complexity score from A to F, where A stands for the simplest |
|
136 and best score and F the most complex and worst one: |
|
137 </p><p> |
|
138 ============= ===================================================== |
|
139 1 - 5 A (low risk - simple block) |
|
140 6 - 10 B (low risk - well structured and stable block) |
|
141 11 - 20 C (moderate risk - slightly complex block) |
|
142 21 - 30 D (more than moderate risk - more complex block) |
|
143 31 - 40 E (high risk - complex block, alarming) |
|
144 41+ F (very high risk - error-prone, unstable block) |
|
145 ============= ===================================================== |
|
146 </p><p> |
|
147 Here *block* is used in place of function, method or class. |
|
148 </p><p> |
|
149 The formula used to convert the score into an index is the following: |
|
150 </p><p> |
|
151 .. math:: |
|
152 </p><p> |
|
153 \text{rank} = \left \lceil \dfrac{\text{score}}{10} \right \rceil |
|
154 - H(5 - \text{score}) |
|
155 </p><p> |
|
156 where ``H(s)`` stands for the Heaviside Step Function. |
|
157 The rank is then associated to a letter (0 = A, 5 = F). |
|
158 </p> |
|
159 <div align="right"><a href="#top">Up</a></div> |
|
160 <hr /><hr /> |
|
161 <a NAME="cc_visit" ID="cc_visit"></a> |
|
162 <h2>cc_visit</h2> |
|
163 <b>cc_visit</b>(<i>code, **kwargs</i>) |
|
164 <p> |
|
165 Visit the given code with :class:`~radon.visitors.ComplexityVisitor`. |
|
166 All the keyword arguments are directly passed to the visitor. |
|
167 </p> |
|
168 <div align="right"><a href="#top">Up</a></div> |
|
169 <hr /><hr /> |
|
170 <a NAME="cc_visit_ast" ID="cc_visit_ast"></a> |
|
171 <h2>cc_visit_ast</h2> |
|
172 <b>cc_visit_ast</b>(<i>ast_node, **kwargs</i>) |
|
173 <p> |
|
174 Visit the AST node with :class:`~radon.visitors.ComplexityVisitor`. All |
|
175 the keyword arguments are directly passed to the visitor. |
|
176 </p> |
|
177 <div align="right"><a href="#top">Up</a></div> |
|
178 <hr /><hr /> |
|
179 <a NAME="sorted_results" ID="sorted_results"></a> |
|
180 <h2>sorted_results</h2> |
|
181 <b>sorted_results</b>(<i>blocks, order=SCORE</i>) |
|
182 <p> |
|
183 Given a ComplexityVisitor instance, returns a list of sorted blocks |
|
184 with respect to complexity. A block is a either |
|
185 :class:`~radon.visitors.Function` object or a |
|
186 :class:`~radon.visitors.Class` object. |
|
187 The blocks are sorted in descending order from the block with the highest |
|
188 complexity. |
|
189 </p><p> |
|
190 The optional `order` parameter indicates how to sort the blocks. It can be: |
|
191 </p><p> |
|
192 * `LINES`: sort by line numbering; |
|
193 * `ALPHA`: sort by name (from A to Z); |
|
194 * `SCORE`: sorty by score (descending). |
|
195 </p><p> |
|
196 Default is `SCORE`. |
|
197 </p> |
|
198 <div align="right"><a href="#top">Up</a></div> |
|
199 <hr /> |
|
200 </body></html> |