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

@@ -102,7 +102,7 @@ export interface NotebookViewModelOptions {
}
export class NotebookViewModel extends Disposable implements EditorFoldingStateDelegate, INotebookViewModel {
private _localStore: DisposableStore = this._register(new DisposableStore());
private readonly _localStore = this._register(new DisposableStore());
private _handleToViewCellMapping = new Map<number, CellViewModel>();
get options(): NotebookViewModelOptions { return this._options; }
private readonly _onDidChangeOptions = this._register(new Emitter<void>());