Conditional expressions which are always true or false can lead to unreachable code.
In the case below, the call of Dispose() never happens.
Dim a = False
If a Then
Dispose() ' Never reached
End If
This rule will not raise an issue in either of these cases:
const bool
Const debug = False
'...
If debug Then
' Print something
End If
true or false. In these cases, it is obvious the code is as intended.
The conditions should be reviewed to decide whether:
Public Sub Sample(ByVal b As Boolean)
Dim a = False
If a Then ' Noncompliant: The true branch is never reached
DoSomething() ' Never reached
End If
If Not a OrElse b Then ' Noncompliant: "not a" is always "True" and the false branch is never reached
DoSomething()
Else
DoSomethingElse() ' Never reached
End If
Dim c = "xxx"
Dim res = If(c, "value") ' Noncompliant: d is always not Nothing, "value" is never used
End Sub
Public Sub Sample(ByVal b As Boolean)
Dim a = False
If Foo(a) Then ' Condition was updated
DoSomething()
End If
If b Then ' Parts of the condition were removed.
DoSomething()
Else
DoSomethingElse()
End If
Dim c = "xxx"
Dim res = c ' "value" was removed
End Sub