Cyclomatic Complexity Analyzer
Description & Learning Section
Cyclomatic Complexity measures how many independent paths exist through your function. It starts at 1 and increments for each decision point:
if,elif,for,while,case,catch- Logical operators:
&&,|| - Ternary
?:expressions
High complexity (>10) often indicates code that is hard to test and maintain. This tool:
- Detects Python
def, JSfunction, ES6 arrow functions, and simple class methods. - Computes each function’s complexity and flags those above your threshold.
- Aggregates overall metrics: sum, min, max, average, median.
- Displays a per‑function list sorted by complexity and a simple histogram.
Example (JS):
function foo(x) {
if (x > 0 && x < 10) {
return x % 2 === 0 ? 'even' : 'odd';
}
return null;
}
Complexity = 1 (base) + 1 (if) + 1 (&&) + 1 (ternary) = 4
Use this tool to pinpoint the most complex functions, guide refactoring, and keep your codebase maintainable.