Skip to content

No floating promises #1576

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2020,
"sourceType": "module"
"sourceType": "module",
"project": true
},
"plugins": ["@typescript-eslint"],
"rules": {
Expand All @@ -13,6 +14,7 @@
// TODO "@typescript-eslint/semi" rule moved to https://eslint.style
"semi": "error",
"no-console": "warn",
"@typescript-eslint/no-floating-promises": "warn",
// Mostly fails tests, ex. expect(...).to.be.true returns a Chai.Assertion
"@typescript-eslint/no-unused-expressions": "off",
"@typescript-eslint/no-non-null-assertion": "off",
Expand Down
18 changes: 18 additions & 0 deletions scripts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"compilerOptions": {
"composite": true,

"rootDir": ".",
"outDir": "dist",

"lib": ["ES2021"],
"target": "ES2020",
"module": "commonjs",

"strict": true,

"sourceMap": true,

"types": []
}
}
2 changes: 1 addition & 1 deletion src/BackgroundCompilation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class BackgroundCompilation implements vscode.Disposable {
this.workspaceFileWatcher.onDidChange(
debounce(
() => {
this.runTask();
void this.runTask();
},
100 /* 10 times per second */,
{ trailing: true }
Expand Down
2 changes: 1 addition & 1 deletion src/FolderContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export class FolderContext implements vscode.Disposable {
* @param event event type
*/
async fireEvent(event: FolderOperation) {
this.workspaceContext.fireEvent(this, event);
await this.workspaceContext.fireEvent(this, event);
}

/** Return edited Packages folder */
Expand Down
14 changes: 10 additions & 4 deletions src/PackageWatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export class PackageWatcher {
async handleSwiftVersionFileChange() {
const version = await this.readSwiftVersionFile();
if (version && version.toString() !== this.currentVersion?.toString()) {
this.workspaceContext.fireEvent(
await this.workspaceContext.fireEvent(
this.folderContext,
FolderOperation.swiftVersionUpdated
);
Expand Down Expand Up @@ -162,7 +162,7 @@ export class PackageWatcher {
async handlePackageSwiftChange() {
// Load SwiftPM Package.swift description
await this.folderContext.reload();
this.workspaceContext.fireEvent(this.folderContext, FolderOperation.packageUpdated);
await this.workspaceContext.fireEvent(this.folderContext, FolderOperation.packageUpdated);
}

/**
Expand All @@ -175,7 +175,10 @@ export class PackageWatcher {
await this.folderContext.reloadPackageResolved();
// if file contents has changed then send resolve updated message
if (this.folderContext.swiftPackage.resolved?.fileHash !== packageResolvedHash) {
this.workspaceContext.fireEvent(this.folderContext, FolderOperation.resolvedUpdated);
await this.workspaceContext.fireEvent(
this.folderContext,
FolderOperation.resolvedUpdated
);
}
}

Expand All @@ -186,6 +189,9 @@ export class PackageWatcher {
*/
private async handleWorkspaceStateChange() {
await this.folderContext.reloadWorkspaceState();
this.workspaceContext.fireEvent(this.folderContext, FolderOperation.workspaceStateUpdated);
await this.workspaceContext.fireEvent(
this.folderContext,
FolderOperation.workspaceStateUpdated
);
}
}
16 changes: 8 additions & 8 deletions src/TestExplorer/TestExplorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ export class TestExplorer {
this.testFileEdited = false;

// only run discover tests if the library has tests
this.folderContext.swiftPackage.getTargets(TargetType.test).then(targets => {
void this.folderContext.swiftPackage.getTargets(TargetType.test).then(targets => {
if (targets.length > 0) {
this.discoverTestsInWorkspace(this.tokenSource.token);
void this.discoverTestsInWorkspace(this.tokenSource.token);
}
});
}
Expand All @@ -98,7 +98,7 @@ export class TestExplorer {
// add file watcher to catch changes to swift test files
const fileWatcher = this.folderContext.workspaceContext.onDidChangeSwiftFiles(({ uri }) => {
if (this.testFileEdited === false) {
this.folderContext.getTestTarget(uri).then(target => {
void this.folderContext.getTestTarget(uri).then(target => {
if (target) {
this.testFileEdited = true;
}
Expand Down Expand Up @@ -138,7 +138,7 @@ export class TestExplorer {
switch (operation) {
case FolderOperation.add:
if (folder) {
folder.swiftPackage.getTargets(TargetType.test).then(targets => {
void folder.swiftPackage.getTargets(TargetType.test).then(targets => {
if (targets.length === 0) {
return;
}
Expand All @@ -149,7 +149,7 @@ export class TestExplorer {
if (
!configuration.folder(folder.workspaceFolder).disableAutoResolve
) {
folder.testExplorer?.discoverTestsInWorkspace(
void folder.testExplorer?.discoverTestsInWorkspace(
tokenSource.token
);
}
Expand All @@ -158,7 +158,7 @@ export class TestExplorer {
break;
case FolderOperation.packageUpdated:
if (folder) {
folder.swiftPackage.getTargets(TargetType.test).then(targets => {
void folder.swiftPackage.getTargets(TargetType.test).then(targets => {
const hasTestTargets = targets.length > 0;
if (hasTestTargets && !folder.hasTestExplorer()) {
folder.addTestExplorer();
Expand All @@ -168,7 +168,7 @@ export class TestExplorer {
!configuration.folder(folder.workspaceFolder)
.disableAutoResolve
) {
folder.testExplorer?.discoverTestsInWorkspace(
void folder.testExplorer?.discoverTestsInWorkspace(
tokenSource.token
);
}
Expand Down Expand Up @@ -219,7 +219,7 @@ export class TestExplorer {
const testExplorer = folder?.testExplorer;
if (testExplorer && symbols && uri && uri.scheme === "file") {
if (isPathInsidePath(uri.fsPath, folder.folder.fsPath)) {
folder.swiftPackage.getTarget(uri.fsPath).then(target => {
void folder.swiftPackage.getTarget(uri.fsPath).then(target => {
if (target && target.type === "test") {
testExplorer.lspTestDiscovery
.getDocumentTests(folder.swiftPackage, uri)
Expand Down
2 changes: 1 addition & 1 deletion src/TestExplorer/TestParsers/SwiftTestingOutputParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ export class SwiftTestingOutputParser {

rl.on("line", line => this.parse(JSON.parse(line), runState));

reader.start(readlinePipe);
void reader.start(readlinePipe);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/TestExplorer/TestRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ export class TestRunner {
// discarded. If the test run has already started this is a no-op so its safe to call it multiple times.
this.testRun.testRunStarted();

this.swiftTestOutputParser.close();
void this.swiftTestOutputParser.close();
}
} finally {
outputStream.end();
Expand Down Expand Up @@ -807,7 +807,7 @@ export class TestRunner {
}
});

this.folderContext.taskQueue.queueOperation(
void this.folderContext.taskQueue.queueOperation(
new TaskOperation(task),
this.testRun.token
);
Expand Down
16 changes: 8 additions & 8 deletions src/WorkspaceContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export class WorkspaceContext implements vscode.Disposable {
break;
case FolderOperation.focus:
this.updateContextKeys(event.folder);
this.updateContextKeysForFile();
void this.updateContextKeysForFile();
break;
case FolderOperation.unfocus:
this.updateContextKeys(event.folder);
Expand Down Expand Up @@ -232,7 +232,7 @@ export class WorkspaceContext implements vscode.Disposable {
return;
}

Promise.all([
void Promise.all([
folderContext.swiftPackage.foundPackage,
folderContext.swiftPackage.dependencies,
]).then(([foundPackage, dependencies]) => {
Expand All @@ -256,7 +256,7 @@ export class WorkspaceContext implements vscode.Disposable {

if (this.currentFolder) {
const languageClient = this.languageClientManager.get(this.currentFolder);
languageClient.useLanguageClient(async client => {
await languageClient.useLanguageClient(async client => {
const experimentalCaps = client.initializeResult?.capabilities.experimental;
if (!experimentalCaps) {
contextKeys.supportsReindexing = false;
Expand Down Expand Up @@ -296,7 +296,7 @@ export class WorkspaceContext implements vscode.Disposable {
console.log("Trying to run onDidChangeWorkspaceFolders on deleted context");
return;
}
this.onDidChangeWorkspaceFolders(event);
void this.onDidChangeWorkspaceFolders(event);
});
// add event listener for when the active edited text document changes
const onDidChangeActiveWindow = vscode.window.onDidChangeActiveTextEditor(async editor => {
Expand Down Expand Up @@ -327,7 +327,7 @@ export class WorkspaceContext implements vscode.Disposable {
await this.focusFolder(null);
}
}
this.initialisationComplete();
await this.initialisationComplete();
}

/**
Expand Down Expand Up @@ -450,7 +450,7 @@ export class WorkspaceContext implements vscode.Disposable {
// if current folder is this folder send unfocus event by setting
// current folder to undefined
if (this.currentFolder === folder) {
this.focusFolder(null);
await this.focusFolder(null);
}
// run observer functions in reverse order when removing
const observersReversed = [...this.observers];
Expand Down Expand Up @@ -519,10 +519,10 @@ export class WorkspaceContext implements vscode.Disposable {
}
}

private initialisationComplete() {
private async initialisationComplete() {
this.initialisationFinished = true;
if (this.lastFocusUri) {
this.focusUri(this.lastFocusUri);
await this.focusUri(this.lastFocusUri);
this.lastFocusUri = undefined;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/commands/createNewProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export async function createNewProject(toolchain: SwiftToolchain | undefined): P
// run before the Swift extension is activated. Show the toolchain error notification in
// this case.
if (!toolchain) {
showToolchainError();
void showToolchainError();
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/commands/dependencies/edit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export async function editDependency(identifier: string, ctx: WorkspaceContext)
);

if (success) {
ctx.fireEvent(currentFolder, FolderOperation.resolvedUpdated);
await ctx.fireEvent(currentFolder, FolderOperation.resolvedUpdated);
// add folder to workspace
const index = vscode.workspace.workspaceFolders?.length ?? 0;
vscode.workspace.updateWorkspaceFolders(index, 0, {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/dependencies/unedit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ async function uneditFolderDependency(
);
await folder.taskQueue.queueOperation(uneditOperation);

ctx.fireEvent(folder, FolderOperation.resolvedUpdated);
await ctx.fireEvent(folder, FolderOperation.resolvedUpdated);
// find workspace folder, and check folder still exists
const folderIndex = vscode.workspace.workspaceFolders?.findIndex(
item => item.name === identifier
Expand Down
2 changes: 1 addition & 1 deletion src/commands/dependencies/updateDepViewList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ import { FolderOperation, WorkspaceContext } from "../../WorkspaceContext";
export function updateDependenciesViewList(ctx: WorkspaceContext, flatList: boolean) {
if (ctx.currentFolder) {
contextKeys.flatDependenciesList = flatList;
ctx.fireEvent(ctx.currentFolder, FolderOperation.packageViewUpdated);
void ctx.fireEvent(ctx.currentFolder, FolderOperation.packageViewUpdated);
}
}
2 changes: 1 addition & 1 deletion src/commands/dependencies/useLocal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export async function useLocalDependency(
true
);
if (success) {
ctx.fireEvent(currentFolder, FolderOperation.resolvedUpdated);
await ctx.fireEvent(currentFolder, FolderOperation.resolvedUpdated);
}
return success;
}
2 changes: 1 addition & 1 deletion src/commands/insertFunctionComment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ export async function insertFunctionComment(workspaceContext: WorkspaceContext)
return;
}
const line = activeEditor.selection.active.line;
workspaceContext.commentCompletionProvider.insert(activeEditor, line);
await workspaceContext.commentCompletionProvider.insert(activeEditor, line);
}
2 changes: 1 addition & 1 deletion src/commands/testMultipleTimes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export async function runTestMultipleTimes(
break;
}
}
runner.testRun.end();
await runner.testRun.end();

return runStates;
}
2 changes: 1 addition & 1 deletion src/commands/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,6 @@ export function updateAfterError(result: boolean, folderContext: FolderContext)
folderContext.hasResolveErrors = !result;

if (triggerResolvedUpdatedEvent && !folderContext.hasResolveErrors) {
folderContext.fireEvent(FolderOperation.resolvedUpdated);
void folderContext.fireEvent(FolderOperation.resolvedUpdated);
}
}
4 changes: 2 additions & 2 deletions src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ export function handleConfigurationChangeEvent(
event.affectsConfiguration("swift.path") &&
configuration.path !== ctx.currentFolder?.toolchain.swiftFolderPath
) {
showReloadExtensionNotification(
void showReloadExtensionNotification(
"Changing the Swift path requires Visual Studio Code be reloaded."
);
} else if (
Expand All @@ -542,7 +542,7 @@ export function handleConfigurationChangeEvent(
) {
vscode.commands.executeCommand("swift.restartLSPServer");
} else if (event.affectsConfiguration("swift.swiftEnvironmentVariables")) {
showReloadExtensionNotification(
void showReloadExtensionNotification(
"Changing environment variables requires the project be reloaded."
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/coverage/LcovResults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export class TestCoverage {
this.coverageDetails.set(uri, detailedCoverage);
}
}
this.lcovTmpFiles.dispose();
await this.lcovTmpFiles.dispose();
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/documentation/DocumentationPreviewEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export class DocumentationPreviewEditor implements vscode.Disposable {
if (!this.activeTextEditor) {
break;
}
this.convertDocumentation(this.activeTextEditor);
void this.convertDocumentation(this.activeTextEditor);
break;
case "rendered":
this.renderEmitter.fire();
Expand All @@ -166,7 +166,7 @@ export class DocumentationPreviewEditor implements vscode.Disposable {
}
this.activeTextEditor = activeTextEditor;
this.activeTextEditorSelection = activeTextEditor.selection;
this.convertDocumentation(activeTextEditor);
void this.convertDocumentation(activeTextEditor);
}

private handleSelectionChange(event: vscode.TextEditorSelectionChangeEvent) {
Expand All @@ -177,12 +177,12 @@ export class DocumentationPreviewEditor implements vscode.Disposable {
return;
}
this.activeTextEditorSelection = event.textEditor.selection;
this.convertDocumentation(event.textEditor);
void this.convertDocumentation(event.textEditor);
}

private handleDocumentChange(event: vscode.TextDocumentChangeEvent) {
if (this.activeTextEditor?.document === event.document) {
this.convertDocumentation(this.activeTextEditor);
void this.convertDocumentation(this.activeTextEditor);
}
}

Expand Down
1 change: 1 addition & 0 deletions src/documentation/webview/webview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//
/* eslint-disable @typescript-eslint/no-floating-promises */

import { RenderNode, WebviewContent, WebviewMessage } from "./WebviewMessage";
import { createCommunicationBridge } from "./CommunicationBridge";
Expand Down
Loading