cyclomatic-complexity

ProComplexity

Enforce a maximum cyclomatic complexity per function to catch AI-generated complex branching

cyclomatic-complexity

Enforce a maximum cyclomatic complexity per function to catch AI-generated complex branching

Category: Complexity | Tier: Pro

Why This Matters

AI tends to build functions with many branching paths -- long if/else chains, switch statements, and nested conditions. High cyclomatic complexity means more test cases are needed and more places where bugs can hide.

Bad Code

// Too many decision paths in one function
function getDiscount(user) {
  if (user.isVIP) { /* ... */ }
  else if (user.isMember) { /* ... */ }
  else if (user.referralCode) { /* ... */ }
  else if (user.coupon) { /* ... */ }
  // 10+ more branches
}

Good Code

// Use a strategy pattern or lookup table
const discountStrategies = {
  vip: (user) => user.vipDiscount,
  member: (user) => MEMBER_DISCOUNT,
  referral: (user) => REFERRAL_DISCOUNT,
};

Configuration

This rule wraps complexity. See upstream documentation for full configuration options.