Rule suggestion: no-compare-to-new #1185
Labels
eslint-compat
Related to compatibility with ESLint
help wanted
Extra attention is needed
new-rule
Suggestion to add a new lint rule
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:
eslint/eslint#15222
The text was updated successfully, but these errors were encountered: