mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-22 17:48:56 +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:
@@ -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>());
|
||||
|
||||
Reference in New Issue
Block a user