noFloatingClasses
Este conteúdo não está disponível em sua língua ainda.
Summary
Section titled “Summary”- Rule available since:
v2.3.12 - Diagnostic Category:
lint/nursery/noFloatingClasses - This rule doesn’t have a fix.
- The default severity of this rule is information.
- Sources:
- Same as
no-new
- Same as
How to configure
Section titled “How to configure”{ "linter": { "rules": { "nursery": { "noFloatingClasses": "error" } } }}Description
Section titled “Description”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.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”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();Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.