Skip to content

Commit 8367286

Browse files
committed
fix: Mark JSXIdentifier has missing dependency
1 parent 032dc52 commit 8367286

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

packages/eslint-plugin-react-hooks/__tests__/ESLintRuleExhaustiveDeps-test.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7947,13 +7947,31 @@ const testsTypescriptEslintParserV4 = {
79477947
// It doesn't use any explicit types but any JS is still valid TS.
79487948
{
79497949
code: normalizeIndent`
7950-
export const Foo = ({ Component }) => {
7950+
function Foo({ Component }) {
79517951
React.useEffect(() => {
79527952
console.log(<Component />);
79537953
}, []);
79547954
};
79557955
`,
7956-
errors: [{message: ''}],
7956+
errors: [
7957+
{
7958+
message:
7959+
"React Hook React.useEffect has a missing dependency: 'Component'. " +
7960+
'Either include it or remove the dependency array.',
7961+
suggestions: [
7962+
{
7963+
desc: 'Update the dependencies array to be: [Component]',
7964+
output: normalizeIndent`
7965+
function Foo({ Component }) {
7966+
React.useEffect(() => {
7967+
console.log(<Component />);
7968+
}, [Component]);
7969+
};
7970+
`,
7971+
},
7972+
],
7973+
},
7974+
],
79577975
},
79587976
],
79597977
};

packages/eslint-plugin-react-hooks/src/ExhaustiveDeps.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1622,7 +1622,7 @@ function markNode(node, optionalChains, result) {
16221622
* Otherwise throw.
16231623
*/
16241624
function analyzePropertyChain(node, optionalChains) {
1625-
if (node.type === 'Identifier') {
1625+
if (node.type === 'Identifier' || node.type === 'JSXIdentifier') {
16261626
const result = node.name;
16271627
if (optionalChains) {
16281628
// Mark as required.
@@ -1779,7 +1779,7 @@ function isNodeLike(val) {
17791779

17801780
function isSameIdentifier(a, b) {
17811781
return (
1782-
a.type === 'Identifier' &&
1782+
(a.type === 'Identifier' || a.type === 'JSXIdentifier') &&
17831783
a.name === b.name &&
17841784
a.range[0] === b.range[0] &&
17851785
a.range[1] === b.range[1]

0 commit comments

Comments
 (0)