Skip to content

Commit 5a7c855

Browse files
committed
refactor: minor improvements
1 parent 6058e9b commit 5a7c855

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

packages/core/src/hook/hook-collector.ts

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,22 @@ export function useHookCollector() {
1515
const onFunctionEnter = (node: AST.TSESTreeFunction) => {
1616
const id = AST.getFunctionIdentifier(node);
1717
const name = O.flatMapNullable(id, (id) => id.name);
18-
const isHook = O.isSome(id) && O.isSome(name) && isReactHookName(name.value);
19-
if (!isHook) {
20-
fStack.push([node, O.none()]);
18+
if (O.isSome(id) && O.isSome(name) && isReactHookName(name.value)) {
19+
const key = uid.rnd();
20+
fStack.push([node, O.some(key)]);
21+
hooks.set(key, {
22+
_: key,
23+
id,
24+
kind: "function",
25+
name,
26+
node,
27+
flag: 0n,
28+
hint: 0n,
29+
hookCalls: [],
30+
});
2131
return;
2232
}
23-
const key = uid.rnd();
24-
fStack.push([node, O.some(key)]);
25-
hooks.set(key, {
26-
_: key,
27-
id,
28-
kind: "function",
29-
name,
30-
node,
31-
flag: 0n,
32-
hint: 0n,
33-
hookCalls: [],
34-
});
33+
fStack.push([node, O.none()]);
3534
};
3635
const onFunctionExit = () => {
3736
fStack.pop();

packages/core/src/render-prop/is.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@ import { AST_NODE_TYPES } from "@typescript-eslint/types";
1919
*/
2020
export function isRenderFunctionLoose(node: AST.TSESTreeFunction, context: RuleContext) {
2121
const { body, parent } = node;
22-
const maybeId = AST.getFunctionIdentifier(node);
23-
if (O.isSome(maybeId) && !maybeId.value.name.startsWith("render")) {
22+
if (O.exists(AST.getFunctionIdentifier(node), (id) => id.name.startsWith("render"))) {
2423
return parent.type === AST_NODE_TYPES.JSXExpressionContainer
2524
&& parent.parent.type === AST_NODE_TYPES.JSXAttribute
2625
&& parent.parent.name.type === AST_NODE_TYPES.JSXIdentifier
2726
&& parent.parent.name.name.startsWith("render");
2827
}
29-
const jsxCtx = { getScope: (node: TSESTree.Node) => context.sourceCode.getScope(node) } as const;
3028
return JSX.isJSXValue(
3129
body,
32-
jsxCtx,
30+
{
31+
getScope: (node: TSESTree.Node) => context.sourceCode.getScope(node),
32+
},
3333
JSX.JSXValueHint.SkipNullLiteral
3434
| JSX.JSXValueHint.SkipUndefinedLiteral
3535
| JSX.JSXValueHint.StrictLogical

0 commit comments

Comments
 (0)