Skip to content

Commit d142159

Browse files
committed
refactor: minor improvements
1 parent 73e00cf commit d142159

File tree

4 files changed

+50
-50
lines changed

4 files changed

+50
-50
lines changed

packages/core/src/component/component-collector-legacy.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ import { ERComponentFlag } from "./component-flag";
77
import type { ERClassComponent } from "./component-semantic-node";
88
import { isClassComponent, isPureComponent } from "./is";
99

10+
export declare namespace useComponentCollectorLegacy {
11+
type ReturnType = {
12+
ctx: {
13+
getAllComponents: (node: TSESTree.Program) => Map<string, ERClassComponent>;
14+
};
15+
listeners: ESLintUtils.RuleListener;
16+
};
17+
}
18+
1019
/**
1120
* Get a ctx and listeners for the rule to collect class components
1221
* @returns The context and listeners for the rule
@@ -55,12 +64,3 @@ export function useComponentCollectorLegacy(): useComponentCollectorLegacy.Retur
5564

5665
return { ctx, listeners } as const;
5766
}
58-
59-
export declare namespace useComponentCollectorLegacy {
60-
type ReturnType = {
61-
ctx: {
62-
getAllComponents: (node: TSESTree.Program) => Map<string, ERClassComponent>;
63-
};
64-
listeners: ESLintUtils.RuleListener;
65-
};
66-
}

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,21 @@ type FunctionEntry = {
2424
isComponent: boolean;
2525
};
2626

27+
export declare namespace useComponentCollector {
28+
type Options = {
29+
collectDisplayName?: boolean;
30+
collectHookCalls?: boolean;
31+
};
32+
type ReturnType = {
33+
ctx: {
34+
getAllComponents: (node: TSESTree.Program) => Map<string, ERFunctionComponent>;
35+
getCurrentEntries: () => FunctionEntry[];
36+
getCurrentEntry: () => FunctionEntry | _;
37+
};
38+
listeners: ESLintUtils.RuleListener;
39+
};
40+
}
41+
2742
/**
2843
* Get a ctx and listeners for the rule to collect function components
2944
* @param context The ESLint rule context
@@ -157,21 +172,6 @@ export function useComponentCollector(
157172
return { ctx, listeners } as const;
158173
}
159174

160-
export declare namespace useComponentCollector {
161-
type Options = {
162-
collectDisplayName?: boolean;
163-
collectHookCalls?: boolean;
164-
};
165-
type ReturnType = {
166-
ctx: {
167-
getAllComponents: (node: TSESTree.Program) => Map<string, ERFunctionComponent>;
168-
getCurrentEntries: () => FunctionEntry[];
169-
getCurrentEntry: () => FunctionEntry | _;
170-
};
171-
listeners: ESLintUtils.RuleListener;
172-
};
173-
}
174-
175175
function hasValidHierarchy(node: AST.TSESTreeFunction, context: RuleContext, hint: bigint) {
176176
if (isChildrenOfCreateElement(node, context) || isFunctionOfRenderMethod(node)) {
177177
return false;

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ type FunctionEntry = {
1212
isHook: boolean;
1313
};
1414

15+
export declare namespace useHookCollector {
16+
type ReturnType = {
17+
ctx: {
18+
getAllHooks(node: TSESTree.Program): Map<string, ERHook>;
19+
};
20+
listeners: ESLintUtils.RuleListener;
21+
};
22+
}
23+
1524
export function useHookCollector(): useHookCollector.ReturnType {
1625
const hooks = new Map<string, ERHook>();
1726
const functionEntries: FunctionEntry[] = [];
@@ -64,12 +73,3 @@ export function useHookCollector(): useHookCollector.ReturnType {
6473
} as const satisfies ESLintUtils.RuleListener;
6574
return { ctx, listeners } as const;
6675
}
67-
68-
export declare namespace useHookCollector {
69-
type ReturnType = {
70-
ctx: {
71-
getAllHooks(node: TSESTree.Program): Map<string, ERHook>;
72-
};
73-
listeners: ESLintUtils.RuleListener;
74-
};
75-
}

packages/core/src/utils/is-from-react.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,13 @@ export function isFromReactMember(
9494
};
9595
}
9696

97+
export declare namespace isCallFromReact {
98+
type ReturnType = {
99+
(context: RuleContext): (node: TSESTree.Node) => node is TSESTree.CallExpression;
100+
(node: TSESTree.Node, context: RuleContext): node is TSESTree.CallExpression;
101+
};
102+
}
103+
97104
export function isCallFromReact(name: string): isCallFromReact.ReturnType {
98105
return dual(2, (node: TSESTree.Node, context: RuleContext): node is TSESTree.CallExpression => {
99106
if (node.type !== T.CallExpression) {
@@ -106,10 +113,17 @@ export function isCallFromReact(name: string): isCallFromReact.ReturnType {
106113
});
107114
}
108115

109-
export declare namespace isCallFromReact {
116+
export declare namespace isCallFromReactMember {
110117
type ReturnType = {
111-
(context: RuleContext): (node: TSESTree.Node) => node is TSESTree.CallExpression;
112-
(node: TSESTree.Node, context: RuleContext): node is TSESTree.CallExpression;
118+
(context: RuleContext): (node: TSESTree.Node) => node is
119+
& TSESTree.CallExpression
120+
& { callee: TSESTree.MemberExpression };
121+
(
122+
node: TSESTree.Node,
123+
context: RuleContext,
124+
): node is
125+
& TSESTree.CallExpression
126+
& { callee: TSESTree.MemberExpression };
113127
};
114128
}
115129

@@ -133,17 +147,3 @@ export function isCallFromReactMember(
133147
return isFromReactMember(pragmaMemberName, name)(node.callee, context);
134148
});
135149
}
136-
137-
export declare namespace isCallFromReactMember {
138-
type ReturnType = {
139-
(context: RuleContext): (node: TSESTree.Node) => node is
140-
& TSESTree.CallExpression
141-
& { callee: TSESTree.MemberExpression };
142-
(
143-
node: TSESTree.Node,
144-
context: RuleContext,
145-
): node is
146-
& TSESTree.CallExpression
147-
& { callee: TSESTree.MemberExpression };
148-
};
149-
}

0 commit comments

Comments
 (0)