Cyclomatic Complexity Calculator
Paste a function (JavaScript, TypeScript, Python, Java, or Go) to instantly calculate its cyclomatic complexity score, identify every decision point, and get the minimum number of test cases required for full branch coverage.
Complexity Score
Decision Points Found
Run analysis to see decision points.
Refactoring Suggestion
Risk Scale
Related Products
on GumroadTypeScript Quick Reference Toolkit
5 practical reference files for TypeScript developers: cheatsheet, TS vs JS comparison, 20 utility types with real examples, tsconfig best practices template, and 15 common mistakes guide. Print it. Keep it on your desk.
Buy on Gumroad →DevPlaybook Interview Vault
210+ real technical interview questions with model answers, asked at Google, Meta, Amazon, Microsoft, Stripe, and Shopify. Covers Frontend (55), Backend (55), System Design (50), and DSA (50). Available in English and Traditional Chinese.
Buy on Gumroad →Developer Productivity Bundle
Stop rebuilding the same setup every project. 51 VSCode snippets, 40 Git aliases, 5 Docker Compose stacks, 5 GitHub Actions workflows, 5 README templates, and a dotfiles kit. Set up a professional dev environment in under an hour.
Buy on Gumroad →You Might Also Need
SQL to TypeScript Types
Convert SQL CREATE TABLE statements to TypeScript interfaces and Zod schemas. Maps SQL column types to TypeScript with nullability.
Open free tool →
TypeScript Discriminated Union Builder
Build TypeScript discriminated unions visually. Add variants with fields and get type-safe switch statements, type guards, and exhaustive checking code.
Open free tool →
Code Tools
10 free code tools: HTML/CSS/JS formatter and minifier, SQL formatter, TypeScript to JavaScript converter, JSON formatter, regex playground, and Git helpers. No signup.
Open free tool →
More Free Tools
Related Articles
Modern TDD in 2026: Test-Driven Development with Vitest, Playwright & AI Copilots
Test-Driven Development has evolved. This practical guide covers modern TDD workflows using Vitest for unit tests, Playwright for E2E, MSW for API mocking, and how AI coding assistants (GitHub Copilot, Claude Code) are changing how we write tests first.
Playwright vs Cypress vs Puppeteer 2026: Which Testing Tool Should You Choose?
Playwright vs Cypress vs Puppeteer 2026 — compare feature sets, performance, developer experience, parallel testing, CI costs, and browser support. Find the right E2E testing tool for your stack.
Vitest: The Fast Unit Testing Framework for Vite Projects - 2026 Guide
Complete guide to Vitest in 2026: setup, configuration, mocking, coverage, watch mode, and a detailed comparison with Jest to help you decide which testing framework fits your project.
Vitest vs Jest vs Mocha: Complete Testing Framework Comparison 2026
A comprehensive comparison of Vitest, Jest, and Mocha for JavaScript and TypeScript projects in 2026. Covers speed benchmarks, configuration, TypeScript support, mocking, code coverage, and migration strategies.
Vitest Complete Guide 2026: Fast Unit Testing for Modern JavaScript
Master Vitest in 2026 — the fastest JavaScript testing framework. Learn setup, writing tests, mocking, snapshot testing, coverage, and CI integration with practical code examples.
Enjoying this tool? Get more like it.
Weekly developer tool guides, productivity playbooks & AI tricks. Free. No spam.
Unlock AI-Powered Dev Tools
- ⚡ AI Code Review, Doc Generator & SQL Builder
- ⚡ All premium templates & early access
- ⚡ Member discounts on Gumroad products
$9/mo after trial · Cancel anytime
Want the full toolkit?
Get DevPlaybook Pro
Every template, guide, boilerplate, and automation script in one bundle. 13 premium products — grab them all at once and save big.
MIT licensed · Instant download · No subscription
See what's included → Browse all deals →Frequently Asked Questions
What is cyclomatic complexity?▼
Cyclomatic complexity (CC) measures the number of linearly independent paths through a function's source code. It equals 1 plus the number of decision points: each if, else if, for, while, do, case, catch, &&, ||, and ternary (?) adds 1. A CC of 1–5 is simple; 6–10 is moderate; 11–20 is high and should be refactored; 21+ is unmaintainable.
What risk level is acceptable?▼
McCabe's original guideline: CC ≤ 10 per function is the widely-accepted safe threshold. Many teams use 15 as a practical ceiling. Functions above 20 are considered too risky to modify safely without comprehensive test coverage. The key insight: CC also equals the minimum number of test cases needed to cover all branches.
What decision points does this tool count?▼
This tool counts: if / else if, for / for-of / for-in, while / do-while, switch case / default, catch blocks, logical && and ||, ternary ? operator, and optional chaining ?. (optional chaining). Each adds one independent path through the code.
How do I reduce cyclomatic complexity?▼
Extract complex conditions into named boolean variables. Use early returns (guard clauses) to flatten nested ifs. Split long functions into smaller single-responsibility helpers. Replace if/else chains with lookup tables or strategy patterns. Use Array methods (filter, map, reduce) instead of manual loops with conditions.
Is cyclomatic complexity the same as cognitive complexity?▼
No. Cyclomatic complexity counts structural paths (good for test coverage planning). Cognitive complexity (SonarSource) counts how hard code is to understand — it adds extra weight for nesting depth. A simple flat switch with 10 cases is CC=10 but low cognitive complexity. A deeply nested if-else tree may be CC=5 but high cognitive complexity. Both metrics are useful.