Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions crates/oxc_linter/src/rules/react/exhaustive_deps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1226,6 +1226,16 @@ impl<'a, 'b> ExhaustiveDepsVisitor<'a, 'b> {
return None;
};

// Only apply destructuring logic when the identifier is directly the RHS of
// the destructuring assignment, not when it's nested inside another expression
// like a function call.
// For example:
// - `const { headers } = props` -> props.headers is the dependency
// - `const { headers } = fn(booleanValue)` -> booleanValue is the dependency, not booleanValue.headers
if self.stack.contains(&AstType::CallExpression) {
return None;
}

if obj.rest.is_some() {
return Some(true);
}
Expand Down Expand Up @@ -4297,6 +4307,12 @@ fn test() {
"const x = {}; function Comp() { useEffect(() => {}, [x]) }",
"const x = {}; function Comp() { useEffect(() => {}, []) }",
),
// Issue #17159: fixer should suggest `booleanValue`, not `booleanValue.headers`
// The destructuring pattern `{ headers }` should not affect the dependency name
(
"function Comp() { const booleanValue = useMemo(() => true, []); const foo = useMemo(() => { const { headers } = fn(booleanValue); return headers; }, []); }",
"function Comp() { const booleanValue = useMemo(() => true, []); const foo = useMemo(() => { const { headers } = fn(booleanValue); return headers; }, [booleanValue]); }",
),
];

Tester::new(
Expand Down
4 changes: 2 additions & 2 deletions crates/oxc_linter/src/snapshots/react_exhaustive_deps.snap
Original file line number Diff line number Diff line change
Expand Up @@ -700,12 +700,12 @@ source: crates/oxc_linter/src/tester.rs
╰────
help: Either include it or remove the dependency array.

⚠ eslint-plugin-react-hooks(exhaustive-deps): React Hook useEffect has a missing dependency: 'foo.bar'
⚠ eslint-plugin-react-hooks(exhaustive-deps): React Hook useEffect has a missing dependency: 'foo'
╭─[exhaustive_deps.tsx:6:14]
3 │ useEffect(() => {
4 │ const { bar } = foo();
· ─┬─
· ╰── useEffect uses `foo.bar` here
· ╰── useEffect uses `foo` here
5 │ console.log(bar);
6 │ }, [props.foo.bar]);
· ───────────────
Expand Down
Loading