eslint/array-callback-return Pedantic β
What it does β
Enforce return statements in callbacks of array methods
Why is this bad? β
Array has several methods for filtering, mapping, and folding. If we forget to write return statement in a callback of those, itβs probably a mistake. If you donβt want to use a return or donβt need the returned results, consider using .forEach instead.
Examples β
Examples of incorrect code for this rule:
let foo = [1, 2, 3, 4];
foo.map((a) => {
console.log(a);
});
Examples of correct code for this rule:
let foo = [1, 2, 3, 4];
foo.map((a) => {
console.log(a);
return a;
});
Configuration β
This rule accepts a configuration object with the following properties:
allowImplicitReturn β
type: boolean
default: false
When set to true, allows callbacks of methods that require a return value to implicitly return undefined with a return statement containing no expression.
checkForEach β
type: boolean
default: false
When set to true, rule will also report forEach callbacks that return a value.
How to use β
To enable this rule in the CLI or using the config file, you can use:
oxlint --deny array-callback-return
{
"rules": {
"array-callback-return": "error"
}
}