Skip to content

oxc/const-comparisons Correctness

This rule is turned on by default.

What it does

Checks for redundant comparisons between constants:

  • Checks for ineffective double comparisons against constants.
  • Checks for impossible comparisons against constants.

Why is this bad?

Only one of the comparisons has any effect on the result, the programmer probably intended to flip one of the comparison operators, or compare a different value entirely.

Example

Examples of incorrect code for this rule:

javascript
status_code <= 400 && status_code > 500;
status_code < 200 && status_code <= 299;
status_code > 500 && status_code >= 500;

Examples of correct code for this rule:

javascript
status_code >= 400 && status_code < 500;
500 <= status_code && 600 > status_code;
500 <= status_code && status_code <= 600;

References

Released under the MIT License.