SKY-Q407 · Quality, structure and performance
Discarded async Array.map result
ids.map(async (id) => ...) used as a statement on its own. map with an async callback returns an array of promises; when nothing keeps that array, nothing waits for the work or sees its errors. Skylos reports it on values it can prove are plain arrays.
- Languages
- TypeScript, JavaScript
- Quality gate
- counted toward the gate limits (full and diff scans)
- Finding type
- defect
Why it matters
The function returns before the notifications are sent, so a caller that reports "done" is wrong, a serverless handler may be frozen with the work half finished, and a failed send becomes an unhandled rejection that can stop a Node.js process.
What Skylos flags
import { sendNotification } from "./push"; export async function notifyAll(userIds: Iterable<string>): Promise<void> { const ids = Array.from(userIds); ids.map(async (id) => { await sendNotification(id); });}What Skylos leaves alone
import { sendNotification } from "./push"; export async function notifyAll(userIds: Iterable<string>): Promise<void> { const ids = Array.from(userIds); const sends = ids.map(async (id) => { await sendNotification(id); }); await Promise.all(sends);}Why Skylos leaves it alone
The array of promises is kept in sends and awaited. Skylos only reports a map result that is thrown away.
More languages
JavaScript
Flagged
import { cache } from "./cache.js"; export async function warmCaches(keys) { const list = Array.from(keys); list.map(async (key) => { await cache.refresh(key); });}Not flagged
import { cache } from "./cache.js"; export async function warmCaches(keys) { const list = Array.from(keys); return Promise.all(list.map(async (key) => cache.refresh(key)));}Why Skylos leaves it alone
The promises are passed to Promise.all and returned, so the caller waits for them and sees any failure.
How Skylos decides
- Runs with
--qualityon.ts,.tsx,.js,.jsx,.mts,.cts,.mjsand.cjsfiles. Generated and minified files, and files that do not parse, are skipped. - Finds
x.map(callback)whose callback isasync: an inlineasyncarrow or function, or a name bound once to one. Async generators do not count. - The receiver must provably be a built-in array, as for SKY-Q406: an array literal, a
constbound to one,new Array(),Array.from(),Array.of()or an array method chain on these, not changed by other code before the call. - The result must be discarded: the call is a statement on its own (also after
void, insidea, bor a ternary or&&chain used as a statement), only its.lengthis read, or it is chained only through.filter(Boolean). Assigning, returning or passing it on counts as using it.await ids.map(...)does not: awaiting an array does not wait for the promises inside it. - Reports HIGH on the line where the call starts.
How to fix it
Await all the promises, or use Promise.allSettled when one failure should not stop the others. To send one at a time, use a for (const id of ids) loop with await.
import { sendNotification } from "./push"; export async function notifyAll(userIds: Iterable<string>): Promise<void> { const ids = Array.from(userIds);Removed: ids.map(async (id) => {Removed: await sendNotification(id);Removed: });Added: await Promise.all(ids.map((id) => sendNotification(id)));}When it can be wrong
- A deliberate fire-and-forget, where each callback catches its own errors and nobody needs to wait, is still reported.
- It misses the same bug on receivers it cannot prove are arrays, such as a parameter typed
string[].
Seeing a case that isn't listed here? Report the wrong result so the rule can be fixed. Don't paste company code: describe the shape of it.
How to silence it
Put the marker on the line where the call starts.
TypeScript ids.map(async (id) => { // skylos: ignore[SKY-Q407] errors handled inside[tool.skylos] ignore = ["SKY-Q407"]turns the rule off for the project.