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
Add no-reduce
rule
#704
Add no-reduce
rule
#704
Conversation
This is failing on existing e.g const bar = {
reduce() {
console.log('foo');
}
}
bar.reduce(); This will also fail. I don't think we can get type info in JS. Let me know! |
No, we can't know what |
Should I try and check the argument of |
@sindresorhus Forbid |
+1
…On Mon, May 4, 2020 at 11:55 PM fisker Cheung ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In test/no-reduce.js
<#704 (comment)>
:
> + var arr = [1,2,3];
+ const sum = (s, i) => s + i;
+ Array.prototype.reduce.call(arr, sum);
I think this var sum are useless for tests, how about just Array.prototype.reduce.call(arr,
sum);, WDYT?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#704 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABSYHF3LEUWBB3E2UIFSMLLRP4CC3ANCNFSM4MXD2PKQ>
.
--
*Ankeet Maini*
*"Just when the caterpillar thought the world was over, it became a
butterfly!"*
|
rules/no-reduce.js
Outdated
|
||
const METHOD_SELECTOR = [ | ||
methodSelector({name: 'reduce', min: 1, max: 2}), | ||
'[callee.object.property.name!="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.
why?
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 fails some tests if this is removed
a.b.call.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.
But a.b.call
should be a array, otherwise there is no reduce
method.
Let's add |
let result = []; | ||
|
||
for (const items of combinations) { | ||
const {length} = items; | ||
const index = indexRemaining % length; | ||
indexRemaining = (indexRemaining - index) / length; | ||
return [items[index], ...combination]; | ||
}, []); | ||
result = [...result, items[index]]; | ||
} | ||
|
||
return result; |
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 bad.
@@ -14,12 +14,16 @@ module.exports = (combinations, length = Infinity) => { | |||
|
|||
const samples = Array.from({length: Math.min(total, length)}, (_, sampleIndex) => { | |||
let indexRemaining = sampleIndex; | |||
return combinations.reduceRight((combination, items) => { | |||
const combination = []; | |||
for (let i = combinations.length - 1; i >= 0; i--) { |
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.
How to loop forward, if you interest https://github.com/fisker/fast-cartesian-product/blob/master/src/algorithms/calculate-from-index.js#L14
Personally, I use a But since we can't tell what the function is doing, we have to report on all the I guess I won't use this rule. Anyway, we are ready to merge. |
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.
@ankeetmaini Thank you for working on this!
Thank you to you too for improving this PR! :) |
Fixes #623