Skip to content

Commit 53dc7c1

Browse files
SamVerschuerensindresorhus
authored andcommitted
Fix no-fn-reference-in-iterator to support static Promise methods (#126)
1 parent 265b734 commit 53dc7c1

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

docs/rules/no-fn-reference-in-iterator.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,3 +165,9 @@ const fn = x => x === 2;
165165

166166
[1, 2, 3].map(x => m({foo: 'bar'})(x));
167167
```
168+
169+
```js
170+
const fn = x => x === 2;
171+
172+
Promise.map(filenames, fn);
173+
```

rules/no-fn-reference-in-iterator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const fix = (context, node) => {
3030
};
3131

3232
const create = context => ({
33-
CallExpression: node => {
33+
'CallExpression[callee.object.name!="Promise"]': node => {
3434
if (isIteratorMethod(node) && hasFunctionArgument(node)) {
3535
const arg = node.arguments[0];
3636

test/no-fn-reference-in-iterator.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ ruleTester.run('no-fn-reference-in-iterator', rule, {
2929
'foo.map(x => parseInt(x, 10))',
3030
'foo.map(x => m({foo: true})(x))',
3131
'foo.reduce((a, b) => a + b, 0)',
32-
'foo.reduceRight((a, b) => a.concat(b), [])'
32+
'foo.reduceRight((a, b) => a.concat(b), [])',
33+
'Promise.map(fn)',
34+
'Promise.forEach(fn)'
3335
],
3436
invalid: [
3537
{

0 commit comments

Comments
 (0)