deno_lint
deno_lint copied to clipboard
Rule suggestion: no-compare-to-new
Using ===
, ==
, or switch
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 object -
x.includes({})
,x.indexOf({})
,x.lastIndexOf({})
ifx
is an Array -
x.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
Seems reasonable 👍 contributions are welcome