Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion packages/core/src/hook/hook-name.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/**
* Catch all identifiers that begin with "use" followed by an uppercase Latin
* character to exclude identifiers like "user".
* @param name The name of the identifier to check.
* @see https://github.com/facebook/react/blob/1d6c8168db1d82713202e842df3167787ffa00ed/packages/eslint-plugin-react-hooks/src/rules/RulesOfHooks.ts#L16
*/
export function isReactHookName(name: string) {
return name.startsWith("use");
return name === "use" || /^use[A-Z0-9]/.test(name);
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ ruleTester.run(RULE_NAME, rule, {
// Allow empty functions.
const useNoop = () => {};
`,
tsx`
export const userInitials = () => {
return;
};
`,
tsx`
import { useState } from "react";

Expand All @@ -155,6 +160,11 @@ ruleTester.run(RULE_NAME, rule, {
return useSWR(key);
}
`,
tsx`
const useData = (key) => {
return swr.useSWR(key);
}
`,
tsx`
function useData(key) {
return useSWR(key);
Expand Down