navigation

CyclomaticComplexity (FL0071)

Reintroduced in 0.20.2

Cause

The cyclomatic complexity of a function or method exceeds the configured maximum complexity threshold.

Rationale

Cyclomatic complexity provides the number of linearly independent paths through a function or method. Metricating cyclomatic complexity is a requirement for many software product assurance activities prescribed in industry.

How To Fix

The cyclomatic complexity of a function or method is incremented by the following contributors:

  • conditional branching (if/else/elif)
  • match cases (also applies to function pattern matching and match!)
  • for (for...in) and foreach (for i in...to) expressions
  • while expressions
  • boolean operators within conditional expressions of the above, or within when expressions in the case of match

Reducing the cyclomatic complexity of a function typically involves decomposing the function into more sub-functions. The cyclomatic complexity calculated by this rule is limited to a single scope of a function or method, i.e. the cyclomatic complexity of a function g nested within function f is calculated independent of the complexity of f and will not contribute to the cyclomatic copmlexity of f.

Rule Settings

There is a single setting applicable to the cyclomatic complexity, which is the maximum cyclomatic complexity.

{
    "enabled": true,
    "config": {
        "maxComplexity": 40
    }
}