-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enforces return statements in callbacks of array's methods (array-callback-return) #859
Comments
Yes. |
|
@dcousens It's fine to use |
I misread it as |
About 7% ecosystem effect:
Examples of failures that I think are good errors to report: const tuples = this.stringTuples().filter((tuple) => {
if (tuple[0] === protocols.names.ipfs.code) {
return true
}
}) tuples.map(tup => {
const proto = protoFromTuple(tup)
parts.push(proto.name)
if (tup.length > 1) {
parts.push(tup[1])
}
}) More marginal cases where more explicitness doesn't hurt: keys.some(function (key, i) {
tasks[key](function (err, result) { each(key, err, result) })
if (i === limit - 1) return true // early return
}) input.some(item => {
if (typeof item === 'string') {
opts.name = corePath.basename(item)
return true
} else if (!item.unknownName) {
opts.name = item.path[item.path.length - 1]
return true
}
}) |
ESLint just promoted this rule to their 'eslint:recommended' rule set, so it's probably pretty reliable. I want to check how much of the ecosystem this effects and consider enabling it.
Array
has several methods for filtering, mapping, and folding. If we forget to writereturn
statement in a callback of those, it's probably a mistake.This rule enforces usage of
return
statement in callbacks of array's methods.This rule finds callback functions of the following methods, then checks usage of return statement.
https://github.com/eslint/eslint/blob/master/docs/rules/array-callback-return.md
The text was updated successfully, but these errors were encountered: