@eslint-react/core 1.24.0-beta.3 → 1.24.0-beta.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +120 -127
- package/dist/index.d.ts +120 -127
- package/dist/index.js +63 -61
- package/dist/index.mjs +56 -57
- package/package.json +11 -11
package/dist/index.d.mts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import * as AST from '@eslint-react/ast';
|
|
2
|
-
import * as
|
|
3
|
-
import {
|
|
2
|
+
import * as _eslint_react_shared from '@eslint-react/shared';
|
|
3
|
+
import { RuleContext, CustomComponentNormalized } from '@eslint-react/shared';
|
|
4
4
|
import { TSESTree } from '@typescript-eslint/types';
|
|
5
|
-
import
|
|
6
|
-
import { RuleContext } from '@eslint-react/types';
|
|
5
|
+
import { _ } from '@eslint-react/eff';
|
|
7
6
|
import { TSESTree as TSESTree$1 } from '@typescript-eslint/utils';
|
|
8
|
-
import
|
|
7
|
+
import * as birecord from 'birecord';
|
|
9
8
|
import * as _typescript_eslint_utils_ts_eslint from '@typescript-eslint/utils/ts-eslint';
|
|
10
9
|
import { Scope } from '@typescript-eslint/scope-manager';
|
|
11
10
|
import { SyntaxKind } from 'typescript';
|
|
@@ -130,14 +129,11 @@ declare function getFunctionComponentIdentifier(node: AST.TSESTreeFunction, cont
|
|
|
130
129
|
|
|
131
130
|
type ERComponentKind = "classComponent" | "functionComponent";
|
|
132
131
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
declare
|
|
137
|
-
declare function
|
|
138
|
-
declare function isComponentName(name: string): boolean;
|
|
139
|
-
|
|
140
|
-
declare function isRenderMethodLike(node: TSESTree$1.Node): node is TSESTree$1.MethodDefinition | TSESTree$1.PropertyDefinition;
|
|
132
|
+
declare function isComponentDidMount(node: TSESTree.Node): node is TSESTree.MethodDefinition | TSESTree.PropertyDefinition;
|
|
133
|
+
declare function isComponentWillUnmount(node: TSESTree.Node): node is TSESTree.MethodDefinition | TSESTree.PropertyDefinition;
|
|
134
|
+
declare function isFunctionOfComponentDidMount(node: TSESTree.Node): boolean;
|
|
135
|
+
declare function isFunctionOfComponentWillUnmount(node: TSESTree.Node): boolean;
|
|
136
|
+
declare function isRenderMethodLike(node: TSESTree.Node): node is TSESTree.MethodDefinition | TSESTree.PropertyDefinition;
|
|
141
137
|
declare function isFunctionOfRenderMethod(node: AST.TSESTreeFunction): boolean;
|
|
142
138
|
/**
|
|
143
139
|
* Check whether given node is declared inside class component's render block
|
|
@@ -154,7 +150,80 @@ declare function isFunctionOfRenderMethod(node: AST.TSESTreeFunction): boolean;
|
|
|
154
150
|
* @param node The AST node being checked
|
|
155
151
|
* @returns `true` if node is inside class component's render block, `false` if not
|
|
156
152
|
*/
|
|
157
|
-
declare function isInsideRenderMethod(node: TSESTree
|
|
153
|
+
declare function isInsideRenderMethod(node: TSESTree.Node): boolean;
|
|
154
|
+
|
|
155
|
+
type EREffectMethodKind = "useEffect" | "useInsertionEffect" | "useLayoutEffect";
|
|
156
|
+
type ERLifecycleMethodKind = "componentDidMount" | "componentWillUnmount";
|
|
157
|
+
|
|
158
|
+
declare const RE_COMPONENT_NAME: RegExp;
|
|
159
|
+
declare function getComponentNameFromIdentifier(node: TSESTree.Identifier | TSESTree.Identifier[] | _): string | undefined;
|
|
160
|
+
declare function isComponentName(name: string): boolean;
|
|
161
|
+
declare function hasNoneOrValidComponentName(node: AST.TSESTreeFunction, context: RuleContext): boolean;
|
|
162
|
+
|
|
163
|
+
type EREffectPhaseKind = "cleanup" | "setup";
|
|
164
|
+
type ERLifecyclePhaseKind = "mount" | "unmount";
|
|
165
|
+
type ERPhaseKind = EREffectPhaseKind | ERLifecyclePhaseKind;
|
|
166
|
+
declare const ERPhaseRelevance: birecord.BiRecord<{
|
|
167
|
+
readonly mount: "unmount";
|
|
168
|
+
readonly setup: "cleanup";
|
|
169
|
+
}>;
|
|
170
|
+
declare const isInversePhase: {
|
|
171
|
+
(a: ERPhaseKind): (b: ERPhaseKind) => boolean;
|
|
172
|
+
(a: ERPhaseKind, b: ERPhaseKind): boolean;
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Unsafe check whether given node is a render function
|
|
177
|
+
* ```jsx
|
|
178
|
+
* const renderRow = () => <div />
|
|
179
|
+
* ` ^^^^^^^^^^^^`
|
|
180
|
+
* _ = <Component renderRow={() => <div />} />
|
|
181
|
+
* ` ^^^^^^^^^^^^^ `
|
|
182
|
+
* ```
|
|
183
|
+
* @param node The AST node to check
|
|
184
|
+
* @param context The rule context
|
|
185
|
+
* @returns `true` if node is a render function, `false` if not
|
|
186
|
+
*/
|
|
187
|
+
declare function isRenderFunctionLoose(node: AST.TSESTreeFunction, context: RuleContext): boolean;
|
|
188
|
+
/**
|
|
189
|
+
* Unsafe check whether given JSXAttribute is a render prop
|
|
190
|
+
* ```jsx
|
|
191
|
+
* _ = <Component renderRow={() => <div />} />
|
|
192
|
+
* ` ^^^^^^^^^^^^^^^^^^^^^^^^^ `
|
|
193
|
+
* ```
|
|
194
|
+
* @param node The AST node to check
|
|
195
|
+
* @param context The rule context
|
|
196
|
+
* @returns `true` if node is a render prop, `false` if not
|
|
197
|
+
*/
|
|
198
|
+
declare function isRenderPropLoose(node: TSESTree.JSXAttribute, context: RuleContext): boolean;
|
|
199
|
+
/**
|
|
200
|
+
* Unsafe check whether given node is declared directly inside a render property
|
|
201
|
+
* ```jsx
|
|
202
|
+
* const rows = { render: () => <div /> }
|
|
203
|
+
* ` ^^^^^^^^^^^^^ `
|
|
204
|
+
* _ = <Component rows={ [{ render: () => <div /> }] } />
|
|
205
|
+
* ` ^^^^^^^^^^^^^ `
|
|
206
|
+
* ```
|
|
207
|
+
* @internal
|
|
208
|
+
* @param node The AST node to check
|
|
209
|
+
* @returns `true` if component is declared inside a render property, `false` if not
|
|
210
|
+
*/
|
|
211
|
+
declare function isDirectValueOfRenderPropertyLoose(node: TSESTree.Node): boolean;
|
|
212
|
+
/**
|
|
213
|
+
* Unsafe check whether given node is declared inside a render prop
|
|
214
|
+
* ```jsx
|
|
215
|
+
* _ = <Component renderRow={"node"} />
|
|
216
|
+
* ` ^^^^^^ `
|
|
217
|
+
* _ = <Component rows={ [{ render: "node" }] } />
|
|
218
|
+
* ` ^^^^^^ `
|
|
219
|
+
* ```
|
|
220
|
+
* @param node The AST node to check
|
|
221
|
+
* @returns `true` if component is declared inside a render prop, `false` if not
|
|
222
|
+
*/
|
|
223
|
+
declare function isDeclaredInRenderPropLoose(node: TSESTree.Node): boolean;
|
|
224
|
+
|
|
225
|
+
type ERStateKind = "actionState" | "state";
|
|
226
|
+
declare function isThisSetState(node: TSESTree.CallExpression): boolean;
|
|
158
227
|
|
|
159
228
|
/**
|
|
160
229
|
* Check if a node is a React class component
|
|
@@ -169,14 +238,12 @@ declare function isClassComponent(node: TSESTree.Node): node is AST.TSESTreeClas
|
|
|
169
238
|
*/
|
|
170
239
|
declare function isPureComponent(node: TSESTree.Node): boolean;
|
|
171
240
|
|
|
172
|
-
declare function hasNoneOrValidComponentName(node: AST.TSESTreeFunction, context: RuleContext): boolean;
|
|
173
|
-
|
|
174
241
|
type EREffectKind = "effect" | "insertionEffect" | "layoutEffect";
|
|
175
242
|
|
|
176
|
-
declare function
|
|
177
|
-
declare function
|
|
243
|
+
declare function isFunctionOfUseEffectSetup(node: TSESTree.Node | _): boolean | undefined;
|
|
244
|
+
declare function isFunctionOfUseEffectCleanup(node: TSESTree.Node): boolean | undefined;
|
|
178
245
|
|
|
179
|
-
declare function
|
|
246
|
+
declare function getElementNameOnJsxAndHtml(node: TSESTree.JSXOpeningElement, context: RuleContext, polymorphicPropName?: string, additionalComponents?: CustomComponentNormalized[]): [string, string];
|
|
180
247
|
|
|
181
248
|
/**
|
|
182
249
|
* Determines whether inside `createElement`'s props.
|
|
@@ -246,85 +313,11 @@ declare const isUseStateCall: (node: TSESTree.CallExpression | undefined, contex
|
|
|
246
313
|
declare const isUseSyncExternalStoreCall: (node: TSESTree.CallExpression | undefined, context: Readonly<_typescript_eslint_utils_ts_eslint.RuleContext<string, readonly unknown[]>>) => boolean;
|
|
247
314
|
declare const isUseTransitionCall: (node: TSESTree.CallExpression | undefined, context: Readonly<_typescript_eslint_utils_ts_eslint.RuleContext<string, readonly unknown[]>>) => boolean;
|
|
248
315
|
|
|
249
|
-
declare function isComponentDidMount(node: TSESTree.Node): node is TSESTree.MethodDefinition | TSESTree.PropertyDefinition;
|
|
250
|
-
declare function isComponentWillUnmount(node: TSESTree.Node): node is TSESTree.MethodDefinition | TSESTree.PropertyDefinition;
|
|
251
|
-
declare function isComponentDidMountFunction(node: TSESTree.Node): boolean;
|
|
252
|
-
declare function isComponentWillUnmountFunction(node: TSESTree.Node): boolean;
|
|
253
|
-
|
|
254
|
-
declare const ERPhaseRelevance: _eslint_react_eff.BiRecord<{
|
|
255
|
-
readonly mount: "unmount";
|
|
256
|
-
readonly setup: "cleanup";
|
|
257
|
-
}>;
|
|
258
|
-
|
|
259
|
-
type EREffectPhaseKind = "cleanup" | "setup";
|
|
260
|
-
type ERLifecyclePhaseKind = "mount" | "unmount";
|
|
261
|
-
type ERPhaseKind = EREffectPhaseKind | ERLifecyclePhaseKind;
|
|
262
|
-
|
|
263
|
-
declare const isInversePhase: {
|
|
264
|
-
(a: ERPhaseKind): (b: ERPhaseKind) => boolean;
|
|
265
|
-
(a: ERPhaseKind, b: ERPhaseKind): boolean;
|
|
266
|
-
};
|
|
267
|
-
|
|
268
|
-
/**
|
|
269
|
-
* Unsafe check whether given node is declared directly inside a render property
|
|
270
|
-
* ```jsx
|
|
271
|
-
* const rows = { render: () => <div /> }
|
|
272
|
-
* ` ^^^^^^^^^^^^^ `
|
|
273
|
-
* _ = <Component rows={ [{ render: () => <div /> }] } />
|
|
274
|
-
* ` ^^^^^^^^^^^^^ `
|
|
275
|
-
* ```
|
|
276
|
-
* @internal
|
|
277
|
-
* @param node The AST node to check
|
|
278
|
-
* @returns `true` if component is declared inside a render property, `false` if not
|
|
279
|
-
*/
|
|
280
|
-
declare function isDirectValueOfRenderPropertyLoose(node: TSESTree.Node): boolean;
|
|
281
|
-
/**
|
|
282
|
-
* Unsafe check whether given node is declared inside a render prop
|
|
283
|
-
* ```jsx
|
|
284
|
-
* _ = <Component renderRow={"node"} />
|
|
285
|
-
* ` ^^^^^^ `
|
|
286
|
-
* _ = <Component rows={ [{ render: "node" }] } />
|
|
287
|
-
* ` ^^^^^^ `
|
|
288
|
-
* ```
|
|
289
|
-
* @param node The AST node to check
|
|
290
|
-
* @returns `true` if component is declared inside a render prop, `false` if not
|
|
291
|
-
*/
|
|
292
|
-
declare function isDeclaredInRenderPropLoose(node: TSESTree.Node): boolean;
|
|
293
|
-
|
|
294
|
-
/**
|
|
295
|
-
* Unsafe check whether given node is a render function
|
|
296
|
-
* ```jsx
|
|
297
|
-
* const renderRow = () => <div />
|
|
298
|
-
* ` ^^^^^^^^^^^^`
|
|
299
|
-
* _ = <Component renderRow={() => <div />} />
|
|
300
|
-
* ` ^^^^^^^^^^^^^ `
|
|
301
|
-
* ```
|
|
302
|
-
* @param node The AST node to check
|
|
303
|
-
* @param context The rule context
|
|
304
|
-
* @returns `true` if node is a render function, `false` if not
|
|
305
|
-
*/
|
|
306
|
-
declare function isRenderFunctionLoose(node: AST.TSESTreeFunction, context: RuleContext): boolean;
|
|
307
|
-
/**
|
|
308
|
-
* Unsafe check whether given JSXAttribute is a render prop
|
|
309
|
-
* ```jsx
|
|
310
|
-
* _ = <Component renderRow={() => <div />} />
|
|
311
|
-
* ` ^^^^^^^^^^^^^^^^^^^^^^^^^ `
|
|
312
|
-
* ```
|
|
313
|
-
* @param node The AST node to check
|
|
314
|
-
* @param context The rule context
|
|
315
|
-
* @returns `true` if node is a render prop, `false` if not
|
|
316
|
-
*/
|
|
317
|
-
declare function isRenderPropLoose(node: TSESTree.JSXAttribute, context: RuleContext): boolean;
|
|
318
|
-
|
|
319
316
|
interface ERSemanticEntry {
|
|
320
317
|
node: TSESTree.Node;
|
|
321
318
|
phase: ERPhaseKind;
|
|
322
319
|
}
|
|
323
320
|
|
|
324
|
-
declare function isThisSetState(node: TSESTree.CallExpression): boolean;
|
|
325
|
-
|
|
326
|
-
type ERStateKind = "actionState" | "state";
|
|
327
|
-
|
|
328
321
|
declare const getId: () => string;
|
|
329
322
|
|
|
330
323
|
/**
|
|
@@ -2503,80 +2496,80 @@ declare function isReactAPIWithName(name: string): ReturnType<typeof isFromReact
|
|
|
2503
2496
|
declare function isReactAPIWithName(name: string, member: string): ReturnType<typeof isFromReactMember>;
|
|
2504
2497
|
declare function isReactAPICallWithName(name: string): ReturnType<typeof isCallFromReact>;
|
|
2505
2498
|
declare function isReactAPICallWithName(name: string, member: string): ReturnType<typeof isCallFromReactMember>;
|
|
2506
|
-
declare const isChildrenCount: (node: MemberExpression, context:
|
|
2507
|
-
declare const isChildrenForEach: (node: MemberExpression, context:
|
|
2508
|
-
declare const isChildrenMap: (node: MemberExpression, context:
|
|
2509
|
-
declare const isChildrenOnly: (node: MemberExpression, context:
|
|
2510
|
-
declare const isChildrenToArray: (node: MemberExpression, context:
|
|
2511
|
-
declare const isCloneElement: (node: Identifier | MemberExpression, context:
|
|
2512
|
-
declare const isCreateContext: (node: Identifier | MemberExpression, context:
|
|
2513
|
-
declare const isCreateElement: (node: Identifier | MemberExpression, context:
|
|
2514
|
-
declare const isCreateRef: (node: Identifier | MemberExpression, context:
|
|
2515
|
-
declare const isForwardRef: (node: Identifier | MemberExpression, context:
|
|
2516
|
-
declare const isMemo: (node: Identifier | MemberExpression, context:
|
|
2499
|
+
declare const isChildrenCount: (node: MemberExpression, context: _eslint_react_shared.RuleContext) => boolean;
|
|
2500
|
+
declare const isChildrenForEach: (node: MemberExpression, context: _eslint_react_shared.RuleContext) => boolean;
|
|
2501
|
+
declare const isChildrenMap: (node: MemberExpression, context: _eslint_react_shared.RuleContext) => boolean;
|
|
2502
|
+
declare const isChildrenOnly: (node: MemberExpression, context: _eslint_react_shared.RuleContext) => boolean;
|
|
2503
|
+
declare const isChildrenToArray: (node: MemberExpression, context: _eslint_react_shared.RuleContext) => boolean;
|
|
2504
|
+
declare const isCloneElement: (node: Identifier | MemberExpression, context: _eslint_react_shared.RuleContext) => boolean;
|
|
2505
|
+
declare const isCreateContext: (node: Identifier | MemberExpression, context: _eslint_react_shared.RuleContext) => boolean;
|
|
2506
|
+
declare const isCreateElement: (node: Identifier | MemberExpression, context: _eslint_react_shared.RuleContext) => boolean;
|
|
2507
|
+
declare const isCreateRef: (node: Identifier | MemberExpression, context: _eslint_react_shared.RuleContext) => boolean;
|
|
2508
|
+
declare const isForwardRef: (node: Identifier | MemberExpression, context: _eslint_react_shared.RuleContext) => boolean;
|
|
2509
|
+
declare const isMemo: (node: Identifier | MemberExpression, context: _eslint_react_shared.RuleContext) => boolean;
|
|
2517
2510
|
declare const isChildrenCountCall: {
|
|
2518
|
-
(context:
|
|
2511
|
+
(context: _eslint_react_shared.RuleContext): (node: Node) => node is CallExpression & {
|
|
2519
2512
|
callee: MemberExpression;
|
|
2520
2513
|
};
|
|
2521
|
-
(node: Node, context:
|
|
2514
|
+
(node: Node, context: _eslint_react_shared.RuleContext): node is CallExpression & {
|
|
2522
2515
|
callee: MemberExpression;
|
|
2523
2516
|
};
|
|
2524
2517
|
};
|
|
2525
2518
|
declare const isChildrenForEachCall: {
|
|
2526
|
-
(context:
|
|
2519
|
+
(context: _eslint_react_shared.RuleContext): (node: Node) => node is CallExpression & {
|
|
2527
2520
|
callee: MemberExpression;
|
|
2528
2521
|
};
|
|
2529
|
-
(node: Node, context:
|
|
2522
|
+
(node: Node, context: _eslint_react_shared.RuleContext): node is CallExpression & {
|
|
2530
2523
|
callee: MemberExpression;
|
|
2531
2524
|
};
|
|
2532
2525
|
};
|
|
2533
2526
|
declare const isChildrenMapCall: {
|
|
2534
|
-
(context:
|
|
2527
|
+
(context: _eslint_react_shared.RuleContext): (node: Node) => node is CallExpression & {
|
|
2535
2528
|
callee: MemberExpression;
|
|
2536
2529
|
};
|
|
2537
|
-
(node: Node, context:
|
|
2530
|
+
(node: Node, context: _eslint_react_shared.RuleContext): node is CallExpression & {
|
|
2538
2531
|
callee: MemberExpression;
|
|
2539
2532
|
};
|
|
2540
2533
|
};
|
|
2541
2534
|
declare const isChildrenOnlyCall: {
|
|
2542
|
-
(context:
|
|
2535
|
+
(context: _eslint_react_shared.RuleContext): (node: Node) => node is CallExpression & {
|
|
2543
2536
|
callee: MemberExpression;
|
|
2544
2537
|
};
|
|
2545
|
-
(node: Node, context:
|
|
2538
|
+
(node: Node, context: _eslint_react_shared.RuleContext): node is CallExpression & {
|
|
2546
2539
|
callee: MemberExpression;
|
|
2547
2540
|
};
|
|
2548
2541
|
};
|
|
2549
2542
|
declare const isChildrenToArrayCall: {
|
|
2550
|
-
(context:
|
|
2543
|
+
(context: _eslint_react_shared.RuleContext): (node: Node) => node is CallExpression & {
|
|
2551
2544
|
callee: MemberExpression;
|
|
2552
2545
|
};
|
|
2553
|
-
(node: Node, context:
|
|
2546
|
+
(node: Node, context: _eslint_react_shared.RuleContext): node is CallExpression & {
|
|
2554
2547
|
callee: MemberExpression;
|
|
2555
2548
|
};
|
|
2556
2549
|
};
|
|
2557
2550
|
declare const isCloneElementCall: {
|
|
2558
|
-
(context:
|
|
2559
|
-
(node: Node, context:
|
|
2551
|
+
(context: _eslint_react_shared.RuleContext): (node: Node) => node is CallExpression;
|
|
2552
|
+
(node: Node, context: _eslint_react_shared.RuleContext): node is CallExpression;
|
|
2560
2553
|
};
|
|
2561
2554
|
declare const isCreateContextCall: {
|
|
2562
|
-
(context:
|
|
2563
|
-
(node: Node, context:
|
|
2555
|
+
(context: _eslint_react_shared.RuleContext): (node: Node) => node is CallExpression;
|
|
2556
|
+
(node: Node, context: _eslint_react_shared.RuleContext): node is CallExpression;
|
|
2564
2557
|
};
|
|
2565
2558
|
declare const isCreateElementCall: {
|
|
2566
|
-
(context:
|
|
2567
|
-
(node: Node, context:
|
|
2559
|
+
(context: _eslint_react_shared.RuleContext): (node: Node) => node is CallExpression;
|
|
2560
|
+
(node: Node, context: _eslint_react_shared.RuleContext): node is CallExpression;
|
|
2568
2561
|
};
|
|
2569
2562
|
declare const isCreateRefCall: {
|
|
2570
|
-
(context:
|
|
2571
|
-
(node: Node, context:
|
|
2563
|
+
(context: _eslint_react_shared.RuleContext): (node: Node) => node is CallExpression;
|
|
2564
|
+
(node: Node, context: _eslint_react_shared.RuleContext): node is CallExpression;
|
|
2572
2565
|
};
|
|
2573
2566
|
declare const isForwardRefCall: {
|
|
2574
|
-
(context:
|
|
2575
|
-
(node: Node, context:
|
|
2567
|
+
(context: _eslint_react_shared.RuleContext): (node: Node) => node is CallExpression;
|
|
2568
|
+
(node: Node, context: _eslint_react_shared.RuleContext): node is CallExpression;
|
|
2576
2569
|
};
|
|
2577
2570
|
declare const isMemoCall: {
|
|
2578
|
-
(context:
|
|
2579
|
-
(node: Node, context:
|
|
2571
|
+
(context: _eslint_react_shared.RuleContext): (node: Node) => node is CallExpression;
|
|
2572
|
+
(node: Node, context: _eslint_react_shared.RuleContext): node is CallExpression;
|
|
2580
2573
|
};
|
|
2581
2574
|
|
|
2582
|
-
export { type ComponentCollectorOptions, DEFAULT_COMPONENT_HINT, type ERClassComponent, ERClassComponentFlag, type ERComponent, ERComponentHint, type ERComponentKind, type EREffectKind, type EREffectMethodKind, type EREffectPhaseKind, type ERFunctionComponent, ERFunctionComponentFlag, type ERHook, type ERHookKind, type ERLifecycleMethodKind, type ERLifecyclePhaseKind, type ERPhaseKind, ERPhaseRelevance, type ERSemanticEntry, type ERSemanticNode, type ERStateKind, RE_COMPONENT_NAME, RE_HOOK_NAME, getComponentNameFromIdentifier,
|
|
2575
|
+
export { type ComponentCollectorOptions, DEFAULT_COMPONENT_HINT, type ERClassComponent, ERClassComponentFlag, type ERComponent, ERComponentHint, type ERComponentKind, type EREffectKind, type EREffectMethodKind, type EREffectPhaseKind, type ERFunctionComponent, ERFunctionComponentFlag, type ERHook, type ERHookKind, type ERLifecycleMethodKind, type ERLifecyclePhaseKind, type ERPhaseKind, ERPhaseRelevance, type ERSemanticEntry, type ERSemanticNode, type ERStateKind, RE_COMPONENT_NAME, RE_HOOK_NAME, getComponentNameFromIdentifier, getElementNameOnJsxAndHtml, getFunctionComponentIdentifier, getId, hasNoneOrValidComponentName, isCallFromReact, isCallFromReactMember, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOfCreateElement, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCloneElement, isCloneElementCall, isComponentDidMount, isComponentName, isComponentWillUnmount, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRef, isForwardRefCall, isFromReact, isFromReactMember, isFunctionOfComponentDidMount, isFunctionOfComponentWillUnmount, isFunctionOfRenderMethod, isFunctionOfUseEffectCleanup, isFunctionOfUseEffectSetup, isInitializedFromReact, isInsideCreateElementProps, isInsideReactHook, isInsideRenderMethod, isInversePhase, isMemo, isMemoCall, isPureComponent, isReactAPICallWithName, isReactAPIWithName, isReactHook, isReactHookCall, isReactHookCallWithName, isReactHookCallWithNameAlias, isReactHookCallWithNameLoose, isReactHookName, isRenderFunctionLoose, isRenderMethodLike, isRenderPropLoose, isThisSetState, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectCallLoose, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseReducerCall, isUseRefCall, isUseStateCall, isUseSyncExternalStoreCall, isUseTransitionCall, useComponentCollector, useComponentCollectorLegacy, useHookCollector };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import * as AST from '@eslint-react/ast';
|
|
2
|
-
import * as
|
|
3
|
-
import {
|
|
2
|
+
import * as _eslint_react_shared from '@eslint-react/shared';
|
|
3
|
+
import { RuleContext, CustomComponentNormalized } from '@eslint-react/shared';
|
|
4
4
|
import { TSESTree } from '@typescript-eslint/types';
|
|
5
|
-
import
|
|
6
|
-
import { RuleContext } from '@eslint-react/types';
|
|
5
|
+
import { _ } from '@eslint-react/eff';
|
|
7
6
|
import { TSESTree as TSESTree$1 } from '@typescript-eslint/utils';
|
|
8
|
-
import
|
|
7
|
+
import * as birecord from 'birecord';
|
|
9
8
|
import * as _typescript_eslint_utils_ts_eslint from '@typescript-eslint/utils/ts-eslint';
|
|
10
9
|
import { Scope } from '@typescript-eslint/scope-manager';
|
|
11
10
|
import { SyntaxKind } from 'typescript';
|
|
@@ -130,14 +129,11 @@ declare function getFunctionComponentIdentifier(node: AST.TSESTreeFunction, cont
|
|
|
130
129
|
|
|
131
130
|
type ERComponentKind = "classComponent" | "functionComponent";
|
|
132
131
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
declare
|
|
137
|
-
declare function
|
|
138
|
-
declare function isComponentName(name: string): boolean;
|
|
139
|
-
|
|
140
|
-
declare function isRenderMethodLike(node: TSESTree$1.Node): node is TSESTree$1.MethodDefinition | TSESTree$1.PropertyDefinition;
|
|
132
|
+
declare function isComponentDidMount(node: TSESTree.Node): node is TSESTree.MethodDefinition | TSESTree.PropertyDefinition;
|
|
133
|
+
declare function isComponentWillUnmount(node: TSESTree.Node): node is TSESTree.MethodDefinition | TSESTree.PropertyDefinition;
|
|
134
|
+
declare function isFunctionOfComponentDidMount(node: TSESTree.Node): boolean;
|
|
135
|
+
declare function isFunctionOfComponentWillUnmount(node: TSESTree.Node): boolean;
|
|
136
|
+
declare function isRenderMethodLike(node: TSESTree.Node): node is TSESTree.MethodDefinition | TSESTree.PropertyDefinition;
|
|
141
137
|
declare function isFunctionOfRenderMethod(node: AST.TSESTreeFunction): boolean;
|
|
142
138
|
/**
|
|
143
139
|
* Check whether given node is declared inside class component's render block
|
|
@@ -154,7 +150,80 @@ declare function isFunctionOfRenderMethod(node: AST.TSESTreeFunction): boolean;
|
|
|
154
150
|
* @param node The AST node being checked
|
|
155
151
|
* @returns `true` if node is inside class component's render block, `false` if not
|
|
156
152
|
*/
|
|
157
|
-
declare function isInsideRenderMethod(node: TSESTree
|
|
153
|
+
declare function isInsideRenderMethod(node: TSESTree.Node): boolean;
|
|
154
|
+
|
|
155
|
+
type EREffectMethodKind = "useEffect" | "useInsertionEffect" | "useLayoutEffect";
|
|
156
|
+
type ERLifecycleMethodKind = "componentDidMount" | "componentWillUnmount";
|
|
157
|
+
|
|
158
|
+
declare const RE_COMPONENT_NAME: RegExp;
|
|
159
|
+
declare function getComponentNameFromIdentifier(node: TSESTree.Identifier | TSESTree.Identifier[] | _): string | undefined;
|
|
160
|
+
declare function isComponentName(name: string): boolean;
|
|
161
|
+
declare function hasNoneOrValidComponentName(node: AST.TSESTreeFunction, context: RuleContext): boolean;
|
|
162
|
+
|
|
163
|
+
type EREffectPhaseKind = "cleanup" | "setup";
|
|
164
|
+
type ERLifecyclePhaseKind = "mount" | "unmount";
|
|
165
|
+
type ERPhaseKind = EREffectPhaseKind | ERLifecyclePhaseKind;
|
|
166
|
+
declare const ERPhaseRelevance: birecord.BiRecord<{
|
|
167
|
+
readonly mount: "unmount";
|
|
168
|
+
readonly setup: "cleanup";
|
|
169
|
+
}>;
|
|
170
|
+
declare const isInversePhase: {
|
|
171
|
+
(a: ERPhaseKind): (b: ERPhaseKind) => boolean;
|
|
172
|
+
(a: ERPhaseKind, b: ERPhaseKind): boolean;
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Unsafe check whether given node is a render function
|
|
177
|
+
* ```jsx
|
|
178
|
+
* const renderRow = () => <div />
|
|
179
|
+
* ` ^^^^^^^^^^^^`
|
|
180
|
+
* _ = <Component renderRow={() => <div />} />
|
|
181
|
+
* ` ^^^^^^^^^^^^^ `
|
|
182
|
+
* ```
|
|
183
|
+
* @param node The AST node to check
|
|
184
|
+
* @param context The rule context
|
|
185
|
+
* @returns `true` if node is a render function, `false` if not
|
|
186
|
+
*/
|
|
187
|
+
declare function isRenderFunctionLoose(node: AST.TSESTreeFunction, context: RuleContext): boolean;
|
|
188
|
+
/**
|
|
189
|
+
* Unsafe check whether given JSXAttribute is a render prop
|
|
190
|
+
* ```jsx
|
|
191
|
+
* _ = <Component renderRow={() => <div />} />
|
|
192
|
+
* ` ^^^^^^^^^^^^^^^^^^^^^^^^^ `
|
|
193
|
+
* ```
|
|
194
|
+
* @param node The AST node to check
|
|
195
|
+
* @param context The rule context
|
|
196
|
+
* @returns `true` if node is a render prop, `false` if not
|
|
197
|
+
*/
|
|
198
|
+
declare function isRenderPropLoose(node: TSESTree.JSXAttribute, context: RuleContext): boolean;
|
|
199
|
+
/**
|
|
200
|
+
* Unsafe check whether given node is declared directly inside a render property
|
|
201
|
+
* ```jsx
|
|
202
|
+
* const rows = { render: () => <div /> }
|
|
203
|
+
* ` ^^^^^^^^^^^^^ `
|
|
204
|
+
* _ = <Component rows={ [{ render: () => <div /> }] } />
|
|
205
|
+
* ` ^^^^^^^^^^^^^ `
|
|
206
|
+
* ```
|
|
207
|
+
* @internal
|
|
208
|
+
* @param node The AST node to check
|
|
209
|
+
* @returns `true` if component is declared inside a render property, `false` if not
|
|
210
|
+
*/
|
|
211
|
+
declare function isDirectValueOfRenderPropertyLoose(node: TSESTree.Node): boolean;
|
|
212
|
+
/**
|
|
213
|
+
* Unsafe check whether given node is declared inside a render prop
|
|
214
|
+
* ```jsx
|
|
215
|
+
* _ = <Component renderRow={"node"} />
|
|
216
|
+
* ` ^^^^^^ `
|
|
217
|
+
* _ = <Component rows={ [{ render: "node" }] } />
|
|
218
|
+
* ` ^^^^^^ `
|
|
219
|
+
* ```
|
|
220
|
+
* @param node The AST node to check
|
|
221
|
+
* @returns `true` if component is declared inside a render prop, `false` if not
|
|
222
|
+
*/
|
|
223
|
+
declare function isDeclaredInRenderPropLoose(node: TSESTree.Node): boolean;
|
|
224
|
+
|
|
225
|
+
type ERStateKind = "actionState" | "state";
|
|
226
|
+
declare function isThisSetState(node: TSESTree.CallExpression): boolean;
|
|
158
227
|
|
|
159
228
|
/**
|
|
160
229
|
* Check if a node is a React class component
|
|
@@ -169,14 +238,12 @@ declare function isClassComponent(node: TSESTree.Node): node is AST.TSESTreeClas
|
|
|
169
238
|
*/
|
|
170
239
|
declare function isPureComponent(node: TSESTree.Node): boolean;
|
|
171
240
|
|
|
172
|
-
declare function hasNoneOrValidComponentName(node: AST.TSESTreeFunction, context: RuleContext): boolean;
|
|
173
|
-
|
|
174
241
|
type EREffectKind = "effect" | "insertionEffect" | "layoutEffect";
|
|
175
242
|
|
|
176
|
-
declare function
|
|
177
|
-
declare function
|
|
243
|
+
declare function isFunctionOfUseEffectSetup(node: TSESTree.Node | _): boolean | undefined;
|
|
244
|
+
declare function isFunctionOfUseEffectCleanup(node: TSESTree.Node): boolean | undefined;
|
|
178
245
|
|
|
179
|
-
declare function
|
|
246
|
+
declare function getElementNameOnJsxAndHtml(node: TSESTree.JSXOpeningElement, context: RuleContext, polymorphicPropName?: string, additionalComponents?: CustomComponentNormalized[]): [string, string];
|
|
180
247
|
|
|
181
248
|
/**
|
|
182
249
|
* Determines whether inside `createElement`'s props.
|
|
@@ -246,85 +313,11 @@ declare const isUseStateCall: (node: TSESTree.CallExpression | undefined, contex
|
|
|
246
313
|
declare const isUseSyncExternalStoreCall: (node: TSESTree.CallExpression | undefined, context: Readonly<_typescript_eslint_utils_ts_eslint.RuleContext<string, readonly unknown[]>>) => boolean;
|
|
247
314
|
declare const isUseTransitionCall: (node: TSESTree.CallExpression | undefined, context: Readonly<_typescript_eslint_utils_ts_eslint.RuleContext<string, readonly unknown[]>>) => boolean;
|
|
248
315
|
|
|
249
|
-
declare function isComponentDidMount(node: TSESTree.Node): node is TSESTree.MethodDefinition | TSESTree.PropertyDefinition;
|
|
250
|
-
declare function isComponentWillUnmount(node: TSESTree.Node): node is TSESTree.MethodDefinition | TSESTree.PropertyDefinition;
|
|
251
|
-
declare function isComponentDidMountFunction(node: TSESTree.Node): boolean;
|
|
252
|
-
declare function isComponentWillUnmountFunction(node: TSESTree.Node): boolean;
|
|
253
|
-
|
|
254
|
-
declare const ERPhaseRelevance: _eslint_react_eff.BiRecord<{
|
|
255
|
-
readonly mount: "unmount";
|
|
256
|
-
readonly setup: "cleanup";
|
|
257
|
-
}>;
|
|
258
|
-
|
|
259
|
-
type EREffectPhaseKind = "cleanup" | "setup";
|
|
260
|
-
type ERLifecyclePhaseKind = "mount" | "unmount";
|
|
261
|
-
type ERPhaseKind = EREffectPhaseKind | ERLifecyclePhaseKind;
|
|
262
|
-
|
|
263
|
-
declare const isInversePhase: {
|
|
264
|
-
(a: ERPhaseKind): (b: ERPhaseKind) => boolean;
|
|
265
|
-
(a: ERPhaseKind, b: ERPhaseKind): boolean;
|
|
266
|
-
};
|
|
267
|
-
|
|
268
|
-
/**
|
|
269
|
-
* Unsafe check whether given node is declared directly inside a render property
|
|
270
|
-
* ```jsx
|
|
271
|
-
* const rows = { render: () => <div /> }
|
|
272
|
-
* ` ^^^^^^^^^^^^^ `
|
|
273
|
-
* _ = <Component rows={ [{ render: () => <div /> }] } />
|
|
274
|
-
* ` ^^^^^^^^^^^^^ `
|
|
275
|
-
* ```
|
|
276
|
-
* @internal
|
|
277
|
-
* @param node The AST node to check
|
|
278
|
-
* @returns `true` if component is declared inside a render property, `false` if not
|
|
279
|
-
*/
|
|
280
|
-
declare function isDirectValueOfRenderPropertyLoose(node: TSESTree.Node): boolean;
|
|
281
|
-
/**
|
|
282
|
-
* Unsafe check whether given node is declared inside a render prop
|
|
283
|
-
* ```jsx
|
|
284
|
-
* _ = <Component renderRow={"node"} />
|
|
285
|
-
* ` ^^^^^^ `
|
|
286
|
-
* _ = <Component rows={ [{ render: "node" }] } />
|
|
287
|
-
* ` ^^^^^^ `
|
|
288
|
-
* ```
|
|
289
|
-
* @param node The AST node to check
|
|
290
|
-
* @returns `true` if component is declared inside a render prop, `false` if not
|
|
291
|
-
*/
|
|
292
|
-
declare function isDeclaredInRenderPropLoose(node: TSESTree.Node): boolean;
|
|
293
|
-
|
|
294
|
-
/**
|
|
295
|
-
* Unsafe check whether given node is a render function
|
|
296
|
-
* ```jsx
|
|
297
|
-
* const renderRow = () => <div />
|
|
298
|
-
* ` ^^^^^^^^^^^^`
|
|
299
|
-
* _ = <Component renderRow={() => <div />} />
|
|
300
|
-
* ` ^^^^^^^^^^^^^ `
|
|
301
|
-
* ```
|
|
302
|
-
* @param node The AST node to check
|
|
303
|
-
* @param context The rule context
|
|
304
|
-
* @returns `true` if node is a render function, `false` if not
|
|
305
|
-
*/
|
|
306
|
-
declare function isRenderFunctionLoose(node: AST.TSESTreeFunction, context: RuleContext): boolean;
|
|
307
|
-
/**
|
|
308
|
-
* Unsafe check whether given JSXAttribute is a render prop
|
|
309
|
-
* ```jsx
|
|
310
|
-
* _ = <Component renderRow={() => <div />} />
|
|
311
|
-
* ` ^^^^^^^^^^^^^^^^^^^^^^^^^ `
|
|
312
|
-
* ```
|
|
313
|
-
* @param node The AST node to check
|
|
314
|
-
* @param context The rule context
|
|
315
|
-
* @returns `true` if node is a render prop, `false` if not
|
|
316
|
-
*/
|
|
317
|
-
declare function isRenderPropLoose(node: TSESTree.JSXAttribute, context: RuleContext): boolean;
|
|
318
|
-
|
|
319
316
|
interface ERSemanticEntry {
|
|
320
317
|
node: TSESTree.Node;
|
|
321
318
|
phase: ERPhaseKind;
|
|
322
319
|
}
|
|
323
320
|
|
|
324
|
-
declare function isThisSetState(node: TSESTree.CallExpression): boolean;
|
|
325
|
-
|
|
326
|
-
type ERStateKind = "actionState" | "state";
|
|
327
|
-
|
|
328
321
|
declare const getId: () => string;
|
|
329
322
|
|
|
330
323
|
/**
|
|
@@ -2503,80 +2496,80 @@ declare function isReactAPIWithName(name: string): ReturnType<typeof isFromReact
|
|
|
2503
2496
|
declare function isReactAPIWithName(name: string, member: string): ReturnType<typeof isFromReactMember>;
|
|
2504
2497
|
declare function isReactAPICallWithName(name: string): ReturnType<typeof isCallFromReact>;
|
|
2505
2498
|
declare function isReactAPICallWithName(name: string, member: string): ReturnType<typeof isCallFromReactMember>;
|
|
2506
|
-
declare const isChildrenCount: (node: MemberExpression, context:
|
|
2507
|
-
declare const isChildrenForEach: (node: MemberExpression, context:
|
|
2508
|
-
declare const isChildrenMap: (node: MemberExpression, context:
|
|
2509
|
-
declare const isChildrenOnly: (node: MemberExpression, context:
|
|
2510
|
-
declare const isChildrenToArray: (node: MemberExpression, context:
|
|
2511
|
-
declare const isCloneElement: (node: Identifier | MemberExpression, context:
|
|
2512
|
-
declare const isCreateContext: (node: Identifier | MemberExpression, context:
|
|
2513
|
-
declare const isCreateElement: (node: Identifier | MemberExpression, context:
|
|
2514
|
-
declare const isCreateRef: (node: Identifier | MemberExpression, context:
|
|
2515
|
-
declare const isForwardRef: (node: Identifier | MemberExpression, context:
|
|
2516
|
-
declare const isMemo: (node: Identifier | MemberExpression, context:
|
|
2499
|
+
declare const isChildrenCount: (node: MemberExpression, context: _eslint_react_shared.RuleContext) => boolean;
|
|
2500
|
+
declare const isChildrenForEach: (node: MemberExpression, context: _eslint_react_shared.RuleContext) => boolean;
|
|
2501
|
+
declare const isChildrenMap: (node: MemberExpression, context: _eslint_react_shared.RuleContext) => boolean;
|
|
2502
|
+
declare const isChildrenOnly: (node: MemberExpression, context: _eslint_react_shared.RuleContext) => boolean;
|
|
2503
|
+
declare const isChildrenToArray: (node: MemberExpression, context: _eslint_react_shared.RuleContext) => boolean;
|
|
2504
|
+
declare const isCloneElement: (node: Identifier | MemberExpression, context: _eslint_react_shared.RuleContext) => boolean;
|
|
2505
|
+
declare const isCreateContext: (node: Identifier | MemberExpression, context: _eslint_react_shared.RuleContext) => boolean;
|
|
2506
|
+
declare const isCreateElement: (node: Identifier | MemberExpression, context: _eslint_react_shared.RuleContext) => boolean;
|
|
2507
|
+
declare const isCreateRef: (node: Identifier | MemberExpression, context: _eslint_react_shared.RuleContext) => boolean;
|
|
2508
|
+
declare const isForwardRef: (node: Identifier | MemberExpression, context: _eslint_react_shared.RuleContext) => boolean;
|
|
2509
|
+
declare const isMemo: (node: Identifier | MemberExpression, context: _eslint_react_shared.RuleContext) => boolean;
|
|
2517
2510
|
declare const isChildrenCountCall: {
|
|
2518
|
-
(context:
|
|
2511
|
+
(context: _eslint_react_shared.RuleContext): (node: Node) => node is CallExpression & {
|
|
2519
2512
|
callee: MemberExpression;
|
|
2520
2513
|
};
|
|
2521
|
-
(node: Node, context:
|
|
2514
|
+
(node: Node, context: _eslint_react_shared.RuleContext): node is CallExpression & {
|
|
2522
2515
|
callee: MemberExpression;
|
|
2523
2516
|
};
|
|
2524
2517
|
};
|
|
2525
2518
|
declare const isChildrenForEachCall: {
|
|
2526
|
-
(context:
|
|
2519
|
+
(context: _eslint_react_shared.RuleContext): (node: Node) => node is CallExpression & {
|
|
2527
2520
|
callee: MemberExpression;
|
|
2528
2521
|
};
|
|
2529
|
-
(node: Node, context:
|
|
2522
|
+
(node: Node, context: _eslint_react_shared.RuleContext): node is CallExpression & {
|
|
2530
2523
|
callee: MemberExpression;
|
|
2531
2524
|
};
|
|
2532
2525
|
};
|
|
2533
2526
|
declare const isChildrenMapCall: {
|
|
2534
|
-
(context:
|
|
2527
|
+
(context: _eslint_react_shared.RuleContext): (node: Node) => node is CallExpression & {
|
|
2535
2528
|
callee: MemberExpression;
|
|
2536
2529
|
};
|
|
2537
|
-
(node: Node, context:
|
|
2530
|
+
(node: Node, context: _eslint_react_shared.RuleContext): node is CallExpression & {
|
|
2538
2531
|
callee: MemberExpression;
|
|
2539
2532
|
};
|
|
2540
2533
|
};
|
|
2541
2534
|
declare const isChildrenOnlyCall: {
|
|
2542
|
-
(context:
|
|
2535
|
+
(context: _eslint_react_shared.RuleContext): (node: Node) => node is CallExpression & {
|
|
2543
2536
|
callee: MemberExpression;
|
|
2544
2537
|
};
|
|
2545
|
-
(node: Node, context:
|
|
2538
|
+
(node: Node, context: _eslint_react_shared.RuleContext): node is CallExpression & {
|
|
2546
2539
|
callee: MemberExpression;
|
|
2547
2540
|
};
|
|
2548
2541
|
};
|
|
2549
2542
|
declare const isChildrenToArrayCall: {
|
|
2550
|
-
(context:
|
|
2543
|
+
(context: _eslint_react_shared.RuleContext): (node: Node) => node is CallExpression & {
|
|
2551
2544
|
callee: MemberExpression;
|
|
2552
2545
|
};
|
|
2553
|
-
(node: Node, context:
|
|
2546
|
+
(node: Node, context: _eslint_react_shared.RuleContext): node is CallExpression & {
|
|
2554
2547
|
callee: MemberExpression;
|
|
2555
2548
|
};
|
|
2556
2549
|
};
|
|
2557
2550
|
declare const isCloneElementCall: {
|
|
2558
|
-
(context:
|
|
2559
|
-
(node: Node, context:
|
|
2551
|
+
(context: _eslint_react_shared.RuleContext): (node: Node) => node is CallExpression;
|
|
2552
|
+
(node: Node, context: _eslint_react_shared.RuleContext): node is CallExpression;
|
|
2560
2553
|
};
|
|
2561
2554
|
declare const isCreateContextCall: {
|
|
2562
|
-
(context:
|
|
2563
|
-
(node: Node, context:
|
|
2555
|
+
(context: _eslint_react_shared.RuleContext): (node: Node) => node is CallExpression;
|
|
2556
|
+
(node: Node, context: _eslint_react_shared.RuleContext): node is CallExpression;
|
|
2564
2557
|
};
|
|
2565
2558
|
declare const isCreateElementCall: {
|
|
2566
|
-
(context:
|
|
2567
|
-
(node: Node, context:
|
|
2559
|
+
(context: _eslint_react_shared.RuleContext): (node: Node) => node is CallExpression;
|
|
2560
|
+
(node: Node, context: _eslint_react_shared.RuleContext): node is CallExpression;
|
|
2568
2561
|
};
|
|
2569
2562
|
declare const isCreateRefCall: {
|
|
2570
|
-
(context:
|
|
2571
|
-
(node: Node, context:
|
|
2563
|
+
(context: _eslint_react_shared.RuleContext): (node: Node) => node is CallExpression;
|
|
2564
|
+
(node: Node, context: _eslint_react_shared.RuleContext): node is CallExpression;
|
|
2572
2565
|
};
|
|
2573
2566
|
declare const isForwardRefCall: {
|
|
2574
|
-
(context:
|
|
2575
|
-
(node: Node, context:
|
|
2567
|
+
(context: _eslint_react_shared.RuleContext): (node: Node) => node is CallExpression;
|
|
2568
|
+
(node: Node, context: _eslint_react_shared.RuleContext): node is CallExpression;
|
|
2576
2569
|
};
|
|
2577
2570
|
declare const isMemoCall: {
|
|
2578
|
-
(context:
|
|
2579
|
-
(node: Node, context:
|
|
2571
|
+
(context: _eslint_react_shared.RuleContext): (node: Node) => node is CallExpression;
|
|
2572
|
+
(node: Node, context: _eslint_react_shared.RuleContext): node is CallExpression;
|
|
2580
2573
|
};
|
|
2581
2574
|
|
|
2582
|
-
export { type ComponentCollectorOptions, DEFAULT_COMPONENT_HINT, type ERClassComponent, ERClassComponentFlag, type ERComponent, ERComponentHint, type ERComponentKind, type EREffectKind, type EREffectMethodKind, type EREffectPhaseKind, type ERFunctionComponent, ERFunctionComponentFlag, type ERHook, type ERHookKind, type ERLifecycleMethodKind, type ERLifecyclePhaseKind, type ERPhaseKind, ERPhaseRelevance, type ERSemanticEntry, type ERSemanticNode, type ERStateKind, RE_COMPONENT_NAME, RE_HOOK_NAME, getComponentNameFromIdentifier,
|
|
2575
|
+
export { type ComponentCollectorOptions, DEFAULT_COMPONENT_HINT, type ERClassComponent, ERClassComponentFlag, type ERComponent, ERComponentHint, type ERComponentKind, type EREffectKind, type EREffectMethodKind, type EREffectPhaseKind, type ERFunctionComponent, ERFunctionComponentFlag, type ERHook, type ERHookKind, type ERLifecycleMethodKind, type ERLifecyclePhaseKind, type ERPhaseKind, ERPhaseRelevance, type ERSemanticEntry, type ERSemanticNode, type ERStateKind, RE_COMPONENT_NAME, RE_HOOK_NAME, getComponentNameFromIdentifier, getElementNameOnJsxAndHtml, getFunctionComponentIdentifier, getId, hasNoneOrValidComponentName, isCallFromReact, isCallFromReactMember, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOfCreateElement, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCloneElement, isCloneElementCall, isComponentDidMount, isComponentName, isComponentWillUnmount, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRef, isForwardRefCall, isFromReact, isFromReactMember, isFunctionOfComponentDidMount, isFunctionOfComponentWillUnmount, isFunctionOfRenderMethod, isFunctionOfUseEffectCleanup, isFunctionOfUseEffectSetup, isInitializedFromReact, isInsideCreateElementProps, isInsideReactHook, isInsideRenderMethod, isInversePhase, isMemo, isMemoCall, isPureComponent, isReactAPICallWithName, isReactAPIWithName, isReactHook, isReactHookCall, isReactHookCallWithName, isReactHookCallWithNameAlias, isReactHookCallWithNameLoose, isReactHookName, isRenderFunctionLoose, isRenderMethodLike, isRenderPropLoose, isThisSetState, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectCallLoose, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseReducerCall, isUseRefCall, isUseStateCall, isUseSyncExternalStoreCall, isUseTransitionCall, useComponentCollector, useComponentCollectorLegacy, useHookCollector };
|
package/dist/index.js
CHANGED
|
@@ -6,6 +6,9 @@ var JSX4 = require('@eslint-react/jsx');
|
|
|
6
6
|
var types = require('@typescript-eslint/types');
|
|
7
7
|
var VAR = require('@eslint-react/var');
|
|
8
8
|
var shared = require('@eslint-react/shared');
|
|
9
|
+
var birecord = require('birecord');
|
|
10
|
+
|
|
11
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
12
|
|
|
10
13
|
function _interopNamespace(e) {
|
|
11
14
|
if (e && e.__esModule) return e;
|
|
@@ -28,24 +31,25 @@ function _interopNamespace(e) {
|
|
|
28
31
|
var AST8__namespace = /*#__PURE__*/_interopNamespace(AST8);
|
|
29
32
|
var JSX4__namespace = /*#__PURE__*/_interopNamespace(JSX4);
|
|
30
33
|
var VAR__namespace = /*#__PURE__*/_interopNamespace(VAR);
|
|
34
|
+
var birecord__default = /*#__PURE__*/_interopDefault(birecord);
|
|
31
35
|
|
|
32
36
|
// src/component/component-collector.ts
|
|
33
|
-
function
|
|
37
|
+
function getElementNameOnJsxAndHtml(node, context, polymorphicPropName, additionalComponents = []) {
|
|
34
38
|
const name = JSX4__namespace.getElementName(node);
|
|
35
39
|
if (name === name.toLowerCase()) return [name, name];
|
|
36
40
|
const component = additionalComponents.findLast((c) => c.name === name || c.re.test(name));
|
|
37
41
|
if (component != null) return [name, component.as];
|
|
38
42
|
if (polymorphicPropName == null) return [name, name];
|
|
39
43
|
const initialScope = context.sourceCode.getScope(node);
|
|
40
|
-
const
|
|
44
|
+
const attributeNode = JSX4__namespace.getAttributeNode(
|
|
41
45
|
polymorphicPropName,
|
|
42
46
|
initialScope,
|
|
43
47
|
node.attributes
|
|
44
48
|
);
|
|
45
|
-
if (
|
|
46
|
-
const
|
|
47
|
-
if (typeof
|
|
48
|
-
return [name,
|
|
49
|
+
if (attributeNode == null) return [name, name];
|
|
50
|
+
const polymorphicPropValue = VAR__namespace.toResolved(JSX4__namespace.getAttributeStaticValue(attributeNode, initialScope)).value;
|
|
51
|
+
if (typeof polymorphicPropValue === "string") {
|
|
52
|
+
return [name, polymorphicPropValue];
|
|
49
53
|
}
|
|
50
54
|
return [name, name];
|
|
51
55
|
}
|
|
@@ -389,14 +393,6 @@ function getFunctionComponentIdentifier(node, context) {
|
|
|
389
393
|
}
|
|
390
394
|
return eff._;
|
|
391
395
|
}
|
|
392
|
-
var RE_COMPONENT_NAME = /^_?[A-Z]/u;
|
|
393
|
-
function getComponentNameFromIdentifier(node) {
|
|
394
|
-
if (node == null) return eff._;
|
|
395
|
-
return Array.isArray(node) ? node.map((n) => n.name).join(".") : node.name;
|
|
396
|
-
}
|
|
397
|
-
function isComponentName(name) {
|
|
398
|
-
return RE_COMPONENT_NAME.test(name);
|
|
399
|
-
}
|
|
400
396
|
function isClassComponent(node) {
|
|
401
397
|
if ("superClass" in node && node.superClass != null) {
|
|
402
398
|
const re = /^(?:Pure)?Component$/u;
|
|
@@ -422,7 +418,19 @@ function isPureComponent(node) {
|
|
|
422
418
|
return false;
|
|
423
419
|
}
|
|
424
420
|
|
|
425
|
-
// src/component/component-
|
|
421
|
+
// src/component/component-lifecycle.ts
|
|
422
|
+
function isComponentDidMount(node) {
|
|
423
|
+
return AST8__namespace.isOneOf([types.AST_NODE_TYPES.MethodDefinition, types.AST_NODE_TYPES.PropertyDefinition])(node) && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentDidMount";
|
|
424
|
+
}
|
|
425
|
+
function isComponentWillUnmount(node) {
|
|
426
|
+
return AST8__namespace.isOneOf([types.AST_NODE_TYPES.MethodDefinition, types.AST_NODE_TYPES.PropertyDefinition])(node) && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentWillUnmount";
|
|
427
|
+
}
|
|
428
|
+
function isFunctionOfComponentDidMount(node) {
|
|
429
|
+
return AST8__namespace.isFunction(node) && isComponentDidMount(node.parent) && node.parent.value === node;
|
|
430
|
+
}
|
|
431
|
+
function isFunctionOfComponentWillUnmount(node) {
|
|
432
|
+
return AST8__namespace.isFunction(node) && isComponentWillUnmount(node.parent) && node.parent.value === node;
|
|
433
|
+
}
|
|
426
434
|
function isRenderMethodLike(node) {
|
|
427
435
|
return (node.type === types.AST_NODE_TYPES.MethodDefinition || node.type === types.AST_NODE_TYPES.PropertyDefinition) && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "render" && node.parent.parent.type === types.AST_NODE_TYPES.ClassDeclaration;
|
|
428
436
|
}
|
|
@@ -435,8 +443,14 @@ function isFunctionOfRenderMethod(node) {
|
|
|
435
443
|
function isInsideRenderMethod(node) {
|
|
436
444
|
return AST8__namespace.findParentNode(node, (node2) => isRenderMethodLike(node2) && isClassComponent(node2.parent.parent)) != null;
|
|
437
445
|
}
|
|
438
|
-
|
|
439
|
-
|
|
446
|
+
var RE_COMPONENT_NAME = /^_?[A-Z]/u;
|
|
447
|
+
function getComponentNameFromIdentifier(node) {
|
|
448
|
+
if (node == null) return eff._;
|
|
449
|
+
return Array.isArray(node) ? node.map((n) => n.name).join(".") : node.name;
|
|
450
|
+
}
|
|
451
|
+
function isComponentName(name) {
|
|
452
|
+
return RE_COMPONENT_NAME.test(name);
|
|
453
|
+
}
|
|
440
454
|
function hasNoneOrValidComponentName(node, context) {
|
|
441
455
|
const id2 = getFunctionComponentIdentifier(node, context);
|
|
442
456
|
if (id2 == null) return true;
|
|
@@ -639,49 +653,11 @@ function useComponentCollectorLegacy() {
|
|
|
639
653
|
};
|
|
640
654
|
return { ctx, listeners };
|
|
641
655
|
}
|
|
642
|
-
|
|
643
|
-
if (node == null) return eff._;
|
|
644
|
-
return node.parent?.type === types.AST_NODE_TYPES.CallExpression && node.parent.callee !== node && node.parent.callee.type === types.AST_NODE_TYPES.Identifier && node.parent.arguments.at(0) === node && isUseEffectCallLoose(node.parent);
|
|
645
|
-
}
|
|
646
|
-
function isCleanupFunction(node) {
|
|
647
|
-
const nearReturn = AST8__namespace.findParentNode(node, AST8__namespace.is(types.AST_NODE_TYPES.ReturnStatement));
|
|
648
|
-
const nearFunction = AST8__namespace.findParentNode(node, AST8__namespace.isFunction);
|
|
649
|
-
const nearFunctionOfReturn = AST8__namespace.findParentNode(nearReturn, AST8__namespace.isFunction);
|
|
650
|
-
return nearFunction === nearFunctionOfReturn && isSetupFunction(nearFunction);
|
|
651
|
-
}
|
|
652
|
-
function isComponentDidMount(node) {
|
|
653
|
-
return AST8__namespace.isOneOf([types.AST_NODE_TYPES.MethodDefinition, types.AST_NODE_TYPES.PropertyDefinition])(node) && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentDidMount";
|
|
654
|
-
}
|
|
655
|
-
function isComponentWillUnmount(node) {
|
|
656
|
-
return AST8__namespace.isOneOf([types.AST_NODE_TYPES.MethodDefinition, types.AST_NODE_TYPES.PropertyDefinition])(node) && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentWillUnmount";
|
|
657
|
-
}
|
|
658
|
-
function isComponentDidMountFunction(node) {
|
|
659
|
-
return AST8__namespace.isFunction(node) && isComponentDidMount(node.parent) && node.parent.value === node;
|
|
660
|
-
}
|
|
661
|
-
function isComponentWillUnmountFunction(node) {
|
|
662
|
-
return AST8__namespace.isFunction(node) && isComponentWillUnmount(node.parent) && node.parent.value === node;
|
|
663
|
-
}
|
|
664
|
-
var ERPhaseRelevance = eff.birecord({
|
|
656
|
+
var ERPhaseRelevance = birecord__default.default({
|
|
665
657
|
mount: "unmount",
|
|
666
658
|
setup: "cleanup"
|
|
667
659
|
});
|
|
668
660
|
var isInversePhase = eff.dual(2, (a, b) => ERPhaseRelevance.get(a) === b);
|
|
669
|
-
function isDirectValueOfRenderPropertyLoose(node) {
|
|
670
|
-
const matching = (node2) => {
|
|
671
|
-
return node2.type === types.AST_NODE_TYPES.Property && node2.key.type === types.AST_NODE_TYPES.Identifier && node2.key.name.startsWith("render");
|
|
672
|
-
};
|
|
673
|
-
return matching(node) || node.parent != null && matching(node.parent);
|
|
674
|
-
}
|
|
675
|
-
function isDeclaredInRenderPropLoose(node) {
|
|
676
|
-
if (isDirectValueOfRenderPropertyLoose(node)) {
|
|
677
|
-
return true;
|
|
678
|
-
}
|
|
679
|
-
const parent = AST8__namespace.findParentNode(node, AST8__namespace.is(types.AST_NODE_TYPES.JSXExpressionContainer))?.parent;
|
|
680
|
-
if (parent?.type !== types.AST_NODE_TYPES.JSXAttribute) {
|
|
681
|
-
return false;
|
|
682
|
-
}
|
|
683
|
-
return parent.name.type === types.AST_NODE_TYPES.JSXIdentifier && parent.name.name.startsWith("render");
|
|
684
|
-
}
|
|
685
661
|
function isRenderFunctionLoose(node, context) {
|
|
686
662
|
const { body, parent } = node;
|
|
687
663
|
if (AST8__namespace.getFunctionIdentifier(node)?.name.startsWith("render")) {
|
|
@@ -701,10 +677,36 @@ function isRenderPropLoose(node, context) {
|
|
|
701
677
|
}
|
|
702
678
|
return node.name.name.startsWith("render") && node.value?.type === types.AST_NODE_TYPES.JSXExpressionContainer && AST8__namespace.isFunction(node.value.expression) && isRenderFunctionLoose(node.value.expression, context);
|
|
703
679
|
}
|
|
680
|
+
function isDirectValueOfRenderPropertyLoose(node) {
|
|
681
|
+
const matching = (node2) => {
|
|
682
|
+
return node2.type === types.AST_NODE_TYPES.Property && node2.key.type === types.AST_NODE_TYPES.Identifier && node2.key.name.startsWith("render");
|
|
683
|
+
};
|
|
684
|
+
return matching(node) || node.parent != null && matching(node.parent);
|
|
685
|
+
}
|
|
686
|
+
function isDeclaredInRenderPropLoose(node) {
|
|
687
|
+
if (isDirectValueOfRenderPropertyLoose(node)) {
|
|
688
|
+
return true;
|
|
689
|
+
}
|
|
690
|
+
const parent = AST8__namespace.findParentNode(node, AST8__namespace.is(types.AST_NODE_TYPES.JSXExpressionContainer))?.parent;
|
|
691
|
+
if (parent?.type !== types.AST_NODE_TYPES.JSXAttribute) {
|
|
692
|
+
return false;
|
|
693
|
+
}
|
|
694
|
+
return parent.name.type === types.AST_NODE_TYPES.JSXIdentifier && parent.name.name.startsWith("render");
|
|
695
|
+
}
|
|
704
696
|
function isThisSetState(node) {
|
|
705
697
|
const { callee } = node;
|
|
706
698
|
return callee.type === types.AST_NODE_TYPES.MemberExpression && AST8__namespace.isThisExpression(callee.object) && callee.property.type === types.AST_NODE_TYPES.Identifier && callee.property.name === "setState";
|
|
707
699
|
}
|
|
700
|
+
function isFunctionOfUseEffectSetup(node) {
|
|
701
|
+
if (node == null) return eff._;
|
|
702
|
+
return node.parent?.type === types.AST_NODE_TYPES.CallExpression && node.parent.callee !== node && node.parent.callee.type === types.AST_NODE_TYPES.Identifier && node.parent.arguments.at(0) === node && isUseEffectCallLoose(node.parent);
|
|
703
|
+
}
|
|
704
|
+
function isFunctionOfUseEffectCleanup(node) {
|
|
705
|
+
const nearReturn = AST8__namespace.findParentNode(node, AST8__namespace.is(types.AST_NODE_TYPES.ReturnStatement));
|
|
706
|
+
const nearFunction = AST8__namespace.findParentNode(node, AST8__namespace.isFunction);
|
|
707
|
+
const nearFunctionOfReturn = AST8__namespace.findParentNode(nearReturn, AST8__namespace.isFunction);
|
|
708
|
+
return nearFunction === nearFunctionOfReturn && isFunctionOfUseEffectSetup(nearFunction);
|
|
709
|
+
}
|
|
708
710
|
|
|
709
711
|
exports.DEFAULT_COMPONENT_HINT = DEFAULT_COMPONENT_HINT;
|
|
710
712
|
exports.ERClassComponentFlag = ERClassComponentFlag;
|
|
@@ -714,7 +716,7 @@ exports.ERPhaseRelevance = ERPhaseRelevance;
|
|
|
714
716
|
exports.RE_COMPONENT_NAME = RE_COMPONENT_NAME;
|
|
715
717
|
exports.RE_HOOK_NAME = RE_HOOK_NAME;
|
|
716
718
|
exports.getComponentNameFromIdentifier = getComponentNameFromIdentifier;
|
|
717
|
-
exports.
|
|
719
|
+
exports.getElementNameOnJsxAndHtml = getElementNameOnJsxAndHtml;
|
|
718
720
|
exports.getFunctionComponentIdentifier = getFunctionComponentIdentifier;
|
|
719
721
|
exports.getId = getId;
|
|
720
722
|
exports.hasNoneOrValidComponentName = hasNoneOrValidComponentName;
|
|
@@ -732,14 +734,11 @@ exports.isChildrenOnlyCall = isChildrenOnlyCall;
|
|
|
732
734
|
exports.isChildrenToArray = isChildrenToArray;
|
|
733
735
|
exports.isChildrenToArrayCall = isChildrenToArrayCall;
|
|
734
736
|
exports.isClassComponent = isClassComponent;
|
|
735
|
-
exports.isCleanupFunction = isCleanupFunction;
|
|
736
737
|
exports.isCloneElement = isCloneElement;
|
|
737
738
|
exports.isCloneElementCall = isCloneElementCall;
|
|
738
739
|
exports.isComponentDidMount = isComponentDidMount;
|
|
739
|
-
exports.isComponentDidMountFunction = isComponentDidMountFunction;
|
|
740
740
|
exports.isComponentName = isComponentName;
|
|
741
741
|
exports.isComponentWillUnmount = isComponentWillUnmount;
|
|
742
|
-
exports.isComponentWillUnmountFunction = isComponentWillUnmountFunction;
|
|
743
742
|
exports.isCreateContext = isCreateContext;
|
|
744
743
|
exports.isCreateContextCall = isCreateContextCall;
|
|
745
744
|
exports.isCreateElement = isCreateElement;
|
|
@@ -752,7 +751,11 @@ exports.isForwardRef = isForwardRef;
|
|
|
752
751
|
exports.isForwardRefCall = isForwardRefCall;
|
|
753
752
|
exports.isFromReact = isFromReact;
|
|
754
753
|
exports.isFromReactMember = isFromReactMember;
|
|
754
|
+
exports.isFunctionOfComponentDidMount = isFunctionOfComponentDidMount;
|
|
755
|
+
exports.isFunctionOfComponentWillUnmount = isFunctionOfComponentWillUnmount;
|
|
755
756
|
exports.isFunctionOfRenderMethod = isFunctionOfRenderMethod;
|
|
757
|
+
exports.isFunctionOfUseEffectCleanup = isFunctionOfUseEffectCleanup;
|
|
758
|
+
exports.isFunctionOfUseEffectSetup = isFunctionOfUseEffectSetup;
|
|
756
759
|
exports.isInitializedFromReact = isInitializedFromReact;
|
|
757
760
|
exports.isInsideCreateElementProps = isInsideCreateElementProps;
|
|
758
761
|
exports.isInsideReactHook = isInsideReactHook;
|
|
@@ -772,7 +775,6 @@ exports.isReactHookName = isReactHookName;
|
|
|
772
775
|
exports.isRenderFunctionLoose = isRenderFunctionLoose;
|
|
773
776
|
exports.isRenderMethodLike = isRenderMethodLike;
|
|
774
777
|
exports.isRenderPropLoose = isRenderPropLoose;
|
|
775
|
-
exports.isSetupFunction = isSetupFunction;
|
|
776
778
|
exports.isThisSetState = isThisSetState;
|
|
777
779
|
exports.isUseCallbackCall = isUseCallbackCall;
|
|
778
780
|
exports.isUseContextCall = isUseContextCall;
|
package/dist/index.mjs
CHANGED
|
@@ -1,27 +1,28 @@
|
|
|
1
1
|
import * as AST8 from '@eslint-react/ast';
|
|
2
|
-
import { flip,
|
|
2
|
+
import { flip, dual, _, returnFalse } from '@eslint-react/eff';
|
|
3
3
|
import * as JSX4 from '@eslint-react/jsx';
|
|
4
4
|
import { AST_NODE_TYPES } from '@typescript-eslint/types';
|
|
5
5
|
import * as VAR from '@eslint-react/var';
|
|
6
6
|
import { unsafeDecodeSettings } from '@eslint-react/shared';
|
|
7
|
+
import birecord from 'birecord';
|
|
7
8
|
|
|
8
9
|
// src/component/component-collector.ts
|
|
9
|
-
function
|
|
10
|
+
function getElementNameOnJsxAndHtml(node, context, polymorphicPropName, additionalComponents = []) {
|
|
10
11
|
const name = JSX4.getElementName(node);
|
|
11
12
|
if (name === name.toLowerCase()) return [name, name];
|
|
12
13
|
const component = additionalComponents.findLast((c) => c.name === name || c.re.test(name));
|
|
13
14
|
if (component != null) return [name, component.as];
|
|
14
15
|
if (polymorphicPropName == null) return [name, name];
|
|
15
16
|
const initialScope = context.sourceCode.getScope(node);
|
|
16
|
-
const
|
|
17
|
+
const attributeNode = JSX4.getAttributeNode(
|
|
17
18
|
polymorphicPropName,
|
|
18
19
|
initialScope,
|
|
19
20
|
node.attributes
|
|
20
21
|
);
|
|
21
|
-
if (
|
|
22
|
-
const
|
|
23
|
-
if (typeof
|
|
24
|
-
return [name,
|
|
22
|
+
if (attributeNode == null) return [name, name];
|
|
23
|
+
const polymorphicPropValue = VAR.toResolved(JSX4.getAttributeStaticValue(attributeNode, initialScope)).value;
|
|
24
|
+
if (typeof polymorphicPropValue === "string") {
|
|
25
|
+
return [name, polymorphicPropValue];
|
|
25
26
|
}
|
|
26
27
|
return [name, name];
|
|
27
28
|
}
|
|
@@ -365,14 +366,6 @@ function getFunctionComponentIdentifier(node, context) {
|
|
|
365
366
|
}
|
|
366
367
|
return _;
|
|
367
368
|
}
|
|
368
|
-
var RE_COMPONENT_NAME = /^_?[A-Z]/u;
|
|
369
|
-
function getComponentNameFromIdentifier(node) {
|
|
370
|
-
if (node == null) return _;
|
|
371
|
-
return Array.isArray(node) ? node.map((n) => n.name).join(".") : node.name;
|
|
372
|
-
}
|
|
373
|
-
function isComponentName(name) {
|
|
374
|
-
return RE_COMPONENT_NAME.test(name);
|
|
375
|
-
}
|
|
376
369
|
function isClassComponent(node) {
|
|
377
370
|
if ("superClass" in node && node.superClass != null) {
|
|
378
371
|
const re = /^(?:Pure)?Component$/u;
|
|
@@ -398,7 +391,19 @@ function isPureComponent(node) {
|
|
|
398
391
|
return false;
|
|
399
392
|
}
|
|
400
393
|
|
|
401
|
-
// src/component/component-
|
|
394
|
+
// src/component/component-lifecycle.ts
|
|
395
|
+
function isComponentDidMount(node) {
|
|
396
|
+
return AST8.isOneOf([AST_NODE_TYPES.MethodDefinition, AST_NODE_TYPES.PropertyDefinition])(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentDidMount";
|
|
397
|
+
}
|
|
398
|
+
function isComponentWillUnmount(node) {
|
|
399
|
+
return AST8.isOneOf([AST_NODE_TYPES.MethodDefinition, AST_NODE_TYPES.PropertyDefinition])(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentWillUnmount";
|
|
400
|
+
}
|
|
401
|
+
function isFunctionOfComponentDidMount(node) {
|
|
402
|
+
return AST8.isFunction(node) && isComponentDidMount(node.parent) && node.parent.value === node;
|
|
403
|
+
}
|
|
404
|
+
function isFunctionOfComponentWillUnmount(node) {
|
|
405
|
+
return AST8.isFunction(node) && isComponentWillUnmount(node.parent) && node.parent.value === node;
|
|
406
|
+
}
|
|
402
407
|
function isRenderMethodLike(node) {
|
|
403
408
|
return (node.type === AST_NODE_TYPES.MethodDefinition || node.type === AST_NODE_TYPES.PropertyDefinition) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "render" && node.parent.parent.type === AST_NODE_TYPES.ClassDeclaration;
|
|
404
409
|
}
|
|
@@ -411,8 +416,14 @@ function isFunctionOfRenderMethod(node) {
|
|
|
411
416
|
function isInsideRenderMethod(node) {
|
|
412
417
|
return AST8.findParentNode(node, (node2) => isRenderMethodLike(node2) && isClassComponent(node2.parent.parent)) != null;
|
|
413
418
|
}
|
|
414
|
-
|
|
415
|
-
|
|
419
|
+
var RE_COMPONENT_NAME = /^_?[A-Z]/u;
|
|
420
|
+
function getComponentNameFromIdentifier(node) {
|
|
421
|
+
if (node == null) return _;
|
|
422
|
+
return Array.isArray(node) ? node.map((n) => n.name).join(".") : node.name;
|
|
423
|
+
}
|
|
424
|
+
function isComponentName(name) {
|
|
425
|
+
return RE_COMPONENT_NAME.test(name);
|
|
426
|
+
}
|
|
416
427
|
function hasNoneOrValidComponentName(node, context) {
|
|
417
428
|
const id2 = getFunctionComponentIdentifier(node, context);
|
|
418
429
|
if (id2 == null) return true;
|
|
@@ -615,49 +626,11 @@ function useComponentCollectorLegacy() {
|
|
|
615
626
|
};
|
|
616
627
|
return { ctx, listeners };
|
|
617
628
|
}
|
|
618
|
-
function isSetupFunction(node) {
|
|
619
|
-
if (node == null) return _;
|
|
620
|
-
return node.parent?.type === AST_NODE_TYPES.CallExpression && node.parent.callee !== node && node.parent.callee.type === AST_NODE_TYPES.Identifier && node.parent.arguments.at(0) === node && isUseEffectCallLoose(node.parent);
|
|
621
|
-
}
|
|
622
|
-
function isCleanupFunction(node) {
|
|
623
|
-
const nearReturn = AST8.findParentNode(node, AST8.is(AST_NODE_TYPES.ReturnStatement));
|
|
624
|
-
const nearFunction = AST8.findParentNode(node, AST8.isFunction);
|
|
625
|
-
const nearFunctionOfReturn = AST8.findParentNode(nearReturn, AST8.isFunction);
|
|
626
|
-
return nearFunction === nearFunctionOfReturn && isSetupFunction(nearFunction);
|
|
627
|
-
}
|
|
628
|
-
function isComponentDidMount(node) {
|
|
629
|
-
return AST8.isOneOf([AST_NODE_TYPES.MethodDefinition, AST_NODE_TYPES.PropertyDefinition])(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentDidMount";
|
|
630
|
-
}
|
|
631
|
-
function isComponentWillUnmount(node) {
|
|
632
|
-
return AST8.isOneOf([AST_NODE_TYPES.MethodDefinition, AST_NODE_TYPES.PropertyDefinition])(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentWillUnmount";
|
|
633
|
-
}
|
|
634
|
-
function isComponentDidMountFunction(node) {
|
|
635
|
-
return AST8.isFunction(node) && isComponentDidMount(node.parent) && node.parent.value === node;
|
|
636
|
-
}
|
|
637
|
-
function isComponentWillUnmountFunction(node) {
|
|
638
|
-
return AST8.isFunction(node) && isComponentWillUnmount(node.parent) && node.parent.value === node;
|
|
639
|
-
}
|
|
640
629
|
var ERPhaseRelevance = birecord({
|
|
641
630
|
mount: "unmount",
|
|
642
631
|
setup: "cleanup"
|
|
643
632
|
});
|
|
644
633
|
var isInversePhase = dual(2, (a, b) => ERPhaseRelevance.get(a) === b);
|
|
645
|
-
function isDirectValueOfRenderPropertyLoose(node) {
|
|
646
|
-
const matching = (node2) => {
|
|
647
|
-
return node2.type === AST_NODE_TYPES.Property && node2.key.type === AST_NODE_TYPES.Identifier && node2.key.name.startsWith("render");
|
|
648
|
-
};
|
|
649
|
-
return matching(node) || node.parent != null && matching(node.parent);
|
|
650
|
-
}
|
|
651
|
-
function isDeclaredInRenderPropLoose(node) {
|
|
652
|
-
if (isDirectValueOfRenderPropertyLoose(node)) {
|
|
653
|
-
return true;
|
|
654
|
-
}
|
|
655
|
-
const parent = AST8.findParentNode(node, AST8.is(AST_NODE_TYPES.JSXExpressionContainer))?.parent;
|
|
656
|
-
if (parent?.type !== AST_NODE_TYPES.JSXAttribute) {
|
|
657
|
-
return false;
|
|
658
|
-
}
|
|
659
|
-
return parent.name.type === AST_NODE_TYPES.JSXIdentifier && parent.name.name.startsWith("render");
|
|
660
|
-
}
|
|
661
634
|
function isRenderFunctionLoose(node, context) {
|
|
662
635
|
const { body, parent } = node;
|
|
663
636
|
if (AST8.getFunctionIdentifier(node)?.name.startsWith("render")) {
|
|
@@ -677,9 +650,35 @@ function isRenderPropLoose(node, context) {
|
|
|
677
650
|
}
|
|
678
651
|
return node.name.name.startsWith("render") && node.value?.type === AST_NODE_TYPES.JSXExpressionContainer && AST8.isFunction(node.value.expression) && isRenderFunctionLoose(node.value.expression, context);
|
|
679
652
|
}
|
|
653
|
+
function isDirectValueOfRenderPropertyLoose(node) {
|
|
654
|
+
const matching = (node2) => {
|
|
655
|
+
return node2.type === AST_NODE_TYPES.Property && node2.key.type === AST_NODE_TYPES.Identifier && node2.key.name.startsWith("render");
|
|
656
|
+
};
|
|
657
|
+
return matching(node) || node.parent != null && matching(node.parent);
|
|
658
|
+
}
|
|
659
|
+
function isDeclaredInRenderPropLoose(node) {
|
|
660
|
+
if (isDirectValueOfRenderPropertyLoose(node)) {
|
|
661
|
+
return true;
|
|
662
|
+
}
|
|
663
|
+
const parent = AST8.findParentNode(node, AST8.is(AST_NODE_TYPES.JSXExpressionContainer))?.parent;
|
|
664
|
+
if (parent?.type !== AST_NODE_TYPES.JSXAttribute) {
|
|
665
|
+
return false;
|
|
666
|
+
}
|
|
667
|
+
return parent.name.type === AST_NODE_TYPES.JSXIdentifier && parent.name.name.startsWith("render");
|
|
668
|
+
}
|
|
680
669
|
function isThisSetState(node) {
|
|
681
670
|
const { callee } = node;
|
|
682
671
|
return callee.type === AST_NODE_TYPES.MemberExpression && AST8.isThisExpression(callee.object) && callee.property.type === AST_NODE_TYPES.Identifier && callee.property.name === "setState";
|
|
683
672
|
}
|
|
673
|
+
function isFunctionOfUseEffectSetup(node) {
|
|
674
|
+
if (node == null) return _;
|
|
675
|
+
return node.parent?.type === AST_NODE_TYPES.CallExpression && node.parent.callee !== node && node.parent.callee.type === AST_NODE_TYPES.Identifier && node.parent.arguments.at(0) === node && isUseEffectCallLoose(node.parent);
|
|
676
|
+
}
|
|
677
|
+
function isFunctionOfUseEffectCleanup(node) {
|
|
678
|
+
const nearReturn = AST8.findParentNode(node, AST8.is(AST_NODE_TYPES.ReturnStatement));
|
|
679
|
+
const nearFunction = AST8.findParentNode(node, AST8.isFunction);
|
|
680
|
+
const nearFunctionOfReturn = AST8.findParentNode(nearReturn, AST8.isFunction);
|
|
681
|
+
return nearFunction === nearFunctionOfReturn && isFunctionOfUseEffectSetup(nearFunction);
|
|
682
|
+
}
|
|
684
683
|
|
|
685
|
-
export { DEFAULT_COMPONENT_HINT, ERClassComponentFlag, ERComponentHint, ERFunctionComponentFlag, ERPhaseRelevance, RE_COMPONENT_NAME, RE_HOOK_NAME, getComponentNameFromIdentifier,
|
|
684
|
+
export { DEFAULT_COMPONENT_HINT, ERClassComponentFlag, ERComponentHint, ERFunctionComponentFlag, ERPhaseRelevance, RE_COMPONENT_NAME, RE_HOOK_NAME, getComponentNameFromIdentifier, getElementNameOnJsxAndHtml, getFunctionComponentIdentifier, getId, hasNoneOrValidComponentName, isCallFromReact, isCallFromReactMember, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOfCreateElement, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCloneElement, isCloneElementCall, isComponentDidMount, isComponentName, isComponentWillUnmount, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRef, isForwardRefCall, isFromReact, isFromReactMember, isFunctionOfComponentDidMount, isFunctionOfComponentWillUnmount, isFunctionOfRenderMethod, isFunctionOfUseEffectCleanup, isFunctionOfUseEffectSetup, isInitializedFromReact, isInsideCreateElementProps, isInsideReactHook, isInsideRenderMethod, isInversePhase, isMemo, isMemoCall, isPureComponent, isReactAPICallWithName, isReactAPIWithName, isReactHook, isReactHookCall, isReactHookCallWithName, isReactHookCallWithNameAlias, isReactHookCallWithNameLoose, isReactHookName, isRenderFunctionLoose, isRenderMethodLike, isRenderPropLoose, isThisSetState, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectCallLoose, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseReducerCall, isUseRefCall, isUseStateCall, isUseSyncExternalStoreCall, isUseTransitionCall, useComponentCollector, useComponentCollectorLegacy, useHookCollector };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/core",
|
|
3
|
-
"version": "1.24.0-beta.
|
|
3
|
+
"version": "1.24.0-beta.8",
|
|
4
4
|
"description": "ESLint React's ESLint utility module for static analysis of React core APIs and Patterns.",
|
|
5
5
|
"homepage": "https://github.com/Rel1cx/eslint-react",
|
|
6
6
|
"bugs": {
|
|
@@ -33,17 +33,17 @@
|
|
|
33
33
|
"./package.json"
|
|
34
34
|
],
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@typescript-eslint/scope-manager": "^8.
|
|
37
|
-
"@typescript-eslint/type-utils": "^8.
|
|
38
|
-
"@typescript-eslint/types": "^8.
|
|
39
|
-
"@typescript-eslint/utils": "^8.
|
|
36
|
+
"@typescript-eslint/scope-manager": "^8.20.0",
|
|
37
|
+
"@typescript-eslint/type-utils": "^8.20.0",
|
|
38
|
+
"@typescript-eslint/types": "^8.20.0",
|
|
39
|
+
"@typescript-eslint/utils": "^8.20.0",
|
|
40
|
+
"birecord": "^0.1.1",
|
|
40
41
|
"ts-pattern": "^5.6.0",
|
|
41
|
-
"@eslint-react/
|
|
42
|
-
"@eslint-react/jsx": "1.24.0-beta.
|
|
43
|
-
"@eslint-react/shared": "1.24.0-beta.
|
|
44
|
-
"@eslint-react/
|
|
45
|
-
"@eslint-react/var": "1.24.0-beta.
|
|
46
|
-
"@eslint-react/ast": "1.24.0-beta.3"
|
|
42
|
+
"@eslint-react/ast": "1.24.0-beta.8",
|
|
43
|
+
"@eslint-react/jsx": "1.24.0-beta.8",
|
|
44
|
+
"@eslint-react/shared": "1.24.0-beta.8",
|
|
45
|
+
"@eslint-react/eff": "1.24.0-beta.8",
|
|
46
|
+
"@eslint-react/var": "1.24.0-beta.8"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"tsup": "^8.3.5",
|