C#-MaxConditions

An expression must not have more than N logical operators

Required inputs: CSharpAST

This rule warns when more than the configured number of logical operators (&& or ||) are used within a single expression.

As an exception, this rule does not warn about complex conditions within custom Equals, op_Equality or op_Inequality definitions. Those operators are often implemented by compare all the class members in a long chain of logical operators.

Rationale
Complex conditions can be hard to understand, and should be split into several statements or extracted into a function.

Possible Messages

Key

Text

Severity

Disabled

excessive_condition_complexity

An expression must not have more than {0} logical operators.

None

False

Options

ignore_in

ignore_in : set[bauhaus.analysis.config.FunctionName] = {'Equals', 'op_Equality', 'op_Inequality'}

Names of routines to ignore for this check.
 

maxconditions

maxconditions : int = 7

Maximum acceptable number of conditions in an expression.