Cyclomatic Complexity Estimator for JavaScript Functions
Finds functions, methods and arrow functions in pasted JavaScript and estimates each one's cyclomatic complexity: one plus the number of if, for, while, case, catch, &&, ||, ?? and ternary operators inside it.
Use the tool
Why this tool exists
Cyclomatic complexity is a rough count of independent paths through a function. High values mean more tests and more places for bugs. Linters report it, but only inside a project with a config.
This tool gives a quick estimate for a pasted file. It is a text scanner, not a parser, so odd syntax can fool it, and optional chaining and default values are not counted. Treat flagged functions as "review", and use a real linter in your build.
How to use it
- Paste JavaScript.
- Set the level above which a function is flagged.
- Read the list of functions and their scores.
- Split or simplify the ones marked REVIEW.
Frequently asked questions
What is counted?
if, for (including in and of), while, case, catch, &&, ||, ?? and the ?: operator, plus one for the function itself.
Are nested functions included in the outer score?
No. Each function is scored on its own, like common linters do.
What limit is sensible?
Many teams use 10 to 15. It is a convention, not a rule.
Does it handle TypeScript?
Simple cases may work, but types are not understood.