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
array-callback-return should check forEach #12551
Comments
Thanks for this issue. Can you provide more information or context to tell us the intention of this change? |
From the documentation for the rule
It is probably a mistake for callbacks of the forEach method to return values (since forEach does not use the result). If you want to use a return or need the returned result, consider using forEach / map confusion is not uncommon. The rule checks one direction (map used when forEach was more appropriate) but not the other direction (forEach used when map is more appropriate) |
However, this rule warns if you forget to return something when using those methods which accept callback, while you want to propose about |
There are two questions you can ask:
since
The name |
The name of the rule suggests it should handle both cases - it’s just only doing half its job right now. An option to check the inverse case on forEach seems ideal. |
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. |
array-callback-return rule now checks if Array.forEach returns a value, and, if it does, reports an error. This feature is being added disabled by default, and can be enabled by setting the option "checkForEach" to true. Signed-off-by: Gabriel R Sezefredo <g@briel.dev>
array-callback-return rule now checks if Array.forEach returns a value, and, if it does, reports an error. This feature is being added disabled by default, and can be enabled by setting the option "checkForEach" to true. Signed-off-by: Gabriel R Sezefredo <g@briel.dev>
array-callback-return rule now checks if Array.forEach returns a value, and, if it does, reports an error. This feature is being added disabled by default, and can be enabled by setting the option "checkForEach" to true. Signed-off-by: Gabriel R Sezefredo <g@briel.dev>
array-callback-return rule now checks if Array.forEach returns a value, and, if it does, reports an error. This feature is being added disabled by default, and can be enabled by setting the option "checkForEach" to true. Signed-off-by: Gabriel R Sezefredo <g@briel.dev>
array-callback-return rule now checks if Array.forEach returns a value, and, if it does, reports an error. This feature is being added disabled by default, and can be enabled by setting the option "checkForEach" to true. Signed-off-by: Gabriel R Sezefredo <g@briel.dev>
array-callback-return rule now checks if Array.forEach returns a value, and, if it does, reports an error. This feature is being added disabled by default, and can be enabled by setting the option "checkForEach" to true. Signed-off-by: Gabriel R Sezefredo <g@briel.dev>
PR #12646 |
array-callback-return rule now checks if Array.forEach returns a value, and, if it does, reports an error. This feature is being added disabled by default, and can be enabled by setting the option "checkForEach" to true. Signed-off-by: Gabriel R Sezefredo <g@briel.dev>
array-callback-return rule now checks if Array.forEach returns a value, and, if it does, reports an error. This feature is being added disabled by default, and can be enabled by setting the option "checkForEach" to true. Signed-off-by: Gabriel R Sezefredo <g@briel.dev>
array-callback-return rule now checks if Array.forEach returns a value, and, if it does, reports an error. This feature is being added disabled by default, and can be enabled by setting the option "checkForEach" to true. Signed-off-by: Gabriel R Sezefredo <g@briel.dev>
array-callback-return rule now checks if Array.forEach returns a value, and, if it does, reports an error. This feature is being added disabled by default, and can be enabled by setting the option "checkForEach" to true. Signed-off-by: Gabriel R Sezefredo <g@briel.dev>
array-callback-return rule now checks if Array.forEach returns a value, and, if it does, reports an error. This feature is being added disabled by default, and can be enabled by setting the option "checkForEach" to true. Signed-off-by: Gabriel R Sezefredo <g@briel.dev>
array-callback-return rule now checks if Array.forEach returns a value, and, if it does, reports an error. This feature is being added disabled by default, and can be enabled by setting the option "checkForEach" to true. Signed-off-by: Gabriel R Sezefredo <g@briel.dev>
array-callback-return rule now checks if Array.forEach returns a value, and, if it does, reports an error. This feature is being added disabled by default, and can be enabled by setting the option "checkForEach" to true. Signed-off-by: Gabriel R Sezefredo <g@briel.dev>
array-callback-return rule now checks if Array.forEach returns a value, and, if it does, reports an error. This feature is being added disabled by default, and can be enabled by setting the option "checkForEach" to true. Signed-off-by: Gabriel R Sezefredo <g@briel.dev>
array-callback-return rule now checks if Array.forEach returns a value, and, if it does, reports an error. This feature is being added disabled by default, and can be enabled by setting the option "checkForEach" to true. Signed-off-by: Gabriel R Sezefredo <g@briel.dev>
array-callback-return rule now checks if Array.forEach returns a value, and, if it does, reports an error. This feature is being added disabled by default, and can be enabled by setting the option "checkForEach" to true. Signed-off-by: Gabriel R Sezefredo <g@briel.dev>
array-callback-return rule now checks if Array.forEach returns a value, and, if it does, reports an error. This feature is being added disabled by default, and can be enabled by setting the option "checkForEach" to true. Signed-off-by: Gabriel R Sezefredo <g@briel.dev>
array-callback-return rule now checks if Array.forEach returns a value, and, if it does, reports an error. This feature is being added disabled by default, and can be enabled by setting the option "checkForEach" to true. Signed-off-by: Gabriel R Sezefredo <g@briel.dev>
… (eslint#12646) array-callback-return rule now checks if Array.forEach returns a value, and, if it does, reports an error. This feature is being added disabled by default, and can be enabled by setting the option "checkForEach" to true. Signed-off-by: Gabriel R Sezefredo <g@briel.dev>
What 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:
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
The text was updated successfully, but these errors were encountered: