Skip to content

Commit dae5107

Browse files
authored
no-fn-reference-in-iterator: Ignore cases obviously not a function reference (#697)
1 parent 47f2246 commit dae5107

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,6 @@ const ignoredCalleeSelector = `${ignoredCallee.map(name => toSelector(name)).joi
7272
function check(context, node, method, options) {
7373
const {type} = node;
7474

75-
if (type === 'FunctionExpression' || type === 'ArrowFunctionExpression') {
76-
return;
77-
}
78-
7975
const name = type === 'Identifier' ? node.name : '';
8076

8177
if (type === 'Identifier' && options.ignore.includes(name)) {
@@ -122,6 +118,15 @@ function check(context, node, method, options) {
122118
context.report(problem);
123119
}
124120

121+
const ignoredFirstArgumentSelector = `:not(${
122+
[
123+
'[arguments.0.type="FunctionExpression"]',
124+
'[arguments.0.type="ArrowFunctionExpression"]',
125+
'[arguments.0.type="Literal"]',
126+
'[arguments.0.type="Identifier"][arguments.0.name="undefined"]'
127+
].join(',')
128+
})`;
129+
125130
const create = context => {
126131
const sourceCode = context.getSourceCode();
127132
const rules = {};
@@ -133,7 +138,8 @@ const create = context => {
133138
min: 1,
134139
max: 2
135140
}),
136-
ignoredCalleeSelector
141+
ignoredCalleeSelector,
142+
ignoredFirstArgumentSelector
137143
].join('');
138144
rules[selector] = node => {
139145
const [iterator] = node.arguments;

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,17 @@ ruleTester.run('no-fn-reference-in-iterator', rule, {
8383
'_.map(fn)',
8484
'Async.map(list, fn)',
8585
'async.map(list, fn)',
86-
'React.children.forEach(children, fn)'
86+
'React.children.forEach(children, fn)',
87+
88+
// Ignored
89+
'foo.map(() => {})',
90+
'foo.map(function() {})',
91+
'foo.map(function bar() {})',
92+
'foo.map("string")',
93+
'foo.map(null)',
94+
'foo.map(1)',
95+
'foo.map(true)',
96+
'foo.map(undefined)'
8797
],
8898
invalid: [
8999
// Suggestions

0 commit comments

Comments
 (0)