Skip to content

Commit

Permalink
Adopt prefer-readonly in JS/TS extension (microsoft#165089)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjbvz authored Nov 15, 2022
1 parent 9ccc7e3 commit 44441de
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 20 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
**/extensions/notebook-renderers/renderer-out/index.js
**/extensions/simple-browser/media/index.js
**/extensions/typescript-language-features/test-workspace/**
**/extensions/typescript-language-features/extension.webpack.config.js
**/extensions/typescript-language-features/extension-browser.webpack.config.js
**/extensions/vscode-api-tests/testWorkspace/**
**/extensions/vscode-api-tests/testWorkspace2/**
**/fixtures/**
Expand Down
10 changes: 10 additions & 0 deletions extensions/typescript-language-features/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
"parserOptions": {
"tsconfigRootDir": __dirname,
"project": "./tsconfig.json"
},
"rules": {
"@typescript-eslint/prefer-optional-chain": "warn",
"@typescript-eslint/prefer-readonly": "warn"
}
};
5 changes: 0 additions & 5 deletions extensions/typescript-language-features/.eslintrc.json

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ export interface IExperimentationTelemetryReporter extends tas.IExperimentationT
* but will only do so when passed to an {@link ExperimentationService}.
*/

export class ExperimentationTelemetryReporter
implements IExperimentationTelemetryReporter {
export class ExperimentationTelemetryReporter implements IExperimentationTelemetryReporter {

private _sharedProperties: Record<string, string> = {};
private _reporter: VsCodeTelemetryReporter;
private readonly _reporter: VsCodeTelemetryReporter;

constructor(reporter: VsCodeTelemetryReporter) {
this._reporter = reporter;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ interface ExperimentTypes {
}

export class ExperimentationService {
private _experimentationServicePromise: Promise<tas.IExperimentationService>;
private _telemetryReporter: IExperimentationTelemetryReporter;
private readonly _experimentationServicePromise: Promise<tas.IExperimentationService>;
private readonly _telemetryReporter: IExperimentationTelemetryReporter;

constructor(telemetryReporter: IExperimentationTelemetryReporter, id: string, version: string, globalState: vscode.Memento) {
this._telemetryReporter = telemetryReporter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export abstract class TypeScriptBaseCodeLensProvider implements vscode.CodeLensP

public constructor(
protected client: ITypeScriptServiceClient,
private cachedResponse: CachedResponse<Proto.NavTreeResponse>
private readonly cachedResponse: CachedResponse<Proto.NavTreeResponse>
) { }


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class TypeScriptDocumentSymbolProvider implements vscode.DocumentSymbolProvider

public constructor(
private readonly client: ITypeScriptServiceClient,
private cachedResponse: CachedResponse<Proto.NavTreeResponse>,
private readonly cachedResponse: CachedResponse<Proto.NavTreeResponse>,
) { }

public async provideDocumentSymbols(document: vscode.TextDocument, token: vscode.CancellationToken): Promise<vscode.DocumentSymbol[] | undefined> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ class SourceAddMissingImports extends SourceAction {

class TypeScriptAutoFixProvider implements vscode.CodeActionProvider {

private static kindProviders = [
private static readonly kindProviders = [
SourceFixAll,
SourceRemoveUnused,
SourceAddMissingImports,
Expand Down
4 changes: 4 additions & 0 deletions extensions/typescript-language-features/src/protocol.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as ts from 'typescript/lib/tsserverlibrary';
export = ts.server.protocol;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ export class WorkerServerProcess implements TsServerProcess {
]);
}

private _onDataHandlers = new Set<(data: Proto.Response) => void>();
private _onErrorHandlers = new Set<(err: Error) => void>();
private _onExitHandlers = new Set<(code: number | null, signal: string | null) => void>();
private readonly _onDataHandlers = new Set<(data: Proto.Response) => void>();
private readonly _onErrorHandlers = new Set<(err: Error) => void>();
private readonly _onExitHandlers = new Set<(code: number | null, signal: string | null) => void>();

public constructor(
private readonly worker: Worker,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ export default class TypeScriptServiceClient extends Disposable implements IType

private readonly workspaceState: vscode.Memento;

private _onReady?: { promise: Promise<void>; resolve: () => void; reject: () => void };
private readonly _onReady?: { promise: Promise<void>; resolve: () => void; reject: () => void };
private _configuration: TypeScriptServiceConfiguration;
private pluginPathsProvider: TypeScriptPluginPathsProvider;
private readonly pluginPathsProvider: TypeScriptPluginPathsProvider;
private readonly _versionManager: TypeScriptVersionManager;

private readonly logger = new Logger();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ export class CreateNewJSFileCommand {
public static readonly id = 'javascript-walkthrough.commands.createJsFile';
public readonly id = CreateNewJSFileCommand.id;

constructor(private walkthroughState: JsWalkthroughState) { }
constructor(
private readonly walkthroughState: JsWalkthroughState
) { }

public execute() {
createNewJSFile(this.walkthroughState);
Expand All @@ -61,7 +63,9 @@ export class DebugJsFileCommand {
public static readonly id = 'javascript-walkthrough.commands.debugJsFile';
public readonly id = DebugJsFileCommand.id;

constructor(private walkthroughState: JsWalkthroughState) { }
constructor(
private readonly walkthroughState: JsWalkthroughState
) { }

public execute() {
debugJsFile(this.walkthroughState);
Expand Down

0 comments on commit 44441de

Please sign in to comment.