Skip to content

Commit b0dccbc

Browse files
committed
Marking a bunch of static variables as readonly
Readonly helps out with TS's type guards and is also a good best practice. Specifically, readonly strings/numbers have their literal type instead of a generic `string` | `number` type, which can help catch dead code and some common programming mistakes
1 parent 90f33dd commit b0dccbc

90 files changed

Lines changed: 218 additions & 218 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/vs/base/browser/touch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export class Gesture extends Disposable {
6767

6868
private static readonly SCROLL_FRICTION = -0.005;
6969
private static INSTANCE: Gesture;
70-
private static HOLD_DELAY = 700;
70+
private static readonly HOLD_DELAY = 700;
7171

7272
private dispatched = false;
7373
private targets: HTMLElement[];

src/vs/base/browser/ui/tree/abstractTree.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ class EventCollection<T> implements Collection<T> {
238238

239239
class TreeRenderer<T, TFilterData, TRef, TTemplateData> implements IListRenderer<ITreeNode<T, TFilterData>, ITreeListTemplateData<TTemplateData>> {
240240

241-
private static DefaultIndent = 8;
241+
private static readonly DefaultIndent = 8;
242242

243243
readonly templateId: string;
244244
private renderedElements = new Map<T, ITreeNode<T, TFilterData>>();

src/vs/base/common/lifecycle.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ export class DisposableStore implements IDisposable {
138138

139139
export abstract class Disposable implements IDisposable {
140140

141-
static None = Object.freeze<IDisposable>({ dispose() { } });
141+
static readonly None = Object.freeze<IDisposable>({ dispose() { } });
142142

143143
private readonly _store = new DisposableStore();
144144

src/vs/base/parts/ipc/electron-main/ipc.electron-main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function createScopedOnMessageEvent(senderId: number, eventName: string): Event<
2323

2424
export class Server extends IPCServer {
2525

26-
private static Clients = new Map<number, IDisposable>();
26+
private static readonly Clients = new Map<number, IDisposable>();
2727

2828
private static getOnDidClientConnect(): Event<ClientConnectionEvent> {
2929
const onHello = Event.fromNodeEventEmitter<WebContents>(ipcMain, 'ipc:hello', ({ sender }) => sender);

src/vs/base/parts/storage/node/storage.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ export interface ISQLiteStorageDatabaseLoggingOptions {
3232

3333
export class SQLiteStorageDatabase implements IStorageDatabase {
3434

35-
static IN_MEMORY_PATH = ':memory:';
35+
static readonly IN_MEMORY_PATH = ':memory:';
3636

3737
get onDidChangeItemsExternal(): Event<IStorageItemsChangeEvent> { return Event.None; } // since we are the only client, there can be no external changes
3838

39-
private static BUSY_OPEN_TIMEOUT = 2000; // timeout in ms to retry when opening DB fails with SQLITE_BUSY
40-
private static MAX_HOST_PARAMETERS = 256; // maximum number of parameters within a statement
39+
private static readonly BUSY_OPEN_TIMEOUT = 2000; // timeout in ms to retry when opening DB fails with SQLITE_BUSY
40+
private static readonly MAX_HOST_PARAMETERS = 256; // maximum number of parameters within a statement
4141

4242
private path: string;
4343
private name: string;

src/vs/base/parts/tree/browser/treeView.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,8 +398,8 @@ function reactionEquals(one: _.IDragOverReaction, other: _.IDragOverReaction | n
398398

399399
export class TreeView extends HeightMap {
400400

401-
static BINDING = 'monaco-tree-row';
402-
static LOADING_DECORATION_DELAY = 800;
401+
static readonly BINDING = 'monaco-tree-row';
402+
static readonly LOADING_DECORATION_DELAY = 800;
403403

404404
private static counter: number = 0;
405405
private instance: number;

src/vs/code/browser/workbench/workbench.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,10 @@ class LocalStorageCredentialsProvider implements ICredentialsProvider {
103103

104104
class PollingURLCallbackProvider extends Disposable implements IURLCallbackProvider {
105105

106-
static FETCH_INTERVAL = 500; // fetch every 500ms
107-
static FETCH_TIMEOUT = 5 * 60 * 1000; // ...but stop after 5min
106+
static readonly FETCH_INTERVAL = 500; // fetch every 500ms
107+
static readonly FETCH_TIMEOUT = 5 * 60 * 1000; // ...but stop after 5min
108108

109-
static QUERY_KEYS = {
109+
static readonly QUERY_KEYS = {
110110
REQUEST_ID: 'vscode-requestId',
111111
SCHEME: 'vscode-scheme',
112112
AUTHORITY: 'vscode-authority',

src/vs/code/electron-browser/sharedProcess/contrib/storageDataCleaner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { IBackupWorkspacesFormat } from 'vs/platform/backup/node/backup';
1313
export class StorageDataCleaner extends Disposable {
1414

1515
// Workspace/Folder storage names are MD5 hashes (128bits / 4 due to hex presentation)
16-
private static NON_EMPTY_WORKSPACE_ID_LENGTH = 128 / 4;
16+
private static readonly NON_EMPTY_WORKSPACE_ID_LENGTH = 128 / 4;
1717

1818
constructor(
1919
@IEnvironmentService private readonly environmentService: IEnvironmentService

src/vs/editor/browser/controller/mouseHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export interface IPointerHandlerHelper {
6565

6666
export class MouseHandler extends ViewEventHandler {
6767

68-
static MOUSE_MOVE_MINIMUM_TIME = 100; // ms
68+
static readonly MOUSE_MOVE_MINIMUM_TIME = 100; // ms
6969

7070
protected _context: ViewContext;
7171
protected viewController: ViewController;

src/vs/editor/browser/controller/textAreaHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ interface LocalClipboardMetadata {
6666
* we can fetch the previous metadata.
6767
*/
6868
class LocalClipboardMetadataManager {
69-
public static INSTANCE = new LocalClipboardMetadataManager();
69+
public static readonly INSTANCE = new LocalClipboardMetadataManager();
7070

7171
private _lastState: LocalClipboardMetadata | null;
7272

0 commit comments

Comments
 (0)