Skip to content

Commit c6051ca

Browse files
authored
Use the void operator to mark floating promises. (#417)
Even internally, noAwait is now discouraged.
1 parent 696d851 commit c6051ca

File tree

6 files changed

+20
-58
lines changed

6 files changed

+20
-58
lines changed

.eslintrc.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717
"@typescript-eslint/explicit-module-boundary-types": "off",
1818
"@typescript-eslint/no-explicit-any": "error",
1919
"@typescript-eslint/no-non-null-assertion": "off",
20-
// Google internally requires that floating promises are annotated with a
21-
// special function. We use eslint-enable and eslint-disable comments for
22-
// this rule to identify these spots for automated transform on import.
2320
"@typescript-eslint/no-floating-promises": "error"
2421
},
2522
"overrides": [

src/playground-code-editor.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -321,9 +321,7 @@ export class PlaygroundCodeEditor extends LitElement {
321321
// Swapping to a document instance doesn't trigger a change event
322322
// which is required for document folding. Manually fold once on
323323
// document instantiation.
324-
/* eslint-disable @typescript-eslint/no-floating-promises */
325-
this._applyHideAndFoldRegions();
326-
/* eslint-enable @typescript-eslint/no-floating-promises */
324+
void this._applyHideAndFoldRegions();
327325
}
328326
this._valueChangingFromOutside = false;
329327
break;
@@ -356,9 +354,7 @@ export class PlaygroundCodeEditor extends LitElement {
356354
cm.setOption('readOnly', this.readonly);
357355
break;
358356
case 'pragmas':
359-
/* eslint-disable @typescript-eslint/no-floating-promises */
360-
this._applyHideAndFoldRegions();
361-
/* eslint-enable @typescript-eslint/no-floating-promises */
357+
void this._applyHideAndFoldRegions();
362358
break;
363359
case 'diagnostics':
364360
this._showDiagnostics();
@@ -501,9 +497,7 @@ export class PlaygroundCodeEditor extends LitElement {
501497
// file it is displaying.
502498
if (this._valueChangingFromOutside) {
503499
// Users can't change hide/fold regions.
504-
/* eslint-disable @typescript-eslint/no-floating-promises */
505-
this._applyHideAndFoldRegions();
506-
/* eslint-enable @typescript-eslint/no-floating-promises */
500+
void this._applyHideAndFoldRegions();
507501
this._showDiagnostics();
508502
} else {
509503
this.dispatchEvent(new Event('change'));
@@ -738,8 +732,7 @@ export class PlaygroundCodeEditor extends LitElement {
738732
// The detail promise is passed into this function only for the item
739733
// currently highlighted from the completions list.
740734
if (detail !== undefined) {
741-
/* eslint-disable @typescript-eslint/no-floating-promises */
742-
detail.then((detailResult: EditorCompletionDetails) => {
735+
void detail.then((detailResult: EditorCompletionDetails) => {
743736
this._renderCompletionItemWithDetails(
744737
objectName,
745738
detailResult,
@@ -753,7 +746,6 @@ export class PlaygroundCodeEditor extends LitElement {
753746
this._renderHint(element, _data, hint);
754747
this._currentCompletionSelectionLabel = hint.text;
755748
});
756-
/* eslint-enable @typescript-eslint/no-floating-promises */
757749
}
758750
}
759751

src/playground-project.ts

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -308,9 +308,7 @@ export class PlaygroundProject extends LitElement {
308308

309309
override async update(changedProperties: PropertyValues) {
310310
if (changedProperties.has('_source')) {
311-
/* eslint-disable @typescript-eslint/no-floating-promises */
312-
this._loadProjectFromSource();
313-
/* eslint-enable @typescript-eslint/no-floating-promises */
311+
void this._loadProjectFromSource();
314312
}
315313
if (
316314
changedProperties.has('sandboxScope') ||
@@ -362,17 +360,16 @@ export class PlaygroundProject extends LitElement {
362360
this._importMap = importMap;
363361
}
364362
break;
365-
default: // Exhaustive check.
363+
default:
364+
// Exhaustive check.
366365
source as void;
367366
break;
368367
}
369368
this._pristineFiles =
370369
this._files && (JSON.parse(JSON.stringify(this._files)) as SampleFile[]);
371370
this._modified = false;
372371
this.dispatchEvent(new FilesChangedEvent(true));
373-
/* eslint-disable @typescript-eslint/no-floating-promises */
374-
this.save();
375-
/* eslint-enable @typescript-eslint/no-floating-promises */
372+
void this.save();
376373
}
377374

378375
override render() {
@@ -496,14 +493,12 @@ export class PlaygroundProject extends LitElement {
496493
port.removeEventListener('message', onMessage);
497494
if (e.data.version === serviceWorkerHash) {
498495
this._serviceWorkerAPI = wrap<ServiceWorkerAPI>(port);
499-
/* eslint-disable @typescript-eslint/no-floating-promises */
500-
this._serviceWorkerAPI.setFileAPI(
496+
void this._serviceWorkerAPI.setFileAPI(
501497
proxy({
502498
getFile: (name: string) => this._getFile(name),
503499
}),
504500
this._sessionId
505501
);
506-
/* eslint-enable @typescript-eslint/no-floating-promises */
507502
} else {
508503
// Version mismatch. Request the service worker be updated
509504
// immediately. We'll get back here again after it updates via a
@@ -568,13 +563,11 @@ export class PlaygroundProject extends LitElement {
568563
if (build.state() !== 'active') {
569564
return;
570565
}
571-
/* eslint-disable @typescript-eslint/no-floating-promises */
572-
workerApi.compileProject(
566+
void workerApi.compileProject(
573567
this._files ?? [],
574568
{importMap: this._importMap},
575569
proxy((result) => build.onOutput(result))
576570
);
577-
/* eslint-enable @typescript-eslint/no-floating-promises */
578571
await build.stateChange;
579572
if (build.state() !== 'done') {
580573
return;
@@ -688,9 +681,7 @@ export class PlaygroundProject extends LitElement {
688681
// want to be doing any searches.
689682
file.content = newContent;
690683
this._modified = undefined;
691-
/* eslint-disable @typescript-eslint/no-floating-promises */
692-
this.saveDebounced();
693-
/* eslint-enable @typescript-eslint/no-floating-promises */
684+
void this.saveDebounced();
694685
}
695686

696687
addFile(name: string) {
@@ -712,9 +703,7 @@ export class PlaygroundProject extends LitElement {
712703
this._modified = undefined;
713704
this.requestUpdate();
714705
this.dispatchEvent(new FilesChangedEvent());
715-
/* eslint-disable @typescript-eslint/no-floating-promises */
716-
this.save();
717-
/* eslint-enable @typescript-eslint/no-floating-promises */
706+
void this.save();
718707
}
719708

720709
deleteFile(filename: string) {
@@ -728,9 +717,7 @@ export class PlaygroundProject extends LitElement {
728717
this._files = [...this._files.slice(0, idx), ...this._files.slice(idx + 1)];
729718
this._modified = undefined;
730719
this.dispatchEvent(new FilesChangedEvent());
731-
/* eslint-disable @typescript-eslint/no-floating-promises */
732-
this.save();
733-
/* eslint-enable @typescript-eslint/no-floating-promises */
720+
void this.save();
734721
}
735722

736723
renameFile(oldName: string, newName: string) {
@@ -750,9 +737,7 @@ export class PlaygroundProject extends LitElement {
750737
this._files = [...this._files];
751738
this._modified = undefined;
752739
this.dispatchEvent(new FilesChangedEvent());
753-
/* eslint-disable @typescript-eslint/no-floating-promises */
754-
this.save();
755-
/* eslint-enable @typescript-eslint/no-floating-promises */
740+
void this.save();
756741
}
757742
}
758743

src/playground-service-worker-proxy.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ import {
1313
UPDATE_SERVICE_WORKER,
1414
} from './shared/worker-api.js';
1515

16-
/* eslint-disable @typescript-eslint/no-floating-promises */
17-
(async () => {
16+
void (async () => {
1817
try {
1918
// Note we detect same-origin here by actually trying to access the parent
2019
// window. We can't trust the parent to compare the origins of the URLs,
@@ -114,16 +113,12 @@ import {
114113
sw.postMessage(swMessage, [port2]);
115114
};
116115

117-
/* eslint-disable @typescript-eslint/no-floating-promises */
118-
connectToNewest();
119-
/* eslint-enable @typescript-eslint/no-floating-promises */
116+
void connectToNewest();
120117

121118
registration.addEventListener('updatefound', () => {
122119
// We can get a new service worker at any time, so we need to listen for
123120
// updates and connect to new workers on demand.
124-
/* eslint-disable @typescript-eslint/no-floating-promises */
125-
connectToNewest();
126-
/* eslint-enable @typescript-eslint/no-floating-promises */
121+
void connectToNewest();
127122
});
128123

129124
// A message from the service worker.
@@ -143,9 +138,7 @@ import {
143138
// Force required because we usually avoid connecting to a service
144139
// worker we've already connected to, but in this case that's exactly
145140
// what we must do.
146-
/* eslint-disable @typescript-eslint/no-floating-promises */
147-
connectToNewest(true);
148-
/* eslint-enable @typescript-eslint/no-floating-promises */
141+
void connectToNewest(true);
149142
}
150143
}
151144
);
@@ -177,4 +170,3 @@ import {
177170
}
178171
);
179172
})();
180-
/* eslint-enable @typescript-eslint/no-floating-promises */

src/service-worker/playground-service-worker.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,7 @@ const parseScopedUrl = (url: string) => {
151151
const onInstall = () => {
152152
// Force this service worker to become the active service worker, in case
153153
// it's an updated worker and waiting.
154-
/* eslint-disable @typescript-eslint/no-floating-promises */
155-
self.skipWaiting();
156-
/* eslint-enable @typescript-eslint/no-floating-promises */
154+
void self.skipWaiting();
157155
};
158156

159157
const onActivate = (event: ExtendableEvent) => {

src/typescript-worker/util.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ export class MergedAsyncIterables<T> {
3737
);
3838
}
3939
this._numSources++;
40-
/* eslint-disable @typescript-eslint/no-floating-promises */
41-
(async () => {
40+
void (async () => {
4241
for await (const value of iterable) {
4342
// Wait for this value to be emitted before continuing
4443
await new Promise<void>((emitted) => {
@@ -49,7 +48,6 @@ export class MergedAsyncIterables<T> {
4948
this._numSources--;
5049
this._notify?.();
5150
})();
52-
/* eslint-enable @typescript-eslint/no-floating-promises */
5351
}
5452
}
5553

0 commit comments

Comments
 (0)