From 03aad5f8612ff3d7d52e14deb5019290b4a9f17f Mon Sep 17 00:00:00 2001 From: Andy Jordan Date: Fri, 7 Apr 2023 12:34:36 -0700 Subject: [PATCH] Enable ESLint `explicit-function-return-type` And fix violations. --- .eslintrc.json | 3 ++ src/features/CodeActions.ts | 4 +-- src/features/Console.ts | 4 +-- src/features/CustomViews.ts | 20 ++++++------ src/features/DebugSession.ts | 18 +++++------ src/features/Examples.ts | 2 +- src/features/ExpandAlias.ts | 2 +- src/features/ExtensionCommands.ts | 10 +++--- src/features/ExternalApi.ts | 2 +- src/features/GenerateBugReport.ts | 2 +- src/features/GetCommands.ts | 10 +++--- src/features/HelpCompletion.ts | 4 +-- src/features/ISECompatibility.ts | 8 ++--- src/features/NewFileOrProject.ts | 10 +++--- src/features/OpenInISE.ts | 2 +- src/features/PesterTests.ts | 2 +- src/features/RemoteFiles.ts | 6 ++-- src/features/RunCode.ts | 8 ++--- src/features/ShowHelp.ts | 2 +- src/features/UpdatePowerShell.ts | 8 ++--- src/languageClientConsumer.ts | 2 +- src/logging.ts | 4 +-- src/process.ts | 12 ++++---- src/session.ts | 42 ++++++++++++++------------ src/utils.ts | 4 +-- test/core/platform.test.ts | 4 +-- test/features/ISECompatibility.test.ts | 8 ++--- test/runTests.ts | 2 +- 28 files changed, 106 insertions(+), 99 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 221115a29e..182412c8d4 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -36,6 +36,9 @@ "error", "always" ], + "@typescript-eslint/explicit-function-return-type": [ + "error" + ], "@typescript-eslint/no-floating-promises": [ "error", { diff --git a/src/features/CodeActions.ts b/src/features/CodeActions.ts index aaf0dbfba3..bf2ee69fec 100644 --- a/src/features/CodeActions.ts +++ b/src/features/CodeActions.ts @@ -30,12 +30,12 @@ export class CodeActionsFeature implements vscode.Disposable { }); } - public dispose() { + public dispose(): void { this.applyEditsCommand.dispose(); this.showDocumentationCommand.dispose(); } - public async showRuleDocumentation(ruleId: string) { + public async showRuleDocumentation(ruleId: string): Promise { const pssaDocBaseURL = "https://docs.microsoft.com/powershell/utility-modules/psscriptanalyzer/rules/"; if (!ruleId) { diff --git a/src/features/Console.ts b/src/features/Console.ts index 445bafa5fc..165716406e 100644 --- a/src/features/Console.ts +++ b/src/features/Console.ts @@ -213,7 +213,7 @@ export class ConsoleFeature extends LanguageClientConsumer { ]; } - public dispose() { + public dispose(): void { for (const command of this.commands) { command.dispose(); } @@ -222,7 +222,7 @@ export class ConsoleFeature extends LanguageClientConsumer { } } - public override setLanguageClient(languageClient: LanguageClient) { + public override setLanguageClient(languageClient: LanguageClient): void { this.languageClient = languageClient; this.handlers = [ this.languageClient.onRequest( diff --git a/src/features/CustomViews.ts b/src/features/CustomViews.ts index 794962d616..f4b0a2f20d 100644 --- a/src/features/CustomViews.ts +++ b/src/features/CustomViews.ts @@ -21,13 +21,13 @@ export class CustomViewsFeature extends LanguageClientConsumer { this.contentProvider)); } - public dispose() { + public dispose(): void { for (const command of this.commands) { command.dispose(); } } - public override setLanguageClient(languageClient: LanguageClient) { + public override setLanguageClient(languageClient: LanguageClient): void { languageClient.onRequest( NewCustomViewRequestType, @@ -81,7 +81,7 @@ class PowerShellContentProvider implements vscode.TextDocumentContentProvider { return this.viewIndex[uri.toString()].getContent(); } - public createView(id: string, title: string, viewType: CustomViewType) { + public createView(id: string, title: string, viewType: CustomViewType): void { let view; switch (viewType) { case CustomViewType.HtmlContent: @@ -91,12 +91,12 @@ class PowerShellContentProvider implements vscode.TextDocumentContentProvider { this.viewIndex[this.getUri(view.id)] = view; } - public showView(id: string, viewColumn: vscode.ViewColumn) { + public showView(id: string, viewColumn: vscode.ViewColumn): void { const uriString = this.getUri(id); (this.viewIndex[uriString] as HtmlContentView).showContent(viewColumn); } - public closeView(id: string) { + public closeView(id: string): void { const uriString = this.getUri(id); vscode.workspace.textDocuments.some((doc) => { @@ -110,7 +110,7 @@ class PowerShellContentProvider implements vscode.TextDocumentContentProvider { }); } - public setHtmlContentView(id: string, content: IHtmlContent) { + public setHtmlContentView(id: string, content: IHtmlContent): void { const uriString = this.getUri(id); const view: CustomView = this.viewIndex[uriString]; @@ -118,7 +118,7 @@ class PowerShellContentProvider implements vscode.TextDocumentContentProvider { this.didChangeEvent.fire(vscode.Uri.parse(uriString)); } - public appendHtmlOutputView(id: string, content: string) { + public appendHtmlOutputView(id: string, content: string): void { const uriString = this.getUri(id); const view: CustomView = this.viewIndex[uriString]; @@ -126,7 +126,7 @@ class PowerShellContentProvider implements vscode.TextDocumentContentProvider { this.didChangeEvent.fire(vscode.Uri.parse(uriString)); } - private getUri(id: string) { + private getUri(id: string): string { return `powershell://views/${id}`; } } @@ -158,11 +158,11 @@ class HtmlContentView extends CustomView { super(id, title, CustomViewType.HtmlContent); } - public setContent(htmlContent: IHtmlContent) { + public setContent(htmlContent: IHtmlContent): void { this.htmlContent = htmlContent; } - public appendContent(content: string) { + public appendContent(content: string): void { this.htmlContent.bodyContent += content; } diff --git a/src/features/DebugSession.ts b/src/features/DebugSession.ts index fddcba4c8c..c7fd0847d2 100644 --- a/src/features/DebugSession.ts +++ b/src/features/DebugSession.ts @@ -91,13 +91,13 @@ export class DebugSessionFeature extends LanguageClientConsumer return new vscode.DebugAdapterNamedPipeServer(sessionDetails.debugServicePipeName); } - public dispose() { + public dispose(): void { for (const handler of this.handlers) { handler.dispose(); } } - public override setLanguageClient(languageClient: LanguageClient) { + public override setLanguageClient(languageClient: LanguageClient): void { this.handlers = [ languageClient.onNotification( StartDebuggerNotificationType, @@ -308,7 +308,7 @@ export class SpecifyScriptArgsFeature implements vscode.Disposable { }); } - public dispose() { + public dispose(): void { this.command.dispose(); } @@ -369,7 +369,7 @@ export class PickPSHostProcessFeature extends LanguageClientConsumer { }); } - public override setLanguageClient(languageClient: LanguageClient) { + public override setLanguageClient(languageClient: LanguageClient): void { this.languageClient = languageClient; if (this.waitingForClientToken && this.getLanguageClientResolve) { @@ -378,7 +378,7 @@ export class PickPSHostProcessFeature extends LanguageClientConsumer { } } - public dispose() { + public dispose(): void { this.command.dispose(); } @@ -456,7 +456,7 @@ export class PickPSHostProcessFeature extends LanguageClientConsumer { return item ? `${item.pid}` : undefined; } - private clearWaitingToken() { + private clearWaitingToken(): void { this.waitingForClientToken?.dispose(); this.waitingForClientToken = undefined; } @@ -494,7 +494,7 @@ export class PickRunspaceFeature extends LanguageClientConsumer { }, this); } - public override setLanguageClient(languageClient: LanguageClient) { + public override setLanguageClient(languageClient: LanguageClient): void { this.languageClient = languageClient; if (this.waitingForClientToken && this.getLanguageClientResolve) { @@ -503,7 +503,7 @@ export class PickRunspaceFeature extends LanguageClientConsumer { } } - public dispose() { + public dispose(): void { this.command.dispose(); } @@ -572,7 +572,7 @@ export class PickRunspaceFeature extends LanguageClientConsumer { return item ? `${item.id}` : undefined; } - private clearWaitingToken() { + private clearWaitingToken(): void { this.waitingForClientToken?.dispose(); this.waitingForClientToken = undefined; } diff --git a/src/features/Examples.ts b/src/features/Examples.ts index ff1f59f7b5..8dcddbeb79 100644 --- a/src/features/Examples.ts +++ b/src/features/Examples.ts @@ -19,7 +19,7 @@ export class ExamplesFeature implements vscode.Disposable { }); } - public dispose() { + public dispose(): void { this.command.dispose(); } } diff --git a/src/features/ExpandAlias.ts b/src/features/ExpandAlias.ts index 6db957c215..32b6bb8d77 100644 --- a/src/features/ExpandAlias.ts +++ b/src/features/ExpandAlias.ts @@ -53,7 +53,7 @@ export class ExpandAliasFeature extends LanguageClientConsumer { }); } - public dispose() { + public dispose(): void { this.command.dispose(); } } diff --git a/src/features/ExtensionCommands.ts b/src/features/ExtensionCommands.ts index dd02abf6f5..3fba8d2f6c 100644 --- a/src/features/ExtensionCommands.ts +++ b/src/features/ExtensionCommands.ts @@ -198,12 +198,12 @@ export class ExtensionCommandsFeature extends LanguageClientConsumer { ]; } - public override setLanguageClient(languageclient: LanguageClient) { + public override setLanguageClient(languageClient: LanguageClient): void { // Clear the current list of extension commands since they were // only relevant to the previous session this.extensionCommands = []; - this.languageClient = languageclient; + this.languageClient = languageClient; this.handlers = [ this.languageClient.onNotification( @@ -267,7 +267,7 @@ export class ExtensionCommandsFeature extends LanguageClientConsumer { ]; } - public dispose() { + public dispose(): void { for (const command of this.commands) { command.dispose(); } @@ -276,7 +276,7 @@ export class ExtensionCommandsFeature extends LanguageClientConsumer { } } - private addExtensionCommand(command: IExtensionCommandAddedNotificationBody) { + private addExtensionCommand(command: IExtensionCommandAddedNotificationBody): void { this.extensionCommands.push({ name: command.name, displayName: command.displayName, @@ -311,7 +311,7 @@ export class ExtensionCommandsFeature extends LanguageClientConsumer { private async onCommandSelected( chosenItem: IExtensionCommandQuickPickItem | undefined, - client: LanguageClient | undefined) { + client: LanguageClient | undefined): Promise { if (chosenItem !== undefined) { await client?.sendRequest( diff --git a/src/features/ExternalApi.ts b/src/features/ExternalApi.ts index c054eb1ba6..3643ad2821 100644 --- a/src/features/ExternalApi.ts +++ b/src/features/ExternalApi.ts @@ -173,7 +173,7 @@ export class ExternalApiFeature extends LanguageClientConsumer implements IPower return this.extensionContext.globalStorageUri.with({ scheme: "file"}); } - public dispose() { + public dispose(): void { // Nothing to dispose. } } diff --git a/src/features/GenerateBugReport.ts b/src/features/GenerateBugReport.ts index bcf957883b..fbb2cf26b2 100644 --- a/src/features/GenerateBugReport.ts +++ b/src/features/GenerateBugReport.ts @@ -25,7 +25,7 @@ export class GenerateBugReportFeature implements vscode.Disposable { }); } - public dispose() { + public dispose(): void { this.command.dispose(); } diff --git a/src/features/GetCommands.ts b/src/features/GetCommands.ts index e74846d546..144240bb1b 100644 --- a/src/features/GetCommands.ts +++ b/src/features/GetCommands.ts @@ -50,20 +50,20 @@ export class GetCommandsFeature extends LanguageClientConsumer { }); } - public dispose() { + public dispose(): void { for (const command of this.commands) { command.dispose(); } } - public override setLanguageClient(languageclient: LanguageClient) { - this.languageClient = languageclient; + public override setLanguageClient(languageClient: LanguageClient): void { + this.languageClient = languageClient; if (this.commandsExplorerTreeView.visible) { void vscode.commands.executeCommand("PowerShell.RefreshCommandsExplorer"); } } - private async CommandExplorerRefresh() { + private async CommandExplorerRefresh(): Promise { if (this.languageClient === undefined) { this.logger.writeVerbose(`<${GetCommandsFeature.name}>: Unable to send getCommand request`); return; @@ -77,7 +77,7 @@ export class GetCommandsFeature extends LanguageClientConsumer { }); } - private async InsertCommand(item: { Name: string; }) { + private async InsertCommand(item: { Name: string; }): Promise { const editor = vscode.window.activeTextEditor; if (editor === undefined) { return; diff --git a/src/features/HelpCompletion.ts b/src/features/HelpCompletion.ts index e2931dc461..a28c2ee0e4 100644 --- a/src/features/HelpCompletion.ts +++ b/src/features/HelpCompletion.ts @@ -39,11 +39,11 @@ export class HelpCompletionFeature extends LanguageClientConsumer { } } - public dispose() { + public dispose(): void { this.disposable?.dispose(); } - public override setLanguageClient(languageClient: LanguageClient) { + public override setLanguageClient(languageClient: LanguageClient): void { this.languageClient = languageClient; if (this.helpCompletionProvider) { this.helpCompletionProvider.languageClient = languageClient; diff --git a/src/features/ISECompatibility.ts b/src/features/ISECompatibility.ts index a2a259023c..8e7d91c459 100644 --- a/src/features/ISECompatibility.ts +++ b/src/features/ISECompatibility.ts @@ -42,13 +42,13 @@ export class ISECompatibilityFeature implements vscode.Disposable { ]; } - public dispose() { + public dispose(): void { for (const command of this._commandRegistrations) { command.dispose(); } } - private async EnableISEMode() { + private async EnableISEMode(): Promise { this._iseModeEnabled = true; for (const iseSetting of ISECompatibilityFeature.settings) { try { @@ -73,7 +73,7 @@ export class ISECompatibilityFeature implements vscode.Disposable { } } - private async DisableISEMode() { + private async DisableISEMode(): Promise { this._iseModeEnabled = false; for (const iseSetting of ISECompatibilityFeature.settings) { const config = vscode.workspace.getConfiguration(iseSetting.path); @@ -84,7 +84,7 @@ export class ISECompatibilityFeature implements vscode.Disposable { } } - private async ToggleISEMode() { + private async ToggleISEMode(): Promise { if (this._iseModeEnabled) { await this.DisableISEMode(); } else { diff --git a/src/features/NewFileOrProject.ts b/src/features/NewFileOrProject.ts index 65e5f780a2..d42e6e7411 100644 --- a/src/features/NewFileOrProject.ts +++ b/src/features/NewFileOrProject.ts @@ -43,11 +43,11 @@ export class NewFileOrProjectFeature extends LanguageClientConsumer { }); } - public dispose() { + public dispose(): void { this.command.dispose(); } - public override setLanguageClient(languageClient: LanguageClient) { + public override setLanguageClient(languageClient: LanguageClient): void { this.languageClient = languageClient; if (this.waitingForClientToken) { @@ -143,7 +143,7 @@ export class NewFileOrProjectFeature extends LanguageClientConsumer { [ { prompt: "Yes", - action: async () => { await this.createProjectFromTemplate(template); } + action: async (): Promise => { await this.createProjectFromTemplate(template); } }, { prompt: "No", @@ -154,7 +154,7 @@ export class NewFileOrProjectFeature extends LanguageClientConsumer { } } - private async openWorkspacePath(workspacePath: string) { + private async openWorkspacePath(workspacePath: string): Promise { // Open the created project in a new window await vscode.commands.executeCommand( "vscode.openFolder", @@ -162,7 +162,7 @@ export class NewFileOrProjectFeature extends LanguageClientConsumer { true); } - private clearWaitingToken() { + private clearWaitingToken(): void { this.waitingForClientToken?.dispose(); this.waitingForClientToken = undefined; } diff --git a/src/features/OpenInISE.ts b/src/features/OpenInISE.ts index 7bc7826bbd..05059eb6ac 100644 --- a/src/features/OpenInISE.ts +++ b/src/features/OpenInISE.ts @@ -30,7 +30,7 @@ export class OpenInISEFeature implements vscode.Disposable { }); } - public dispose() { + public dispose(): void { this.command.dispose(); } } diff --git a/src/features/PesterTests.ts b/src/features/PesterTests.ts index b2ced26211..7a49df2cf2 100644 --- a/src/features/PesterTests.ts +++ b/src/features/PesterTests.ts @@ -43,7 +43,7 @@ export class PesterTestsFeature implements vscode.Disposable { ]; } - public dispose() { + public dispose(): void { for (const command of this.commands) { command.dispose(); } diff --git a/src/features/RemoteFiles.ts b/src/features/RemoteFiles.ts index cf797c647f..a27728d02a 100644 --- a/src/features/RemoteFiles.ts +++ b/src/features/RemoteFiles.ts @@ -47,17 +47,17 @@ export class RemoteFilesFeature extends LanguageClientConsumer { }); } - public dispose() { + public dispose(): void { this.command.dispose(); // Close any leftover remote files before exiting this.closeRemoteFiles(); } - private isDocumentRemote(doc: vscode.TextDocument) { + private isDocumentRemote(doc: vscode.TextDocument): boolean { return doc.fileName.toLowerCase().startsWith(this.tempSessionPathPrefix); } - private closeRemoteFiles() { + private closeRemoteFiles(): void { const remoteDocuments = vscode.workspace.textDocuments.filter((doc) => this.isDocumentRemote(doc)); diff --git a/src/features/RunCode.ts b/src/features/RunCode.ts index b260bbf43c..896ae7dd0f 100644 --- a/src/features/RunCode.ts +++ b/src/features/RunCode.ts @@ -22,21 +22,21 @@ export class RunCodeFeature implements vscode.Disposable { }); } - public dispose() { + public dispose(): void { this.command.dispose(); } private async launchTask( runInDebugger: boolean, scriptToRun: string, - args: string[]) { + args: string[]): Promise { const launchType = runInDebugger ? LaunchType.Debug : LaunchType.Run; const launchConfig = createLaunchConfig(launchType, scriptToRun, args); await this.launch(launchConfig); } - private async launch(launchConfig: string | vscode.DebugConfiguration) { + private async launch(launchConfig: string | vscode.DebugConfiguration): Promise { // Create or show the interactive console // TODO: #367: Check if "newSession" mode is configured this.sessionManager.showDebugTerminal(true); @@ -46,7 +46,7 @@ export class RunCodeFeature implements vscode.Disposable { } } -function createLaunchConfig(launchType: LaunchType, commandToRun: string, args: string[]) { +function createLaunchConfig(launchType: LaunchType, commandToRun: string, args: string[]): vscode.DebugConfiguration { const settings = getSettings(); const launchConfig = { diff --git a/src/features/ShowHelp.ts b/src/features/ShowHelp.ts index 0ea08e3b28..d668735455 100644 --- a/src/features/ShowHelp.ts +++ b/src/features/ShowHelp.ts @@ -37,7 +37,7 @@ export class ShowHelpFeature extends LanguageClientConsumer { }); } - public dispose() { + public dispose(): void { this.command.dispose(); } diff --git a/src/features/UpdatePowerShell.ts b/src/features/UpdatePowerShell.ts index 88c2c46e6d..a206e5e220 100644 --- a/src/features/UpdatePowerShell.ts +++ b/src/features/UpdatePowerShell.ts @@ -156,7 +156,7 @@ export class UpdatePowerShell { return undefined; } - public async checkForUpdate() { + public async checkForUpdate(): Promise { try { const tag = await this.maybeGetNewRelease(); if (tag) { @@ -168,12 +168,12 @@ export class UpdatePowerShell { } } - private async openReleaseInBrowser(tag: string) { + private async openReleaseInBrowser(tag: string): Promise { const url = vscode.Uri.parse(UpdatePowerShell.GitHubWebReleaseURL + tag); await vscode.env.openExternal(url); } - private async updateWindows(tag: string) { + private async updateWindows(tag: string): Promise { let msiMatcher: string; if (this.architecture === "x64") { msiMatcher = "win-x64.msi"; @@ -233,7 +233,7 @@ export class UpdatePowerShell { }); } - private async installUpdate(tag: string) { + private async installUpdate(tag: string): Promise { const releaseVersion = new SemVer(tag); const result = await vscode.window.showInformationMessage( `You have an old version of PowerShell (${this.localVersion.version}). The current latest release is ${releaseVersion.version}. diff --git a/src/languageClientConsumer.ts b/src/languageClientConsumer.ts index ddbceeb97e..fb5d1e84b0 100644 --- a/src/languageClientConsumer.ts +++ b/src/languageClientConsumer.ts @@ -8,7 +8,7 @@ export abstract class LanguageClientConsumer { private _languageClient: LanguageClient | undefined; - public setLanguageClient(languageClient: LanguageClient) { + public setLanguageClient(languageClient: LanguageClient): void { this.languageClient = languageClient; } diff --git a/src/logging.ts b/src/logging.ts index 877d35e59c..87f88dad61 100644 --- a/src/logging.ts +++ b/src/logging.ts @@ -72,7 +72,7 @@ export class Logger implements ILogger { ]; } - public dispose() { + public dispose(): void { this.logChannel.dispose(); for (const command of this.commands) { command.dispose(); @@ -147,7 +147,7 @@ export class Logger implements ILogger { const fullActions = [ ...actions, - { prompt: "Show Logs", action: () => { this.showLogPanel(); } }, + { prompt: "Show Logs", action: (): void => { this.showLogPanel(); } }, ]; const actionKeys: string[] = fullActions.map((action) => action.prompt); diff --git a/src/process.ts b/src/process.ts index c0b94663d6..26647b441a 100644 --- a/src/process.ts +++ b/src/process.ts @@ -134,11 +134,11 @@ export class PowerShellProcess { return sessionDetails; } - public showTerminal(preserveFocus?: boolean) { + public showTerminal(preserveFocus?: boolean): void { this.consoleTerminal?.show(preserveFocus); } - public async dispose() { + public async dispose(): Promise { // Clean up the session file this.logger.write("Terminating PowerShell process..."); @@ -151,7 +151,7 @@ export class PowerShellProcess { this.consoleTerminal = undefined; } - public sendKeyPress() { + public sendKeyPress(): void { // NOTE: This is a regular character instead of something like \0 // because non-printing characters can cause havoc with different // languages and terminal settings. We discard the character server-side @@ -159,7 +159,7 @@ export class PowerShellProcess { this.consoleTerminal?.sendText("p", false); } - private logTerminalPid(pid: number, exeName: string) { + private logTerminalPid(pid: number, exeName: string): void { this.logger.write(`${exeName} PID: ${pid}`); } @@ -182,7 +182,7 @@ export class PowerShellProcess { return JSON.parse(fileContents.toString()); } - private static async deleteSessionFile(sessionFilePath: vscode.Uri) { + private static async deleteSessionFile(sessionFilePath: vscode.Uri): Promise { try { await vscode.workspace.fs.delete(sessionFilePath); } catch (e) { @@ -218,7 +218,7 @@ export class PowerShellProcess { throw new Error(err); } - private onTerminalClose(terminal: vscode.Terminal) { + private onTerminalClose(terminal: vscode.Terminal): void { if (terminal !== this.consoleTerminal) { return; } diff --git a/src/session.ts b/src/session.ts index a7dd12058c..7178095bbb 100644 --- a/src/session.ts +++ b/src/session.ts @@ -111,7 +111,7 @@ export class SessionManager implements Middleware { this.languageStatusItem = this.createStatusBarItem(); // We have to override the scheme because it defaults to // 'vscode-userdata' which breaks UNC paths. - this.sessionsFolder = vscode.Uri.joinPath(extensionContext.globalStorageUri.with({ scheme: "file"}), "sessions"); + this.sessionsFolder = vscode.Uri.joinPath(extensionContext.globalStorageUri.with({ scheme: "file" }), "sessions"); this.platformDetails = getPlatformDetails(); this.HostName = hostName; this.DisplayName = displayName; @@ -148,12 +148,12 @@ export class SessionManager implements Middleware { await this.languageClient?.dispose(); } - public setLanguageClientConsumers(languageClientConsumers: LanguageClientConsumer[]) { + public setLanguageClientConsumers(languageClientConsumers: LanguageClientConsumer[]): void { this.languageClientConsumers = languageClientConsumers; } // The `exeNameOverride` is used by `restartSession` to override ANY other setting. - public async start(exeNameOverride?: string) { + public async start(exeNameOverride?: string): Promise { // A simple lock because this function isn't re-entrant. if (this.started || this.starting) { return await this.waitUntilStarted(); @@ -174,7 +174,7 @@ export class SessionManager implements Middleware { } } - public async stop() { + public async stop(): Promise { this.logger.write("Shutting down language client..."); try { @@ -209,7 +209,7 @@ export class SessionManager implements Middleware { } } - public async restartSession(exeNameOverride?: string) { + public async restartSession(exeNameOverride?: string): Promise { await this.stop(); // Re-load and validate the settings. @@ -341,7 +341,7 @@ export class SessionManager implements Middleware { } // Move old setting codeFormatting.whitespaceAroundPipe to new setting codeFormatting.addWhitespaceAroundPipe - private async migrateWhitespaceAroundPipeSetting() { + private async migrateWhitespaceAroundPipeSetting(): Promise { const configuration = vscode.workspace.getConfiguration(utils.PowerShellLanguageId); const deprecatedSetting = "codeFormatting.whitespaceAroundPipe"; const newSetting = "codeFormatting.addWhitespaceAroundPipe"; @@ -355,7 +355,7 @@ export class SessionManager implements Middleware { } // TODO: Remove this migration code. - private async promptPowerShellExeSettingsCleanup() { + private async promptPowerShellExeSettingsCleanup(): Promise { if (this.sessionSettings.powerShellExePath === "") { return; } @@ -385,7 +385,7 @@ export class SessionManager implements Middleware { } } - private async onConfigurationUpdated() { + private async onConfigurationUpdated(): Promise { const settings = getSettings(); this.logger.updateLogLevel(settings.developer.editorServicesLogLevel); @@ -521,7 +521,7 @@ export class SessionManager implements Middleware { await this.logger.writeAndShowErrorWithActions(message, [ { prompt: "Get PowerShell", - action: async () => { + action: async (): Promise => { const getPSUri = vscode.Uri.parse("https://aka.ms/get-powershell-vscode"); await vscode.env.openExternal(getPSUri); }, @@ -591,13 +591,13 @@ Type 'help' to get help. return editorServicesArgs; } - private async promptForRestart() { + private async promptForRestart(): Promise { await this.logger.writeAndShowErrorWithActions( "The PowerShell Extension Terminal has stopped, would you like to restart it? IntelliSense and other features will not work without it!", [ { prompt: "Yes", - action: async () => { await this.restartSession(); } + action: async (): Promise => { await this.restartSession(); } }, { prompt: "No", @@ -607,17 +607,21 @@ Type 'help' to get help. ); } - private sendTelemetryEvent(eventName: string, properties?: TelemetryEventProperties, measures?: TelemetryEventMeasurements) { + private sendTelemetryEvent( + eventName: string, + properties?: TelemetryEventProperties, + measures?: TelemetryEventMeasurements): void { + if (this.extensionContext.extensionMode === vscode.ExtensionMode.Production) { this.telemetryReporter.sendTelemetryEvent(eventName, properties, measures); } } - private async startLanguageClient(sessionDetails: IEditorServicesSessionDetails) { + private async startLanguageClient(sessionDetails: IEditorServicesSessionDetails): Promise { this.logger.write(`Connecting to language service on pipe: ${sessionDetails.languageServicePipeName}`); this.logger.write("Session details: " + JSON.stringify(sessionDetails)); - const connectFunc = () => { + const connectFunc = (): Promise => { return new Promise( (resolve, _reject) => { const socket = net.connect(sessionDetails.languageServicePipeName); @@ -781,7 +785,7 @@ Type 'help' to get help. void this.logger.writeAndShowError(message, ...additionalMessages); } - private async changePowerShellDefaultVersion(exePath: IPowerShellExeDetails) { + private async changePowerShellDefaultVersion(exePath: IPowerShellExeDetails): Promise { this.suppressRestartPrompt = true; try { await changeSetting("powerShellDefaultVersion", exePath.displayName, true, this.logger); @@ -797,7 +801,7 @@ Type 'help' to get help. } // Shows the temp debug terminal if it exists, otherwise the session terminal. - public showDebugTerminal(isExecute?: boolean) { + public showDebugTerminal(isExecute?: boolean): void { if (this.debugSessionProcess) { this.debugSessionProcess.showTerminal(isExecute && !this.sessionSettings.integratedConsole.focusConsoleOnExecute); } else { @@ -806,11 +810,11 @@ Type 'help' to get help. } // Always shows the session terminal. - public showSessionTerminal(isExecute?: boolean) { + public showSessionTerminal(isExecute?: boolean): void { this.languageServerProcess?.showTerminal(isExecute && !this.sessionSettings.integratedConsole.focusConsoleOnExecute); } - private async showSessionMenu() { + private async showSessionMenu(): Promise { const powershellExeFinder = new PowerShellExeFinder( this.platformDetails, this.sessionSettings.powerShellAdditionalExePaths, @@ -900,6 +904,6 @@ class SessionMenuItem implements vscode.QuickPickItem { constructor( public readonly label: string, // eslint-disable-next-line @typescript-eslint/no-empty-function - public readonly callback = async () => { }) { + public readonly callback = async (): Promise => { }) { } } diff --git a/src/utils.ts b/src/utils.ts index 61c3875744..8422291b72 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -11,7 +11,7 @@ export function escapeSingleQuotes(p: string): string { return p.replace(new RegExp("'", "g"), "''"); } -export function getPipePath(pipeName: string) { +export function getPipePath(pipeName: string): string { if (os.platform() === "win32") { return "\\\\.\\pipe\\" + pipeName; } else { @@ -55,7 +55,7 @@ export async function readDirectory(directoryPath: string | vscode.Uri): Promise return items.map(([name, _type]) => name); } -export function getTimestampString() { +export function getTimestampString(): string { const time = new Date(); return `[${time.getHours()}:${time.getMinutes()}:${time.getSeconds()}]`; } diff --git a/test/core/platform.test.ts b/test/core/platform.test.ts index 2dcd7541ec..f61ad60721 100644 --- a/test/core/platform.test.ts +++ b/test/core/platform.test.ts @@ -667,7 +667,7 @@ const errorTestCases: ITestPlatform[] = [ }, ]; -function setupTestEnvironment(testPlatform: ITestPlatform) { +function setupTestEnvironment(testPlatform: ITestPlatform): void { mockFS(testPlatform.filesystem); for (const envVar of Object.keys(testPlatform.environmentVars)) { @@ -816,7 +816,7 @@ describe("Platform module", function () { it(`Corrects the Windows PowerShell path on ${testPlatform.name}`, function () { setupTestEnvironment(testPlatform); - function getWinPSPath(systemDir: string) { + function getWinPSPath(systemDir: string): string { return path.join( testPlatform.environmentVars.windir!, systemDir, diff --git a/test/features/ISECompatibility.test.ts b/test/features/ISECompatibility.test.ts index 01d8504cf8..792c3dd7bb 100644 --- a/test/features/ISECompatibility.test.ts +++ b/test/features/ISECompatibility.test.ts @@ -9,9 +9,9 @@ import utils = require("../utils"); describe("ISE compatibility feature", function () { let currentTheme: string | undefined; - async function enableISEMode() { await vscode.commands.executeCommand("PowerShell.EnableISEMode"); } - async function disableISEMode() { await vscode.commands.executeCommand("PowerShell.DisableISEMode"); } - async function toggleISEMode() { await vscode.commands.executeCommand("PowerShell.ToggleISEMode"); } + async function enableISEMode(): Promise { await vscode.commands.executeCommand("PowerShell.EnableISEMode"); } + async function disableISEMode(): Promise { await vscode.commands.executeCommand("PowerShell.DisableISEMode"); } + async function toggleISEMode(): Promise { await vscode.commands.executeCommand("PowerShell.ToggleISEMode"); } before(async function () { // Save user's current theme. @@ -75,7 +75,7 @@ describe("ISE compatibility feature", function () { describe("Color theme interactions", function () { beforeEach(enableISEMode); - function assertISESettings() { + function assertISESettings(): void { for (const iseSetting of ISECompatibilityFeature.settings) { const currently = vscode.workspace.getConfiguration(iseSetting.path).get(iseSetting.name); assert.notStrictEqual(currently, iseSetting.value); diff --git a/test/runTests.ts b/test/runTests.ts index 1e58705560..a54f424d74 100644 --- a/test/runTests.ts +++ b/test/runTests.ts @@ -8,7 +8,7 @@ import * as path from "path"; import { runTests } from "@vscode/test-electron"; -async function main() { +async function main(): Promise { try { // The folder containing the Extension Manifest package.json // Passed to `--extensionDevelopmentPath`