test(linter): add more tests fo rules-of-hooks (#7683)

closes #6651
This commit is contained in:
camc314 2024-12-05 15:18:14 +00:00
parent 1925ddc59b
commit be9863a415
2 changed files with 13 additions and 1 deletions

View file

@ -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();

View file

@ -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(); });
· ───
╰────