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.
instanceofis 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-instanceofand the default toErrorand whatever you encounter the most often.This rule is accepted.
Correct
Sounds good
Yeah, I think we should just do
Errorfor now.Erroris usually the problematic global.