Add eslint warning for unawaited async functions

pull/256/head
Candid Dauth 2024-03-15 23:28:15 +01:00
rodzic 26753061a7
commit b42e54245d
28 zmienionych plików z 55 dodań i 53 usunięć

Wyświetl plik

@ -40,6 +40,7 @@ module.exports = {
"@typescript-eslint/no-base-to-string": ["error"],
"@typescript-eslint/no-misused-promises": ["error", { checksVoidReturn: false }],
"vue/return-in-computed-property": ["off"],
"@typescript-eslint/no-floating-promises": ["error"],
"constructor-super": ["error"],
"for-direction": ["error"],

Wyświetl plik

@ -111,7 +111,7 @@ export default class Client {
this.on(i, this._handlers[i] as EventHandler<ClientEvents, typeof i>);
}
Promise.resolve().then(() => {
void Promise.resolve().then(() => {
this._simulateEvent("loadStart");
});

Wyświetl plik

@ -57,7 +57,7 @@
function handleMapDrop(event: Event): void {
event.preventDefault();
importFiles((event as DragEvent).dataTransfer?.files);
void importFiles((event as DragEvent).dataTransfer?.files);
}
async function importFiles(fileList: FileList | undefined): Promise<void> {

Wyświetl plik

@ -242,7 +242,7 @@ function useSelectionHandler(map: Ref<Map>, context: FacilMapContext, mapContext
});
selectionHandler.on("fmLongClick", (event: any) => {
context.components.clickMarkerTab?.openClickMarker({ lat: event.latlng.lat, lon: event.latlng.lng });
void context.components.clickMarkerTab?.openClickMarker({ lat: event.latlng.lat, lon: event.latlng.lng });
});
return selectionHandler;

Wyświetl plik

@ -109,8 +109,8 @@
toasts.showToast(`fm${context.id}-line-info-move`, `Edit waypoints`, "Use the routing form or drag the line around to change it. Click “Finish” to save the changes.", {
noCloseButton: true,
actions: [
{ label: "Finish", variant: "primary", onClick: () => { done(true); }},
{ label: "Cancel", onClick: () => { done(false); } }
{ label: "Finish", variant: "primary", onClick: () => { void done(true); }},
{ label: "Cancel", onClick: () => { void done(false); } }
]
});

Wyświetl plik

@ -140,7 +140,7 @@
draggable.on({
insert: (e: any) => {
destinations.value.splice(e.idx, 0, makeCoordDestination(e.latlng));
reroute(false);
void reroute(false);
},
dragstart: (e: any) => {
hoverDestinationIdx.value = e.idx;
@ -153,12 +153,12 @@
}, 300),
dragend: (e: any) => {
destinations.value[e.idx] = makeCoordDestination(e.to);
reroute(false);
void reroute(false);
},
remove: (e: any) => {
hoverDestinationIdx.value = undefined;
destinations.value.splice(e.idx, 1);
reroute(false);
void reroute(false);
},
dragmouseover: (e: any) => {
destinationMouseOver(e.idx);
@ -227,7 +227,7 @@
});
watch(routeMode, () => {
reroute(false);
void reroute(false);
});
function addDestination(): void {
@ -388,7 +388,7 @@
const marker = routeLayer._draggableLines?.dragMarkers[idx];
if (marker) {
Promise.resolve().then(() => {
void Promise.resolve().then(() => {
// If mouseout event is directly followed by a dragend event, the marker will be removed. Only update the icon if the marker is not removed.
if (marker["_map"])
marker.setIcon(getIcon(idx, routeLayer._draggableLines!.dragMarkers.length));
@ -456,7 +456,7 @@
const points = destinations.value.map((dest) => getSelectedSuggestion(dest));
if(!points.some((point) => point == null))
route(zoom, smooth);
await route(zoom, smooth);
}
}
@ -485,7 +485,7 @@
function handleSubmit(event: Event): void {
submitButton.value?.focus();
route(true);
void route(true);
}
const linesWithTags = computed((): LineWithTags[] | undefined => routeObj.value && [{
@ -504,22 +504,22 @@
while (destinations.value.length < 2)
destinations.value.push({ query: "" });
routeMode.value = split.mode ?? "car";
route(zoom, smooth);
void route(zoom, smooth);
}
function setFrom(data: Parameters<typeof makeDestination>[0]): void {
destinations.value[0] = makeDestination(data);
reroute(true);
void reroute(true);
}
function addVia(data: Parameters<typeof makeDestination>[0]): void {
destinations.value.splice(destinations.value.length - 1, 0, makeDestination(data));
reroute(true);
void reroute(true);
}
function setTo(data: Parameters<typeof makeDestination>[0]): void {
destinations.value[destinations.value.length - 1] = makeDestination(data);
reroute(true);
void reroute(true);
}
defineExpose({ setQuery, setFrom, addVia, setTo });

Wyświetl plik

@ -48,13 +48,13 @@
restoreHeight.value = undefined;
if (expand) {
nextTick(() => {
void nextTick(() => {
doExpand();
});
}
if (autofocus && !context.isNarrow) {
nextTick(() => {
void nextTick(() => {
containerRef.value?.querySelector<HTMLElement>(":scope > .card-body.active [autofocus],:scope > .card-body.active .fm-autofocus")?.focus();
});
}

Wyświetl plik

@ -68,7 +68,7 @@
function handleSubmit(): void {
searchInput.value?.blur();
search(storage.autoZoom, storage.zoomToAll);
void search(storage.autoZoom, storage.zoomToAll);
}
async function search(zoom: boolean, zoomToAll?: boolean, smooth = true): Promise<void> {

Wyświetl plik

@ -27,7 +27,7 @@
await sleep(0); // For some reason this is necessary for the dropdown to close itself
drawMarker(type, context, toasts);
} else if(type.type == "line") {
drawLine(type, context, toasts);
await drawLine(type, context, toasts);
}
}
</script>

Wyświetl plik

@ -66,7 +66,7 @@
const newVal = arrowNavigation(colours, value.value, gridRef.value, event);
if (newVal) {
emit('update:modelValue', newVal);
nextTick(() => {
void nextTick(() => {
(gridRef.value?.querySelector(".active a") as HTMLAnchorElement | undefined)?.focus();
});
}

Wyświetl plik

@ -54,7 +54,7 @@
const newVal = arrowNavigation(Object.keys(items), props.modelValue, gridRef.value!.containerRef!, event);
if (newVal) {
emit("update:modelValue", newVal);
nextTick(() => {
void nextTick(() => {
gridRef.value?.containerRef?.querySelector<HTMLElement>(".active > a")?.focus();
});
}

Wyświetl plik

@ -79,12 +79,12 @@
try {
const res = callback(...args);
Promise.resolve(res).catch((err) => {
result.showErrorToast(undefined, 'Unexpected error', err);
void result.showErrorToast(undefined, 'Unexpected error', err);
throw err;
});
return res;
} catch (err: any) {
result.showErrorToast(undefined, 'Unexpected error', err);
void result.showErrorToast(undefined, 'Unexpected error', err);
}
}) as C;
},
@ -92,7 +92,7 @@
showToast: async (id, title, message, options = {}) => {
await appMountP;
if (id != null) {
result.hideToast(id);
void result.hideToast(id);
}
const toast: ToastInstance = { ...options, key: getUniqueId("fm-toast"), id, title, message, contextId };

Wyświetl plik

@ -33,7 +33,7 @@
function resolveValidationResult(results: ValidationResult[], signal: AbortSignal): AsyncValidationResult {
return new Promise<SyncValidationResult>((resolve, reject) => {
for (const result of results) {
Promise.resolve(result).then((res) => {
void Promise.resolve(result).then((res) => {
if (res) {
resolve(res);
}

Wyświetl plik

@ -71,7 +71,7 @@
if (validationPromises.get(element) !== promise) {
validationPromises.set(element, promise);
isValidating.set(element, true);
promise.finally(() => {
void promise.finally(() => {
if (validationPromises.get(element) === promise) {
isValidating.set(element, false);
}
@ -90,7 +90,7 @@
useDomEventListener(formRef, "submit", (e) => {
e.preventDefault();
data.submit();
void data.submit();
});
allForms.set(formRef, data);

Wyświetl plik

@ -73,13 +73,13 @@ export function moveMarker(markerId: ID, context: FacilMapContext, toasts: Toast
label: "Save",
variant: "primary",
onClick: () => {
finish(true);
void finish(true);
}
},
{
label: "Cancel",
onClick: () => {
finish(false);
void finish(false);
}
}
]

Wyświetl plik

@ -41,17 +41,15 @@ function load(): void {
}
}
function save() {
async function save() {
try {
const currentItem = JSON.parse(localStorage.getItem("facilmap") || "null");
if (!currentItem || !isEqual(currentItem, storage)) {
localStorage.setItem("facilmap", JSON.stringify(storage));
if (storage.bookmarks.length > 0 && !isEqual(currentItem?.bookmarks, storage.bookmarks) && navigator.storage?.persist)
navigator.storage.persist();
await navigator.storage.persist();
}
} catch (err) {
console.error("Error saving to local storage", err);
}

Wyświetl plik

@ -61,6 +61,7 @@ export const extendableEventMixin: ExtendableEventMixin = {
} else if (this._promises) {
this._promises.push(promise);
} else {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
this._promises = [promise];
}
},

Wyświetl plik

@ -14,8 +14,11 @@ if (import.meta.hot) {
});
}
if ('serviceWorker' in navigator && location.hostname !== "localhost")
navigator.serviceWorker.register('./_app/static/sw.js', { scope: "./" });
if ('serviceWorker' in navigator && location.hostname !== "localhost") {
navigator.serviceWorker.register('./_app/static/sw.js', { scope: "./" }).catch((err) => {
console.error("Error registering service worker", err);
});
}
setLayerOptions({
limaLabsToken: config.limaLabsToken

Wyświetl plik

@ -36,7 +36,7 @@ export default class BboxHandler extends Handler {
this._map.unproject(pixelBounds.getBottomLeft(), zoom),
this._map.unproject(pixelBounds.getTopRight(), zoom)
);
this.client.updateBbox(leafletToFmBbox(bounds ?? this._map.getBounds(), zoom ?? this._map.getZoom()));
void this.client.updateBbox(leafletToFmBbox(bounds ?? this._map.getBounds(), zoom ?? this._map.getZoom()));
}
handleMoveEnd = (): void => {

Wyświetl plik

@ -107,7 +107,7 @@ export default class LinesLayer extends FeatureGroup {
protected handleMoveEnd = (): void => {
// Rerender all lines to recall disconnectSegmentsOutsideViewport()
// Run it on next tick because the renderers need to run first
Promise.resolve().then(() => {
void Promise.resolve().then(() => {
const lastMapBounds = this.lastMapBounds;
const mapBounds = this.lastMapBounds = this._map.getBounds();
for(const lineId of numberKeys(this.client.lines)) {
@ -209,7 +209,7 @@ export default class LinesLayer extends FeatureGroup {
const handleClick = (pos: Point) => {
handler = undefined;
if(routePoints.length > 0 && pos.lon == routePoints[routePoints.length-1].lon && pos.lat == routePoints[routePoints.length-1].lat)
finishLine(true);
void finishLine(true);
else
addPoint(pos);
}

Wyświetl plik

@ -59,7 +59,7 @@ export default class OverpassLayer extends FeatureGroup {
}
onAdd(): this {
this.redraw();
void this.redraw();
return this;
}
@ -73,7 +73,7 @@ export default class OverpassLayer extends FeatureGroup {
setQuery(query?: string | ReadonlyArray<Readonly<OverpassPreset>>): void {
this._query = query;
this.redraw();
void this.redraw();
this.fire("setQuery", { query });
if (this.isEmpty())

Wyświetl plik

@ -29,7 +29,7 @@ export default class RouteDragHandler extends DraggableLines {
const routePoints = (e.layer as Polyline).getDraggableLinesRoutePoints();
if (routePoints) {
this.client.setRoute({
void this.client.setRoute({
...route,
routePoints: routePoints.map((p) => ({ lat: p.lat, lon: p.lng }))
});

Wyświetl plik

@ -327,8 +327,7 @@ export class AsyncIcon extends Icon {
this._asyncIconUrl.then((url) => {
this.options.iconUrl = url;
delete this._asyncIconUrl;
});
this._asyncIconUrl.catch((err) => {
}).catch((err) => {
console.error("Error loading async icon", err);
});
}
@ -341,7 +340,7 @@ export class AsyncIcon extends Icon {
icon._fmIconAbortController?.abort();
const abortController = new AbortController();
icon._fmIconAbortController = abortController;
this._asyncIconUrl.then((url) => {
void this._asyncIconUrl.then((url) => {
if (!icon._fmIconAbortController!.signal.aborted) {
icon.setAttribute("src", url);
}

Wyświetl plik

@ -61,7 +61,7 @@ export default class DatabaseRoutes {
async afterConnect(): Promise<void> {
// Delete all route points, clients will have to reconnect and recalculate their routes anyways
this.RoutePointModel.truncate();
await this.RoutePointModel.truncate();
}
async getRoutePoints(routeId: string, bboxWithZoom?: BboxWithZoom & BboxWithExcept, getCompleteBasicRoute = false): Promise<TrackPoint[]> {

Wyświetl plik

@ -18,7 +18,7 @@ export function exportCsv(
const stringifier = stringify();
stringifier.write(tabular.fields);
tabular.objects.pipeTo(Writable.toWeb(stringifier));
void tabular.objects.pipeTo(Writable.toWeb(stringifier));
return Readable.toWeb(stringifier);
})());

Wyświetl plik

@ -153,7 +153,7 @@ export function exportGpx(database: Database, padId: PadId, useTracks: boolean,
export function exportGpxZip(database: Database, padId: PadId, useTracks: boolean, filter?: string): ReadableStream<Uint8Array> {
const encodeZipStream = getZipEncodeStream();
asyncIteratorToStream((async function*(): AsyncIterable<ZipEncodeStreamItem> {
void asyncIteratorToStream((async function*(): AsyncIterable<ZipEncodeStreamItem> {
const filterFunc = compileExpression(filter);
const [padData, types] = await Promise.all([

Wyświetl plik

@ -80,7 +80,7 @@ export function flatMapStream<T, O>(stream: ReadableStream<T>, mapper: (it: T) =
}
}
});
stream.pipeTo(transform.writable);
void stream.pipeTo(transform.writable);
return transform.readable;
}

Wyświetl plik

@ -105,7 +105,7 @@ export async function initWebserver(database: Database, port: number, host?: str
res.set("Content-type", "application/gpx+xml");
res.attachment(`${getSafeFilename(normalizePadName(padData.name))}.gpx`);
exportGpx(database, padData ? padData.id : req.params.padId, query.useTracks == "1", query.filter).pipeTo(Writable.toWeb(res));
void exportGpx(database, padData ? padData.id : req.params.padId, query.useTracks == "1", query.filter).pipeTo(Writable.toWeb(res));
});
app.get("/:padId/gpx/zip", async (req: Request<{ padId: string }>, res: Response<string>) => {
@ -121,7 +121,7 @@ export async function initWebserver(database: Database, port: number, host?: str
res.set("Content-type", "application/zip");
res.attachment(padData.name.replace(/[\\/:*?"<>|]+/g, '_') + ".zip");
exportGpxZip(database, padData ? padData.id : req.params.padId, query.useTracks == "1", query.filter).pipeTo(Writable.toWeb(res));
void exportGpxZip(database, padData ? padData.id : req.params.padId, query.useTracks == "1", query.filter).pipeTo(Writable.toWeb(res));
});
app.get("/:padId/table", async (req: Request<{ padId: string }>, res: Response<string>) => {
@ -132,7 +132,7 @@ export async function initWebserver(database: Database, port: number, host?: str
res.type("html");
res.setHeader("Referrer-Policy", "origin");
createTable(
void createTable(
database,
req.params.padId,
query.filter,
@ -149,7 +149,7 @@ export async function initWebserver(database: Database, port: number, host?: str
res.type("html");
res.setHeader("Referrer-Policy", "origin");
createSingleTable(
void createSingleTable(
database,
req.params.padId,
typeId,