Aller au contenu

noFloatingClasses

Ce contenu n’est pas encore disponible dans votre langue.

biome.json
{
"linter": {
"rules": {
"nursery": {
"noFloatingClasses": "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/nursery/noFloatingClasses ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

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.

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

const thing = new Thing();