Metric-CognitiveComplexity¶
Cognitive Complexity
Required inputs: IR, RFG
Computes the cognitive complexity of routines based on its statement sequence.
The value of Metric.CognitiveComplexity is computed roughly by summing up
- the number of if- and preprocessor if-statements,
- the number of else if- and preprocessor elif-statements,
- the number of else- and preprocessor else-statements,
- the number of loop statements (e.g. for and while),
- the number of conditional (?) operators,
- the number of switch statements,
- the number of catch clauses
- the number of goto-statements
- the number of binary logical operator changes in operator sequences, and
- if the routine is in a static call cycle: the number of routines contained within the cycle.
Additionally a nesting modifier is added, which gets incremented for statements inside
- if-statements or preprocessor if-statements,
- else if- and preprocessor elif-statements,
- else- and preprocessor else-statements,
- loop statements (e.g. for and while),
- conditional (?) operators,
- switch statements,
- catch clauses, and
- lambda expressions.
The nesting modifier gets added to
- if-statements or preprocessor if-statements,
- loop statements (e.g. for and while),
- conditional (?) operators,
- switch statements, and
- catch clauses.
Possible Messages
This rule has no predefined messages.
Options¶
This rule shares the following common options: exclude_messages_in_system_headers, excludes, includes, justification_checker, post_processing, provider, severity
This rule shares the following common metric options: excluded_node_types, hierarchy_edge_name, hierarchy_view_name, propagate, report_all_values, report_propagated_values
The following places define options that affect this rule: Analysis-GlobalOptions
display_name¶
display_name : str | None = 'Cognitive Complexity'
include_disabled_code_sections¶
include_disabled_code_sections : bool = False
#if.
Does not add routines that where disabled completely.
Note: Possibly slow and not 100% accurate due to parsing limitations.
include_recursive_call_cycles¶
include_recursive_call_cycles : bool = True
max_value¶
max_value : int | None = 20
min_value¶
min_value : int | None = 0
rfg_metric_name¶
rfg_metric_name : str = 'Metric.CognitiveComplexity'