@eslint-react/core 1.22.1 → 1.22.2-beta.11

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
@@ -5,7 +5,6 @@ import * as _eslint_react_types from '@eslint-react/types';
5
5
  import { RuleContext } from '@eslint-react/types';
6
6
  import { TSESTree as TSESTree$1 } from '@typescript-eslint/utils';
7
7
  import * as _typescript_eslint_utils_ts_eslint from '@typescript-eslint/utils/ts-eslint';
8
- import * as birecord from 'birecord';
9
8
  import { ESLintReactSettings } from '@eslint-react/shared';
10
9
  import { Scope } from '@typescript-eslint/scope-manager';
11
10
  import { SyntaxKind } from 'typescript';
@@ -161,12 +160,18 @@ declare function isCleanupFunction(node: TSESTree.Node): boolean;
161
160
  declare function getElementRepresentName(node: TSESTree.JSXOpeningElement, context: RuleContext): string;
162
161
 
163
162
  /**
164
- * Determines whether inside createElement's props.
163
+ * Determines whether inside `createElement`'s props.
165
164
  * @param node The AST node to check
166
165
  * @param context The rule context
167
166
  * @returns `true` if the node is inside createElement's props
168
167
  */
169
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
+ */
170
175
  declare function isChildrenOfCreateElement(node: TSESTree.Node, context: RuleContext): boolean;
171
176
 
172
177
  /**
@@ -178,7 +183,6 @@ declare function isChildrenOfCreateElement(node: TSESTree.Node, context: RuleCon
178
183
  declare function isFragmentElement(node: TSESTree.JSXElement, context: RuleContext): boolean;
179
184
 
180
185
  declare function isInsideReactHook(node: TSESTree.Node): boolean;
181
- declare function isInsideReactHookCall(node: TSESTree.Node): boolean;
182
186
 
183
187
  interface ERHook extends ERSemanticNode {
184
188
  id: O.Some<TSESTree.Identifier>;
@@ -210,7 +214,7 @@ declare function isReactHook(node: AST.TSESTreeFunction): boolean;
210
214
  * @param node The node to check.
211
215
  * @returns `true` if the node is a React Hook call, `false` otherwise.
212
216
  */
213
- declare function isReactHookCall(node: TSESTree.CallExpression): boolean;
217
+ declare function isReactHookCall(node: TSESTree.Node): boolean;
214
218
  declare function isReactHookCallWithName(node: TSESTree.CallExpression, context: RuleContext): (name: string) => boolean;
215
219
  declare function isReactHookCallWithNameLoose(node: TSESTree.CallExpression): (name: string) => boolean;
216
220
  declare function isReactHookCallWithNameAlias(name: string, context: RuleContext, alias: string[]): (node: TSESTree.CallExpression) => boolean;
@@ -231,7 +235,7 @@ declare const isUseStateCall: (node: TSESTree.CallExpression, context: Readonly<
231
235
  declare const isUseSyncExternalStoreCall: (node: TSESTree.CallExpression, context: Readonly<_typescript_eslint_utils_ts_eslint.RuleContext<string, readonly unknown[]>>) => boolean;
232
236
  declare const isUseTransitionCall: (node: TSESTree.CallExpression, context: Readonly<_typescript_eslint_utils_ts_eslint.RuleContext<string, readonly unknown[]>>) => boolean;
233
237
 
234
- declare const ERPhaseRelevance: birecord.BiRecord<{
238
+ declare const ERPhaseRelevance: _eslint_react_types.BiRecord<{
235
239
  readonly mount: "unmount";
236
240
  readonly setup: "cleanup";
237
241
  }>;
@@ -318,8 +322,20 @@ declare function isFromReact(name: string): (node: TSESTree.Identifier | TSESTre
318
322
  * @returns A function that checks if a given node is a member expression of a Pragma member.
319
323
  */
320
324
  declare function isFromReactMember(memberName: string, name: string): (node: TSESTree.MemberExpression, context: RuleContext) => boolean;
321
- declare function isCallFromReact(name: string): (node: TSESTree.CallExpression, context: RuleContext) => boolean;
322
- 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;
323
339
 
324
340
  /**
325
341
  * Check if an identifier is initialized from React
@@ -575,6 +591,21 @@ declare enum AST_NODE_TYPES {
575
591
  TSUnknownKeyword = "TSUnknownKeyword",
576
592
  TSVoidKeyword = "TSVoidKeyword"
577
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
+ }
578
609
  declare interface AwaitExpression extends BaseNode {
579
610
  type: AST_NODE_TYPES.AwaitExpression;
580
611
  argument: Expression;
@@ -582,6 +613,10 @@ declare interface AwaitExpression extends BaseNode {
582
613
  declare interface BaseNode extends NodeOrTokenData {
583
614
  type: AST_NODE_TYPES;
584
615
  }
616
+ declare interface BaseToken extends NodeOrTokenData {
617
+ type: AST_TOKEN_TYPES;
618
+ value: string;
619
+ }
585
620
  declare interface BigIntLiteral extends LiteralBase {
586
621
  bigint: string;
587
622
  value: bigint | null;
@@ -620,6 +655,9 @@ declare interface BinaryOperatorToText {
620
655
  }
621
656
  declare type BindingName = BindingPattern | Identifier;
622
657
  declare type BindingPattern = ArrayPattern | ObjectPattern;
658
+ declare interface BlockComment extends BaseToken {
659
+ type: AST_TOKEN_TYPES.Block;
660
+ }
623
661
  declare interface BlockStatement extends BaseNode {
624
662
  type: AST_NODE_TYPES.BlockStatement;
625
663
  body: Statement[];
@@ -628,6 +666,9 @@ declare interface BooleanLiteral extends LiteralBase {
628
666
  raw: 'false' | 'true';
629
667
  value: boolean;
630
668
  }
669
+ declare interface BooleanToken extends BaseToken {
670
+ type: AST_TOKEN_TYPES.Boolean;
671
+ }
631
672
  declare interface BreakStatement extends BaseNode {
632
673
  type: AST_NODE_TYPES.BreakStatement;
633
674
  label: Identifier | null;
@@ -708,6 +749,7 @@ declare interface ClassBody extends BaseNode {
708
749
  type: AST_NODE_TYPES.ClassBody;
709
750
  body: ClassElement[];
710
751
  }
752
+ declare type ClassDeclaration = ClassDeclarationWithName | ClassDeclarationWithOptionalName;
711
753
  declare interface ClassDeclarationBase extends ClassBase {
712
754
  type: AST_NODE_TYPES.ClassDeclaration;
713
755
  }
@@ -744,6 +786,7 @@ declare interface ClassPropertyDefinitionNonComputedNameBase extends PropertyDef
744
786
  key: ClassPropertyNameNonComputed;
745
787
  }
746
788
  declare type ClassPropertyNameNonComputed = PrivateIdentifier | PropertyNameNonComputed;
789
+ declare type Comment = BlockComment | LineComment;
747
790
  declare interface ConditionalExpression extends BaseNode {
748
791
  type: AST_NODE_TYPES.ConditionalExpression;
749
792
  alternate: Expression;
@@ -1036,6 +1079,7 @@ declare interface FunctionBase extends BaseNode {
1036
1079
  */
1037
1080
  typeParameters: TSTypeParameterDeclaration | undefined;
1038
1081
  }
1082
+ declare type FunctionDeclaration = FunctionDeclarationWithName | FunctionDeclarationWithOptionalName;
1039
1083
  declare interface FunctionDeclarationBase extends FunctionBase {
1040
1084
  type: AST_NODE_TYPES.FunctionDeclaration;
1041
1085
  body: BlockStatement;
@@ -1072,6 +1116,9 @@ declare interface Identifier extends BaseNode {
1072
1116
  optional: boolean;
1073
1117
  typeAnnotation: TSTypeAnnotation | undefined;
1074
1118
  }
1119
+ declare interface IdentifierToken extends BaseToken {
1120
+ type: AST_TOKEN_TYPES.Identifier;
1121
+ }
1075
1122
  declare interface IfStatement extends BaseNode {
1076
1123
  type: AST_NODE_TYPES.IfStatement;
1077
1124
  alternate: Statement | null;
@@ -1197,6 +1244,9 @@ declare interface JSXIdentifier extends BaseNode {
1197
1244
  type: AST_NODE_TYPES.JSXIdentifier;
1198
1245
  name: string;
1199
1246
  }
1247
+ declare interface JSXIdentifierToken extends BaseToken {
1248
+ type: AST_TOKEN_TYPES.JSXIdentifier;
1249
+ }
1200
1250
  declare interface JSXMemberExpression extends BaseNode {
1201
1251
  type: AST_NODE_TYPES.JSXMemberExpression;
1202
1252
  object: JSXTagNameExpression;
@@ -1231,6 +1281,12 @@ declare interface JSXText extends BaseNode {
1231
1281
  raw: string;
1232
1282
  value: string;
1233
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
+ }
1234
1290
  declare interface LabeledStatement extends BaseNode {
1235
1291
  type: AST_NODE_TYPES.LabeledStatement;
1236
1292
  body: Statement;
@@ -1294,6 +1350,9 @@ declare interface LetOrVarNonDeclaredDeclaration extends LetOrConstOrVarDeclarat
1294
1350
  declare: false;
1295
1351
  kind: 'let' | 'var';
1296
1352
  }
1353
+ declare interface LineComment extends BaseToken {
1354
+ type: AST_TOKEN_TYPES.Line;
1355
+ }
1297
1356
  declare type Literal = BigIntLiteral | BooleanLiteral | NullLiteral | NumberLiteral | RegExpLiteral | StringLiteral;
1298
1357
  declare interface LiteralBase extends BaseNode {
1299
1358
  type: AST_NODE_TYPES.Literal;
@@ -1363,6 +1422,7 @@ declare interface NewExpression extends BaseNode {
1363
1422
  callee: Expression;
1364
1423
  typeArguments: TSTypeParameterInstantiation | undefined;
1365
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;
1366
1426
  declare interface NodeOrTokenData {
1367
1427
  type: string;
1368
1428
  /**
@@ -1377,9 +1437,15 @@ declare interface NullLiteral extends LiteralBase {
1377
1437
  raw: 'null';
1378
1438
  value: null;
1379
1439
  }
1440
+ declare interface NullToken extends BaseToken {
1441
+ type: AST_TOKEN_TYPES.Null;
1442
+ }
1380
1443
  declare interface NumberLiteral extends LiteralBase {
1381
1444
  value: number;
1382
1445
  }
1446
+ declare interface NumericToken extends BaseToken {
1447
+ type: AST_TOKEN_TYPES.Numeric;
1448
+ }
1383
1449
  declare interface ObjectExpression extends BaseNode {
1384
1450
  type: AST_NODE_TYPES.ObjectExpression;
1385
1451
  properties: ObjectLiteralElement[];
@@ -1407,6 +1473,13 @@ declare interface PrivateIdentifier extends BaseNode {
1407
1473
  type: AST_NODE_TYPES.PrivateIdentifier;
1408
1474
  name: string;
1409
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
+ }
1410
1483
  declare type ProgramStatement = ExportAllDeclaration | ExportDefaultDeclaration | ExportNamedDeclaration | ImportDeclaration | Statement | TSImportEqualsDeclaration | TSNamespaceExportDeclaration;
1411
1484
  declare type Property = PropertyComputedName | PropertyNonComputedName;
1412
1485
  declare interface PropertyBase extends BaseNode {
@@ -1459,6 +1532,57 @@ declare interface PropertyNonComputedName extends PropertyBase {
1459
1532
  computed: false;
1460
1533
  key: PropertyNameNonComputed;
1461
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
+ }
1462
1586
  /**
1463
1587
  * An array of two numbers.
1464
1588
  * Both numbers are a 0-based index which is the position in the array of source code characters.
@@ -1472,6 +1596,13 @@ declare interface RegExpLiteral extends LiteralBase {
1472
1596
  };
1473
1597
  value: RegExp | null;
1474
1598
  }
1599
+ declare interface RegularExpressionToken extends BaseToken {
1600
+ type: AST_TOKEN_TYPES.RegularExpression;
1601
+ regex: {
1602
+ flags: string;
1603
+ pattern: string;
1604
+ };
1605
+ }
1475
1606
  declare interface RestElement extends BaseNode {
1476
1607
  type: AST_NODE_TYPES.RestElement;
1477
1608
  argument: DestructuringPattern;
@@ -1510,6 +1641,9 @@ declare interface StaticBlock extends BaseNode {
1510
1641
  declare interface StringLiteral extends LiteralBase {
1511
1642
  value: string;
1512
1643
  }
1644
+ declare interface StringToken extends BaseToken {
1645
+ type: AST_TOKEN_TYPES.String;
1646
+ }
1513
1647
  declare interface Super extends BaseNode {
1514
1648
  type: AST_NODE_TYPES.Super;
1515
1649
  }
@@ -1542,6 +1676,9 @@ declare interface TemplateLiteral extends BaseNode {
1542
1676
  expressions: Expression[];
1543
1677
  quasis: TemplateElement[];
1544
1678
  }
1679
+ declare interface TemplateToken extends BaseToken {
1680
+ type: AST_TOKEN_TYPES.Template;
1681
+ }
1545
1682
  declare interface ThisExpression extends BaseNode {
1546
1683
  type: AST_NODE_TYPES.ThisExpression;
1547
1684
  }
@@ -1549,6 +1686,7 @@ declare interface ThrowStatement extends BaseNode {
1549
1686
  type: AST_NODE_TYPES.ThrowStatement;
1550
1687
  argument: Expression;
1551
1688
  }
1689
+ declare type Token = BooleanToken | Comment | IdentifierToken | JSXIdentifierToken | JSXTextToken | KeywordToken | NullToken | NumericToken | PunctuatorToken | RegularExpressionToken | StringToken | TemplateToken;
1552
1690
  declare interface TryStatement extends BaseNode {
1553
1691
  type: AST_NODE_TYPES.TryStatement;
1554
1692
  block: BlockStatement;
@@ -2264,6 +2402,7 @@ declare interface UsingDeclarationBase extends BaseNode {
2264
2402
  */
2265
2403
  kind: 'await using' | 'using';
2266
2404
  }
2405
+ declare type UsingDeclarator = UsingInForOfDeclarator | UsingInNormalContextDeclarator;
2267
2406
  declare interface UsingInForOfDeclaration extends UsingDeclarationBase {
2268
2407
  /**
2269
2408
  * The variables declared by this declaration.
@@ -2299,6 +2438,7 @@ declare interface UsingInNormalContextDeclarator extends VariableDeclaratorBase
2299
2438
  }
2300
2439
  declare type ValueOf<T> = T[keyof T];
2301
2440
  declare type VariableDeclaration = LetOrConstOrVarDeclaration | UsingDeclaration;
2441
+ declare type VariableDeclarator = LetOrConstOrVarDeclarator | UsingDeclarator;
2302
2442
  declare interface VariableDeclaratorBase extends BaseNode {
2303
2443
  type: AST_NODE_TYPES.VariableDeclarator;
2304
2444
  /**
@@ -2363,16 +2503,69 @@ declare const isCreateElement: (node: Identifier | MemberExpression, context: _e
2363
2503
  declare const isCreateRef: (node: Identifier | MemberExpression, context: _eslint_react_types.RuleContext) => boolean;
2364
2504
  declare const isForwardRef: (node: Identifier | MemberExpression, context: _eslint_react_types.RuleContext) => boolean;
2365
2505
  declare const isMemo: (node: Identifier | MemberExpression, context: _eslint_react_types.RuleContext) => boolean;
2366
- declare const isChildrenCountCall: (node: CallExpression, context: _eslint_react_types.RuleContext) => boolean;
2367
- declare const isChildrenForEachCall: (node: CallExpression, context: _eslint_react_types.RuleContext) => boolean;
2368
- declare const isChildrenMapCall: (node: CallExpression, context: _eslint_react_types.RuleContext) => boolean;
2369
- declare const isChildrenOnlyCall: (node: CallExpression, context: _eslint_react_types.RuleContext) => boolean;
2370
- declare const isChildrenToArrayCall: (node: CallExpression, context: _eslint_react_types.RuleContext) => boolean;
2371
- declare const isCloneElementCall: (node: CallExpression, context: _eslint_react_types.RuleContext) => boolean;
2372
- declare const isCreateContextCall: (node: CallExpression, context: _eslint_react_types.RuleContext) => boolean;
2373
- declare const isCreateElementCall: (node: CallExpression, context: _eslint_react_types.RuleContext) => boolean;
2374
- declare const isCreateRefCall: (node: CallExpression, context: _eslint_react_types.RuleContext) => boolean;
2375
- declare const isForwardRefCall: (node: CallExpression, context: _eslint_react_types.RuleContext) => boolean;
2376
- 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
+ };
2377
2570
 
2378
- 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
@@ -5,7 +5,6 @@ import * as _eslint_react_types from '@eslint-react/types';
5
5
  import { RuleContext } from '@eslint-react/types';
6
6
  import { TSESTree as TSESTree$1 } from '@typescript-eslint/utils';
7
7
  import * as _typescript_eslint_utils_ts_eslint from '@typescript-eslint/utils/ts-eslint';
8
- import * as birecord from 'birecord';
9
8
  import { ESLintReactSettings } from '@eslint-react/shared';
10
9
  import { Scope } from '@typescript-eslint/scope-manager';
11
10
  import { SyntaxKind } from 'typescript';
@@ -161,12 +160,18 @@ declare function isCleanupFunction(node: TSESTree.Node): boolean;
161
160
  declare function getElementRepresentName(node: TSESTree.JSXOpeningElement, context: RuleContext): string;
162
161
 
163
162
  /**
164
- * Determines whether inside createElement's props.
163
+ * Determines whether inside `createElement`'s props.
165
164
  * @param node The AST node to check
166
165
  * @param context The rule context
167
166
  * @returns `true` if the node is inside createElement's props
168
167
  */
169
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
+ */
170
175
  declare function isChildrenOfCreateElement(node: TSESTree.Node, context: RuleContext): boolean;
171
176
 
172
177
  /**
@@ -178,7 +183,6 @@ declare function isChildrenOfCreateElement(node: TSESTree.Node, context: RuleCon
178
183
  declare function isFragmentElement(node: TSESTree.JSXElement, context: RuleContext): boolean;
179
184
 
180
185
  declare function isInsideReactHook(node: TSESTree.Node): boolean;
181
- declare function isInsideReactHookCall(node: TSESTree.Node): boolean;
182
186
 
183
187
  interface ERHook extends ERSemanticNode {
184
188
  id: O.Some<TSESTree.Identifier>;
@@ -210,7 +214,7 @@ declare function isReactHook(node: AST.TSESTreeFunction): boolean;
210
214
  * @param node The node to check.
211
215
  * @returns `true` if the node is a React Hook call, `false` otherwise.
212
216
  */
213
- declare function isReactHookCall(node: TSESTree.CallExpression): boolean;
217
+ declare function isReactHookCall(node: TSESTree.Node): boolean;
214
218
  declare function isReactHookCallWithName(node: TSESTree.CallExpression, context: RuleContext): (name: string) => boolean;
215
219
  declare function isReactHookCallWithNameLoose(node: TSESTree.CallExpression): (name: string) => boolean;
216
220
  declare function isReactHookCallWithNameAlias(name: string, context: RuleContext, alias: string[]): (node: TSESTree.CallExpression) => boolean;
@@ -231,7 +235,7 @@ declare const isUseStateCall: (node: TSESTree.CallExpression, context: Readonly<
231
235
  declare const isUseSyncExternalStoreCall: (node: TSESTree.CallExpression, context: Readonly<_typescript_eslint_utils_ts_eslint.RuleContext<string, readonly unknown[]>>) => boolean;
232
236
  declare const isUseTransitionCall: (node: TSESTree.CallExpression, context: Readonly<_typescript_eslint_utils_ts_eslint.RuleContext<string, readonly unknown[]>>) => boolean;
233
237
 
234
- declare const ERPhaseRelevance: birecord.BiRecord<{
238
+ declare const ERPhaseRelevance: _eslint_react_types.BiRecord<{
235
239
  readonly mount: "unmount";
236
240
  readonly setup: "cleanup";
237
241
  }>;
@@ -318,8 +322,20 @@ declare function isFromReact(name: string): (node: TSESTree.Identifier | TSESTre
318
322
  * @returns A function that checks if a given node is a member expression of a Pragma member.
319
323
  */
320
324
  declare function isFromReactMember(memberName: string, name: string): (node: TSESTree.MemberExpression, context: RuleContext) => boolean;
321
- declare function isCallFromReact(name: string): (node: TSESTree.CallExpression, context: RuleContext) => boolean;
322
- 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;
323
339
 
324
340
  /**
325
341
  * Check if an identifier is initialized from React
@@ -575,6 +591,21 @@ declare enum AST_NODE_TYPES {
575
591
  TSUnknownKeyword = "TSUnknownKeyword",
576
592
  TSVoidKeyword = "TSVoidKeyword"
577
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
+ }
578
609
  declare interface AwaitExpression extends BaseNode {
579
610
  type: AST_NODE_TYPES.AwaitExpression;
580
611
  argument: Expression;
@@ -582,6 +613,10 @@ declare interface AwaitExpression extends BaseNode {
582
613
  declare interface BaseNode extends NodeOrTokenData {
583
614
  type: AST_NODE_TYPES;
584
615
  }
616
+ declare interface BaseToken extends NodeOrTokenData {
617
+ type: AST_TOKEN_TYPES;
618
+ value: string;
619
+ }
585
620
  declare interface BigIntLiteral extends LiteralBase {
586
621
  bigint: string;
587
622
  value: bigint | null;
@@ -620,6 +655,9 @@ declare interface BinaryOperatorToText {
620
655
  }
621
656
  declare type BindingName = BindingPattern | Identifier;
622
657
  declare type BindingPattern = ArrayPattern | ObjectPattern;
658
+ declare interface BlockComment extends BaseToken {
659
+ type: AST_TOKEN_TYPES.Block;
660
+ }
623
661
  declare interface BlockStatement extends BaseNode {
624
662
  type: AST_NODE_TYPES.BlockStatement;
625
663
  body: Statement[];
@@ -628,6 +666,9 @@ declare interface BooleanLiteral extends LiteralBase {
628
666
  raw: 'false' | 'true';
629
667
  value: boolean;
630
668
  }
669
+ declare interface BooleanToken extends BaseToken {
670
+ type: AST_TOKEN_TYPES.Boolean;
671
+ }
631
672
  declare interface BreakStatement extends BaseNode {
632
673
  type: AST_NODE_TYPES.BreakStatement;
633
674
  label: Identifier | null;
@@ -708,6 +749,7 @@ declare interface ClassBody extends BaseNode {
708
749
  type: AST_NODE_TYPES.ClassBody;
709
750
  body: ClassElement[];
710
751
  }
752
+ declare type ClassDeclaration = ClassDeclarationWithName | ClassDeclarationWithOptionalName;
711
753
  declare interface ClassDeclarationBase extends ClassBase {
712
754
  type: AST_NODE_TYPES.ClassDeclaration;
713
755
  }
@@ -744,6 +786,7 @@ declare interface ClassPropertyDefinitionNonComputedNameBase extends PropertyDef
744
786
  key: ClassPropertyNameNonComputed;
745
787
  }
746
788
  declare type ClassPropertyNameNonComputed = PrivateIdentifier | PropertyNameNonComputed;
789
+ declare type Comment = BlockComment | LineComment;
747
790
  declare interface ConditionalExpression extends BaseNode {
748
791
  type: AST_NODE_TYPES.ConditionalExpression;
749
792
  alternate: Expression;
@@ -1036,6 +1079,7 @@ declare interface FunctionBase extends BaseNode {
1036
1079
  */
1037
1080
  typeParameters: TSTypeParameterDeclaration | undefined;
1038
1081
  }
1082
+ declare type FunctionDeclaration = FunctionDeclarationWithName | FunctionDeclarationWithOptionalName;
1039
1083
  declare interface FunctionDeclarationBase extends FunctionBase {
1040
1084
  type: AST_NODE_TYPES.FunctionDeclaration;
1041
1085
  body: BlockStatement;
@@ -1072,6 +1116,9 @@ declare interface Identifier extends BaseNode {
1072
1116
  optional: boolean;
1073
1117
  typeAnnotation: TSTypeAnnotation | undefined;
1074
1118
  }
1119
+ declare interface IdentifierToken extends BaseToken {
1120
+ type: AST_TOKEN_TYPES.Identifier;
1121
+ }
1075
1122
  declare interface IfStatement extends BaseNode {
1076
1123
  type: AST_NODE_TYPES.IfStatement;
1077
1124
  alternate: Statement | null;
@@ -1197,6 +1244,9 @@ declare interface JSXIdentifier extends BaseNode {
1197
1244
  type: AST_NODE_TYPES.JSXIdentifier;
1198
1245
  name: string;
1199
1246
  }
1247
+ declare interface JSXIdentifierToken extends BaseToken {
1248
+ type: AST_TOKEN_TYPES.JSXIdentifier;
1249
+ }
1200
1250
  declare interface JSXMemberExpression extends BaseNode {
1201
1251
  type: AST_NODE_TYPES.JSXMemberExpression;
1202
1252
  object: JSXTagNameExpression;
@@ -1231,6 +1281,12 @@ declare interface JSXText extends BaseNode {
1231
1281
  raw: string;
1232
1282
  value: string;
1233
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
+ }
1234
1290
  declare interface LabeledStatement extends BaseNode {
1235
1291
  type: AST_NODE_TYPES.LabeledStatement;
1236
1292
  body: Statement;
@@ -1294,6 +1350,9 @@ declare interface LetOrVarNonDeclaredDeclaration extends LetOrConstOrVarDeclarat
1294
1350
  declare: false;
1295
1351
  kind: 'let' | 'var';
1296
1352
  }
1353
+ declare interface LineComment extends BaseToken {
1354
+ type: AST_TOKEN_TYPES.Line;
1355
+ }
1297
1356
  declare type Literal = BigIntLiteral | BooleanLiteral | NullLiteral | NumberLiteral | RegExpLiteral | StringLiteral;
1298
1357
  declare interface LiteralBase extends BaseNode {
1299
1358
  type: AST_NODE_TYPES.Literal;
@@ -1363,6 +1422,7 @@ declare interface NewExpression extends BaseNode {
1363
1422
  callee: Expression;
1364
1423
  typeArguments: TSTypeParameterInstantiation | undefined;
1365
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;
1366
1426
  declare interface NodeOrTokenData {
1367
1427
  type: string;
1368
1428
  /**
@@ -1377,9 +1437,15 @@ declare interface NullLiteral extends LiteralBase {
1377
1437
  raw: 'null';
1378
1438
  value: null;
1379
1439
  }
1440
+ declare interface NullToken extends BaseToken {
1441
+ type: AST_TOKEN_TYPES.Null;
1442
+ }
1380
1443
  declare interface NumberLiteral extends LiteralBase {
1381
1444
  value: number;
1382
1445
  }
1446
+ declare interface NumericToken extends BaseToken {
1447
+ type: AST_TOKEN_TYPES.Numeric;
1448
+ }
1383
1449
  declare interface ObjectExpression extends BaseNode {
1384
1450
  type: AST_NODE_TYPES.ObjectExpression;
1385
1451
  properties: ObjectLiteralElement[];
@@ -1407,6 +1473,13 @@ declare interface PrivateIdentifier extends BaseNode {
1407
1473
  type: AST_NODE_TYPES.PrivateIdentifier;
1408
1474
  name: string;
1409
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
+ }
1410
1483
  declare type ProgramStatement = ExportAllDeclaration | ExportDefaultDeclaration | ExportNamedDeclaration | ImportDeclaration | Statement | TSImportEqualsDeclaration | TSNamespaceExportDeclaration;
1411
1484
  declare type Property = PropertyComputedName | PropertyNonComputedName;
1412
1485
  declare interface PropertyBase extends BaseNode {
@@ -1459,6 +1532,57 @@ declare interface PropertyNonComputedName extends PropertyBase {
1459
1532
  computed: false;
1460
1533
  key: PropertyNameNonComputed;
1461
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
+ }
1462
1586
  /**
1463
1587
  * An array of two numbers.
1464
1588
  * Both numbers are a 0-based index which is the position in the array of source code characters.
@@ -1472,6 +1596,13 @@ declare interface RegExpLiteral extends LiteralBase {
1472
1596
  };
1473
1597
  value: RegExp | null;
1474
1598
  }
1599
+ declare interface RegularExpressionToken extends BaseToken {
1600
+ type: AST_TOKEN_TYPES.RegularExpression;
1601
+ regex: {
1602
+ flags: string;
1603
+ pattern: string;
1604
+ };
1605
+ }
1475
1606
  declare interface RestElement extends BaseNode {
1476
1607
  type: AST_NODE_TYPES.RestElement;
1477
1608
  argument: DestructuringPattern;
@@ -1510,6 +1641,9 @@ declare interface StaticBlock extends BaseNode {
1510
1641
  declare interface StringLiteral extends LiteralBase {
1511
1642
  value: string;
1512
1643
  }
1644
+ declare interface StringToken extends BaseToken {
1645
+ type: AST_TOKEN_TYPES.String;
1646
+ }
1513
1647
  declare interface Super extends BaseNode {
1514
1648
  type: AST_NODE_TYPES.Super;
1515
1649
  }
@@ -1542,6 +1676,9 @@ declare interface TemplateLiteral extends BaseNode {
1542
1676
  expressions: Expression[];
1543
1677
  quasis: TemplateElement[];
1544
1678
  }
1679
+ declare interface TemplateToken extends BaseToken {
1680
+ type: AST_TOKEN_TYPES.Template;
1681
+ }
1545
1682
  declare interface ThisExpression extends BaseNode {
1546
1683
  type: AST_NODE_TYPES.ThisExpression;
1547
1684
  }
@@ -1549,6 +1686,7 @@ declare interface ThrowStatement extends BaseNode {
1549
1686
  type: AST_NODE_TYPES.ThrowStatement;
1550
1687
  argument: Expression;
1551
1688
  }
1689
+ declare type Token = BooleanToken | Comment | IdentifierToken | JSXIdentifierToken | JSXTextToken | KeywordToken | NullToken | NumericToken | PunctuatorToken | RegularExpressionToken | StringToken | TemplateToken;
1552
1690
  declare interface TryStatement extends BaseNode {
1553
1691
  type: AST_NODE_TYPES.TryStatement;
1554
1692
  block: BlockStatement;
@@ -2264,6 +2402,7 @@ declare interface UsingDeclarationBase extends BaseNode {
2264
2402
  */
2265
2403
  kind: 'await using' | 'using';
2266
2404
  }
2405
+ declare type UsingDeclarator = UsingInForOfDeclarator | UsingInNormalContextDeclarator;
2267
2406
  declare interface UsingInForOfDeclaration extends UsingDeclarationBase {
2268
2407
  /**
2269
2408
  * The variables declared by this declaration.
@@ -2299,6 +2438,7 @@ declare interface UsingInNormalContextDeclarator extends VariableDeclaratorBase
2299
2438
  }
2300
2439
  declare type ValueOf<T> = T[keyof T];
2301
2440
  declare type VariableDeclaration = LetOrConstOrVarDeclaration | UsingDeclaration;
2441
+ declare type VariableDeclarator = LetOrConstOrVarDeclarator | UsingDeclarator;
2302
2442
  declare interface VariableDeclaratorBase extends BaseNode {
2303
2443
  type: AST_NODE_TYPES.VariableDeclarator;
2304
2444
  /**
@@ -2363,16 +2503,69 @@ declare const isCreateElement: (node: Identifier | MemberExpression, context: _e
2363
2503
  declare const isCreateRef: (node: Identifier | MemberExpression, context: _eslint_react_types.RuleContext) => boolean;
2364
2504
  declare const isForwardRef: (node: Identifier | MemberExpression, context: _eslint_react_types.RuleContext) => boolean;
2365
2505
  declare const isMemo: (node: Identifier | MemberExpression, context: _eslint_react_types.RuleContext) => boolean;
2366
- declare const isChildrenCountCall: (node: CallExpression, context: _eslint_react_types.RuleContext) => boolean;
2367
- declare const isChildrenForEachCall: (node: CallExpression, context: _eslint_react_types.RuleContext) => boolean;
2368
- declare const isChildrenMapCall: (node: CallExpression, context: _eslint_react_types.RuleContext) => boolean;
2369
- declare const isChildrenOnlyCall: (node: CallExpression, context: _eslint_react_types.RuleContext) => boolean;
2370
- declare const isChildrenToArrayCall: (node: CallExpression, context: _eslint_react_types.RuleContext) => boolean;
2371
- declare const isCloneElementCall: (node: CallExpression, context: _eslint_react_types.RuleContext) => boolean;
2372
- declare const isCreateContextCall: (node: CallExpression, context: _eslint_react_types.RuleContext) => boolean;
2373
- declare const isCreateElementCall: (node: CallExpression, context: _eslint_react_types.RuleContext) => boolean;
2374
- declare const isCreateRefCall: (node: CallExpression, context: _eslint_react_types.RuleContext) => boolean;
2375
- declare const isForwardRefCall: (node: CallExpression, context: _eslint_react_types.RuleContext) => boolean;
2376
- 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
+ };
2377
2570
 
2378
- 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
@@ -8,7 +8,7 @@ var ShortUniqueId = require('short-unique-id');
8
8
  var tsPattern = require('ts-pattern');
9
9
  var shared = require('@eslint-react/shared');
10
10
  var VAR = require('@eslint-react/var');
11
- var birecord = require('birecord');
11
+ var types$1 = require('@eslint-react/types');
12
12
 
13
13
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
14
14
 
@@ -34,7 +34,6 @@ var AST9__namespace = /*#__PURE__*/_interopNamespace(AST9);
34
34
  var JSX4__namespace = /*#__PURE__*/_interopNamespace(JSX4);
35
35
  var ShortUniqueId__default = /*#__PURE__*/_interopDefault(ShortUniqueId);
36
36
  var VAR__namespace = /*#__PURE__*/_interopNamespace(VAR);
37
- var birecord__default = /*#__PURE__*/_interopDefault(birecord);
38
37
 
39
38
  // src/component/component-collector.ts
40
39
  function getElementRepresentName(node, context) {
@@ -85,16 +84,18 @@ function isFromReactMember(memberName, name) {
85
84
  };
86
85
  }
87
86
  function isCallFromReact(name) {
88
- return (node, context) => {
87
+ return eff.F.dual(2, (node, context) => {
88
+ if (node.type !== types.AST_NODE_TYPES.CallExpression) return false;
89
89
  if (!AST9__namespace.isOneOf([types.AST_NODE_TYPES.Identifier, types.AST_NODE_TYPES.MemberExpression])(node.callee)) return false;
90
90
  return isFromReact(name)(node.callee, context);
91
- };
91
+ });
92
92
  }
93
93
  function isCallFromReactMember(pragmaMemberName, name) {
94
- return (node, context) => {
94
+ return eff.F.dual(2, (node, context) => {
95
+ if (node.type !== types.AST_NODE_TYPES.CallExpression) return false;
95
96
  if (!AST9__namespace.is(types.AST_NODE_TYPES.MemberExpression)(node.callee)) return false;
96
97
  return isFromReactMember(pragmaMemberName, name)(node.callee, context);
97
- };
98
+ });
98
99
  }
99
100
 
100
101
  // src/utils/is-react-api.ts
@@ -130,19 +131,18 @@ var isMemoCall = isReactAPICallWithName("memo");
130
131
  // src/element/hierarchy.ts
131
132
  function isInsideCreateElementProps(node, context) {
132
133
  return eff.F.pipe(
133
- AST9__namespace.traverseUp(node, (n) => AST9__namespace.is(types.AST_NODE_TYPES.CallExpression)(n) && isCreateElementCall(n, context)),
134
- eff.O.filter(AST9__namespace.is(types.AST_NODE_TYPES.CallExpression)),
135
- eff.O.flatMapNullable((c) => c.arguments.at(1)),
136
- eff.O.filter(AST9__namespace.is(types.AST_NODE_TYPES.ObjectExpression)),
137
- eff.O.zipWith(AST9__namespace.traverseUp(node, AST9__namespace.is(types.AST_NODE_TYPES.ObjectExpression)), (a, b) => a === b),
138
- 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)
139
139
  );
140
140
  }
141
141
  function isChildrenOfCreateElement(node, context) {
142
142
  return eff.F.pipe(
143
143
  eff.O.fromNullable(node.parent),
144
144
  eff.O.filter(AST9__namespace.is(types.AST_NODE_TYPES.CallExpression)),
145
- eff.O.filter((n) => isCreateElementCall(n, context)),
145
+ eff.O.filter(isCreateElementCall(context)),
146
146
  eff.O.exists(
147
147
  (n) => n.arguments.slice(2).some((arg) => arg === node)
148
148
  )
@@ -171,6 +171,7 @@ function isReactHook(node) {
171
171
  );
172
172
  }
173
173
  function isReactHookCall(node) {
174
+ if (node.type !== types.AST_NODE_TYPES.CallExpression) return false;
174
175
  if (node.callee.type === types.AST_NODE_TYPES.Identifier) return isReactHookName(node.callee.name);
175
176
  if (node.callee.type === types.AST_NODE_TYPES.MemberExpression) {
176
177
  return node.callee.property.type === types.AST_NODE_TYPES.Identifier && isReactHookName(node.callee.property.name);
@@ -248,9 +249,6 @@ var isUseTransitionCall = eff.F.flip(isReactHookCallWithName)("useTransition");
248
249
  function isInsideReactHook(node) {
249
250
  return eff.O.exists(AST9__namespace.traverseUpGuard(node, AST9__namespace.isFunction), isReactHook);
250
251
  }
251
- function isInsideReactHookCall(node) {
252
- return eff.O.isSome(AST9__namespace.traverseUp(node, (n) => AST9__namespace.is(types.AST_NODE_TYPES.CallExpression)(n) && isReactHookCall(n)));
253
- }
254
252
  var uid = new ShortUniqueId__default.default({ length: 10 });
255
253
  function useHookCollector() {
256
254
  const hooks = /* @__PURE__ */ new Map();
@@ -258,23 +256,22 @@ function useHookCollector() {
258
256
  const onFunctionEnter = (node) => {
259
257
  const id = AST9__namespace.getFunctionIdentifier(node);
260
258
  const name = eff.O.flatMapNullable(id, (id2) => id2.name);
261
- const isHook = eff.O.isSome(id) && eff.O.isSome(name) && isReactHookName(name.value);
262
- if (!isHook) {
263
- 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
+ });
264
272
  return;
265
273
  }
266
- const key = uid.rnd();
267
- fStack.push([node, eff.O.some(key)]);
268
- hooks.set(key, {
269
- _: key,
270
- id,
271
- kind: "function",
272
- name,
273
- node,
274
- flag: 0n,
275
- hint: 0n,
276
- hookCalls: []
277
- });
274
+ fStack.push([node, eff.O.none()]);
278
275
  };
279
276
  const onFunctionExit = () => {
280
277
  fStack.pop();
@@ -467,10 +464,9 @@ function isFunctionOfRenderMethod(node) {
467
464
  return isClassComponent(node.parent.parent.parent);
468
465
  }
469
466
  function isInsideRenderMethod(node) {
470
- const predicate = (node2) => {
467
+ return eff.O.isSome(AST9__namespace.traverseUp(node, (node2) => {
471
468
  return isRenderMethodLike(node2) && isClassComponent(node2.parent.parent);
472
- };
473
- return eff.O.isSome(AST9__namespace.traverseUp(node, predicate));
469
+ }));
474
470
  }
475
471
  function hasNoneOrValidComponentName(node, context) {
476
472
  return eff.O.match(
@@ -641,7 +637,7 @@ function isCleanupFunction(node) {
641
637
  if (!nearestFunction || !nearestFunctionOfRet) return false;
642
638
  return nearestFunction === nearestFunctionOfRet && isSetupFunction(nearestFunction);
643
639
  }
644
- var ERPhaseRelevance = birecord__default.default({
640
+ var ERPhaseRelevance = types$1.birecord({
645
641
  mount: "unmount",
646
642
  setup: "cleanup"
647
643
  });
@@ -673,14 +669,14 @@ function isDeclaredInRenderPropLoose(node) {
673
669
  }
674
670
  function isRenderFunctionLoose(node, context) {
675
671
  const { body, parent } = node;
676
- const maybeId = AST9__namespace.getFunctionIdentifier(node);
677
- if (eff.O.isSome(maybeId) && !maybeId.value.name.startsWith("render")) {
672
+ if (eff.O.exists(AST9__namespace.getFunctionIdentifier(node), (id) => id.name.startsWith("render"))) {
678
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");
679
674
  }
680
- const jsxCtx = { getScope: (node2) => context.sourceCode.getScope(node2) };
681
675
  return JSX4__namespace.isJSXValue(
682
676
  body,
683
- jsxCtx,
677
+ {
678
+ getScope: (node2) => context.sourceCode.getScope(node2)
679
+ },
684
680
  JSX4__namespace.JSXValueHint.SkipNullLiteral | JSX4__namespace.JSXValueHint.SkipUndefinedLiteral | JSX4__namespace.JSXValueHint.StrictLogical | JSX4__namespace.JSXValueHint.StrictConditional
685
681
  );
686
682
  }
@@ -743,7 +739,6 @@ exports.isFunctionOfRenderMethod = isFunctionOfRenderMethod;
743
739
  exports.isInitializedFromReact = isInitializedFromReact;
744
740
  exports.isInsideCreateElementProps = isInsideCreateElementProps;
745
741
  exports.isInsideReactHook = isInsideReactHook;
746
- exports.isInsideReactHookCall = isInsideReactHookCall;
747
742
  exports.isInsideRenderMethod = isInsideRenderMethod;
748
743
  exports.isInversePhase = isInversePhase;
749
744
  exports.isMemo = isMemo;
package/dist/index.mjs CHANGED
@@ -6,7 +6,7 @@ import ShortUniqueId from 'short-unique-id';
6
6
  import { isMatching, P, match } from 'ts-pattern';
7
7
  import { normalizeSettings, decodeSettings, unsafeReadSettings } from '@eslint-react/shared';
8
8
  import * as VAR from '@eslint-react/var';
9
- import birecord from 'birecord';
9
+ import { birecord } from '@eslint-react/types';
10
10
 
11
11
  // src/component/component-collector.ts
12
12
  function getElementRepresentName(node, context) {
@@ -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,19 +1,18 @@
1
1
  {
2
2
  "name": "@eslint-react/core",
3
- "version": "1.22.1",
3
+ "version": "1.22.2-beta.11",
4
4
  "description": "ESLint React's ESLint utility module for static analysis of React core APIs and Patterns.",
5
- "homepage": "https://github.com/rel1cx/eslint-react",
5
+ "homepage": "https://github.com/rEl1cx/eslint-react",
6
6
  "bugs": {
7
- "url": "https://github.com/rel1cx/eslint-react/issues"
7
+ "url": "https://github.com/rEl1cx/eslint-react/issues"
8
8
  },
9
9
  "repository": {
10
10
  "type": "git",
11
- "url": "https://github.com/Rel1cx/eslint-react",
11
+ "url": "git+https://github.com/rEl1cx/eslint-react.git",
12
12
  "directory": "packages/core"
13
13
  },
14
14
  "license": "MIT",
15
15
  "author": "Eva1ent<rel1cx@proton.me>",
16
- "sideEffects": false,
17
16
  "exports": {
18
17
  ".": {
19
18
  "import": {
@@ -28,7 +27,6 @@
28
27
  "./package.json": "./package.json"
29
28
  },
30
29
  "main": "dist/index.js",
31
- "module": "dist/index.mjs",
32
30
  "types": "dist/index.d.ts",
33
31
  "files": [
34
32
  "dist",
@@ -39,20 +37,25 @@
39
37
  "@typescript-eslint/type-utils": "^8.18.2",
40
38
  "@typescript-eslint/types": "^8.18.2",
41
39
  "@typescript-eslint/utils": "^8.18.2",
42
- "birecord": "^0.1.1",
43
40
  "short-unique-id": "^5.2.0",
44
41
  "ts-pattern": "^5.6.0",
45
- "@eslint-react/ast": "1.22.1",
46
- "@eslint-react/eff": "1.22.1",
47
- "@eslint-react/jsx": "1.22.1",
48
- "@eslint-react/types": "1.22.1",
49
- "@eslint-react/shared": "1.22.1",
50
- "@eslint-react/var": "1.22.1"
42
+ "@eslint-react/ast": "1.22.2-beta.11",
43
+ "@eslint-react/eff": "1.22.2-beta.11",
44
+ "@eslint-react/shared": "1.22.2-beta.11",
45
+ "@eslint-react/types": "1.22.2-beta.11",
46
+ "@eslint-react/var": "1.22.2-beta.11",
47
+ "@eslint-react/jsx": "1.22.2-beta.11"
51
48
  },
52
49
  "devDependencies": {
53
50
  "tsup": "^8.3.5",
54
51
  "@workspace/configs": "0.0.0"
55
52
  },
53
+ "engines": {
54
+ "bun": ">=1.0.15",
55
+ "node": ">=18.18.0"
56
+ },
57
+ "sideEffects": false,
58
+ "module": "dist/index.mjs",
56
59
  "scripts": {
57
60
  "build": "tsup",
58
61
  "build:docs": "typedoc",