-
Notifications
You must be signed in to change notification settings - Fork 886
no-unnecessary-callback-wrapper: Allow x => x(x)
#2524
no-unnecessary-callback-wrapper: Allow x => x(x)
#2524
Conversation
I disagree with some changes made here. +1 for allowing |
That's technically true... but that would be a pretty cruel place to hide a side effect. Most of the time code is better off evaluating |
Agreed, but that's definitely not the responsibility of this rule. What if the arrow function is not used as callback. It's totally valid to write all functions as arrow function. If that's the case, side effects are expected and it's not just an "unnecessary wrapper" |
OK, I've reverted to only check for identifiers. |
return true; | ||
return isIdentifier(name) && isIdentifier(arg) && name.text === arg.text | ||
// If the invoked expression is one of the parameters, bail. | ||
&& expression.text !== name.text; |
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.
this is the only line that really changed
please consider keeping the diff small and just add this line to the source as it is on master.
Btw. sorry for the rather big refactor and therefore unnecessary big diff in #2510 😕
x => x(x)
Updated changelog entry to reflect what this PR ended up actually doing. |
PR checklist
Overview of change:
#2510 is too simple; there are cases of non-identifier calls that are still an unnecessary callback, like
x => f()(x)
. We can solve #2509 by looking for uses of the parameters in the called expression, so thatx => x(x)
is still not a failure.CHANGELOG.md entry:
[enhancement]
no-unnecessary-callback-wrapper
: Allowx => x(x)