Open rotu opened 1 year ago
Using ===, ==, or switch with an object or array literal is always false.
===
==
switch
The below are all examples of erroneous comparisons that could be flagged:
x === {}
switch (x) { case {}: /* ... */ }
Object.is(x, {})
Object.is
Additionally, if the type of x is known, the following could be flagged:
x == {}
x.includes({})
x.indexOf({})
x.lastIndexOf({})
x
x.has({})
x.get({})
x.delete({})
Map
WeakMap
Set
WeakSet
Similar to this suggested eslint rule: https://github.com/eslint/eslint/issues/15222
Seems reasonable 👍 contributions are welcome
Using
===
,==
, orswitch
with an object or array literal is always false.The below are all examples of erroneous comparisons that could be flagged:
x === {}
switch (x) { case {}: /* ... */ }
Object.is(x, {})
(assumingObject.is
has not been deleted or tampered with)Additionally, if the type of x is known, the following could be flagged:
x == {}
if x is not an objectx.includes({})
,x.indexOf({})
,x.lastIndexOf({})
ifx
is an Arrayx.has({})
,x.get({})
,x.delete({})
ifx
is aMap
orWeakMap
x.has({})
,x.delete({})
ifx
is aSet
orWeakSet
Similar to this suggested eslint rule: https://github.com/eslint/eslint/issues/15222