Skip to content

Commit 26af302

Browse files
committed
fix(linter/exhaustive-deps): check stable value is on lhs of assignment expr (#13815)
we were not checking that the value was assigned to just that it’s parent was an assignment expression
1 parent cb080de commit 26af302

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

crates/oxc_linter/src/rules/react/exhaustive_deps.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,10 +1074,15 @@ fn is_stable_value<'a, 'b>(
10741074
ctx.scoping().get_reference(ident_reference_id).symbol_id().unwrap(),
10751075
)
10761076
.any(|reference| {
1077-
matches!(
1078-
ctx.nodes().parent_kind(reference.node_id()),
1079-
AstKind::AssignmentExpression(_)
1080-
)
1077+
if let AstKind::AssignmentExpression(assignment_expression) =
1078+
ctx.nodes().parent_kind(reference.node_id())
1079+
{
1080+
assignment_expression.left.span().contains_inclusive(
1081+
ctx.nodes().get_node(reference.node_id()).span(),
1082+
)
1083+
} else {
1084+
false
1085+
}
10811086
})
10821087
{
10831088
return true;
@@ -2600,6 +2605,7 @@ fn test() {
26002605
r"function MyComponent(props) { useEffect(() => { console.log((props.foo).bar) }, [props.foo!.bar]) }",
26012606
r"function MyComponent(props) { const external = {}; const y = useMemo(() => { const z = foo<typeof external>(); return z; }, []) }",
26022607
r#"function Test() { const [state, setState] = useState(); useEffect(() => { console.log("state", state); }); }"#,
2608+
"function Test() { const [foo, setFoo] = useState(true); _setFoo = setFoo; useEffect(() => { setFoo(false) }, []); }",
26032609
];
26042610

26052611
let fail = vec![

0 commit comments

Comments
 (0)