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:
Matt Bierner
2024-04-04 10:34:45 -07:00
committed by GitHub
parent b4378dfa1d
commit ae91138701
85 changed files with 151 additions and 111 deletions

View File

@@ -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;