Skip to content

Commit

Permalink
Revert "Fix ExhaustiveDeps ESLint rule throwing with optional chaining (
Browse files Browse the repository at this point in the history
#19260)"

This reverts commit 0f84b0f.
  • Loading branch information
gaearon authored Jul 6, 2020
1 parent c3e42a9 commit 2142f31
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6628,44 +6628,6 @@ const testsTypescript = {
},
],
},
{
// https://github.com/facebook/react/issues/19243
code: normalizeIndent`
function MyComponent() {
const pizza = {};
useEffect(() => ({
crust: pizza.crust,
toppings: pizza?.toppings,
}), []);
}
`,
errors: [
{
message:
"React Hook useEffect has missing dependencies: 'pizza.crust' and 'pizza.toppings'. " +
'Either include them or remove the dependency array.',
suggestions: [
{
// TODO the description and suggestions should probably also
// preserve the optional chaining.
desc:
'Update the dependencies array to be: [pizza.crust, pizza.toppings]',
output: normalizeIndent`
function MyComponent() {
const pizza = {};
useEffect(() => ({
crust: pizza.crust,
toppings: pizza?.toppings,
}), [pizza.crust, pizza.toppings]);
}
`,
},
],
},
],
},
],
};

Expand Down
6 changes: 3 additions & 3 deletions packages/eslint-plugin-react-hooks/src/ExhaustiveDeps.js
Original file line number Diff line number Diff line change
Expand Up @@ -1016,11 +1016,11 @@ export default {
// Is this a variable from top scope?
const topScopeRef = componentScope.set.get(missingDep);
const usedDep = dependencies.get(missingDep);
if (usedDep && usedDep.references[0].resolved !== topScopeRef) {
if (usedDep.references[0].resolved !== topScopeRef) {
return;
}
// Is this a destructured prop?
const def = topScopeRef && topScopeRef.defs[0];
const def = topScopeRef.defs[0];
if (def == null || def.name == null || def.type !== 'Parameter') {
return;
}
Expand Down Expand Up @@ -1062,7 +1062,7 @@ export default {
return;
}
const usedDep = dependencies.get(missingDep);
const references = usedDep ? usedDep.references : [];
const references = usedDep.references;
let id;
let maybeCall;
for (let i = 0; i < references.length; i++) {
Expand Down

0 comments on commit 2142f31

Please sign in to comment.