array-callback-return should check forEach
See original GitHub issueWhat rule do you want to change? array-callback-return
Does this change cause the rule to produce more or fewer warnings? more
How will the change be implemented? (New option, new default behavior, etc.)? new default behavior
Please provide some example code that this change will affect:
[
"abc",
"def"
].forEach((word) => {
"use strict";
return word;
});
What does the rule currently do for this code? Pass
What will the rule do after it’s changed? Warn that the forEach callback potentially returns a value
Are you willing to submit a pull request to implement this change? Yes
Issue Analytics
- State:
- Created 4 years ago
- Reactions:4
- Comments:8 (6 by maintainers)
Top Results From Across the Web
array-callback-return - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >Where does the return value go for a forEach callback?
If you are testing the array elements for a predicate and need a Boolean return value, you can use every() or some() instead....
Read more >Array.prototype.forEach() - JavaScript - MDN Web Docs
The forEach() method is an iterative method. It calls a provided callbackFn function once for each element in an array in ascending-index order....
Read more >JavaScript Array.forEach() Tutorial – How to Iterate Through ...
In JavaScript, you'll often need to iterate through an array collection and execute a callback method for each iteration.
Read more >How to Return a Value From a forEach Loop - Mastering JS
You can't make JavaScript's forEach() function return a custom value. Using return in a forEach() is equivalent to a continue in a ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ll champion this. While this would be a change of scope, I agree that this is in the spirit of the rule and is useful. I don’t think we should create another rule for this.
That being said, I think this has to go behind an option that is turned off by default and that we should make it the default behavior in a future major release.
This is now accepted.