Skip to content

Commit 50aa757

Browse files
authored
fix: fixed hooks-extra/no-unnecessary-use-prefix case sensitivity fails, closes #1053 (#1054)
1 parent 83c9903 commit 50aa757

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/**
2+
* Catch all identifiers that begin with "use" followed by an uppercase Latin
3+
* character to exclude identifiers like "user".
4+
* @param name The name of the identifier to check.
5+
* @see https://github.com/facebook/react/blob/1d6c8168db1d82713202e842df3167787ffa00ed/packages/eslint-plugin-react-hooks/src/rules/RulesOfHooks.ts#L16
6+
*/
17
export function isReactHookName(name: string) {
2-
return name.startsWith("use");
8+
return name === "use" || /^use[A-Z0-9]/.test(name);
39
}

packages/plugins/eslint-plugin-react-hooks-extra/src/rules/no-unnecessary-use-prefix.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@ ruleTester.run(RULE_NAME, rule, {
141141
// Allow empty functions.
142142
const useNoop = () => {};
143143
`,
144+
tsx`
145+
export const userInitials = () => {
146+
return;
147+
};
148+
`,
144149
tsx`
145150
import { useState } from "react";
146151
@@ -155,6 +160,11 @@ ruleTester.run(RULE_NAME, rule, {
155160
return useSWR(key);
156161
}
157162
`,
163+
tsx`
164+
const useData = (key) => {
165+
return swr.useSWR(key);
166+
}
167+
`,
158168
tsx`
159169
function useData(key) {
160170
return useSWR(key);

0 commit comments

Comments
 (0)