Cognitive-Complexity-TS icon indicating copy to clipboard operation
Cognitive-Complexity-TS copied to clipboard

Doesn't calculate logical operator sequences correctly

Open douglasg14b opened this issue 5 months ago • 0 comments

Take this example:

function stuff() {
    if (val > someConstant && (condition2 || condition3) && condition4 && !condition5 || val < someOtherConstant) {
    
    }
}

This is calculated as a complexity of 3. You can add or remove as many conditions to this as you want and it will still only ever count as 3.

The cognitive complexity spec this is based on specifies that the complexity grows with each mixed condition.

Similarly, negations should also increment this number as this increases cognitive load directly.

douglasg14b avatar Sep 04 '24 19:09 douglasg14b