Skip to content

Commit 7018c1f

Browse files
authored
fix(plugins/x): 'no-array-index-key' mistaking 'foo.bar.map' for 'React.Children.map' method, fixes #860 (#868)
1 parent 7dc9d64 commit 7018c1f

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

packages/plugins/eslint-plugin-react-x/src/rules/no-array-index-key.spec.ts

+4
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,10 @@ ruleTester.run(RULE_NAME, rule, {
237237
`,
238238
errors: [{ messageId: "noArrayIndexKey" }],
239239
},
240+
{
241+
code: /* tsx */ `foo.bar.map((value, index) => <MyComponent key={index} />);`,
242+
errors: [{ messageId: "noArrayIndexKey" }],
243+
},
240244
],
241245
valid: [
242246
...allValid,

packages/plugins/eslint-plugin-react-x/src/rules/no-array-index-key.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ function isUsingReactChildren(node: TSESTree.CallExpression, context: RuleContex
6868
const initialScope = context.sourceCode.getScope(node);
6969
if (callee.object.type === AST_NODE_TYPES.Identifier && callee.object.name === "Children") return true;
7070
if (callee.object.type === AST_NODE_TYPES.MemberExpression && "name" in callee.object.object) {
71-
return isInitializedFromReact(callee.object.object.name, initialScope, settings);
71+
return isInitializedFromReact(callee.object.object.name, initialScope, { ...settings, strictImportCheck: true });
7272
}
7373
return false;
7474
}

0 commit comments

Comments
 (0)