Statements are nested deeper than the configured maximum

tx0/csharp:deep-nestingrecommendedwarningmaintainability/complexitydepth fastmaintainability

What it finds

Each nested if, loop, switch, try, lock or using adds a condition the reader has to keep in mind; deep nesting is where cases get forgotten. Early returns and helper methods flatten it. The depth counts control statements within one member; else if does not add a level. The maximum is the parameter max_depth, 4 by default.

From the rule's source, deep_nesting.rs.

Example from the rule's tests
class Deep{    void Run(int a)    {        if (a > 0)        {            for (int i = 0; i < a; i++)            {                while (a > i)                {                    if (i == 2)                    {                        if (a == 3)tx0 reports: this if is nested 5 levels deep, more than 4                        {                            a--;                        }                    }                    else if (i == 3)                    {                        a++;                    }                }            }        }    }}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/csharp:deep-nesting" = "warning"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/csharp:deep-nesting] reason="..."

tx0 explain tx0/csharp:deep-nesting shows the same in the terminal. Found a false positive? Report it.