Skip to content
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

Open
feross opened this issue Apr 13, 2017 · 4 comments

Comments

@feross
Copy link
Member

commented Apr 13, 2017

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 write return 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.

Array.from
Array.prototype.every
Array.prototype.filter
Array.prototype.find
Array.prototype.findIndex
Array.prototype.map
Array.prototype.reduce
Array.prototype.reduceRight
Array.prototype.some
Array.prototype.sort

https://github.com/eslint/eslint/blob/master/docs/rules/array-callback-return.md

@feross feross added the enhancement label Apr 13, 2017

@dcousens

This comment has been minimized.

Copy link
Member

commented Apr 13, 2017

Yes.

@dcousens

This comment has been minimized.

Copy link
Member

commented Apr 13, 2017

Though, I have used .some in the past to short-circuit a forEach loop

@feross

This comment has been minimized.

Copy link
Member Author

commented Apr 13, 2017

@dcousens It's fine to use .some in that way. You're still using return in the function callback right?

@dcousens

This comment has been minimized.

Copy link
Member

commented Apr 14, 2017

If we forget to write return statement in a callback of those, it's probably a mistake.

I misread it as if we forget to write return statement for those, indeed, you are right 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
2 participants
You can’t perform that action at this time.