This rule looks for operands of a boolean expression never changing the result of the expression. It also applies to the https://learn.microsoft.com/en-us/dotnet/visual-basic/language-reference/operators/null-conditional-operators[null conditional operator] when one of the operands always evaluates to `Nothing`.
Public Sub Sample(ByVal b As Boolean, ByVal c As Boolean, ByVal s As String)
Dim a = IsAllowed()
If a Then ' Compliant
DoSomething()
End If
If b AndAlso a Then ' Compliant
DoSomething()
End If
If c OrElse Not a Then ' Compliant
DoSomething()
End If
Dim d As String = GetStringData()
Dim v1 = If(d, "value") ' Compliant
Dim v2 = If(s, d) ' Compliant
End Sub
----
== Resources
=== Documentation
* https://cwe.mitre.org/data/definitions/571[MITRE, CWE-571] - Expression is Always True
* https://cwe.mitre.org/data/definitions/570[MITRE, CWE-570] - Expression is Always False
* Microsoft Learn - https://learn.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/operators-and-expressions/logical-and-bitwise-operators[Logical and Bitwise Operators in Visual Basic]
* Microsoft Learn - https://learn.microsoft.com/en-us/dotnet/visual-basic/language-reference/operators/null-conditional-operators[?. and ?() null-conditional operators (Visual Basic)]
* Microsoft Learn - https://learn.microsoft.com/en-us/dotnet/visual-basic/language-reference/operators/null-conditional-operators[If operator called with two arguments]
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
* Change this condition so that it does not always evaluate to "[true|false]".
* Change this expression which always evaluates to the same result.