@eslint-react/core 1.22.2-next.8 → 1.22.2

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 CHANGED
@@ -160,12 +160,18 @@ declare function isCleanupFunction(node: TSESTree.Node): boolean;
160
160
  declare function getElementRepresentName(node: TSESTree.JSXOpeningElement, context: RuleContext): string;
161
161
 
162
162
  /**
163
- * Determines whether inside createElement's props.
163
+ * Determines whether inside `createElement`'s props.
164
164
  * @param node The AST node to check
165
165
  * @param context The rule context
166
166
  * @returns `true` if the node is inside createElement's props
167
167
  */
168
168
  declare function isInsideCreateElementProps(node: TSESTree.Node, context: RuleContext): boolean;
169
+ /**
170
+ * Determines whether inside `createElement`'s children.
171
+ * @param node The AST node to check
172
+ * @param context The rule context
173
+ * @returns `true` if the node is inside createElement's children
174
+ */
169
175
  declare function isChildrenOfCreateElement(node: TSESTree.Node, context: RuleContext): boolean;
170
176
 
171
177
  /**
@@ -177,7 +183,6 @@ declare function isChildrenOfCreateElement(node: TSESTree.Node, context: RuleCon
177
183
  declare function isFragmentElement(node: TSESTree.JSXElement, context: RuleContext): boolean;
178
184
 
179
185
  declare function isInsideReactHook(node: TSESTree.Node): boolean;
180
- declare function isInsideReactHookCall(node: TSESTree.Node): boolean;
181
186
 
182
187
  interface ERHook extends ERSemanticNode {
183
188
  id: O.Some<TSESTree.Identifier>;
@@ -209,7 +214,7 @@ declare function isReactHook(node: AST.TSESTreeFunction): boolean;
209
214
  * @param node The node to check.
210
215
  * @returns `true` if the node is a React Hook call, `false` otherwise.
211
216
  */
212
- declare function isReactHookCall(node: TSESTree.CallExpression): boolean;
217
+ declare function isReactHookCall(node: TSESTree.Node): boolean;
213
218
  declare function isReactHookCallWithName(node: TSESTree.CallExpression, context: RuleContext): (name: string) => boolean;
214
219
  declare function isReactHookCallWithNameLoose(node: TSESTree.CallExpression): (name: string) => boolean;
215
220
  declare function isReactHookCallWithNameAlias(name: string, context: RuleContext, alias: string[]): (node: TSESTree.CallExpression) => boolean;
@@ -317,8 +322,20 @@ declare function isFromReact(name: string): (node: TSESTree.Identifier | TSESTre
317
322
  * @returns A function that checks if a given node is a member expression of a Pragma member.
318
323
  */
319
324
  declare function isFromReactMember(memberName: string, name: string): (node: TSESTree.MemberExpression, context: RuleContext) => boolean;
320
- declare function isCallFromReact(name: string): (node: TSESTree.CallExpression, context: RuleContext) => boolean;
321
- declare function isCallFromReactMember(pragmaMemberName: string, name: string): (node: TSESTree.CallExpression, context: RuleContext) => boolean;
325
+ type IsCallFromReact = {
326
+ (context: RuleContext): (node: TSESTree.Node) => node is TSESTree.CallExpression;
327
+ (node: TSESTree.Node, context: RuleContext): node is TSESTree.CallExpression;
328
+ };
329
+ declare function isCallFromReact(name: string): IsCallFromReact;
330
+ type IsCallFromReactMember = {
331
+ (context: RuleContext): (node: TSESTree.Node) => node is TSESTree.CallExpression & {
332
+ callee: TSESTree.MemberExpression;
333
+ };
334
+ (node: TSESTree.Node, context: RuleContext): node is TSESTree.CallExpression & {
335
+ callee: TSESTree.MemberExpression;
336
+ };
337
+ };
338
+ declare function isCallFromReactMember(pragmaMemberName: string, name: string): IsCallFromReactMember;
322
339
 
323
340
  /**
324
341
  * Check if an identifier is initialized from React
@@ -574,6 +591,21 @@ declare enum AST_NODE_TYPES {
574
591
  TSUnknownKeyword = "TSUnknownKeyword",
575
592
  TSVoidKeyword = "TSVoidKeyword"
576
593
  }
594
+ declare enum AST_TOKEN_TYPES {
595
+ Boolean = "Boolean",
596
+ Identifier = "Identifier",
597
+ JSXIdentifier = "JSXIdentifier",
598
+ JSXText = "JSXText",
599
+ Keyword = "Keyword",
600
+ Null = "Null",
601
+ Numeric = "Numeric",
602
+ Punctuator = "Punctuator",
603
+ RegularExpression = "RegularExpression",
604
+ String = "String",
605
+ Template = "Template",
606
+ Block = "Block",
607
+ Line = "Line"
608
+ }
577
609
  declare interface AwaitExpression extends BaseNode {
578
610
  type: AST_NODE_TYPES.AwaitExpression;
579
611
  argument: Expression;
@@ -581,6 +613,10 @@ declare interface AwaitExpression extends BaseNode {
581
613
  declare interface BaseNode extends NodeOrTokenData {
582
614
  type: AST_NODE_TYPES;
583
615
  }
616
+ declare interface BaseToken extends NodeOrTokenData {
617
+ type: AST_TOKEN_TYPES;
618
+ value: string;
619
+ }
584
620
  declare interface BigIntLiteral extends LiteralBase {
585
621
  bigint: string;
586
622
  value: bigint | null;
@@ -619,6 +655,9 @@ declare interface BinaryOperatorToText {
619
655
  }
620
656
  declare type BindingName = BindingPattern | Identifier;
621
657
  declare type BindingPattern = ArrayPattern | ObjectPattern;
658
+ declare interface BlockComment extends BaseToken {
659
+ type: AST_TOKEN_TYPES.Block;
660
+ }
622
661
  declare interface BlockStatement extends BaseNode {
623
662
  type: AST_NODE_TYPES.BlockStatement;
624
663
  body: Statement[];
@@ -627,6 +666,9 @@ declare interface BooleanLiteral extends LiteralBase {
627
666
  raw: 'false' | 'true';
628
667
  value: boolean;
629
668
  }
669
+ declare interface BooleanToken extends BaseToken {
670
+ type: AST_TOKEN_TYPES.Boolean;
671
+ }
630
672
  declare interface BreakStatement extends BaseNode {
631
673
  type: AST_NODE_TYPES.BreakStatement;
632
674
  label: Identifier | null;
@@ -707,6 +749,7 @@ declare interface ClassBody extends BaseNode {
707
749
  type: AST_NODE_TYPES.ClassBody;
708
750
  body: ClassElement[];
709
751
  }
752
+ declare type ClassDeclaration = ClassDeclarationWithName | ClassDeclarationWithOptionalName;
710
753
  declare interface ClassDeclarationBase extends ClassBase {
711
754
  type: AST_NODE_TYPES.ClassDeclaration;
712
755
  }
@@ -743,6 +786,7 @@ declare interface ClassPropertyDefinitionNonComputedNameBase extends PropertyDef
743
786
  key: ClassPropertyNameNonComputed;
744
787
  }
745
788
  declare type ClassPropertyNameNonComputed = PrivateIdentifier | PropertyNameNonComputed;
789
+ declare type Comment = BlockComment | LineComment;
746
790
  declare interface ConditionalExpression extends BaseNode {
747
791
  type: AST_NODE_TYPES.ConditionalExpression;
748
792
  alternate: Expression;
@@ -1035,6 +1079,7 @@ declare interface FunctionBase extends BaseNode {
1035
1079
  */
1036
1080
  typeParameters: TSTypeParameterDeclaration | undefined;
1037
1081
  }
1082
+ declare type FunctionDeclaration = FunctionDeclarationWithName | FunctionDeclarationWithOptionalName;
1038
1083
  declare interface FunctionDeclarationBase extends FunctionBase {
1039
1084
  type: AST_NODE_TYPES.FunctionDeclaration;
1040
1085
  body: BlockStatement;
@@ -1071,6 +1116,9 @@ declare interface Identifier extends BaseNode {
1071
1116
  optional: boolean;
1072
1117
  typeAnnotation: TSTypeAnnotation | undefined;
1073
1118
  }
1119
+ declare interface IdentifierToken extends BaseToken {
1120
+ type: AST_TOKEN_TYPES.Identifier;
1121
+ }
1074
1122
  declare interface IfStatement extends BaseNode {
1075
1123
  type: AST_NODE_TYPES.IfStatement;
1076
1124
  alternate: Statement | null;
@@ -1196,6 +1244,9 @@ declare interface JSXIdentifier extends BaseNode {
1196
1244
  type: AST_NODE_TYPES.JSXIdentifier;
1197
1245
  name: string;
1198
1246
  }
1247
+ declare interface JSXIdentifierToken extends BaseToken {
1248
+ type: AST_TOKEN_TYPES.JSXIdentifier;
1249
+ }
1199
1250
  declare interface JSXMemberExpression extends BaseNode {
1200
1251
  type: AST_NODE_TYPES.JSXMemberExpression;
1201
1252
  object: JSXTagNameExpression;
@@ -1230,6 +1281,12 @@ declare interface JSXText extends BaseNode {
1230
1281
  raw: string;
1231
1282
  value: string;
1232
1283
  }
1284
+ declare interface JSXTextToken extends BaseToken {
1285
+ type: AST_TOKEN_TYPES.JSXText;
1286
+ }
1287
+ declare interface KeywordToken extends BaseToken {
1288
+ type: AST_TOKEN_TYPES.Keyword;
1289
+ }
1233
1290
  declare interface LabeledStatement extends BaseNode {
1234
1291
  type: AST_NODE_TYPES.LabeledStatement;
1235
1292
  body: Statement;
@@ -1293,6 +1350,9 @@ declare interface LetOrVarNonDeclaredDeclaration extends LetOrConstOrVarDeclarat
1293
1350
  declare: false;
1294
1351
  kind: 'let' | 'var';
1295
1352
  }
1353
+ declare interface LineComment extends BaseToken {
1354
+ type: AST_TOKEN_TYPES.Line;
1355
+ }
1296
1356
  declare type Literal = BigIntLiteral | BooleanLiteral | NullLiteral | NumberLiteral | RegExpLiteral | StringLiteral;
1297
1357
  declare interface LiteralBase extends BaseNode {
1298
1358
  type: AST_NODE_TYPES.Literal;
@@ -1362,6 +1422,7 @@ declare interface NewExpression extends BaseNode {
1362
1422
  callee: Expression;
1363
1423
  typeArguments: TSTypeParameterInstantiation | undefined;
1364
1424
  }
1425
+ declare type Node = AccessorProperty | ArrayExpression | ArrayPattern | ArrowFunctionExpression | AssignmentExpression | AssignmentPattern | AwaitExpression | BinaryExpression | BlockStatement | BreakStatement | CallExpression | CatchClause | ChainExpression | ClassBody | ClassDeclaration | ClassExpression | ConditionalExpression | ContinueStatement | DebuggerStatement | Decorator | DoWhileStatement | EmptyStatement | ExportAllDeclaration | ExportDefaultDeclaration | ExportNamedDeclaration | ExportSpecifier | ExpressionStatement | ForInStatement | ForOfStatement | ForStatement | FunctionDeclaration | FunctionExpression | Identifier | IfStatement | ImportAttribute | ImportDeclaration | ImportDefaultSpecifier | ImportExpression | ImportNamespaceSpecifier | ImportSpecifier | JSXAttribute | JSXClosingElement | JSXClosingFragment | JSXElement | JSXEmptyExpression | JSXExpressionContainer | JSXFragment | JSXIdentifier | JSXMemberExpression | JSXNamespacedName | JSXOpeningElement | JSXOpeningFragment | JSXSpreadAttribute | JSXSpreadChild | JSXText | LabeledStatement | Literal | LogicalExpression | MemberExpression | MetaProperty | MethodDefinition | NewExpression | ObjectExpression | ObjectPattern | PrivateIdentifier | Program | Property | PropertyDefinition | RestElement | ReturnStatement | SequenceExpression | SpreadElement | StaticBlock | Super | SwitchCase | SwitchStatement | TaggedTemplateExpression | TemplateElement | TemplateLiteral | ThisExpression | ThrowStatement | TryStatement | TSAbstractAccessorProperty | TSAbstractKeyword | TSAbstractMethodDefinition | TSAbstractPropertyDefinition | TSAnyKeyword | TSArrayType | TSAsExpression | TSAsyncKeyword | TSBigIntKeyword | TSBooleanKeyword | TSCallSignatureDeclaration | TSClassImplements | TSConditionalType | TSConstructorType | TSConstructSignatureDeclaration | TSDeclareFunction | TSDeclareKeyword | TSEmptyBodyFunctionExpression | TSEnumBody | TSEnumDeclaration | TSEnumMember | TSExportAssignment | TSExportKeyword | TSExternalModuleReference | TSFunctionType | TSImportEqualsDeclaration | TSImportType | TSIndexedAccessType | TSIndexSignature | TSInferType | TSInstantiationExpression | TSInterfaceBody | TSInterfaceDeclaration | TSInterfaceHeritage | TSIntersectionType | TSIntrinsicKeyword | TSLiteralType | TSMappedType | TSMethodSignature | TSModuleBlock | TSModuleDeclaration | TSNamedTupleMember | TSNamespaceExportDeclaration | TSNeverKeyword | TSNonNullExpression | TSNullKeyword | TSNumberKeyword | TSObjectKeyword | TSOptionalType | TSParameterProperty | TSPrivateKeyword | TSPropertySignature | TSProtectedKeyword | TSPublicKeyword | TSQualifiedName | TSReadonlyKeyword | TSRestType | TSSatisfiesExpression | TSStaticKeyword | TSStringKeyword | TSSymbolKeyword | TSTemplateLiteralType | TSThisType | TSTupleType | TSTypeAliasDeclaration | TSTypeAnnotation | TSTypeAssertion | TSTypeLiteral | TSTypeOperator | TSTypeParameter | TSTypeParameterDeclaration | TSTypeParameterInstantiation | TSTypePredicate | TSTypeQuery | TSTypeReference | TSUndefinedKeyword | TSUnionType | TSUnknownKeyword | TSVoidKeyword | UnaryExpression | UpdateExpression | VariableDeclaration | VariableDeclarator | WhileStatement | WithStatement | YieldExpression;
1365
1426
  declare interface NodeOrTokenData {
1366
1427
  type: string;
1367
1428
  /**
@@ -1376,9 +1437,15 @@ declare interface NullLiteral extends LiteralBase {
1376
1437
  raw: 'null';
1377
1438
  value: null;
1378
1439
  }
1440
+ declare interface NullToken extends BaseToken {
1441
+ type: AST_TOKEN_TYPES.Null;
1442
+ }
1379
1443
  declare interface NumberLiteral extends LiteralBase {
1380
1444
  value: number;
1381
1445
  }
1446
+ declare interface NumericToken extends BaseToken {
1447
+ type: AST_TOKEN_TYPES.Numeric;
1448
+ }
1382
1449
  declare interface ObjectExpression extends BaseNode {
1383
1450
  type: AST_NODE_TYPES.ObjectExpression;
1384
1451
  properties: ObjectLiteralElement[];
@@ -1406,6 +1473,13 @@ declare interface PrivateIdentifier extends BaseNode {
1406
1473
  type: AST_NODE_TYPES.PrivateIdentifier;
1407
1474
  name: string;
1408
1475
  }
1476
+ declare interface Program extends NodeOrTokenData {
1477
+ type: AST_NODE_TYPES.Program;
1478
+ body: ProgramStatement[];
1479
+ comments: Comment[] | undefined;
1480
+ sourceType: 'module' | 'script';
1481
+ tokens: Token[] | undefined;
1482
+ }
1409
1483
  declare type ProgramStatement = ExportAllDeclaration | ExportDefaultDeclaration | ExportNamedDeclaration | ImportDeclaration | Statement | TSImportEqualsDeclaration | TSNamespaceExportDeclaration;
1410
1484
  declare type Property = PropertyComputedName | PropertyNonComputedName;
1411
1485
  declare interface PropertyBase extends BaseNode {
@@ -1458,6 +1532,57 @@ declare interface PropertyNonComputedName extends PropertyBase {
1458
1532
  computed: false;
1459
1533
  key: PropertyNameNonComputed;
1460
1534
  }
1535
+ declare interface PunctuatorToken extends BaseToken {
1536
+ type: AST_TOKEN_TYPES.Punctuator;
1537
+ value: ValueOf<PunctuatorTokenToText>;
1538
+ }
1539
+ declare interface PunctuatorTokenToText extends AssignmentOperatorToText {
1540
+ [SyntaxKind.AmpersandAmpersandToken]: '&&';
1541
+ [SyntaxKind.AmpersandToken]: '&';
1542
+ [SyntaxKind.AsteriskAsteriskToken]: '**';
1543
+ [SyntaxKind.AsteriskToken]: '*';
1544
+ [SyntaxKind.AtToken]: '@';
1545
+ [SyntaxKind.BacktickToken]: '`';
1546
+ [SyntaxKind.BarBarToken]: '||';
1547
+ [SyntaxKind.BarToken]: '|';
1548
+ [SyntaxKind.CaretToken]: '^';
1549
+ [SyntaxKind.CloseBraceToken]: '}';
1550
+ [SyntaxKind.CloseBracketToken]: ']';
1551
+ [SyntaxKind.CloseParenToken]: ')';
1552
+ [SyntaxKind.ColonToken]: ':';
1553
+ [SyntaxKind.CommaToken]: ',';
1554
+ [SyntaxKind.DotDotDotToken]: '...';
1555
+ [SyntaxKind.DotToken]: '.';
1556
+ [SyntaxKind.EqualsEqualsEqualsToken]: '===';
1557
+ [SyntaxKind.EqualsEqualsToken]: '==';
1558
+ [SyntaxKind.EqualsGreaterThanToken]: '=>';
1559
+ [SyntaxKind.ExclamationEqualsEqualsToken]: '!==';
1560
+ [SyntaxKind.ExclamationEqualsToken]: '!=';
1561
+ [SyntaxKind.ExclamationToken]: '!';
1562
+ [SyntaxKind.GreaterThanEqualsToken]: '>=';
1563
+ [SyntaxKind.GreaterThanGreaterThanGreaterThanToken]: '>>>';
1564
+ [SyntaxKind.GreaterThanGreaterThanToken]: '>>';
1565
+ [SyntaxKind.GreaterThanToken]: '>';
1566
+ [SyntaxKind.HashToken]: '#';
1567
+ [SyntaxKind.LessThanEqualsToken]: '<=';
1568
+ [SyntaxKind.LessThanLessThanToken]: '<<';
1569
+ [SyntaxKind.LessThanSlashToken]: '</';
1570
+ [SyntaxKind.LessThanToken]: '<';
1571
+ [SyntaxKind.MinusMinusToken]: '--';
1572
+ [SyntaxKind.MinusToken]: '-';
1573
+ [SyntaxKind.OpenBraceToken]: '{';
1574
+ [SyntaxKind.OpenBracketToken]: '[';
1575
+ [SyntaxKind.OpenParenToken]: '(';
1576
+ [SyntaxKind.PercentToken]: '%';
1577
+ [SyntaxKind.PlusPlusToken]: '++';
1578
+ [SyntaxKind.PlusToken]: '+';
1579
+ [SyntaxKind.QuestionDotToken]: '?.';
1580
+ [SyntaxKind.QuestionQuestionToken]: '??';
1581
+ [SyntaxKind.QuestionToken]: '?';
1582
+ [SyntaxKind.SemicolonToken]: ';';
1583
+ [SyntaxKind.SlashToken]: '/';
1584
+ [SyntaxKind.TildeToken]: '~';
1585
+ }
1461
1586
  /**
1462
1587
  * An array of two numbers.
1463
1588
  * Both numbers are a 0-based index which is the position in the array of source code characters.
@@ -1471,6 +1596,13 @@ declare interface RegExpLiteral extends LiteralBase {
1471
1596
  };
1472
1597
  value: RegExp | null;
1473
1598
  }
1599
+ declare interface RegularExpressionToken extends BaseToken {
1600
+ type: AST_TOKEN_TYPES.RegularExpression;
1601
+ regex: {
1602
+ flags: string;
1603
+ pattern: string;
1604
+ };
1605
+ }
1474
1606
  declare interface RestElement extends BaseNode {
1475
1607
  type: AST_NODE_TYPES.RestElement;
1476
1608
  argument: DestructuringPattern;
@@ -1509,6 +1641,9 @@ declare interface StaticBlock extends BaseNode {
1509
1641
  declare interface StringLiteral extends LiteralBase {
1510
1642
  value: string;
1511
1643
  }
1644
+ declare interface StringToken extends BaseToken {
1645
+ type: AST_TOKEN_TYPES.String;
1646
+ }
1512
1647
  declare interface Super extends BaseNode {
1513
1648
  type: AST_NODE_TYPES.Super;
1514
1649
  }
@@ -1541,6 +1676,9 @@ declare interface TemplateLiteral extends BaseNode {
1541
1676
  expressions: Expression[];
1542
1677
  quasis: TemplateElement[];
1543
1678
  }
1679
+ declare interface TemplateToken extends BaseToken {
1680
+ type: AST_TOKEN_TYPES.Template;
1681
+ }
1544
1682
  declare interface ThisExpression extends BaseNode {
1545
1683
  type: AST_NODE_TYPES.ThisExpression;
1546
1684
  }
@@ -1548,6 +1686,7 @@ declare interface ThrowStatement extends BaseNode {
1548
1686
  type: AST_NODE_TYPES.ThrowStatement;
1549
1687
  argument: Expression;
1550
1688
  }
1689
+ declare type Token = BooleanToken | Comment | IdentifierToken | JSXIdentifierToken | JSXTextToken | KeywordToken | NullToken | NumericToken | PunctuatorToken | RegularExpressionToken | StringToken | TemplateToken;
1551
1690
  declare interface TryStatement extends BaseNode {
1552
1691
  type: AST_NODE_TYPES.TryStatement;
1553
1692
  block: BlockStatement;
@@ -2263,6 +2402,7 @@ declare interface UsingDeclarationBase extends BaseNode {
2263
2402
  */
2264
2403
  kind: 'await using' | 'using';
2265
2404
  }
2405
+ declare type UsingDeclarator = UsingInForOfDeclarator | UsingInNormalContextDeclarator;
2266
2406
  declare interface UsingInForOfDeclaration extends UsingDeclarationBase {
2267
2407
  /**
2268
2408
  * The variables declared by this declaration.
@@ -2298,6 +2438,7 @@ declare interface UsingInNormalContextDeclarator extends VariableDeclaratorBase
2298
2438
  }
2299
2439
  declare type ValueOf<T> = T[keyof T];
2300
2440
  declare type VariableDeclaration = LetOrConstOrVarDeclaration | UsingDeclaration;
2441
+ declare type VariableDeclarator = LetOrConstOrVarDeclarator | UsingDeclarator;
2301
2442
  declare interface VariableDeclaratorBase extends BaseNode {
2302
2443
  type: AST_NODE_TYPES.VariableDeclarator;
2303
2444
  /**
@@ -2362,16 +2503,69 @@ declare const isCreateElement: (node: Identifier | MemberExpression, context: _e
2362
2503
  declare const isCreateRef: (node: Identifier | MemberExpression, context: _eslint_react_types.RuleContext) => boolean;
2363
2504
  declare const isForwardRef: (node: Identifier | MemberExpression, context: _eslint_react_types.RuleContext) => boolean;
2364
2505
  declare const isMemo: (node: Identifier | MemberExpression, context: _eslint_react_types.RuleContext) => boolean;
2365
- declare const isChildrenCountCall: (node: CallExpression, context: _eslint_react_types.RuleContext) => boolean;
2366
- declare const isChildrenForEachCall: (node: CallExpression, context: _eslint_react_types.RuleContext) => boolean;
2367
- declare const isChildrenMapCall: (node: CallExpression, context: _eslint_react_types.RuleContext) => boolean;
2368
- declare const isChildrenOnlyCall: (node: CallExpression, context: _eslint_react_types.RuleContext) => boolean;
2369
- declare const isChildrenToArrayCall: (node: CallExpression, context: _eslint_react_types.RuleContext) => boolean;
2370
- declare const isCloneElementCall: (node: CallExpression, context: _eslint_react_types.RuleContext) => boolean;
2371
- declare const isCreateContextCall: (node: CallExpression, context: _eslint_react_types.RuleContext) => boolean;
2372
- declare const isCreateElementCall: (node: CallExpression, context: _eslint_react_types.RuleContext) => boolean;
2373
- declare const isCreateRefCall: (node: CallExpression, context: _eslint_react_types.RuleContext) => boolean;
2374
- declare const isForwardRefCall: (node: CallExpression, context: _eslint_react_types.RuleContext) => boolean;
2375
- declare const isMemoCall: (node: CallExpression, context: _eslint_react_types.RuleContext) => boolean;
2506
+ declare const isChildrenCountCall: {
2507
+ (context: _eslint_react_types.RuleContext): (node: Node) => node is CallExpression & {
2508
+ callee: MemberExpression;
2509
+ };
2510
+ (node: Node, context: _eslint_react_types.RuleContext): node is CallExpression & {
2511
+ callee: MemberExpression;
2512
+ };
2513
+ };
2514
+ declare const isChildrenForEachCall: {
2515
+ (context: _eslint_react_types.RuleContext): (node: Node) => node is CallExpression & {
2516
+ callee: MemberExpression;
2517
+ };
2518
+ (node: Node, context: _eslint_react_types.RuleContext): node is CallExpression & {
2519
+ callee: MemberExpression;
2520
+ };
2521
+ };
2522
+ declare const isChildrenMapCall: {
2523
+ (context: _eslint_react_types.RuleContext): (node: Node) => node is CallExpression & {
2524
+ callee: MemberExpression;
2525
+ };
2526
+ (node: Node, context: _eslint_react_types.RuleContext): node is CallExpression & {
2527
+ callee: MemberExpression;
2528
+ };
2529
+ };
2530
+ declare const isChildrenOnlyCall: {
2531
+ (context: _eslint_react_types.RuleContext): (node: Node) => node is CallExpression & {
2532
+ callee: MemberExpression;
2533
+ };
2534
+ (node: Node, context: _eslint_react_types.RuleContext): node is CallExpression & {
2535
+ callee: MemberExpression;
2536
+ };
2537
+ };
2538
+ declare const isChildrenToArrayCall: {
2539
+ (context: _eslint_react_types.RuleContext): (node: Node) => node is CallExpression & {
2540
+ callee: MemberExpression;
2541
+ };
2542
+ (node: Node, context: _eslint_react_types.RuleContext): node is CallExpression & {
2543
+ callee: MemberExpression;
2544
+ };
2545
+ };
2546
+ declare const isCloneElementCall: {
2547
+ (context: _eslint_react_types.RuleContext): (node: Node) => node is CallExpression;
2548
+ (node: Node, context: _eslint_react_types.RuleContext): node is CallExpression;
2549
+ };
2550
+ declare const isCreateContextCall: {
2551
+ (context: _eslint_react_types.RuleContext): (node: Node) => node is CallExpression;
2552
+ (node: Node, context: _eslint_react_types.RuleContext): node is CallExpression;
2553
+ };
2554
+ declare const isCreateElementCall: {
2555
+ (context: _eslint_react_types.RuleContext): (node: Node) => node is CallExpression;
2556
+ (node: Node, context: _eslint_react_types.RuleContext): node is CallExpression;
2557
+ };
2558
+ declare const isCreateRefCall: {
2559
+ (context: _eslint_react_types.RuleContext): (node: Node) => node is CallExpression;
2560
+ (node: Node, context: _eslint_react_types.RuleContext): node is CallExpression;
2561
+ };
2562
+ declare const isForwardRefCall: {
2563
+ (context: _eslint_react_types.RuleContext): (node: Node) => node is CallExpression;
2564
+ (node: Node, context: _eslint_react_types.RuleContext): node is CallExpression;
2565
+ };
2566
+ declare const isMemoCall: {
2567
+ (context: _eslint_react_types.RuleContext): (node: Node) => node is CallExpression;
2568
+ (node: Node, context: _eslint_react_types.RuleContext): node is CallExpression;
2569
+ };
2376
2570
 
2377
- export { 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, getElementRepresentName, getFunctionComponentIdentifier, hasNoneOrValidComponentName, isCallFromReact, isCallFromReactMember, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOfCreateElement, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCleanupFunction, isCloneElement, isCloneElementCall, isComponentDidMount, isComponentDidMountFunction, isComponentName, isComponentWillUnmount, isComponentWillUnmountFunction, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRef, isForwardRefCall, isFragmentElement, isFromReact, isFromReactMember, isFunctionOfRenderMethod, isInitializedFromReact, isInsideCreateElementProps, isInsideReactHook, isInsideReactHookCall, isInsideRenderMethod, isInversePhase, isMemo, isMemoCall, isPureComponent, isReactAPICallWithName, isReactAPIWithName, isReactHook, isReactHookCall, isReactHookCallWithName, isReactHookCallWithNameAlias, isReactHookCallWithNameLoose, isReactHookName, isRenderFunctionLoose, isRenderPropLoose, isSetupFunction, isThisSetState, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectCallLoose, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseReducerCall, isUseRefCall, isUseStateCall, isUseSyncExternalStoreCall, isUseTransitionCall, useComponentCollector, useComponentCollectorLegacy, useHookCollector };
2571
+ export { 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, getElementRepresentName, getFunctionComponentIdentifier, hasNoneOrValidComponentName, isCallFromReact, isCallFromReactMember, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOfCreateElement, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCleanupFunction, isCloneElement, isCloneElementCall, isComponentDidMount, isComponentDidMountFunction, isComponentName, isComponentWillUnmount, isComponentWillUnmountFunction, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRef, isForwardRefCall, isFragmentElement, isFromReact, isFromReactMember, isFunctionOfRenderMethod, isInitializedFromReact, isInsideCreateElementProps, isInsideReactHook, isInsideRenderMethod, isInversePhase, isMemo, isMemoCall, isPureComponent, isReactAPICallWithName, isReactAPIWithName, isReactHook, isReactHookCall, isReactHookCallWithName, isReactHookCallWithNameAlias, isReactHookCallWithNameLoose, isReactHookName, isRenderFunctionLoose, isRenderPropLoose, isSetupFunction, 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
@@ -160,12 +160,18 @@ declare function isCleanupFunction(node: TSESTree.Node): boolean;
160
160
  declare function getElementRepresentName(node: TSESTree.JSXOpeningElement, context: RuleContext): string;
161
161
 
162
162
  /**
163
- * Determines whether inside createElement's props.
163
+ * Determines whether inside `createElement`'s props.
164
164
  * @param node The AST node to check
165
165
  * @param context The rule context
166
166
  * @returns `true` if the node is inside createElement's props
167
167
  */
168
168
  declare function isInsideCreateElementProps(node: TSESTree.Node, context: RuleContext): boolean;
169
+ /**
170
+ * Determines whether inside `createElement`'s children.
171
+ * @param node The AST node to check
172
+ * @param context The rule context
173
+ * @returns `true` if the node is inside createElement's children
174
+ */
169
175
  declare function isChildrenOfCreateElement(node: TSESTree.Node, context: RuleContext): boolean;
170
176
 
171
177
  /**
@@ -177,7 +183,6 @@ declare function isChildrenOfCreateElement(node: TSESTree.Node, context: RuleCon
177
183
  declare function isFragmentElement(node: TSESTree.JSXElement, context: RuleContext): boolean;
178
184
 
179
185
  declare function isInsideReactHook(node: TSESTree.Node): boolean;
180
- declare function isInsideReactHookCall(node: TSESTree.Node): boolean;
181
186
 
182
187
  interface ERHook extends ERSemanticNode {
183
188
  id: O.Some<TSESTree.Identifier>;
@@ -209,7 +214,7 @@ declare function isReactHook(node: AST.TSESTreeFunction): boolean;
209
214
  * @param node The node to check.
210
215
  * @returns `true` if the node is a React Hook call, `false` otherwise.
211
216
  */
212
- declare function isReactHookCall(node: TSESTree.CallExpression): boolean;
217
+ declare function isReactHookCall(node: TSESTree.Node): boolean;
213
218
  declare function isReactHookCallWithName(node: TSESTree.CallExpression, context: RuleContext): (name: string) => boolean;
214
219
  declare function isReactHookCallWithNameLoose(node: TSESTree.CallExpression): (name: string) => boolean;
215
220
  declare function isReactHookCallWithNameAlias(name: string, context: RuleContext, alias: string[]): (node: TSESTree.CallExpression) => boolean;
@@ -317,8 +322,20 @@ declare function isFromReact(name: string): (node: TSESTree.Identifier | TSESTre
317
322
  * @returns A function that checks if a given node is a member expression of a Pragma member.
318
323
  */
319
324
  declare function isFromReactMember(memberName: string, name: string): (node: TSESTree.MemberExpression, context: RuleContext) => boolean;
320
- declare function isCallFromReact(name: string): (node: TSESTree.CallExpression, context: RuleContext) => boolean;
321
- declare function isCallFromReactMember(pragmaMemberName: string, name: string): (node: TSESTree.CallExpression, context: RuleContext) => boolean;
325
+ type IsCallFromReact = {
326
+ (context: RuleContext): (node: TSESTree.Node) => node is TSESTree.CallExpression;
327
+ (node: TSESTree.Node, context: RuleContext): node is TSESTree.CallExpression;
328
+ };
329
+ declare function isCallFromReact(name: string): IsCallFromReact;
330
+ type IsCallFromReactMember = {
331
+ (context: RuleContext): (node: TSESTree.Node) => node is TSESTree.CallExpression & {
332
+ callee: TSESTree.MemberExpression;
333
+ };
334
+ (node: TSESTree.Node, context: RuleContext): node is TSESTree.CallExpression & {
335
+ callee: TSESTree.MemberExpression;
336
+ };
337
+ };
338
+ declare function isCallFromReactMember(pragmaMemberName: string, name: string): IsCallFromReactMember;
322
339
 
323
340
  /**
324
341
  * Check if an identifier is initialized from React
@@ -574,6 +591,21 @@ declare enum AST_NODE_TYPES {
574
591
  TSUnknownKeyword = "TSUnknownKeyword",
575
592
  TSVoidKeyword = "TSVoidKeyword"
576
593
  }
594
+ declare enum AST_TOKEN_TYPES {
595
+ Boolean = "Boolean",
596
+ Identifier = "Identifier",
597
+ JSXIdentifier = "JSXIdentifier",
598
+ JSXText = "JSXText",
599
+ Keyword = "Keyword",
600
+ Null = "Null",
601
+ Numeric = "Numeric",
602
+ Punctuator = "Punctuator",
603
+ RegularExpression = "RegularExpression",
604
+ String = "String",
605
+ Template = "Template",
606
+ Block = "Block",
607
+ Line = "Line"
608
+ }
577
609
  declare interface AwaitExpression extends BaseNode {
578
610
  type: AST_NODE_TYPES.AwaitExpression;
579
611
  argument: Expression;
@@ -581,6 +613,10 @@ declare interface AwaitExpression extends BaseNode {
581
613
  declare interface BaseNode extends NodeOrTokenData {
582
614
  type: AST_NODE_TYPES;
583
615
  }
616
+ declare interface BaseToken extends NodeOrTokenData {
617
+ type: AST_TOKEN_TYPES;
618
+ value: string;
619
+ }
584
620
  declare interface BigIntLiteral extends LiteralBase {
585
621
  bigint: string;
586
622
  value: bigint | null;
@@ -619,6 +655,9 @@ declare interface BinaryOperatorToText {
619
655
  }
620
656
  declare type BindingName = BindingPattern | Identifier;
621
657
  declare type BindingPattern = ArrayPattern | ObjectPattern;
658
+ declare interface BlockComment extends BaseToken {
659
+ type: AST_TOKEN_TYPES.Block;
660
+ }
622
661
  declare interface BlockStatement extends BaseNode {
623
662
  type: AST_NODE_TYPES.BlockStatement;
624
663
  body: Statement[];
@@ -627,6 +666,9 @@ declare interface BooleanLiteral extends LiteralBase {
627
666
  raw: 'false' | 'true';
628
667
  value: boolean;
629
668
  }
669
+ declare interface BooleanToken extends BaseToken {
670
+ type: AST_TOKEN_TYPES.Boolean;
671
+ }
630
672
  declare interface BreakStatement extends BaseNode {
631
673
  type: AST_NODE_TYPES.BreakStatement;
632
674
  label: Identifier | null;
@@ -707,6 +749,7 @@ declare interface ClassBody extends BaseNode {
707
749
  type: AST_NODE_TYPES.ClassBody;
708
750
  body: ClassElement[];
709
751
  }
752
+ declare type ClassDeclaration = ClassDeclarationWithName | ClassDeclarationWithOptionalName;
710
753
  declare interface ClassDeclarationBase extends ClassBase {
711
754
  type: AST_NODE_TYPES.ClassDeclaration;
712
755
  }
@@ -743,6 +786,7 @@ declare interface ClassPropertyDefinitionNonComputedNameBase extends PropertyDef
743
786
  key: ClassPropertyNameNonComputed;
744
787
  }
745
788
  declare type ClassPropertyNameNonComputed = PrivateIdentifier | PropertyNameNonComputed;
789
+ declare type Comment = BlockComment | LineComment;
746
790
  declare interface ConditionalExpression extends BaseNode {
747
791
  type: AST_NODE_TYPES.ConditionalExpression;
748
792
  alternate: Expression;
@@ -1035,6 +1079,7 @@ declare interface FunctionBase extends BaseNode {
1035
1079
  */
1036
1080
  typeParameters: TSTypeParameterDeclaration | undefined;
1037
1081
  }
1082
+ declare type FunctionDeclaration = FunctionDeclarationWithName | FunctionDeclarationWithOptionalName;
1038
1083
  declare interface FunctionDeclarationBase extends FunctionBase {
1039
1084
  type: AST_NODE_TYPES.FunctionDeclaration;
1040
1085
  body: BlockStatement;
@@ -1071,6 +1116,9 @@ declare interface Identifier extends BaseNode {
1071
1116
  optional: boolean;
1072
1117
  typeAnnotation: TSTypeAnnotation | undefined;
1073
1118
  }
1119
+ declare interface IdentifierToken extends BaseToken {
1120
+ type: AST_TOKEN_TYPES.Identifier;
1121
+ }
1074
1122
  declare interface IfStatement extends BaseNode {
1075
1123
  type: AST_NODE_TYPES.IfStatement;
1076
1124
  alternate: Statement | null;
@@ -1196,6 +1244,9 @@ declare interface JSXIdentifier extends BaseNode {
1196
1244
  type: AST_NODE_TYPES.JSXIdentifier;
1197
1245
  name: string;
1198
1246
  }
1247
+ declare interface JSXIdentifierToken extends BaseToken {
1248
+ type: AST_TOKEN_TYPES.JSXIdentifier;
1249
+ }
1199
1250
  declare interface JSXMemberExpression extends BaseNode {
1200
1251
  type: AST_NODE_TYPES.JSXMemberExpression;
1201
1252
  object: JSXTagNameExpression;
@@ -1230,6 +1281,12 @@ declare interface JSXText extends BaseNode {
1230
1281
  raw: string;
1231
1282
  value: string;
1232
1283
  }
1284
+ declare interface JSXTextToken extends BaseToken {
1285
+ type: AST_TOKEN_TYPES.JSXText;
1286
+ }
1287
+ declare interface KeywordToken extends BaseToken {
1288
+ type: AST_TOKEN_TYPES.Keyword;
1289
+ }
1233
1290
  declare interface LabeledStatement extends BaseNode {
1234
1291
  type: AST_NODE_TYPES.LabeledStatement;
1235
1292
  body: Statement;
@@ -1293,6 +1350,9 @@ declare interface LetOrVarNonDeclaredDeclaration extends LetOrConstOrVarDeclarat
1293
1350
  declare: false;
1294
1351
  kind: 'let' | 'var';
1295
1352
  }
1353
+ declare interface LineComment extends BaseToken {
1354
+ type: AST_TOKEN_TYPES.Line;
1355
+ }
1296
1356
  declare type Literal = BigIntLiteral | BooleanLiteral | NullLiteral | NumberLiteral | RegExpLiteral | StringLiteral;
1297
1357
  declare interface LiteralBase extends BaseNode {
1298
1358
  type: AST_NODE_TYPES.Literal;
@@ -1362,6 +1422,7 @@ declare interface NewExpression extends BaseNode {
1362
1422
  callee: Expression;
1363
1423
  typeArguments: TSTypeParameterInstantiation | undefined;
1364
1424
  }
1425
+ declare type Node = AccessorProperty | ArrayExpression | ArrayPattern | ArrowFunctionExpression | AssignmentExpression | AssignmentPattern | AwaitExpression | BinaryExpression | BlockStatement | BreakStatement | CallExpression | CatchClause | ChainExpression | ClassBody | ClassDeclaration | ClassExpression | ConditionalExpression | ContinueStatement | DebuggerStatement | Decorator | DoWhileStatement | EmptyStatement | ExportAllDeclaration | ExportDefaultDeclaration | ExportNamedDeclaration | ExportSpecifier | ExpressionStatement | ForInStatement | ForOfStatement | ForStatement | FunctionDeclaration | FunctionExpression | Identifier | IfStatement | ImportAttribute | ImportDeclaration | ImportDefaultSpecifier | ImportExpression | ImportNamespaceSpecifier | ImportSpecifier | JSXAttribute | JSXClosingElement | JSXClosingFragment | JSXElement | JSXEmptyExpression | JSXExpressionContainer | JSXFragment | JSXIdentifier | JSXMemberExpression | JSXNamespacedName | JSXOpeningElement | JSXOpeningFragment | JSXSpreadAttribute | JSXSpreadChild | JSXText | LabeledStatement | Literal | LogicalExpression | MemberExpression | MetaProperty | MethodDefinition | NewExpression | ObjectExpression | ObjectPattern | PrivateIdentifier | Program | Property | PropertyDefinition | RestElement | ReturnStatement | SequenceExpression | SpreadElement | StaticBlock | Super | SwitchCase | SwitchStatement | TaggedTemplateExpression | TemplateElement | TemplateLiteral | ThisExpression | ThrowStatement | TryStatement | TSAbstractAccessorProperty | TSAbstractKeyword | TSAbstractMethodDefinition | TSAbstractPropertyDefinition | TSAnyKeyword | TSArrayType | TSAsExpression | TSAsyncKeyword | TSBigIntKeyword | TSBooleanKeyword | TSCallSignatureDeclaration | TSClassImplements | TSConditionalType | TSConstructorType | TSConstructSignatureDeclaration | TSDeclareFunction | TSDeclareKeyword | TSEmptyBodyFunctionExpression | TSEnumBody | TSEnumDeclaration | TSEnumMember | TSExportAssignment | TSExportKeyword | TSExternalModuleReference | TSFunctionType | TSImportEqualsDeclaration | TSImportType | TSIndexedAccessType | TSIndexSignature | TSInferType | TSInstantiationExpression | TSInterfaceBody | TSInterfaceDeclaration | TSInterfaceHeritage | TSIntersectionType | TSIntrinsicKeyword | TSLiteralType | TSMappedType | TSMethodSignature | TSModuleBlock | TSModuleDeclaration | TSNamedTupleMember | TSNamespaceExportDeclaration | TSNeverKeyword | TSNonNullExpression | TSNullKeyword | TSNumberKeyword | TSObjectKeyword | TSOptionalType | TSParameterProperty | TSPrivateKeyword | TSPropertySignature | TSProtectedKeyword | TSPublicKeyword | TSQualifiedName | TSReadonlyKeyword | TSRestType | TSSatisfiesExpression | TSStaticKeyword | TSStringKeyword | TSSymbolKeyword | TSTemplateLiteralType | TSThisType | TSTupleType | TSTypeAliasDeclaration | TSTypeAnnotation | TSTypeAssertion | TSTypeLiteral | TSTypeOperator | TSTypeParameter | TSTypeParameterDeclaration | TSTypeParameterInstantiation | TSTypePredicate | TSTypeQuery | TSTypeReference | TSUndefinedKeyword | TSUnionType | TSUnknownKeyword | TSVoidKeyword | UnaryExpression | UpdateExpression | VariableDeclaration | VariableDeclarator | WhileStatement | WithStatement | YieldExpression;
1365
1426
  declare interface NodeOrTokenData {
1366
1427
  type: string;
1367
1428
  /**
@@ -1376,9 +1437,15 @@ declare interface NullLiteral extends LiteralBase {
1376
1437
  raw: 'null';
1377
1438
  value: null;
1378
1439
  }
1440
+ declare interface NullToken extends BaseToken {
1441
+ type: AST_TOKEN_TYPES.Null;
1442
+ }
1379
1443
  declare interface NumberLiteral extends LiteralBase {
1380
1444
  value: number;
1381
1445
  }
1446
+ declare interface NumericToken extends BaseToken {
1447
+ type: AST_TOKEN_TYPES.Numeric;
1448
+ }
1382
1449
  declare interface ObjectExpression extends BaseNode {
1383
1450
  type: AST_NODE_TYPES.ObjectExpression;
1384
1451
  properties: ObjectLiteralElement[];
@@ -1406,6 +1473,13 @@ declare interface PrivateIdentifier extends BaseNode {
1406
1473
  type: AST_NODE_TYPES.PrivateIdentifier;
1407
1474
  name: string;
1408
1475
  }
1476
+ declare interface Program extends NodeOrTokenData {
1477
+ type: AST_NODE_TYPES.Program;
1478
+ body: ProgramStatement[];
1479
+ comments: Comment[] | undefined;
1480
+ sourceType: 'module' | 'script';
1481
+ tokens: Token[] | undefined;
1482
+ }
1409
1483
  declare type ProgramStatement = ExportAllDeclaration | ExportDefaultDeclaration | ExportNamedDeclaration | ImportDeclaration | Statement | TSImportEqualsDeclaration | TSNamespaceExportDeclaration;
1410
1484
  declare type Property = PropertyComputedName | PropertyNonComputedName;
1411
1485
  declare interface PropertyBase extends BaseNode {
@@ -1458,6 +1532,57 @@ declare interface PropertyNonComputedName extends PropertyBase {
1458
1532
  computed: false;
1459
1533
  key: PropertyNameNonComputed;
1460
1534
  }
1535
+ declare interface PunctuatorToken extends BaseToken {
1536
+ type: AST_TOKEN_TYPES.Punctuator;
1537
+ value: ValueOf<PunctuatorTokenToText>;
1538
+ }
1539
+ declare interface PunctuatorTokenToText extends AssignmentOperatorToText {
1540
+ [SyntaxKind.AmpersandAmpersandToken]: '&&';
1541
+ [SyntaxKind.AmpersandToken]: '&';
1542
+ [SyntaxKind.AsteriskAsteriskToken]: '**';
1543
+ [SyntaxKind.AsteriskToken]: '*';
1544
+ [SyntaxKind.AtToken]: '@';
1545
+ [SyntaxKind.BacktickToken]: '`';
1546
+ [SyntaxKind.BarBarToken]: '||';
1547
+ [SyntaxKind.BarToken]: '|';
1548
+ [SyntaxKind.CaretToken]: '^';
1549
+ [SyntaxKind.CloseBraceToken]: '}';
1550
+ [SyntaxKind.CloseBracketToken]: ']';
1551
+ [SyntaxKind.CloseParenToken]: ')';
1552
+ [SyntaxKind.ColonToken]: ':';
1553
+ [SyntaxKind.CommaToken]: ',';
1554
+ [SyntaxKind.DotDotDotToken]: '...';
1555
+ [SyntaxKind.DotToken]: '.';
1556
+ [SyntaxKind.EqualsEqualsEqualsToken]: '===';
1557
+ [SyntaxKind.EqualsEqualsToken]: '==';
1558
+ [SyntaxKind.EqualsGreaterThanToken]: '=>';
1559
+ [SyntaxKind.ExclamationEqualsEqualsToken]: '!==';
1560
+ [SyntaxKind.ExclamationEqualsToken]: '!=';
1561
+ [SyntaxKind.ExclamationToken]: '!';
1562
+ [SyntaxKind.GreaterThanEqualsToken]: '>=';
1563
+ [SyntaxKind.GreaterThanGreaterThanGreaterThanToken]: '>>>';
1564
+ [SyntaxKind.GreaterThanGreaterThanToken]: '>>';
1565
+ [SyntaxKind.GreaterThanToken]: '>';
1566
+ [SyntaxKind.HashToken]: '#';
1567
+ [SyntaxKind.LessThanEqualsToken]: '<=';
1568
+ [SyntaxKind.LessThanLessThanToken]: '<<';
1569
+ [SyntaxKind.LessThanSlashToken]: '</';
1570
+ [SyntaxKind.LessThanToken]: '<';
1571
+ [SyntaxKind.MinusMinusToken]: '--';
1572
+ [SyntaxKind.MinusToken]: '-';
1573
+ [SyntaxKind.OpenBraceToken]: '{';
1574
+ [SyntaxKind.OpenBracketToken]: '[';
1575
+ [SyntaxKind.OpenParenToken]: '(';
1576
+ [SyntaxKind.PercentToken]: '%';
1577
+ [SyntaxKind.PlusPlusToken]: '++';
1578
+ [SyntaxKind.PlusToken]: '+';
1579
+ [SyntaxKind.QuestionDotToken]: '?.';
1580
+ [SyntaxKind.QuestionQuestionToken]: '??';
1581
+ [SyntaxKind.QuestionToken]: '?';
1582
+ [SyntaxKind.SemicolonToken]: ';';
1583
+ [SyntaxKind.SlashToken]: '/';
1584
+ [SyntaxKind.TildeToken]: '~';
1585
+ }
1461
1586
  /**
1462
1587
  * An array of two numbers.
1463
1588
  * Both numbers are a 0-based index which is the position in the array of source code characters.
@@ -1471,6 +1596,13 @@ declare interface RegExpLiteral extends LiteralBase {
1471
1596
  };
1472
1597
  value: RegExp | null;
1473
1598
  }
1599
+ declare interface RegularExpressionToken extends BaseToken {
1600
+ type: AST_TOKEN_TYPES.RegularExpression;
1601
+ regex: {
1602
+ flags: string;
1603
+ pattern: string;
1604
+ };
1605
+ }
1474
1606
  declare interface RestElement extends BaseNode {
1475
1607
  type: AST_NODE_TYPES.RestElement;
1476
1608
  argument: DestructuringPattern;
@@ -1509,6 +1641,9 @@ declare interface StaticBlock extends BaseNode {
1509
1641
  declare interface StringLiteral extends LiteralBase {
1510
1642
  value: string;
1511
1643
  }
1644
+ declare interface StringToken extends BaseToken {
1645
+ type: AST_TOKEN_TYPES.String;
1646
+ }
1512
1647
  declare interface Super extends BaseNode {
1513
1648
  type: AST_NODE_TYPES.Super;
1514
1649
  }
@@ -1541,6 +1676,9 @@ declare interface TemplateLiteral extends BaseNode {
1541
1676
  expressions: Expression[];
1542
1677
  quasis: TemplateElement[];
1543
1678
  }
1679
+ declare interface TemplateToken extends BaseToken {
1680
+ type: AST_TOKEN_TYPES.Template;
1681
+ }
1544
1682
  declare interface ThisExpression extends BaseNode {
1545
1683
  type: AST_NODE_TYPES.ThisExpression;
1546
1684
  }
@@ -1548,6 +1686,7 @@ declare interface ThrowStatement extends BaseNode {
1548
1686
  type: AST_NODE_TYPES.ThrowStatement;
1549
1687
  argument: Expression;
1550
1688
  }
1689
+ declare type Token = BooleanToken | Comment | IdentifierToken | JSXIdentifierToken | JSXTextToken | KeywordToken | NullToken | NumericToken | PunctuatorToken | RegularExpressionToken | StringToken | TemplateToken;
1551
1690
  declare interface TryStatement extends BaseNode {
1552
1691
  type: AST_NODE_TYPES.TryStatement;
1553
1692
  block: BlockStatement;
@@ -2263,6 +2402,7 @@ declare interface UsingDeclarationBase extends BaseNode {
2263
2402
  */
2264
2403
  kind: 'await using' | 'using';
2265
2404
  }
2405
+ declare type UsingDeclarator = UsingInForOfDeclarator | UsingInNormalContextDeclarator;
2266
2406
  declare interface UsingInForOfDeclaration extends UsingDeclarationBase {
2267
2407
  /**
2268
2408
  * The variables declared by this declaration.
@@ -2298,6 +2438,7 @@ declare interface UsingInNormalContextDeclarator extends VariableDeclaratorBase
2298
2438
  }
2299
2439
  declare type ValueOf<T> = T[keyof T];
2300
2440
  declare type VariableDeclaration = LetOrConstOrVarDeclaration | UsingDeclaration;
2441
+ declare type VariableDeclarator = LetOrConstOrVarDeclarator | UsingDeclarator;
2301
2442
  declare interface VariableDeclaratorBase extends BaseNode {
2302
2443
  type: AST_NODE_TYPES.VariableDeclarator;
2303
2444
  /**
@@ -2362,16 +2503,69 @@ declare const isCreateElement: (node: Identifier | MemberExpression, context: _e
2362
2503
  declare const isCreateRef: (node: Identifier | MemberExpression, context: _eslint_react_types.RuleContext) => boolean;
2363
2504
  declare const isForwardRef: (node: Identifier | MemberExpression, context: _eslint_react_types.RuleContext) => boolean;
2364
2505
  declare const isMemo: (node: Identifier | MemberExpression, context: _eslint_react_types.RuleContext) => boolean;
2365
- declare const isChildrenCountCall: (node: CallExpression, context: _eslint_react_types.RuleContext) => boolean;
2366
- declare const isChildrenForEachCall: (node: CallExpression, context: _eslint_react_types.RuleContext) => boolean;
2367
- declare const isChildrenMapCall: (node: CallExpression, context: _eslint_react_types.RuleContext) => boolean;
2368
- declare const isChildrenOnlyCall: (node: CallExpression, context: _eslint_react_types.RuleContext) => boolean;
2369
- declare const isChildrenToArrayCall: (node: CallExpression, context: _eslint_react_types.RuleContext) => boolean;
2370
- declare const isCloneElementCall: (node: CallExpression, context: _eslint_react_types.RuleContext) => boolean;
2371
- declare const isCreateContextCall: (node: CallExpression, context: _eslint_react_types.RuleContext) => boolean;
2372
- declare const isCreateElementCall: (node: CallExpression, context: _eslint_react_types.RuleContext) => boolean;
2373
- declare const isCreateRefCall: (node: CallExpression, context: _eslint_react_types.RuleContext) => boolean;
2374
- declare const isForwardRefCall: (node: CallExpression, context: _eslint_react_types.RuleContext) => boolean;
2375
- declare const isMemoCall: (node: CallExpression, context: _eslint_react_types.RuleContext) => boolean;
2506
+ declare const isChildrenCountCall: {
2507
+ (context: _eslint_react_types.RuleContext): (node: Node) => node is CallExpression & {
2508
+ callee: MemberExpression;
2509
+ };
2510
+ (node: Node, context: _eslint_react_types.RuleContext): node is CallExpression & {
2511
+ callee: MemberExpression;
2512
+ };
2513
+ };
2514
+ declare const isChildrenForEachCall: {
2515
+ (context: _eslint_react_types.RuleContext): (node: Node) => node is CallExpression & {
2516
+ callee: MemberExpression;
2517
+ };
2518
+ (node: Node, context: _eslint_react_types.RuleContext): node is CallExpression & {
2519
+ callee: MemberExpression;
2520
+ };
2521
+ };
2522
+ declare const isChildrenMapCall: {
2523
+ (context: _eslint_react_types.RuleContext): (node: Node) => node is CallExpression & {
2524
+ callee: MemberExpression;
2525
+ };
2526
+ (node: Node, context: _eslint_react_types.RuleContext): node is CallExpression & {
2527
+ callee: MemberExpression;
2528
+ };
2529
+ };
2530
+ declare const isChildrenOnlyCall: {
2531
+ (context: _eslint_react_types.RuleContext): (node: Node) => node is CallExpression & {
2532
+ callee: MemberExpression;
2533
+ };
2534
+ (node: Node, context: _eslint_react_types.RuleContext): node is CallExpression & {
2535
+ callee: MemberExpression;
2536
+ };
2537
+ };
2538
+ declare const isChildrenToArrayCall: {
2539
+ (context: _eslint_react_types.RuleContext): (node: Node) => node is CallExpression & {
2540
+ callee: MemberExpression;
2541
+ };
2542
+ (node: Node, context: _eslint_react_types.RuleContext): node is CallExpression & {
2543
+ callee: MemberExpression;
2544
+ };
2545
+ };
2546
+ declare const isCloneElementCall: {
2547
+ (context: _eslint_react_types.RuleContext): (node: Node) => node is CallExpression;
2548
+ (node: Node, context: _eslint_react_types.RuleContext): node is CallExpression;
2549
+ };
2550
+ declare const isCreateContextCall: {
2551
+ (context: _eslint_react_types.RuleContext): (node: Node) => node is CallExpression;
2552
+ (node: Node, context: _eslint_react_types.RuleContext): node is CallExpression;
2553
+ };
2554
+ declare const isCreateElementCall: {
2555
+ (context: _eslint_react_types.RuleContext): (node: Node) => node is CallExpression;
2556
+ (node: Node, context: _eslint_react_types.RuleContext): node is CallExpression;
2557
+ };
2558
+ declare const isCreateRefCall: {
2559
+ (context: _eslint_react_types.RuleContext): (node: Node) => node is CallExpression;
2560
+ (node: Node, context: _eslint_react_types.RuleContext): node is CallExpression;
2561
+ };
2562
+ declare const isForwardRefCall: {
2563
+ (context: _eslint_react_types.RuleContext): (node: Node) => node is CallExpression;
2564
+ (node: Node, context: _eslint_react_types.RuleContext): node is CallExpression;
2565
+ };
2566
+ declare const isMemoCall: {
2567
+ (context: _eslint_react_types.RuleContext): (node: Node) => node is CallExpression;
2568
+ (node: Node, context: _eslint_react_types.RuleContext): node is CallExpression;
2569
+ };
2376
2570
 
2377
- export { 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, getElementRepresentName, getFunctionComponentIdentifier, hasNoneOrValidComponentName, isCallFromReact, isCallFromReactMember, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOfCreateElement, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCleanupFunction, isCloneElement, isCloneElementCall, isComponentDidMount, isComponentDidMountFunction, isComponentName, isComponentWillUnmount, isComponentWillUnmountFunction, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRef, isForwardRefCall, isFragmentElement, isFromReact, isFromReactMember, isFunctionOfRenderMethod, isInitializedFromReact, isInsideCreateElementProps, isInsideReactHook, isInsideReactHookCall, isInsideRenderMethod, isInversePhase, isMemo, isMemoCall, isPureComponent, isReactAPICallWithName, isReactAPIWithName, isReactHook, isReactHookCall, isReactHookCallWithName, isReactHookCallWithNameAlias, isReactHookCallWithNameLoose, isReactHookName, isRenderFunctionLoose, isRenderPropLoose, isSetupFunction, isThisSetState, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectCallLoose, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseReducerCall, isUseRefCall, isUseStateCall, isUseSyncExternalStoreCall, isUseTransitionCall, useComponentCollector, useComponentCollectorLegacy, useHookCollector };
2571
+ export { 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, getElementRepresentName, getFunctionComponentIdentifier, hasNoneOrValidComponentName, isCallFromReact, isCallFromReactMember, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOfCreateElement, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCleanupFunction, isCloneElement, isCloneElementCall, isComponentDidMount, isComponentDidMountFunction, isComponentName, isComponentWillUnmount, isComponentWillUnmountFunction, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRef, isForwardRefCall, isFragmentElement, isFromReact, isFromReactMember, isFunctionOfRenderMethod, isInitializedFromReact, isInsideCreateElementProps, isInsideReactHook, isInsideRenderMethod, isInversePhase, isMemo, isMemoCall, isPureComponent, isReactAPICallWithName, isReactAPIWithName, isReactHook, isReactHookCall, isReactHookCallWithName, isReactHookCallWithNameAlias, isReactHookCallWithNameLoose, isReactHookName, isRenderFunctionLoose, isRenderPropLoose, isSetupFunction, 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
@@ -84,16 +84,18 @@ function isFromReactMember(memberName, name) {
84
84
  };
85
85
  }
86
86
  function isCallFromReact(name) {
87
- return (node, context) => {
87
+ return eff.F.dual(2, (node, context) => {
88
+ if (node.type !== types.AST_NODE_TYPES.CallExpression) return false;
88
89
  if (!AST9__namespace.isOneOf([types.AST_NODE_TYPES.Identifier, types.AST_NODE_TYPES.MemberExpression])(node.callee)) return false;
89
90
  return isFromReact(name)(node.callee, context);
90
- };
91
+ });
91
92
  }
92
93
  function isCallFromReactMember(pragmaMemberName, name) {
93
- return (node, context) => {
94
+ return eff.F.dual(2, (node, context) => {
95
+ if (node.type !== types.AST_NODE_TYPES.CallExpression) return false;
94
96
  if (!AST9__namespace.is(types.AST_NODE_TYPES.MemberExpression)(node.callee)) return false;
95
97
  return isFromReactMember(pragmaMemberName, name)(node.callee, context);
96
- };
98
+ });
97
99
  }
98
100
 
99
101
  // src/utils/is-react-api.ts
@@ -129,19 +131,18 @@ var isMemoCall = isReactAPICallWithName("memo");
129
131
  // src/element/hierarchy.ts
130
132
  function isInsideCreateElementProps(node, context) {
131
133
  return eff.F.pipe(
132
- AST9__namespace.traverseUp(node, (n) => AST9__namespace.is(types.AST_NODE_TYPES.CallExpression)(n) && isCreateElementCall(n, context)),
133
- eff.O.filter(AST9__namespace.is(types.AST_NODE_TYPES.CallExpression)),
134
- eff.O.flatMapNullable((c) => c.arguments.at(1)),
135
- eff.O.filter(AST9__namespace.is(types.AST_NODE_TYPES.ObjectExpression)),
136
- eff.O.zipWith(AST9__namespace.traverseUp(node, AST9__namespace.is(types.AST_NODE_TYPES.ObjectExpression)), (a, b) => a === b),
137
- eff.O.getOrElse(eff.F.constFalse)
134
+ eff.O.Do,
135
+ eff.O.bind("call", () => AST9__namespace.traverseUpGuard(node, isCreateElementCall(context))),
136
+ eff.O.bind("prop", () => AST9__namespace.traverseUpGuard(node, AST9__namespace.is(types.AST_NODE_TYPES.ObjectExpression))),
137
+ eff.O.bind("arg1", ({ call }) => eff.O.fromNullable(call.arguments[1])),
138
+ eff.O.exists(({ arg1, prop }) => prop === arg1)
138
139
  );
139
140
  }
140
141
  function isChildrenOfCreateElement(node, context) {
141
142
  return eff.F.pipe(
142
143
  eff.O.fromNullable(node.parent),
143
144
  eff.O.filter(AST9__namespace.is(types.AST_NODE_TYPES.CallExpression)),
144
- eff.O.filter((n) => isCreateElementCall(n, context)),
145
+ eff.O.filter(isCreateElementCall(context)),
145
146
  eff.O.exists(
146
147
  (n) => n.arguments.slice(2).some((arg) => arg === node)
147
148
  )
@@ -170,6 +171,7 @@ function isReactHook(node) {
170
171
  );
171
172
  }
172
173
  function isReactHookCall(node) {
174
+ if (node.type !== types.AST_NODE_TYPES.CallExpression) return false;
173
175
  if (node.callee.type === types.AST_NODE_TYPES.Identifier) return isReactHookName(node.callee.name);
174
176
  if (node.callee.type === types.AST_NODE_TYPES.MemberExpression) {
175
177
  return node.callee.property.type === types.AST_NODE_TYPES.Identifier && isReactHookName(node.callee.property.name);
@@ -247,9 +249,6 @@ var isUseTransitionCall = eff.F.flip(isReactHookCallWithName)("useTransition");
247
249
  function isInsideReactHook(node) {
248
250
  return eff.O.exists(AST9__namespace.traverseUpGuard(node, AST9__namespace.isFunction), isReactHook);
249
251
  }
250
- function isInsideReactHookCall(node) {
251
- return eff.O.isSome(AST9__namespace.traverseUp(node, (n) => AST9__namespace.is(types.AST_NODE_TYPES.CallExpression)(n) && isReactHookCall(n)));
252
- }
253
252
  var uid = new ShortUniqueId__default.default({ length: 10 });
254
253
  function useHookCollector() {
255
254
  const hooks = /* @__PURE__ */ new Map();
@@ -257,23 +256,22 @@ function useHookCollector() {
257
256
  const onFunctionEnter = (node) => {
258
257
  const id = AST9__namespace.getFunctionIdentifier(node);
259
258
  const name = eff.O.flatMapNullable(id, (id2) => id2.name);
260
- const isHook = eff.O.isSome(id) && eff.O.isSome(name) && isReactHookName(name.value);
261
- if (!isHook) {
262
- fStack.push([node, eff.O.none()]);
259
+ if (eff.O.isSome(id) && eff.O.isSome(name) && isReactHookName(name.value)) {
260
+ const key = uid.rnd();
261
+ fStack.push([node, eff.O.some(key)]);
262
+ hooks.set(key, {
263
+ _: key,
264
+ id,
265
+ kind: "function",
266
+ name,
267
+ node,
268
+ flag: 0n,
269
+ hint: 0n,
270
+ hookCalls: []
271
+ });
263
272
  return;
264
273
  }
265
- const key = uid.rnd();
266
- fStack.push([node, eff.O.some(key)]);
267
- hooks.set(key, {
268
- _: key,
269
- id,
270
- kind: "function",
271
- name,
272
- node,
273
- flag: 0n,
274
- hint: 0n,
275
- hookCalls: []
276
- });
274
+ fStack.push([node, eff.O.none()]);
277
275
  };
278
276
  const onFunctionExit = () => {
279
277
  fStack.pop();
@@ -466,10 +464,9 @@ function isFunctionOfRenderMethod(node) {
466
464
  return isClassComponent(node.parent.parent.parent);
467
465
  }
468
466
  function isInsideRenderMethod(node) {
469
- const predicate = (node2) => {
467
+ return eff.O.isSome(AST9__namespace.traverseUp(node, (node2) => {
470
468
  return isRenderMethodLike(node2) && isClassComponent(node2.parent.parent);
471
- };
472
- return eff.O.isSome(AST9__namespace.traverseUp(node, predicate));
469
+ }));
473
470
  }
474
471
  function hasNoneOrValidComponentName(node, context) {
475
472
  return eff.O.match(
@@ -672,14 +669,14 @@ function isDeclaredInRenderPropLoose(node) {
672
669
  }
673
670
  function isRenderFunctionLoose(node, context) {
674
671
  const { body, parent } = node;
675
- const maybeId = AST9__namespace.getFunctionIdentifier(node);
676
- if (eff.O.isSome(maybeId) && !maybeId.value.name.startsWith("render")) {
672
+ if (eff.O.exists(AST9__namespace.getFunctionIdentifier(node), (id) => id.name.startsWith("render"))) {
677
673
  return parent.type === types.AST_NODE_TYPES.JSXExpressionContainer && parent.parent.type === types.AST_NODE_TYPES.JSXAttribute && parent.parent.name.type === types.AST_NODE_TYPES.JSXIdentifier && parent.parent.name.name.startsWith("render");
678
674
  }
679
- const jsxCtx = { getScope: (node2) => context.sourceCode.getScope(node2) };
680
675
  return JSX4__namespace.isJSXValue(
681
676
  body,
682
- jsxCtx,
677
+ {
678
+ getScope: (node2) => context.sourceCode.getScope(node2)
679
+ },
683
680
  JSX4__namespace.JSXValueHint.SkipNullLiteral | JSX4__namespace.JSXValueHint.SkipUndefinedLiteral | JSX4__namespace.JSXValueHint.StrictLogical | JSX4__namespace.JSXValueHint.StrictConditional
684
681
  );
685
682
  }
@@ -742,7 +739,6 @@ exports.isFunctionOfRenderMethod = isFunctionOfRenderMethod;
742
739
  exports.isInitializedFromReact = isInitializedFromReact;
743
740
  exports.isInsideCreateElementProps = isInsideCreateElementProps;
744
741
  exports.isInsideReactHook = isInsideReactHook;
745
- exports.isInsideReactHookCall = isInsideReactHookCall;
746
742
  exports.isInsideRenderMethod = isInsideRenderMethod;
747
743
  exports.isInversePhase = isInversePhase;
748
744
  exports.isMemo = isMemo;
package/dist/index.mjs CHANGED
@@ -57,16 +57,18 @@ function isFromReactMember(memberName, name) {
57
57
  };
58
58
  }
59
59
  function isCallFromReact(name) {
60
- return (node, context) => {
60
+ return F.dual(2, (node, context) => {
61
+ if (node.type !== AST_NODE_TYPES.CallExpression) return false;
61
62
  if (!AST9.isOneOf([AST_NODE_TYPES.Identifier, AST_NODE_TYPES.MemberExpression])(node.callee)) return false;
62
63
  return isFromReact(name)(node.callee, context);
63
- };
64
+ });
64
65
  }
65
66
  function isCallFromReactMember(pragmaMemberName, name) {
66
- return (node, context) => {
67
+ return F.dual(2, (node, context) => {
68
+ if (node.type !== AST_NODE_TYPES.CallExpression) return false;
67
69
  if (!AST9.is(AST_NODE_TYPES.MemberExpression)(node.callee)) return false;
68
70
  return isFromReactMember(pragmaMemberName, name)(node.callee, context);
69
- };
71
+ });
70
72
  }
71
73
 
72
74
  // src/utils/is-react-api.ts
@@ -102,19 +104,18 @@ var isMemoCall = isReactAPICallWithName("memo");
102
104
  // src/element/hierarchy.ts
103
105
  function isInsideCreateElementProps(node, context) {
104
106
  return F.pipe(
105
- AST9.traverseUp(node, (n) => AST9.is(AST_NODE_TYPES.CallExpression)(n) && isCreateElementCall(n, context)),
106
- O.filter(AST9.is(AST_NODE_TYPES.CallExpression)),
107
- O.flatMapNullable((c) => c.arguments.at(1)),
108
- O.filter(AST9.is(AST_NODE_TYPES.ObjectExpression)),
109
- O.zipWith(AST9.traverseUp(node, AST9.is(AST_NODE_TYPES.ObjectExpression)), (a, b) => a === b),
110
- O.getOrElse(F.constFalse)
107
+ O.Do,
108
+ O.bind("call", () => AST9.traverseUpGuard(node, isCreateElementCall(context))),
109
+ O.bind("prop", () => AST9.traverseUpGuard(node, AST9.is(AST_NODE_TYPES.ObjectExpression))),
110
+ O.bind("arg1", ({ call }) => O.fromNullable(call.arguments[1])),
111
+ O.exists(({ arg1, prop }) => prop === arg1)
111
112
  );
112
113
  }
113
114
  function isChildrenOfCreateElement(node, context) {
114
115
  return F.pipe(
115
116
  O.fromNullable(node.parent),
116
117
  O.filter(AST9.is(AST_NODE_TYPES.CallExpression)),
117
- O.filter((n) => isCreateElementCall(n, context)),
118
+ O.filter(isCreateElementCall(context)),
118
119
  O.exists(
119
120
  (n) => n.arguments.slice(2).some((arg) => arg === node)
120
121
  )
@@ -143,6 +144,7 @@ function isReactHook(node) {
143
144
  );
144
145
  }
145
146
  function isReactHookCall(node) {
147
+ if (node.type !== AST_NODE_TYPES.CallExpression) return false;
146
148
  if (node.callee.type === AST_NODE_TYPES.Identifier) return isReactHookName(node.callee.name);
147
149
  if (node.callee.type === AST_NODE_TYPES.MemberExpression) {
148
150
  return node.callee.property.type === AST_NODE_TYPES.Identifier && isReactHookName(node.callee.property.name);
@@ -220,9 +222,6 @@ var isUseTransitionCall = F.flip(isReactHookCallWithName)("useTransition");
220
222
  function isInsideReactHook(node) {
221
223
  return O.exists(AST9.traverseUpGuard(node, AST9.isFunction), isReactHook);
222
224
  }
223
- function isInsideReactHookCall(node) {
224
- return O.isSome(AST9.traverseUp(node, (n) => AST9.is(AST_NODE_TYPES.CallExpression)(n) && isReactHookCall(n)));
225
- }
226
225
  var uid = new ShortUniqueId({ length: 10 });
227
226
  function useHookCollector() {
228
227
  const hooks = /* @__PURE__ */ new Map();
@@ -230,23 +229,22 @@ function useHookCollector() {
230
229
  const onFunctionEnter = (node) => {
231
230
  const id = AST9.getFunctionIdentifier(node);
232
231
  const name = O.flatMapNullable(id, (id2) => id2.name);
233
- const isHook = O.isSome(id) && O.isSome(name) && isReactHookName(name.value);
234
- if (!isHook) {
235
- fStack.push([node, O.none()]);
232
+ if (O.isSome(id) && O.isSome(name) && isReactHookName(name.value)) {
233
+ const key = uid.rnd();
234
+ fStack.push([node, O.some(key)]);
235
+ hooks.set(key, {
236
+ _: key,
237
+ id,
238
+ kind: "function",
239
+ name,
240
+ node,
241
+ flag: 0n,
242
+ hint: 0n,
243
+ hookCalls: []
244
+ });
236
245
  return;
237
246
  }
238
- const key = uid.rnd();
239
- fStack.push([node, O.some(key)]);
240
- hooks.set(key, {
241
- _: key,
242
- id,
243
- kind: "function",
244
- name,
245
- node,
246
- flag: 0n,
247
- hint: 0n,
248
- hookCalls: []
249
- });
247
+ fStack.push([node, O.none()]);
250
248
  };
251
249
  const onFunctionExit = () => {
252
250
  fStack.pop();
@@ -439,10 +437,9 @@ function isFunctionOfRenderMethod(node) {
439
437
  return isClassComponent(node.parent.parent.parent);
440
438
  }
441
439
  function isInsideRenderMethod(node) {
442
- const predicate = (node2) => {
440
+ return O.isSome(AST9.traverseUp(node, (node2) => {
443
441
  return isRenderMethodLike(node2) && isClassComponent(node2.parent.parent);
444
- };
445
- return O.isSome(AST9.traverseUp(node, predicate));
442
+ }));
446
443
  }
447
444
  function hasNoneOrValidComponentName(node, context) {
448
445
  return O.match(
@@ -645,14 +642,14 @@ function isDeclaredInRenderPropLoose(node) {
645
642
  }
646
643
  function isRenderFunctionLoose(node, context) {
647
644
  const { body, parent } = node;
648
- const maybeId = AST9.getFunctionIdentifier(node);
649
- if (O.isSome(maybeId) && !maybeId.value.name.startsWith("render")) {
645
+ if (O.exists(AST9.getFunctionIdentifier(node), (id) => id.name.startsWith("render"))) {
650
646
  return parent.type === AST_NODE_TYPES.JSXExpressionContainer && parent.parent.type === AST_NODE_TYPES.JSXAttribute && parent.parent.name.type === AST_NODE_TYPES.JSXIdentifier && parent.parent.name.name.startsWith("render");
651
647
  }
652
- const jsxCtx = { getScope: (node2) => context.sourceCode.getScope(node2) };
653
648
  return JSX4.isJSXValue(
654
649
  body,
655
- jsxCtx,
650
+ {
651
+ getScope: (node2) => context.sourceCode.getScope(node2)
652
+ },
656
653
  JSX4.JSXValueHint.SkipNullLiteral | JSX4.JSXValueHint.SkipUndefinedLiteral | JSX4.JSXValueHint.StrictLogical | JSX4.JSXValueHint.StrictConditional
657
654
  );
658
655
  }
@@ -665,4 +662,4 @@ function isThisSetState(node) {
665
662
  return callee.type === AST_NODE_TYPES.MemberExpression && AST9.isThisExpression(callee.object) && callee.property.type === AST_NODE_TYPES.Identifier && callee.property.name === "setState";
666
663
  }
667
664
 
668
- export { DEFAULT_COMPONENT_HINT, ERClassComponentFlag, ERComponentHint, ERFunctionComponentFlag, ERPhaseRelevance, RE_COMPONENT_NAME, RE_HOOK_NAME, getComponentNameFromIdentifier, getElementRepresentName, getFunctionComponentIdentifier, hasNoneOrValidComponentName, isCallFromReact, isCallFromReactMember, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOfCreateElement, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCleanupFunction, isCloneElement, isCloneElementCall, isComponentDidMount, isComponentDidMountFunction, isComponentName, isComponentWillUnmount, isComponentWillUnmountFunction, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRef, isForwardRefCall, isFragmentElement, isFromReact, isFromReactMember, isFunctionOfRenderMethod, isInitializedFromReact, isInsideCreateElementProps, isInsideReactHook, isInsideReactHookCall, isInsideRenderMethod, isInversePhase, isMemo, isMemoCall, isPureComponent, isReactAPICallWithName, isReactAPIWithName, isReactHook, isReactHookCall, isReactHookCallWithName, isReactHookCallWithNameAlias, isReactHookCallWithNameLoose, isReactHookName, isRenderFunctionLoose, isRenderPropLoose, isSetupFunction, isThisSetState, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectCallLoose, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseReducerCall, isUseRefCall, isUseStateCall, isUseSyncExternalStoreCall, isUseTransitionCall, useComponentCollector, useComponentCollectorLegacy, useHookCollector };
665
+ export { DEFAULT_COMPONENT_HINT, ERClassComponentFlag, ERComponentHint, ERFunctionComponentFlag, ERPhaseRelevance, RE_COMPONENT_NAME, RE_HOOK_NAME, getComponentNameFromIdentifier, getElementRepresentName, getFunctionComponentIdentifier, hasNoneOrValidComponentName, isCallFromReact, isCallFromReactMember, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOfCreateElement, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCleanupFunction, isCloneElement, isCloneElementCall, isComponentDidMount, isComponentDidMountFunction, isComponentName, isComponentWillUnmount, isComponentWillUnmountFunction, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRef, isForwardRefCall, isFragmentElement, isFromReact, isFromReactMember, isFunctionOfRenderMethod, isInitializedFromReact, isInsideCreateElementProps, isInsideReactHook, isInsideRenderMethod, isInversePhase, isMemo, isMemoCall, isPureComponent, isReactAPICallWithName, isReactAPIWithName, isReactHook, isReactHookCall, isReactHookCallWithName, isReactHookCallWithNameAlias, isReactHookCallWithNameLoose, isReactHookName, isRenderFunctionLoose, isRenderPropLoose, isSetupFunction, 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.22.2-next.8",
3
+ "version": "1.22.2",
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": {
@@ -39,12 +39,12 @@
39
39
  "@typescript-eslint/utils": "^8.18.2",
40
40
  "short-unique-id": "^5.2.0",
41
41
  "ts-pattern": "^5.6.0",
42
- "@eslint-react/eff": "1.22.2-next.8",
43
- "@eslint-react/jsx": "1.22.2-next.8",
44
- "@eslint-react/ast": "1.22.2-next.8",
45
- "@eslint-react/shared": "1.22.2-next.8",
46
- "@eslint-react/var": "1.22.2-next.8",
47
- "@eslint-react/types": "1.22.2-next.8"
42
+ "@eslint-react/ast": "1.22.2",
43
+ "@eslint-react/jsx": "1.22.2",
44
+ "@eslint-react/types": "1.22.2",
45
+ "@eslint-react/shared": "1.22.2",
46
+ "@eslint-react/var": "1.22.2",
47
+ "@eslint-react/eff": "1.22.2"
48
48
  },
49
49
  "devDependencies": {
50
50
  "tsup": "^8.3.5",