-
-
Notifications
You must be signed in to change notification settings - Fork 412
no-array-reduce
- enable reporting of optional chaining and calling of .reduce()
#2721
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
Conversation
no-array-reduce
- add test cases for optional reduceno-array-reduce
- enable reporting of optional chaining and calling of .reduce()
@@ -12,6 +12,8 @@ test({ | |||
'a[b.reduce]()', | |||
'a(b.reduce)', | |||
'a.reduce()', | |||
'a?.reduce()', | |||
'a.reduce?.()', |
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.
It doesn't make sense to allow optional call.
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.
Added it because I saw it in no-array-sort
and no-array-reverse
🤷♂️
https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/test/no-array-sort.js#L14
https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/test/no-array-reverse.js#L14
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.
They are valid cases in these two rules, and they both use optionalCall: false,
optionalCall: false, |
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.
I mean a?.reduce()
should be invalid, but a.reduce?.()
should be valid.
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.
Sorry, I comment this in a misleading place, I mean L112
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.
I don't understand, sorry :(
Why one should be valid and another invalid? I thought this rule finds usages of reduce
, and reports it (except trivial callback cases, if corresponding option is provided). Why reporting of a?.reduce()
should be different to a.reduce?.()
and a.reduce()
?
Or array.reduce((str, item) => str += item, "")
different to array?.reduce((str, item) => str += item, "")
and array.reduce?.((str, item) => str += item, "")
if we talk about L112?
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.
Because it's doesn't make sense to check Array#reduce
, if user using foo.reduce?.()
then foo
can be a non-array
object.
Explained in this commit 8240f4f
(#2721)
@sindresorhus I plan to go through all rules to check if |
Fixes #2720
This PR enables checking for optionally chainged
.reduce()
calls forno-array-reduce
rule.