mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-23 18:19:12 +01:00
Add eslint rule for potentially unsafe disposable patterns (#209555)
`DisposableStore`/`MutableDisposable` properties should almost always be `readonly`. Otherwise it's easy to accidentally overwrite the property and leak the previous value. This commonly happens with code such as:
```ts
class Foo {
private disposables = new DisposableStore();
bar() {
this.disposables = new DisposableStore(); // leaks old values
...
}
```
This change adds an eslint rule to enforce this and adopts `readonly` for the caught cases. I only needed to add 2 suppression comments, which seems like an acceptable tradeoff for helping catch a common mistake
This commit is contained in:
@@ -397,7 +397,7 @@ export function createExtHostComments(mainContext: IMainContext, commands: ExtHo
|
||||
|
||||
private _commentsMap: Map<vscode.Comment, number> = new Map<vscode.Comment, number>();
|
||||
|
||||
private _acceptInputDisposables = new MutableDisposable<DisposableStore>();
|
||||
private readonly _acceptInputDisposables = new MutableDisposable<DisposableStore>();
|
||||
|
||||
readonly value: vscode.CommentThread2;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user