An equality operator should be used instead of an assignment operator in a conditional statement
This rule applies when an assignment operator is unintentionally used in a conditional statement instead of an equality operator.
Note: There are cases where an assignment operator is intentionally used in a conditional statement to simplify an assignment and a truthy value check. In order not to detect these intentional cases as alarms, this rule only applies when the RHS of the assignment is evaluated to a constant value.
Noncompliant Code Example
x = str.indexOf(y); if (x = -1) return "no"; // BAD_ASSIGN_IN_CONDITION alarm. The true branch is always taken and "no" is returned. else return "yes";
Compliant Code Example
x = str.indexOf(y); if (x == -1) return "no"; else return "yes";
This rule was introduced in DeepScan 1.0.0-alpha.