in and instanceof should have a right operand of proper type

  • BAD_OPERAND_TYPE
  • Error
  • High
  • No tags

This rule applies when in and instanceof operators have a right operand of wrong type.

It can be applied to the following:

  1. Right operand of in operator is not an object.
  2. Right operand of instanceof operator is not a constructor.

Noncompliant Code Example

View with compliant examples side by side
// Example 1
var a = "prop" in 42; // BAD_OPERAND_TYPE alarm

// Example 2
function Foo() {
}
var x = new Foo();
var b = x instanceof "string"; // BAD_OPERAND_TYPE alarm

Compliant Code Example

View with noncompliant examples side by side
// Example 1
var a = "prop" in obj;

// Example 2
function Foo() {
}
var x = new Foo();
var b = x instanceof Foo;

Version

This rule was introduced in DeepScan 1.0.0-alpha.

See

Was this documentation helpful?