code-complexity

July 2, 2025 ยท View on GitHub

Category Badge Default Severity Badge warn

Description

Function has cyclomatic complexity "current" but allowed no more than configured max complexity.

Options

This rule accepts an array of options:

IndexDescriptionDefault Value
0Rule severity. Must be one of "error", "warn", "off".warn
1Function cyclomatic complexity reached.7

Example Config

{
  "rules": {
    "code-complexity": [
      "warn",
      7
    ]
  }
}

Examples

๐Ÿ‘ Examples of correct code for this rule

Low code complexity

 if (a > b) {                   
   if (b > c) {                 
     if (c > d) {               
     }                          
   }                            
 }                              
for (i = 0; i < b; i += 1) { }  
do { d++; } while (b > c);       
while (d > e) { }               

๐Ÿ‘Ž Examples of incorrect code for this rule

High code complexity

 if (a > b) {                   
   if (b > c) {                 
     if (c > d) {               
       if (d > e) {             
       } else {                 
       }                        
     }                          
   }                            
 }                              
for (i = 0; i < b; i += 1) { }  
do { d++; } while (b > c);       
while (d > e) { }               

Version

This rule was introduced in Solhint 5.0.4

Resources