The comparison operator should not be applied 2 or more times in a row

  • BAD_COMPARISON_SEQUENCE
  • Error
  • Medium
  • No tags

This rule applies when the comparison operator is applied two or more times in a row.

Because comparison operator is a binary operator, it is impossible to compare three or more operands at once.

If comparison operator is used to compare three or more operands, only the first two operands are compared and the rest is compared with its result of boolean type.

If you need to compare three or more operands, you should connect each comparison operation with logical AND operator (&&). Otherwise, if comparison of boolean values is indeed intended, use parentheses to clarify the intention.

Noncompliant Code Example

View with compliant examples side by side
if (a == b == c) {
    console.log("a, b, and c are the same");
}

Compliant Code Example

View with noncompliant examples side by side
if (a == b && b == c) {
    console.log("a, b, and c are the same");
}

Version

This rule was introduced in DeepScan 1.12.0-beta.

See

Was this documentation helpful?