Boolean Assigned in If/Else Branches

Identifies conditional assignments to mutually exclusive Boolean literal values in conditional branches.

Reasoning

The assignment could be made directly to the result of the conditional Boolean expression instead.

Default severity

Warning

Inspection type

NamingAndConventionsIssues

Examples

This example should trigger a result

MyModule (StandardModule)
Public Sub DoSomething(ByVal value As Long) Dim result As Boolean If value > 10 Then result = True Else result = False End If Debug.Print result End Sub

This example should NOT trigger a result

MyModule (StandardModule)
Public Sub DoSomething(ByVal value As Long) Dim result As Boolean result = value > 10 Debug.Print result End Sub

Rubberduck.CodeAnalysis.Inspections.Concrete.BooleanAssignedInIfElseInspection.cs (Prerelease-v2.5.9.6289)