Skip to content

noUnusedInstantiation

  • Rule available since: v2.3.12
  • Diagnostic Category: lint/correctness/noUnusedInstantiation
  • This rule isn’t recommended, so you need to enable it.
  • This rule doesn’t have a fix.
  • The default severity of this rule is error.
  • Sources:
biome.json
{
"linter": {
"rules": {
"correctness": {
"noUnusedInstantiation": "error"
}
}
}
}

Disallow new operators outside of assignments or comparisons.

The goal of using new with a constructor is typically to create an object of a particular type and store that object in a variable, such as:

const person = new Person();

It’s less common to use new and not store the result, such as:

new Person();

In this case, the created object is thrown away because its reference isn’t stored anywhere, and in many cases, this means that the constructor should be replaced with a function that doesn’t require new to be used.

new Thing();
code-block.js:1:1 lint/correctness/noUnusedInstantiation ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Using the `new` operator outside of assignments or comparisons is not allowed.

> 1 │ new Thing();
^^^^^^^^^^^
2 │

The created object is thrown away because its reference isn’t stored anywhere. Assign the object to a variable or replace with a function that doesn’t require `new` to be used.

const thing = new Thing();