javascript.lang.correctness.useless-eqeq.eqeq-is-bad

Verifed by r2c
Community Favorite
profile photo of semgrepsemgrep
Author
56,498
Download Count*

Detected a useless comparison operation $X == $X or $X != $X. This operation is always true. If testing for floating point NaN, use math.isnan, or cmath.isnan if the number is complex.

Run Locally

Run in CI

Defintion

rules:
  - id: eqeq-is-bad
    patterns:
      - pattern-not-inside: assert(...)
      - pattern-either:
          - pattern: $X == $X
          - pattern: $X != $X
      - pattern-not: 1 == 1
    message: Detected a useless comparison operation `$X == $X` or `$X != $X`. This
      operation is always true. If testing for floating point NaN, use
      `math.isnan`, or `cmath.isnan` if the number is complex.
    languages:
      - javascript
      - typescript
    severity: INFO
    metadata:
      category: correctness
      technology:
        - javascript
      license: Commons Clause License Condition v1.0[LGPL-2.1-only]

Examples

useless-eqeq.js


// ruleid:eqeq-is-bad
x == x

// ok:eqeq-is-bad
assert(x == x)

// ok, harmless
1 == 1