Skip to content

Commit 130fa4d

Browse files
committed
Eliminate problematic flaoting promises
We have a lot of floating promises in our code, some explicitly so, others likely being oversights. Will add a new eslint rule to watch for floating promises, fixing some and using "void" to ignore the others.
1 parent 3f1fc9a commit 130fa4d

39 files changed

+173
-128
lines changed

.eslintrc.json

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,20 @@
33
"parser": "@typescript-eslint/parser",
44
"parserOptions": {
55
"ecmaVersion": 2020,
6-
"sourceType": "module"
6+
"sourceType": "module",
7+
"project": true
78
},
8-
"plugins": ["@typescript-eslint"],
9+
"plugins": [
10+
"@typescript-eslint"
11+
],
912
"rules": {
1013
"curly": "error",
1114
"eqeqeq": "warn",
1215
"no-throw-literal": "warn",
1316
// TODO "@typescript-eslint/semi" rule moved to https://eslint.style
1417
"semi": "error",
1518
"no-console": "warn",
19+
"@typescript-eslint/no-floating-promises": "warn",
1620
// Mostly fails tests, ex. expect(...).to.be.true returns a Chai.Assertion
1721
"@typescript-eslint/no-unused-expressions": "off",
1822
"@typescript-eslint/no-non-null-assertion": "off",
@@ -25,6 +29,15 @@
2529
}
2630
]
2731
},
28-
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended", "prettier"],
29-
"ignorePatterns": ["assets", "out", "dist", "**/*.d.ts"]
30-
}
32+
"extends": [
33+
"eslint:recommended",
34+
"plugin:@typescript-eslint/recommended",
35+
"prettier"
36+
],
37+
"ignorePatterns": [
38+
"assets",
39+
"out",
40+
"dist",
41+
"**/*.d.ts"
42+
]
43+
}

scripts/tsconfig.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"compilerOptions": {
3+
"composite": true,
4+
5+
"rootDir": ".",
6+
"outDir": "dist",
7+
8+
"lib": ["ES2021"],
9+
"target": "ES2020",
10+
"module": "commonjs",
11+
12+
"strict": true,
13+
14+
"sourceMap": true,
15+
16+
"types": []
17+
}
18+
}

src/BackgroundCompilation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export class BackgroundCompilation implements vscode.Disposable {
5858
this.workspaceFileWatcher.onDidChange(
5959
debounce(
6060
() => {
61-
this.runTask();
61+
void this.runTask();
6262
},
6363
100 /* 10 times per second */,
6464
{ trailing: true }

src/FolderContext.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ export class FolderContext implements vscode.Disposable {
154154
* @param event event type
155155
*/
156156
async fireEvent(event: FolderOperation) {
157-
this.workspaceContext.fireEvent(this, event);
157+
await this.workspaceContext.fireEvent(this, event);
158158
}
159159

160160
/** Return edited Packages folder */

src/PackageWatcher.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ export class PackageWatcher {
128128
async handleSwiftVersionFileChange() {
129129
const version = await this.readSwiftVersionFile();
130130
if (version && version.toString() !== this.currentVersion?.toString()) {
131-
this.workspaceContext.fireEvent(
131+
await this.workspaceContext.fireEvent(
132132
this.folderContext,
133133
FolderOperation.swiftVersionUpdated
134134
);
@@ -162,7 +162,7 @@ export class PackageWatcher {
162162
async handlePackageSwiftChange() {
163163
// Load SwiftPM Package.swift description
164164
await this.folderContext.reload();
165-
this.workspaceContext.fireEvent(this.folderContext, FolderOperation.packageUpdated);
165+
await this.workspaceContext.fireEvent(this.folderContext, FolderOperation.packageUpdated);
166166
}
167167

168168
/**
@@ -175,7 +175,10 @@ export class PackageWatcher {
175175
await this.folderContext.reloadPackageResolved();
176176
// if file contents has changed then send resolve updated message
177177
if (this.folderContext.swiftPackage.resolved?.fileHash !== packageResolvedHash) {
178-
this.workspaceContext.fireEvent(this.folderContext, FolderOperation.resolvedUpdated);
178+
await this.workspaceContext.fireEvent(
179+
this.folderContext,
180+
FolderOperation.resolvedUpdated
181+
);
179182
}
180183
}
181184

@@ -186,6 +189,9 @@ export class PackageWatcher {
186189
*/
187190
private async handleWorkspaceStateChange() {
188191
await this.folderContext.reloadWorkspaceState();
189-
this.workspaceContext.fireEvent(this.folderContext, FolderOperation.workspaceStateUpdated);
192+
await this.workspaceContext.fireEvent(
193+
this.folderContext,
194+
FolderOperation.workspaceStateUpdated
195+
);
190196
}
191197
}

src/TestExplorer/TestExplorer.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ export class TestExplorer {
8787
this.testFileEdited = false;
8888

8989
// only run discover tests if the library has tests
90-
this.folderContext.swiftPackage.getTargets(TargetType.test).then(targets => {
90+
void this.folderContext.swiftPackage.getTargets(TargetType.test).then(targets => {
9191
if (targets.length > 0) {
92-
this.discoverTestsInWorkspace(this.tokenSource.token);
92+
void this.discoverTestsInWorkspace(this.tokenSource.token);
9393
}
9494
});
9595
}
@@ -98,7 +98,7 @@ export class TestExplorer {
9898
// add file watcher to catch changes to swift test files
9999
const fileWatcher = this.folderContext.workspaceContext.onDidChangeSwiftFiles(({ uri }) => {
100100
if (this.testFileEdited === false) {
101-
this.folderContext.getTestTarget(uri).then(target => {
101+
void this.folderContext.getTestTarget(uri).then(target => {
102102
if (target) {
103103
this.testFileEdited = true;
104104
}
@@ -138,7 +138,7 @@ export class TestExplorer {
138138
switch (operation) {
139139
case FolderOperation.add:
140140
if (folder) {
141-
folder.swiftPackage.getTargets(TargetType.test).then(targets => {
141+
void folder.swiftPackage.getTargets(TargetType.test).then(targets => {
142142
if (targets.length === 0) {
143143
return;
144144
}
@@ -149,7 +149,7 @@ export class TestExplorer {
149149
if (
150150
!configuration.folder(folder.workspaceFolder).disableAutoResolve
151151
) {
152-
folder.testExplorer?.discoverTestsInWorkspace(
152+
void folder.testExplorer?.discoverTestsInWorkspace(
153153
tokenSource.token
154154
);
155155
}
@@ -158,7 +158,7 @@ export class TestExplorer {
158158
break;
159159
case FolderOperation.packageUpdated:
160160
if (folder) {
161-
folder.swiftPackage.getTargets(TargetType.test).then(targets => {
161+
void folder.swiftPackage.getTargets(TargetType.test).then(targets => {
162162
const hasTestTargets = targets.length > 0;
163163
if (hasTestTargets && !folder.hasTestExplorer()) {
164164
folder.addTestExplorer();
@@ -168,7 +168,7 @@ export class TestExplorer {
168168
!configuration.folder(folder.workspaceFolder)
169169
.disableAutoResolve
170170
) {
171-
folder.testExplorer?.discoverTestsInWorkspace(
171+
void folder.testExplorer?.discoverTestsInWorkspace(
172172
tokenSource.token
173173
);
174174
}
@@ -219,7 +219,7 @@ export class TestExplorer {
219219
const testExplorer = folder?.testExplorer;
220220
if (testExplorer && symbols && uri && uri.scheme === "file") {
221221
if (isPathInsidePath(uri.fsPath, folder.folder.fsPath)) {
222-
folder.swiftPackage.getTarget(uri.fsPath).then(target => {
222+
void folder.swiftPackage.getTarget(uri.fsPath).then(target => {
223223
if (target && target.type === "test") {
224224
testExplorer.lspTestDiscovery
225225
.getDocumentTests(folder.swiftPackage, uri)

src/TestExplorer/TestParsers/SwiftTestingOutputParser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ export class SwiftTestingOutputParser {
211211

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

214-
reader.start(readlinePipe);
214+
await reader.start(readlinePipe);
215215
}
216216

217217
/**

src/TestExplorer/TestRunner.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,7 @@ export class TestRunner {
729729
// discarded. If the test run has already started this is a no-op so its safe to call it multiple times.
730730
this.testRun.testRunStarted();
731731

732-
this.swiftTestOutputParser.close();
732+
await this.swiftTestOutputParser.close();
733733
}
734734
} finally {
735735
outputStream.end();
@@ -807,7 +807,7 @@ export class TestRunner {
807807
}
808808
});
809809

810-
this.folderContext.taskQueue.queueOperation(
810+
void this.folderContext.taskQueue.queueOperation(
811811
new TaskOperation(task),
812812
this.testRun.token
813813
);

src/WorkspaceContext.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ export class WorkspaceContext implements vscode.Disposable {
133133
break;
134134
case FolderOperation.focus:
135135
this.updateContextKeys(event.folder);
136-
this.updateContextKeysForFile();
136+
void this.updateContextKeysForFile();
137137
break;
138138
case FolderOperation.unfocus:
139139
this.updateContextKeys(event.folder);
@@ -232,7 +232,7 @@ export class WorkspaceContext implements vscode.Disposable {
232232
return;
233233
}
234234

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

257257
if (this.currentFolder) {
258258
const languageClient = this.languageClientManager.get(this.currentFolder);
259-
languageClient.useLanguageClient(async client => {
259+
await languageClient.useLanguageClient(async client => {
260260
const experimentalCaps = client.initializeResult?.capabilities.experimental;
261261
if (!experimentalCaps) {
262262
contextKeys.supportsReindexing = false;
@@ -296,7 +296,7 @@ export class WorkspaceContext implements vscode.Disposable {
296296
console.log("Trying to run onDidChangeWorkspaceFolders on deleted context");
297297
return;
298298
}
299-
this.onDidChangeWorkspaceFolders(event);
299+
void this.onDidChangeWorkspaceFolders(event);
300300
});
301301
// add event listener for when the active edited text document changes
302302
const onDidChangeActiveWindow = vscode.window.onDidChangeActiveTextEditor(async editor => {
@@ -327,7 +327,7 @@ export class WorkspaceContext implements vscode.Disposable {
327327
await this.focusFolder(null);
328328
}
329329
}
330-
this.initialisationComplete();
330+
await this.initialisationComplete();
331331
}
332332

333333
/**
@@ -450,7 +450,7 @@ export class WorkspaceContext implements vscode.Disposable {
450450
// if current folder is this folder send unfocus event by setting
451451
// current folder to undefined
452452
if (this.currentFolder === folder) {
453-
this.focusFolder(null);
453+
await this.focusFolder(null);
454454
}
455455
// run observer functions in reverse order when removing
456456
const observersReversed = [...this.observers];
@@ -519,10 +519,10 @@ export class WorkspaceContext implements vscode.Disposable {
519519
}
520520
}
521521

522-
private initialisationComplete() {
522+
private async initialisationComplete() {
523523
this.initialisationFinished = true;
524524
if (this.lastFocusUri) {
525-
this.focusUri(this.lastFocusUri);
525+
await this.focusUri(this.lastFocusUri);
526526
this.lastFocusUri = undefined;
527527
}
528528
}

src/commands/createNewProject.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export async function createNewProject(toolchain: SwiftToolchain | undefined): P
3030
// run before the Swift extension is activated. Show the toolchain error notification in
3131
// this case.
3232
if (!toolchain) {
33-
showToolchainError();
33+
void showToolchainError();
3434
return;
3535
}
3636

src/commands/dependencies/edit.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export async function editDependency(identifier: string, ctx: WorkspaceContext)
4747
);
4848

4949
if (success) {
50-
ctx.fireEvent(currentFolder, FolderOperation.resolvedUpdated);
50+
await ctx.fireEvent(currentFolder, FolderOperation.resolvedUpdated);
5151
// add folder to workspace
5252
const index = vscode.workspace.workspaceFolders?.length ?? 0;
5353
vscode.workspace.updateWorkspaceFolders(index, 0, {

src/commands/dependencies/unedit.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ async function uneditFolderDependency(
6060
);
6161
await folder.taskQueue.queueOperation(uneditOperation);
6262

63-
ctx.fireEvent(folder, FolderOperation.resolvedUpdated);
63+
await ctx.fireEvent(folder, FolderOperation.resolvedUpdated);
6464
// find workspace folder, and check folder still exists
6565
const folderIndex = vscode.workspace.workspaceFolders?.findIndex(
6666
item => item.name === identifier

src/commands/dependencies/updateDepViewList.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ import { FolderOperation, WorkspaceContext } from "../../WorkspaceContext";
1818
export function updateDependenciesViewList(ctx: WorkspaceContext, flatList: boolean) {
1919
if (ctx.currentFolder) {
2020
contextKeys.flatDependenciesList = flatList;
21-
ctx.fireEvent(ctx.currentFolder, FolderOperation.packageViewUpdated);
21+
void ctx.fireEvent(ctx.currentFolder, FolderOperation.packageViewUpdated);
2222
}
2323
}

src/commands/dependencies/useLocal.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export async function useLocalDependency(
7373
true
7474
);
7575
if (success) {
76-
ctx.fireEvent(currentFolder, FolderOperation.resolvedUpdated);
76+
await ctx.fireEvent(currentFolder, FolderOperation.resolvedUpdated);
7777
}
7878
return success;
7979
}

src/commands/insertFunctionComment.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@ export async function insertFunctionComment(workspaceContext: WorkspaceContext)
2626
return;
2727
}
2828
const line = activeEditor.selection.active.line;
29-
workspaceContext.commentCompletionProvider.insert(activeEditor, line);
29+
await workspaceContext.commentCompletionProvider.insert(activeEditor, line);
3030
}

src/commands/testMultipleTimes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export async function runTestMultipleTimes(
7171
break;
7272
}
7373
}
74-
runner.testRun.end();
74+
await runner.testRun.end();
7575

7676
return runStates;
7777
}

src/commands/utilities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,6 @@ export function updateAfterError(result: boolean, folderContext: FolderContext)
7171
folderContext.hasResolveErrors = !result;
7272

7373
if (triggerResolvedUpdatedEvent && !folderContext.hasResolveErrors) {
74-
folderContext.fireEvent(FolderOperation.resolvedUpdated);
74+
void folderContext.fireEvent(FolderOperation.resolvedUpdated);
7575
}
7676
}

src/configuration.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ export function handleConfigurationChangeEvent(
532532
event.affectsConfiguration("swift.path") &&
533533
configuration.path !== ctx.currentFolder?.toolchain.swiftFolderPath
534534
) {
535-
showReloadExtensionNotification(
535+
void showReloadExtensionNotification(
536536
"Changing the Swift path requires Visual Studio Code be reloaded."
537537
);
538538
} else if (
@@ -542,7 +542,7 @@ export function handleConfigurationChangeEvent(
542542
) {
543543
vscode.commands.executeCommand("swift.restartLSPServer");
544544
} else if (event.affectsConfiguration("swift.swiftEnvironmentVariables")) {
545-
showReloadExtensionNotification(
545+
void showReloadExtensionNotification(
546546
"Changing environment variables requires the project be reloaded."
547547
);
548548
}

src/coverage/LcovResults.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export class TestCoverage {
8888
this.coverageDetails.set(uri, detailedCoverage);
8989
}
9090
}
91-
this.lcovTmpFiles.dispose();
91+
await this.lcovTmpFiles.dispose();
9292
}
9393

9494
/**

0 commit comments

Comments
 (0)