Skip to content

Commit e5300ed

Browse files
committed
refactor: minor improvements
1 parent adaa264 commit e5300ed

File tree

14 files changed

+65
-57
lines changed

14 files changed

+65
-57
lines changed

examples/vite-react-dom-js-with-babel-eslint-parser-app/eslint.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export default defineConfig([
6767
eslintPluginReactWebApi.configs.recommended,
6868
eslintPluginReactNamingConvention.configs.recommended,
6969
eslintPluginReactRefresh.configs.recommended,
70-
eslintPluginReactDebug.configs.all,
70+
// eslintPluginReactDebug.configs.all,
7171
],
7272
plugins: {
7373
"react-hooks": eslintPluginReactHooks,

packages/core/docs/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@
140140
- [isReactHookCallWithName](functions/isReactHookCallWithName.md)
141141
- [isReactHookCallWithNameAlias](functions/isReactHookCallWithNameAlias.md)
142142
- [isReactHookCallWithNameLoose](functions/isReactHookCallWithNameLoose.md)
143+
- [isReactHookId](functions/isReactHookId.md)
143144
- [isReactHookName](functions/isReactHookName.md)
144145
- [isRenderFunctionLoose](functions/isRenderFunctionLoose.md)
145146
- [isRenderLike](functions/isRenderLike.md)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[**@eslint-react/core**](../README.md)
2+
3+
***
4+
5+
[@eslint-react/core](../README.md) / isReactHookId
6+
7+
# Function: isReactHookId()
8+
9+
> **isReactHookId**(`id`): `boolean`
10+
11+
## Parameters
12+
13+
### id
14+
15+
`Identifier` | `MemberExpression`
16+
17+
## Returns
18+
19+
`boolean`
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import type { TSESTree } from "@typescript-eslint/types";
22
import { AST_NODE_TYPES as T } from "@typescript-eslint/types";
3+
import { isReactHookName } from "./hook-name";
34

4-
export function isReactHookIdentifier(id: TSESTree.Identifier | TSESTree.MemberExpression) {
5+
export function isReactHookId(id: TSESTree.Identifier | TSESTree.MemberExpression) {
56
switch (id.type) {
67
case T.Identifier:
7-
return id.name.startsWith("use");
8+
return isReactHookName(id.name);
89
case T.MemberExpression:
910
return "name" in id.property
10-
&& id.property.name.startsWith("use");
11+
&& isReactHookName(id.property.name);
1112
default:
1213
return false;
1314
}

packages/core/src/hook/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export * from "./hook-collector";
2+
export * from "./hook-id";
23
export * from "./hook-is";
34
export type * from "./hook-kind";
45
export * from "./hook-name";

packages/plugins/eslint-plugin-react-x/src/hooks/use-no-direct-set-state-in-use-effect.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,7 @@ import * as VAR from "@eslint-react/var";
99
import { AST_NODE_TYPES as T } from "@typescript-eslint/types";
1010
import { match } from "ts-pattern";
1111

12-
import {
13-
isFromUseStateCall,
14-
isFunctionOfImmediatelyInvoked,
15-
isSetFunctionCall,
16-
isThenCall,
17-
isVariableDeclaratorFromHookCall,
18-
} from "../utils";
12+
import { isFromUseStateCall, isSetFunctionCall, isVariableDeclaratorFromHookCall } from "../utils";
1913

2014
type CallKind =
2115
| "useEffect"
@@ -93,14 +87,14 @@ export function useNoDirectSetStateInUseEffect<Ctx extends RuleContext>(
9387
.when(isUseStateCall, () => "useState")
9488
.when(isUseEffectLikeCall, () => useEffectKind)
9589
.when(isSetStateCall, () => "setState")
96-
.when(isThenCall, () => "then")
90+
.when(AST.isThenCall, () => "then")
9791
.otherwise(() => "other");
9892
}
9993

10094
function getFunctionKind(node: AST.TSESTreeFunction) {
10195
return match<AST.TSESTreeFunction, FunctionKind>(node)
10296
.when(isFunctionOfUseEffectSetup, () => "setup")
103-
.when(isFunctionOfImmediatelyInvoked, () => "immediate")
97+
.when(AST.isImmediatelyInvokedFunction, () => "immediate")
10498
.otherwise(() => "other");
10599
}
106100

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
export const REACT_BUILD_IN_HOOKS = [
2+
"use",
3+
"useActionState",
4+
"useCallback",
5+
"useContext",
6+
"useDebugValue",
7+
"useDeferredValue",
8+
"useEffect",
9+
"useFormStatus",
10+
"useId",
11+
"useImperativeHandle",
12+
"useInsertionEffect",
13+
"useLayoutEffect",
14+
"useMemo",
15+
"useOptimistic",
16+
"useReducer",
17+
"useRef",
18+
"useState",
19+
"useSyncExternalStore",
20+
"useTransition",
21+
] as const;
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1+
export * from "./constants";
12
export * from "./create-rule";
23
export * from "./is-from-hook-call";
34
export * from "./is-from-use-state-call";
4-
export * from "./is-function-of-immediately-invoked";
5-
export * from "./is-react-hook-identifier";
65
export * from "./is-set-function-call";
7-
export * from "./is-then-call";
86
export * from "./is-variable-declarator-from-hook-call";

packages/plugins/eslint-plugin-react-x/src/utils/is-from-hook-call.ts

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,12 @@
11
import type { RuleContext } from "@eslint-react/kit";
22
import type { ESLintReactSettingsNormalized } from "@eslint-react/shared";
33
import type { TSESTree } from "@typescript-eslint/types";
4+
import type { REACT_BUILD_IN_HOOKS } from "./constants";
45
import * as ER from "@eslint-react/core";
56
import { constTrue } from "@eslint-react/eff";
67
import * as VAR from "@eslint-react/var";
78
import { AST_NODE_TYPES as T } from "@typescript-eslint/types";
89

9-
export const REACT_BUILD_IN_HOOKS = [
10-
"use",
11-
"useActionState",
12-
"useCallback",
13-
"useContext",
14-
"useDebugValue",
15-
"useDeferredValue",
16-
"useEffect",
17-
"useFormStatus",
18-
"useId",
19-
"useImperativeHandle",
20-
"useInsertionEffect",
21-
"useLayoutEffect",
22-
"useMemo",
23-
"useOptimistic",
24-
"useReducer",
25-
"useRef",
26-
"useState",
27-
"useSyncExternalStore",
28-
"useTransition",
29-
] as const;
30-
3110
export function isFromHookCall(
3211
context: RuleContext,
3312
name: (typeof REACT_BUILD_IN_HOOKS)[number],

packages/plugins/eslint-plugin-react-x/src/utils/is-function-of-immediately-invoked.ts

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)