diff --git a/crates/oxc_linter/src/rules/react/rules_of_hooks.rs b/crates/oxc_linter/src/rules/react/rules_of_hooks.rs index dbdf678a8..6a719a89d 100644 --- a/crates/oxc_linter/src/rules/react/rules_of_hooks.rs +++ b/crates/oxc_linter/src/rules/react/rules_of_hooks.rs @@ -943,7 +943,11 @@ fn test() { const useSWRFn = immutable ? useSWRImutable : useSWR; return useSWRFn(options ? () => ['cloud', options.query.id, options.variables] : null, options ? () => fetcher(options) : null, configWithSuspense); - };" + };", + // https://github.com/oxc-project/oxc/issues/6651 + r"const MyComponent = makeComponent(() => { useHook(); });", + r"const MyComponent2 = makeComponent(function () { useHook(); });", + r"const MyComponent4 = makeComponent(function InnerComponent() { useHook(); });" ]; let fail = vec![ @@ -1577,6 +1581,8 @@ fn test() { // }); // } // " , + // https://github.com/oxc-project/oxc/issues/6651 + r"const MyComponent3 = makeComponent(function foo () { useHook(); });", ]; Tester::new(RulesOfHooks::NAME, RulesOfHooks::CATEGORY, pass, fail).test_and_snapshot(); diff --git a/crates/oxc_linter/src/snapshots/react_rules_of_hooks.snap b/crates/oxc_linter/src/snapshots/react_rules_of_hooks.snap index e918a449a..de971c984 100644 --- a/crates/oxc_linter/src/snapshots/react_rules_of_hooks.snap +++ b/crates/oxc_linter/src/snapshots/react_rules_of_hooks.snap @@ -674,3 +674,9 @@ source: crates/oxc_linter/src/tester.rs · ─────────── 5 │ } ╰──── + + ⚠ eslint-plugin-react-hooks(rules-of-hooks): React Hook "useHook" is called in function "foo" that is neither a React function component nor a custom React Hook function. React component names must start with an uppercase letter. React Hook names must start with the word "use". + ╭─[rules_of_hooks.tsx:1:45] + 1 │ const MyComponent3 = makeComponent(function foo () { useHook(); }); + · ─── + ╰────