eslint-plugin-unicorn: Rule proposal: `no-instanceof-error`
Disallow instanceof Error
checks.
Fail
const isError = foo instanceof Error;
Pass
const isError = Object.prototype.toString.call(foo) === '[object Error]'
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 2
- Comments: 17 (8 by maintainers)
Is it though? If I load the same library in 2 realms I have the same issue. It’s just that built-ins are more common.
instanceof
is never safe, it’s just easy to use until you have to check something cross-realm.Example
I think if you want to add this rule it should be a configurable
no-instanceof
and the default toError
and whatever you encounter the most often.This rule is accepted.
Correct
Sounds good
Yeah, I think we should just do
Error
for now.Error
is usually the problematic global.