useDisposables
Este conteúdo não está disponível em sua língua ainda.
Summary
Section titled “Summary”- Rule available since:
v2.4.11 - Diagnostic Category:
lint/nursery/useDisposables - This rule has an unsafe fix.
- The default severity of this rule is information.
- This rule belongs to the following domains:
How to configure
Section titled “How to configure”{ "linter": { "rules": { "nursery": { "useDisposables": "error" } } }}Description
Section titled “Description”Detects a disposable object assigned to a variable without using or await using syntax.
Disposable objects, which implements Disposable or AsyncDisposable interface, are intended to dispose after use. Not disposing them can lead some resource or memory leak depending on the implementation.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”function createDisposable(): Disposable { return { [Symbol.dispose]() { // do something }, };}
const disposable = createDisposable();/example1.ts:9:7 lint/nursery/useDisposables FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ Disposable object is assigned here but never disposed.
7 │ }
8 │
> 9 │ const disposable = createDisposable();
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10 │
ℹ The object implements the Disposable interface, which is intended to be disposed after use with using syntax.
ℹ Not disposing the object properly can lead some resource or memory leak.
ℹ 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.
ℹ Unsafe fix: Add the using keyword to dispose the object when leaving the scope.
7 7 │ }
8 8 │
9 │ - const·disposable·=·createDisposable();
9 │ + using·disposable·=·createDisposable();
10 10 │
class MyClass implements AsyncDisposable { async [Symbol.asyncDispose]() { // do something }}
const instance = new MyClass();/example2.ts:7:7 lint/nursery/useDisposables FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ Disposable object is assigned here but never disposed.
5 │ }
6 │
> 7 │ const instance = new MyClass();
│ ^^^^^^^^^^^^^^^^^^^^^^^^
8 │
ℹ The object implements the AsyncDisposable interface, which is intended to be disposed after use with await using syntax.
ℹ Not disposing the object properly can lead some resource or memory leak.
ℹ 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.
ℹ Unsafe fix: Add the using keyword to dispose the object when leaving the scope.
5 5 │ }
6 6 │
7 │ - const·instance·=·new·MyClass();
7 │ + await·using·instance·=·new·MyClass();
8 8 │
function createDisposable(): Disposable { return { [Symbol.dispose]() { // do something }, };}
using disposable = createDisposable();class MyClass implements AsyncDisposable { async [Symbol.asyncDispose]() { // do something }}
await using instance = new MyClass();Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.