Skip to content

Commit

Permalink
test(linter): add more tests fo rules-of-hooks (#7683)
Browse files Browse the repository at this point in the history
closes #6651
  • Loading branch information
camc314 committed Dec 5, 2024
1 parent 1925ddc commit be9863a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
8 changes: 7 additions & 1 deletion crates/oxc_linter/src/rules/react/rules_of_hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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![
Expand Down Expand Up @@ -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();
Expand Down
6 changes: 6 additions & 0 deletions crates/oxc_linter/src/snapshots/react_rules_of_hooks.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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(); });
· ───
╰────

0 comments on commit be9863a

Please sign in to comment.