-
-
Notifications
You must be signed in to change notification settings - Fork 924
Closed
Bug
Copy link
Labels
A-linterArea - LinterArea - Linter
Description
What version of Oxlint are you using?
latest (main branch, commit 553e638)
What command did you run?
oxlint -c .oxlintrc.json
What does your .oxlintrc.json (or oxlint.config.ts) config file look like?
What happened?
When property reads like obj.a and obj.b occur inside an IIFE (Immediately Invoked Function Expression) within a hook callback, oxlint incorrectly reports obj as a missing dependency and obj.a / obj.b as unnecessary. ESLint's react-hooks/exhaustive-deps does not report any error for the same code.
Reproduction:
import { useMemo } from 'react';
function MyComponent({ obj, flag }: { obj: { a: string; b: string }; flag: boolean }) {
return useMemo(() => {
return (() => {
return flag ? obj.a : obj.b;
})();
}, [obj.a, obj.b, flag]);
}oxlint output:
⚠ React Hook useMemo has a missing dependency: 'obj'.
Either include it or remove the dependency array.
⚠ React Hook useMemo has an unnecessary dependency: 'obj.a'.
Either exclude it or remove the dependency array.
⚠ React Hook useMemo has an unnecessary dependency: 'obj.b'.
Either exclude it or remove the dependency array.
Expected: No warnings. [obj.a, obj.b, flag] is the correct dependency array.
The same issue also applies to function expression IIFEs:
function MyComponent({ obj }) {
return useMemo(() => {
return (function() {
return obj.a;
})();
}, [obj.a]);
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-linterArea - LinterArea - Linter
Type
Fields
Give feedbackPriority
None yet
Effort
None yet
{ "plugins": ["react"], "rules": { "react-hooks/exhaustive-deps": "warn" } }