Cyclomatic Complexity
ID: cyclomatic_complexity | Severity: Medium (default)
This detector identifies functions with high Cyclomatic Complexity.
Why this is a smell
- Hard to Understand: Too many branching paths make the code hard to follow.
- Bug Prone: Higher chance of missing edge cases during testing.
- Maintenance Nightmare: Small changes can have unpredictable effects due to complex logic.
How to fix
- Extract Method: Break complex logic into smaller, named functions.
- Guard Clauses: Use early returns to reduce nesting levels.
- Replace Conditional with Polymorphism: Use objects or strategies instead of large
switchorif/elseblocks.
Configuration
yaml
rules:
cyclomatic_complexity:
severity: medium
max_complexity: 15ESLint Rule
This detector is available as an ESLint rule for real-time feedback in your editor.
javascript
// eslint.config.js
export default [
{
rules: {
'@archlinter/no-high-cyclomatic-complexity': 'warn',
},
},
];See ESLint Integration for setup instructions.