This is essentially a refactoring, so we are classifying it as a Hidden diagnostic.
Condition to raise diagnostic: more than one statement inside if block.
Scenario 1: return void
Additional condition to raise diagnostic: no code after if statement.
This:
void Foo()
{
if (condition)
{
//some code
}
}
Becomes:
void Foo()
{
if (!condition)
return;
//some code
}
Scenario 2: return something
Additional condition to raise diagnostic: only a return statement after if statement and a return at the end of the if block (or in every branch).
This:
int Foo()
{
if (condition)
{
//some code
return 2;
}
return 1;
}
Becomes:
int Foo()
{
if (!condition)
return 1;
//some code
return 2;
}
This code should also raise a diagnostic:
int Foo()
{
if (condition)
{
//some code
if (anotherCondition)
return 2;
else
return 3;
}
return 1;
}
Category: Refactoring
Severity: Hidden
Diagnostic id: CC0087
This is essentially a refactoring, so we are classifying it as a
Hiddendiagnostic.Condition to raise diagnostic: more than one statement inside if block.
Scenario 1: return
voidAdditional condition to raise diagnostic: no code after if statement.
This:
Becomes:
Scenario 2: return something
Additional condition to raise diagnostic: only a return statement after if statement and a return at the end of the if block (or in every branch).
This:
Becomes:
This code should also raise a diagnostic:
Category:
RefactoringSeverity:
HiddenDiagnostic id:
CC0087