-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
Update: array-callback-return checks Array.forEach (fixes #12551) #12646
Conversation
updated PR description with required information |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gabrieldrs thanks for the PR! Left a couple of notes where I believe we should change the approach.
In general, this option should report any return value
from forEach
. I believe it should also report implicit returns from arrow functions.
Fill free to ask if you have any questions!
1b8f1f7
to
fd5023e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we document/test how the two options interact? Or should they be mutually exclusive? i.e. what happens when the rule is configured as { checkForEach: true, allowImplicit: false }
?
I think they shouldn't be mutually exclusive, and, at the same time, one should not effect the other, in the sense that setting allowImplicit should not change the behaviour of checkForEach, and vice versa. I will create tests with both options set to ensure this. |
@gabrieldrs That makes sense to me! I think we'll just need to update the documentation for |
That makes sense to me, too. I think that this rule shouldn't disallow Also, |
8afba9a
to
7e6c585
Compare
ed33f8e
to
8b3dd07
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the changes, this looks good in general! I left some notes, mostly about the documentation and tests.
IMHO, no need to add the option, just make it as default behavior -- a breaking change in ESLint v7. thoughts? @mdjermanovic @kaicataldo |
It's always better imo to add an option in a minor, and then flip the default in a major - that also gives users a super easy way to bypass the breakages and more easily upgrade. |
emm...yes, a tradeoff! the dark side is: it added complexity, but I didn't see how it's useful -- returning a value in |
There are many people who intentionally omit the curly braces in forEach, knowing the return value is ignored, and would not want warnings there. I'm not one of those people, nor hopefully is anyone touching any code I have to work with, but these people do exist :-) |
If someone doesn't want this for some reason (e.g., because of implicit arrow functions or something else may appear), the only choice for them would be to completely turn off the rule and thus lose the current default behavior. So it might be safe to start with an option and see from the feedback is there a need for additional options to tweak this option (i.e. options of the option), and those options would stay when we eventually remove this one. |
8b3dd07
to
d8649b7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Left just a couple of notes.
d8649b7
to
58b1c34
Compare
58b1c34
to
ffe1985
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a couple of minor details, otherwise this looks really great!
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 <[email protected]>
ffe1985
to
b6adcae
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! All details are covered well (and that includes details from the previous behavior since this change required a redesign of the existing code).
Thanks for the great work, @gabrieldrs!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks for sticking with all the feedback!
Thanks for contributing to ESLint! |
… (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 <[email protected]>
What is the purpose of this pull request? (put an "X" next to item)
[x] Changes an existing rule
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 option checkForEach created, defaulted to false. when true, rule will also check if Array.forEach callback has a return statement and warn if it does
Please provide some example code that this change will affect:
Examples of incorrect code for the
{ "checkForEach": true }
option:Examples of correct code for the
{ "checkForEach": true }
option:What does the rule currently do for this code?
doesn't check
What will the rule do after it's changed?
check if Array.forEach callback has a return statement and warn if it does
What changes did you make? (Give an overview)
added
checkForEach
option which enables/disables the new rule checkIs there anything you'd like reviewers to focus on?