diff --git a/crates/oxc_linter/src/rules/react/exhaustive_deps.rs b/crates/oxc_linter/src/rules/react/exhaustive_deps.rs index 3602b63ec9e09..79d1b7f0193ca 100644 --- a/crates/oxc_linter/src/rules/react/exhaustive_deps.rs +++ b/crates/oxc_linter/src/rules/react/exhaustive_deps.rs @@ -556,11 +556,14 @@ impl Rule for ExhaustiveDeps { } } - ctx.diagnostic(unnecessary_outer_scope_dependency_diagnostic( - hook_name, - &dependency.name, - dependency.span, - )); + ctx.diagnostic_with_fix( + unnecessary_outer_scope_dependency_diagnostic( + hook_name, + &dependency.name, + dependency.span, + ), + |fixer| fix::remove_dependency(fixer, dependency, dependencies_node), + ); } let undeclared_deps = found_dependencies.difference(&declared_dependencies).filter(|dep| { @@ -4197,6 +4200,10 @@ fn test() { "function MyComponent() { const local = {}; useEffect(() => { console.log(local); }, [local, local]); }", "function MyComponent() { const local = {}; useEffect(() => { console.log(local); }, [local]); }", ), + ( + "const x = {}; function Comp() { useEffect(() => {}, [x]) }", + "const x = {}; function Comp() { useEffect(() => {}, []) }", + ), ]; Tester::new(