Skip to content

Commit e63a769

Browse files
refactor: add no-floating-promises rule (#338)
* refactor: add no-floating-promises rule and fix linting errors that appeared * refactor: use void for storage * refactor: wait for activation in tests * refactor: await deactivating * refactor: remove void * refactor: remove one more void
1 parent 8d53bc0 commit e63a769

36 files changed

+199
-196
lines changed

.eslintrc.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ module.exports = {
4848
'restrict-template-expressions': 0,
4949
'@typescript-eslint/restrict-template-expressions': 0,
5050

51+
'@typescript-eslint/no-floating-promises': 2,
52+
5153
// VV These rules we'd like to turn off one day so they error.
5254
'@typescript-eslint/no-unsafe-assignment': 0,
5355
'@typescript-eslint/no-unsafe-member-access': 0,

src/commands/launchMongoShell.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ const openMongoDBShell = (connectionController: ConnectionController): Promise<b
9595
if (
9696
!connectionController.isCurrentlyConnected()
9797
) {
98-
vscode.window.showErrorMessage(
98+
void vscode.window.showErrorMessage(
9999
'You need to be connected before launching the MongoDB Shell.'
100100
);
101101

@@ -106,15 +106,15 @@ const openMongoDBShell = (connectionController: ConnectionController): Promise<b
106106
const shellCommand: string | undefined = vscode.workspace.getConfiguration('mdb').get('shell');
107107

108108
if (!userShell) {
109-
vscode.window.showErrorMessage(
109+
void vscode.window.showErrorMessage(
110110
'Error: No shell found, please set your default shell environment in vscode.'
111111
);
112112

113113
return Promise.resolve(false);
114114
}
115115

116116
if (!shellCommand) {
117-
vscode.window.showErrorMessage(
117+
void vscode.window.showErrorMessage(
118118
'No MongoDB shell command found. Please set the shell command in the MongoDB extension settings.'
119119
);
120120
return Promise.resolve(false);

src/connectionController.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ export default class ConnectionController {
210210
try {
211211
return this.addNewConnectionStringAndConnect(connectionString);
212212
} catch (error) {
213-
vscode.window.showErrorMessage(error.message);
213+
void vscode.window.showErrorMessage(error.message);
214214

215215
return false;
216216
}
@@ -244,7 +244,7 @@ export default class ConnectionController {
244244
connectionModel: ConnectionModel,
245245
connectionType: ConnectionTypes
246246
): void {
247-
this._telemetryService.trackNewConnection(
247+
void this._telemetryService.trackNewConnection(
248248
newDataService.client.client,
249249
connectionModel,
250250
connectionType
@@ -323,7 +323,7 @@ export default class ConnectionController {
323323
connectionId,
324324
connectionInfoAsString
325325
);
326-
this._storageController.storeNewConnection(newLoadedConnection);
326+
void this._storageController.storeNewConnection(newLoadedConnection);
327327
}
328328

329329
return this.connect(connectionId, connectionModel, connectionType);
@@ -412,7 +412,7 @@ export default class ConnectionController {
412412
}
413413

414414
log.info('Successfully connected');
415-
vscode.window.showInformationMessage('MongoDB connection successful.');
415+
void vscode.window.showInformationMessage('MongoDB connection successful.');
416416

417417
this._activeDataService = newDataService;
418418
this._activeConnectionModel = connectionModel;
@@ -449,7 +449,7 @@ export default class ConnectionController {
449449
: savedConnectionModel
450450
);
451451
} catch (error) {
452-
vscode.window.showErrorMessage(`Unable to load connection: ${error}`);
452+
void vscode.window.showErrorMessage(`Unable to load connection: ${error}`);
453453

454454
return false;
455455
}
@@ -463,7 +463,7 @@ export default class ConnectionController {
463463

464464
return connectResult.successfullyConnected;
465465
} catch (error) {
466-
vscode.window.showErrorMessage(error.message);
466+
void vscode.window.showErrorMessage(error.message);
467467

468468
return false;
469469
}
@@ -476,7 +476,7 @@ export default class ConnectionController {
476476
);
477477

478478
if (!this._activeDataService) {
479-
vscode.window.showErrorMessage(
479+
void vscode.window.showErrorMessage(
480480
'Unable to disconnect: no active connection.'
481481
);
482482

@@ -502,10 +502,10 @@ export default class ConnectionController {
502502

503503
try {
504504
await _disconnect();
505-
vscode.window.showInformationMessage('MongoDB disconnected.');
505+
void vscode.window.showInformationMessage('MongoDB disconnected.');
506506
} catch (error) {
507507
// Show an error, however we still reset the active connection to free up the extension.
508-
vscode.window.showErrorMessage(
508+
void vscode.window.showErrorMessage(
509509
'An error occured while disconnecting from the current connection.'
510510
);
511511
}
@@ -533,7 +533,7 @@ export default class ConnectionController {
533533
async removeMongoDBConnection(connectionId: string): Promise<boolean> {
534534
if (!this._connections[connectionId]) {
535535
// No active connection(s) to remove.
536-
vscode.window.showErrorMessage('Connection does not exist.');
536+
void vscode.window.showErrorMessage('Connection does not exist.');
537537

538538
return false;
539539
}
@@ -559,7 +559,7 @@ export default class ConnectionController {
559559

560560
await this.removeSavedConnection(connectionId);
561561

562-
vscode.window.showInformationMessage('MongoDB connection removed.');
562+
void vscode.window.showInformationMessage('MongoDB connection removed.');
563563

564564
return true;
565565
}
@@ -571,7 +571,7 @@ export default class ConnectionController {
571571

572572
if (connectionIds.length === 0) {
573573
// No active connection(s) to remove.
574-
vscode.window.showErrorMessage('No connections to remove.');
574+
void vscode.window.showErrorMessage('No connections to remove.');
575575

576576
return false;
577577
}

src/editors/collectionDocumentsProvider.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ implements vscode.TextDocumentContentProvider {
4545
const operationId = uriParams.get(OPERATION_ID_URI_IDENTIFIER);
4646

4747
if (!operationId) {
48-
vscode.window.showErrorMessage(
48+
void vscode.window.showErrorMessage(
4949
'Unable to list documents: invalid operation'
5050
);
5151

@@ -58,7 +58,7 @@ implements vscode.TextDocumentContentProvider {
5858
// Ensure we're still connected to the correct connection.
5959
if (connectionId !== this._connectionController.getActiveConnectionId()) {
6060
operation.isCurrentlyFetchingMoreDocuments = false;
61-
vscode.window.showErrorMessage(
61+
void vscode.window.showErrorMessage(
6262
`Unable to list documents: no longer connected to ${connectionId}`
6363
);
6464

@@ -74,7 +74,7 @@ implements vscode.TextDocumentContentProvider {
7474
if (dataservice === null) {
7575
const errorMessage = `Unable to list documents: no longer connected to ${connectionId}`;
7676

77-
vscode.window.showErrorMessage(errorMessage);
77+
void vscode.window.showErrorMessage(errorMessage);
7878

7979
throw new Error(errorMessage);
8080
}
@@ -108,7 +108,7 @@ implements vscode.TextDocumentContentProvider {
108108
const printableError = error as { message: string };
109109
const errorMessage = `Unable to list documents: ${printableError.message}`;
110110

111-
vscode.window.showErrorMessage(errorMessage);
111+
void vscode.window.showErrorMessage(errorMessage);
112112

113113
throw Error(errorMessage);
114114
}

src/editors/editorsController.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ export default class EditorsController {
121121
)) as EJSON.SerializableTypes;
122122

123123
if (mdbDocument === null) {
124-
vscode.window.showErrorMessage(`
124+
void vscode.window.showErrorMessage(`
125125
Unable to open mongodb document: document ${JSON.stringify(data.documentId)} not found
126126
`);
127127

@@ -148,7 +148,7 @@ export default class EditorsController {
148148
} catch (error) {
149149
const printableError = error as { message: string };
150150

151-
vscode.window.showErrorMessage(printableError.message);
151+
void vscode.window.showErrorMessage(printableError.message);
152152

153153
return false;
154154
}
@@ -196,17 +196,17 @@ export default class EditorsController {
196196
});
197197

198198
// Save document changes to active editor.
199-
activeEditor?.document.save();
199+
await activeEditor?.document.save();
200200

201-
vscode.window.showInformationMessage(
201+
void vscode.window.showInformationMessage(
202202
`The document was saved successfully to '${namespace}'`
203203
);
204204

205205
return true;
206206
} catch (error) {
207207
const printableError = error as { message: string };
208208

209-
vscode.window.showErrorMessage(printableError.message);
209+
void vscode.window.showErrorMessage(printableError.message);
210210

211211
return false;
212212
}
@@ -251,7 +251,7 @@ export default class EditorsController {
251251
} catch (error) {
252252
const printableError = error as { message: string };
253253

254-
vscode.window.showErrorMessage(
254+
void vscode.window.showErrorMessage(
255255
`Unable to open documents: ${printableError.message}`
256256
);
257257

@@ -272,7 +272,7 @@ export default class EditorsController {
272272
this._collectionDocumentsOperationsStore.operations[operationId]
273273
.isCurrentlyFetchingMoreDocuments
274274
) {
275-
vscode.window.showErrorMessage(
275+
void vscode.window.showErrorMessage(
276276
'Already fetching more documents...'
277277
);
278278

@@ -281,7 +281,7 @@ export default class EditorsController {
281281

282282
// Ensure we're still connected to the correct connection.
283283
if (connectionId !== this._connectionController.getActiveConnectionId()) {
284-
vscode.window.showErrorMessage(
284+
void vscode.window.showErrorMessage(
285285
`Unable to view more documents: no longer connected to ${connectionId}`
286286
);
287287

src/editors/playgroundController.ts

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,7 @@ export default class PlaygroundController {
9999
this._connectionController.addEventListener(
100100
DataServiceEventTypes.ACTIVE_CONNECTION_CHANGED,
101101
() => {
102-
this._disconnectFromServiceProvider();
103-
}
104-
);
105-
106-
this._connectionController.addEventListener(
107-
DataServiceEventTypes.ACTIVE_CONNECTION_CHANGED,
108-
() => {
109-
this._connectToServiceProvider();
102+
void this._connectToServiceProvider();
110103
}
111104
);
112105

@@ -140,7 +133,7 @@ export default class PlaygroundController {
140133
.map((selection) => this._getSelectedText(selection))
141134
.join('\n');
142135

143-
this._showCodeLensForSelection(
136+
void this._showCodeLensForSelection(
144137
sortedSelections,
145138
changeEvent.textEditor
146139
);
@@ -173,7 +166,7 @@ export default class PlaygroundController {
173166
lastSelection.end.line === editor.document.lineCount - 1 &&
174167
lastSelectedLineContent.trim().length > 0
175168
) {
176-
editor.edit(edit => {
169+
void editor.edit(edit => {
177170
edit.insert(
178171
new vscode.Position(lastSelection.end.line + 1, 0),
179172
'\n'
@@ -190,10 +183,6 @@ export default class PlaygroundController {
190183
);
191184
}
192185

193-
_disconnectFromServiceProvider(): void {
194-
this._languageServerController.disconnectFromServiceProvider();
195-
}
196-
197186
async _connectToServiceProvider(): Promise<void> {
198187
await this._languageServerController.disconnectFromServiceProvider();
199188

@@ -246,7 +235,7 @@ export default class PlaygroundController {
246235
} catch (error) {
247236
const printableError = error as { message: string };
248237

249-
vscode.window.showErrorMessage(
238+
void vscode.window.showErrorMessage(
250239
`Unable to create a playground: ${printableError.message}`
251240
);
252241

@@ -323,7 +312,7 @@ export default class PlaygroundController {
323312
} catch (error) {
324313
const printableError = error as { message: string };
325314

326-
vscode.window.showErrorMessage(
315+
void vscode.window.showErrorMessage(
327316
`Unable to create a playground: ${printableError.message}`
328317
);
329318

@@ -455,7 +444,7 @@ export default class PlaygroundController {
455444
} catch (error) {
456445
const printableError = error as { message: string };
457446

458-
vscode.window.showErrorMessage(
447+
void vscode.window.showErrorMessage(
459448
`Unable to open a result document: ${printableError.message}`
460449
);
461450
}
@@ -467,7 +456,7 @@ export default class PlaygroundController {
467456
.get('confirmRunAll');
468457

469458
if (!this._connectionController.isCurrentlyConnected()) {
470-
vscode.window.showErrorMessage(
459+
void vscode.window.showErrorMessage(
471460
'Please connect to a database before running a playground.'
472461
);
473462

@@ -508,7 +497,8 @@ export default class PlaygroundController {
508497

509498
this._playgroundResult = evaluateResponse.result;
510499

511-
await this._explorerController.refresh();
500+
this._explorerController.refresh();
501+
512502
await this._openPlaygroundResult();
513503

514504
return true;
@@ -519,7 +509,7 @@ export default class PlaygroundController {
519509
!this._activeTextEditor ||
520510
this._activeTextEditor.document.languageId !== 'mongodb'
521511
) {
522-
vscode.window.showErrorMessage(
512+
void vscode.window.showErrorMessage(
523513
"Please open a '.mongodb' playground file before running it."
524514
);
525515

@@ -533,7 +523,7 @@ export default class PlaygroundController {
533523
!Array.isArray(selections) ||
534524
(selections.length === 1 && this._getSelectedText(selections[0]) === '')
535525
) {
536-
vscode.window.showInformationMessage(
526+
void vscode.window.showInformationMessage(
537527
'Please select one or more lines in the playground.'
538528
);
539529

@@ -551,7 +541,7 @@ export default class PlaygroundController {
551541
!this._activeTextEditor ||
552542
this._activeTextEditor.document.languageId !== 'mongodb'
553543
) {
554-
vscode.window.showErrorMessage(
544+
void vscode.window.showErrorMessage(
555545
"Please open a '.mongodb' playground file before running it."
556546
);
557547

@@ -569,7 +559,7 @@ export default class PlaygroundController {
569559
!this._activeTextEditor ||
570560
this._activeTextEditor.document.languageId !== 'mongodb'
571561
) {
572-
vscode.window.showErrorMessage(
562+
void vscode.window.showErrorMessage(
573563
"Please open a '.mongodb' playground file before running it."
574564
);
575565

@@ -603,7 +593,7 @@ export default class PlaygroundController {
603593
} catch (error) {
604594
const printableError = error as { message: string };
605595

606-
vscode.window.showErrorMessage(
596+
void vscode.window.showErrorMessage(
607597
`Unable to open a playground: ${printableError.message}`
608598
);
609599

src/explorer/collectionTreeItem.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,9 +388,10 @@ export default class CollectionTreeItem extends vscode.TreeItem
388388
`${this.databaseName}.${collectionName}`,
389389
(err: Error | null, successfullyDroppedCollection = false) => {
390390
if (err) {
391-
vscode.window.showErrorMessage(
391+
void vscode.window.showErrorMessage(
392392
`Drop collection failed: ${err.message}`
393393
);
394+
394395
return resolve(false);
395396
}
396397

src/explorer/connectionTreeItem.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,8 @@ export default class ConnectionTreeItem extends vscode.TreeItem
249249
() => resolve(true),
250250
(err) => {
251251
this.isExpanded = false;
252-
vscode.window.showErrorMessage(err);
252+
void vscode.window.showErrorMessage(err);
253+
253254
return resolve(false);
254255
}
255256
);

0 commit comments

Comments
 (0)