The callback of an array method that uses its result never returns one
What it finds
const names = users.map(user => { user.name; }): the callback of map, filter, find, reduce, sort or another array method that uses its result never returns a value, so the method works with undefined and its result is not what was meant.
Only callbacks with a block body and parameters, whose result the code goes on to use, are reported: when the result is discarded, the call is a loop written with the wrong method, and a callback without parameters or with an empty body returns undefined on purpose. Async and generator callbacks return a promise or an iterator in any case. Callbacks that return a value on some paths only are not reported, since an implicit undefined there is often meant, as for a map whose result is filtered afterwards. The rule is recommended rather than on by default because a method of the same name on another type may expect nothing back.
From the rule's source, array_callback_return.rs.
function names(users: { name: string }[], log: (x: unknown) => void) { const all = users.map(user => {tx0 reports: this callback of map never returns a value user.name.trim(); }); const admins = users.filter(function (user) {tx0 reports: this callback of filter never returns a value log(user); }); users.map(user => { log(user); }); const empty = users.map(() => {}); const some = users.map(user => { if (user.name) { return user.name; } }); const sorted = users.sort((a, b) => a.name.localeCompare(b.name)); const copies = Array.from(users, user => {tx0 reports: this callback of from never returns a value log(user); }); const promises = users.map(async user => { await log(user); }); return [all, admins, empty, some, sorted, copies, promises];} Turn it on, off or suppress it
The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/ts:array-callback-return" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/ts:array-callback-return] reason="..."tx0 explain tx0/ts:array-callback-return shows the same in the terminal. Found a false positive? Report it.