@eslint-react/core 5.28.8 → 5.30.0-beta.1

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.ts CHANGED
@@ -4,7 +4,6 @@ import { TSESTree } from "@typescript-eslint/types";
4
4
  import { RegExpLike } from "@eslint-react/shared";
5
5
  import ts from "typescript";
6
6
  import { ESLintUtils } from "@typescript-eslint/utils";
7
- //#region src/api.d.ts
8
7
  export declare namespace isAPI {
9
8
  /** The dual-signature predicate type returned by {@link isAPI}. */
10
9
  type ReturnType = {
@@ -165,16 +164,12 @@ export declare const isUseStateCall: isAPICall.ReturnType;
165
164
  export declare const isUseSyncExternalStoreCall: isAPICall.ReturnType;
166
165
  /** Check if the node is a call expression to the React `useTransition` API. */
167
166
  export declare const isUseTransitionCall: isAPICall.ReturnType;
168
- //#endregion
169
- //#region src/class.d.ts
170
167
  /**
171
168
  * Get the class identifier of a class node.
172
169
  * @param node The class node to get the identifier from.
173
170
  * @returns The class identifier or `null` if not found.
174
171
  */
175
172
  export declare function getClassId(node: TSESTreeClass): TSESTree.BindingName | null;
176
- //#endregion
177
- //#region src/semantic.d.ts
178
173
  /**
179
174
  * Represents a semantic node in the AST.
180
175
  * This is the base interface for all semantic nodes in the React semantic analysis.
@@ -217,8 +212,6 @@ export interface SemanticFunc extends SemanticNode {
217
212
  /** The type parameters of the function. */
218
213
  typeParameters: TSESTree.TSTypeParameterDeclaration | null;
219
214
  }
220
- //#endregion
221
- //#region src/class-component.d.ts
222
215
  /**
223
216
  * @deprecated Class components are legacy. This type exists only to support legacy rules.
224
217
  */
@@ -250,7 +243,7 @@ export declare function isClassComponent(node: TSESTree.Node): node is TSESTreeC
250
243
  * @returns `true` if the node is a pure component.
251
244
  * @deprecated Class components are legacy. This function exists only to support legacy rules.
252
245
  */
253
- export declare function isPureComponent(node: TSESTree.Node): boolean;
246
+ export declare function isPureComponent(node: TSESTreeClass): boolean;
254
247
  /** @deprecated Class components are legacy. */
255
248
  export declare const isRender: (node: TSESTree.Node) => node is TSESTreeMethodOrPropertyDefinition;
256
249
  /** @deprecated Class components are legacy. */
@@ -315,8 +308,6 @@ export declare function isRenderMethodCallback(node: TSESTreeFunction): boolean;
315
308
  * @deprecated Class components are legacy. This function exists only to support legacy rules.
316
309
  */
317
310
  export declare function isThisSetStateCall(node: TSESTree.CallExpression): boolean;
318
- //#endregion
319
- //#region src/class-component-collector.d.ts
320
311
  /**
321
312
  * @deprecated Class components are legacy. This namespace exists only to support legacy rules.
322
313
  */
@@ -335,71 +326,6 @@ export declare namespace getClassComponentCollector {
335
326
  * @deprecated Class components are legacy. This function exists only to support legacy rules.
336
327
  */
337
328
  export declare function getClassComponentCollector(context: RuleContext): getClassComponentCollector.ReturnType;
338
- //#endregion
339
- //#region src/create-element.d.ts
340
- /**
341
- * Get the type argument (the first argument) of a `createElement` call.
342
- * @param context The ESLint rule context.
343
- * @param node The node to inspect.
344
- * @returns The type argument, or `null` when the node is not a `createElement` call or has no arguments.
345
- */
346
- export declare function getCreateElementTypeArgument(context: RuleContext, node: null | TSESTree.Node): TSESTree.CallExpressionArgument | null;
347
- /**
348
- * Get the props object (the second argument) of a `createElement` call.
349
- *
350
- * Type expressions and chain expressions wrapping the argument are unwrapped
351
- * before the object check; `null`, spread, or otherwise non-object props
352
- * arguments yield `null`.
353
- *
354
- * @param context The ESLint rule context.
355
- * @param node The node to inspect.
356
- * @returns The props `ObjectExpression`, or `null` when absent or not statically an object literal.
357
- */
358
- export declare function getCreateElementPropsObject(context: RuleContext, node: null | TSESTree.Node): TSESTree.ObjectExpression | null;
359
- /**
360
- * Get the children arguments (the arguments after the props object) of a `createElement` call.
361
- * @param context The ESLint rule context.
362
- * @param node The node to inspect.
363
- * @returns The children arguments, or an empty array when the node is not a `createElement` call.
364
- */
365
- export declare function getCreateElementChildrenArguments(context: RuleContext, node: null | TSESTree.Node): TSESTree.CallExpressionArgument[];
366
- /**
367
- * Find a statically named property in the props object of a `createElement` call.
368
- *
369
- * Statically resolvable names include plain identifier keys as well as
370
- * string-literal and simple template-literal keys (computed or not).
371
- * @param context The ESLint rule context.
372
- * @param node The node to inspect.
373
- * @param name The property name to look for (ex: `"children"`, `"key"`).
374
- * @returns The matching `Property` node, or `null` when the call has no static property with that name.
375
- *
376
- * @example
377
- * ```ts
378
- * import { getCreateElementProp } from "@eslint-react/core";
379
- *
380
- * const childrenProp = getCreateElementProp(context, node, "children");
381
- * ```
382
- */
383
- export declare function getCreateElementProp(context: RuleContext, node: null | TSESTree.Node, name: string): TSESTree.Property | null;
384
- /**
385
- * Check if the node is passed as a children argument (the third argument or
386
- * later) of a `createElement` call.
387
- * @param context The ESLint rule context.
388
- * @param node The node to check.
389
- * @returns `true` if the node is a direct children argument of a `createElement` call.
390
- */
391
- export declare function isCreateElementChildrenArgument(context: RuleContext, node: TSESTree.Node): boolean;
392
- /**
393
- * Check if the node is directly inside the props object (the second argument) of a `createElement` call,
394
- * that is, its closest `ObjectExpression` ancestor is the props object itself. Nodes nested deeper
395
- * (ex: inside an object nested in the props object) are not considered inside.
396
- * @param context The ESLint rule context.
397
- * @param node The node to check.
398
- * @returns `true` if the node is directly inside `createElement`'s props object.
399
- */
400
- export declare function isInsideCreateElementProps(context: RuleContext, node: TSESTree.Node): boolean;
401
- //#endregion
402
- //#region src/function.d.ts
403
329
  /** The return type of {@link getFunctionId}. */
404
330
  export type FunctionID = ReturnType<typeof getFunctionId>;
405
331
  /**
@@ -443,7 +369,7 @@ export type FunctionSemanticNode = ClientFunctionSemanticNode | ServerFunctionSe
443
369
  * @param node The function node to analyze.
444
370
  * @returns The identifier node if found, `null` otherwise.
445
371
  */
446
- export declare function getFunctionId(node: TSESTree.Expression | TSESTreeFunction): TSESTree.ArrayExpression | TSESTree.ArrayPattern | TSESTree.ArrowFunctionExpressionWithBlockBody | TSESTree.ArrowFunctionExpressionWithExpressionBody | TSESTree.AssignmentExpression | TSESTree.AwaitExpression | TSESTree.PrivateInExpression | TSESTree.SymmetricBinaryExpression | TSESTree.CallExpression | TSESTree.ChainExpression | TSESTree.ClassExpression | TSESTree.ConditionalExpression | TSESTree.FunctionExpression | TSESTree.Identifier | TSESTree.ImportExpression | TSESTree.JSXElement | TSESTree.JSXFragment | TSESTree.BigIntLiteral | TSESTree.BooleanLiteral | TSESTree.NullLiteral | TSESTree.NumberLiteral | TSESTree.RegExpLiteral | TSESTree.StringLiteral | TSESTree.LogicalExpression | TSESTree.MemberExpressionComputedName | TSESTree.MemberExpressionNonComputedName | TSESTree.MetaProperty | TSESTree.NewExpression | TSESTree.ObjectExpression | TSESTree.ObjectPattern | TSESTree.PrivateIdentifier | TSESTree.SequenceExpression | TSESTree.Super | TSESTree.TaggedTemplateExpression | TSESTree.TemplateLiteral | TSESTree.ThisExpression | TSESTree.TSAsExpression | TSESTree.TSInstantiationExpression | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion | TSESTree.UnaryExpressionBitwiseNot | TSESTree.UnaryExpressionDelete | TSESTree.UnaryExpressionMinus | TSESTree.UnaryExpressionNot | TSESTree.UnaryExpressionPlus | TSESTree.UnaryExpressionTypeof | TSESTree.UnaryExpressionVoid | TSESTree.UpdateExpression | TSESTree.YieldNoStarExpression | TSESTree.YieldStarExpression | null;
372
+ export declare function getFunctionId(node: TSESTree.Expression | TSESTreeFunction): TSESTree.ClassExpression | TSESTree.ArrayExpression | TSESTree.ArrayPattern | TSESTree.ArrowFunctionExpressionWithBlockBody | TSESTree.ArrowFunctionExpressionWithExpressionBody | TSESTree.CallExpression | TSESTree.FunctionExpression | TSESTree.Identifier | TSESTree.JSXElement | TSESTree.JSXFragment | TSESTree.BigIntLiteral | TSESTree.BooleanLiteral | TSESTree.NullLiteral | TSESTree.NumberLiteral | TSESTree.RegExpLiteral | TSESTree.StringLiteral | TSESTree.TemplateLiteral | TSESTree.MemberExpressionComputedName | TSESTree.MemberExpressionNonComputedName | TSESTree.MetaProperty | TSESTree.ObjectExpression | TSESTree.ObjectPattern | TSESTree.SequenceExpression | TSESTree.Super | TSESTree.TaggedTemplateExpression | TSESTree.ThisExpression | TSESTree.TSAsExpression | TSESTree.TSNonNullExpression | TSESTree.TSTypeAssertion | TSESTree.AssignmentExpression | TSESTree.AwaitExpression | TSESTree.PrivateInExpression | TSESTree.SymmetricBinaryExpression | TSESTree.ChainExpression | TSESTree.ConditionalExpression | TSESTree.ImportExpression | TSESTree.LogicalExpression | TSESTree.NewExpression | TSESTree.PrivateIdentifier | TSESTree.TSInstantiationExpression | TSESTree.TSSatisfiesExpression | TSESTree.UnaryExpressionBitwiseNot | TSESTree.UnaryExpressionDelete | TSESTree.UnaryExpressionMinus | TSESTree.UnaryExpressionNot | TSESTree.UnaryExpressionPlus | TSESTree.UnaryExpressionTypeof | TSESTree.UnaryExpressionVoid | TSESTree.UpdateExpression | TSESTree.YieldNoStarExpression | TSESTree.YieldStarExpression | null;
447
373
  /**
448
374
  * Get the initialization path of a function node in the AST.
449
375
  *
@@ -499,8 +425,6 @@ export type FunctionDisplayNameAssignment = TSESTree.AssignmentExpression & {
499
425
  };
500
426
  /** The esquery selector matching `displayName` assignment expressions with a statically determinable property name. */
501
427
  export declare const SEL_FUNCTION_DISPLAY_NAME_ASSIGNMENT: string;
502
- //#endregion
503
- //#region src/hook.d.ts
504
428
  /**
505
429
  * Represents a semantic hook node in the AST.
506
430
  */
@@ -538,54 +462,52 @@ export declare function isHookId(id: TSESTree.Node): id is TSESTree.Identifier |
538
462
  * @param tag The expression node to check.
539
463
  * @returns `true` if the expression is a hook identifier or member expression with hook name, `false` otherwise.
540
464
  */
541
- export declare function isHookTag(tag: TSESTree.Node | null): boolean;
465
+ export declare function isHookTag(tag: TSESTree.Node): boolean;
542
466
  /**
543
467
  * Check if the function node is a hook definition based on its name.
544
468
  * @param node The function node to check.
545
469
  * @returns `true` if the function is a hook definition.
546
470
  */
547
- export declare function isHookDefinition(node: TSESTreeFunction | null): boolean;
471
+ export declare function isHookDefinition(node: TSESTreeFunction): boolean;
548
472
  /**
549
473
  * Check if the node is a React Hook call by its name.
550
474
  * @param node The node to check.
551
475
  * @returns `true` if the node is a React Hook call, `false` otherwise.
552
476
  */
553
- export declare function isHookCall(node: TSESTree.Node | null): node is TSESTree.CallExpression;
477
+ export declare function isHookCall(node: TSESTree.CallExpression): boolean;
554
478
  /**
555
479
  * Check if the node is a useRef-like call (ex: `useRef` or a custom ref hook).
556
480
  * @param node The AST node to check.
557
481
  * @param additionalRefHooks Regex pattern matching custom hooks that should be treated as ref hooks.
558
482
  * @returns `true` if the node is a useRef-like call.
559
483
  */
560
- export declare function isUseRefLikeCall(node: TSESTree.Node | null, additionalRefHooks?: RegExpLike): node is TSESTree.CallExpression;
484
+ export declare function isUseRefLikeCall(node: TSESTree.CallExpression, additionalRefHooks?: RegExpLike): boolean;
561
485
  /**
562
486
  * Check if the node is a useState-like call (ex: `useState` or a custom state hook).
563
487
  * @param node The AST node to check.
564
488
  * @param additionalStateHooks Regex pattern matching custom hooks that should be treated as state hooks.
565
489
  * @returns `true` if the node is a useState-like call.
566
490
  */
567
- export declare function isUseStateLikeCall(node: TSESTree.Node | null, additionalStateHooks?: RegExpLike): node is TSESTree.CallExpression;
491
+ export declare function isUseStateLikeCall(node: TSESTree.CallExpression, additionalStateHooks?: RegExpLike): boolean;
568
492
  /**
569
493
  * Check if the node is a useEffect-like call (ex: `useEffect`, `useLayoutEffect`, or a custom effect hook).
570
494
  * @param node The AST node to check.
571
495
  * @param additionalEffectHooks Regex pattern matching custom hooks that should be treated as effect hooks.
572
496
  * @returns `true` if the node is a useEffect-like call.
573
497
  */
574
- export declare function isUseEffectLikeCall(node: TSESTree.Node | null, additionalEffectHooks?: RegExpLike): node is TSESTree.CallExpression;
498
+ export declare function isUseEffectLikeCall(node: TSESTree.CallExpression, additionalEffectHooks?: RegExpLike): boolean;
575
499
  /**
576
500
  * Check if the node is the setup callback passed to a useEffect-like call.
577
501
  * @param node The AST node to check.
578
502
  * @returns `true` if the node is a useEffect setup callback.
579
503
  */
580
- export declare function isUseEffectSetupCallback(node: TSESTree.Node | null): boolean;
504
+ export declare function isUseEffectSetupCallback(node: TSESTree.Node): boolean;
581
505
  /**
582
506
  * Check if the node is the cleanup callback returned by a useEffect-like setup callback.
583
507
  * @param node The AST node to check.
584
508
  * @returns `true` if the node is a useEffect cleanup callback.
585
509
  */
586
- export declare function isUseEffectCleanupCallback(node: TSESTree.Node | null): boolean;
587
- //#endregion
588
- //#region src/function-component.d.ts
510
+ export declare function isUseEffectCleanupCallback(node: TSESTree.Node): boolean;
589
511
  /**
590
512
  * Represents a React Function Component.
591
513
  */
@@ -649,14 +571,14 @@ export declare function getFunctionComponentFlagFromInitPath(initPath: FunctionC
649
571
  * @param node The node to check.
650
572
  * @returns `true` if the node is a call expression for a component wrapper.
651
573
  */
652
- export declare function isFunctionComponentWrapperCall(context: RuleContext, node: TSESTree.Node): boolean;
574
+ export declare function isFunctionComponentWrapperCall(context: RuleContext, node: TSESTree.CallExpression): boolean;
653
575
  /**
654
576
  * Check if the node is a callback function passed to a component wrapper.
655
577
  * @param context The ESLint rule context.
656
578
  * @param node The node to check.
657
579
  * @returns `true` if the node is a callback function passed to a component wrapper.
658
580
  */
659
- export declare function isFunctionComponentWrapperCallback(context: RuleContext, node: TSESTree.Node): boolean;
581
+ export declare function isFunctionComponentWrapperCallback(context: RuleContext, node: TSESTreeFunction): boolean;
660
582
  /**
661
583
  * Get function component identifier from `const Component = memo(() => {});`.
662
584
  * @param context The rule context.
@@ -732,8 +654,6 @@ export declare const DEFAULT_COMPONENT_DETECTION_HINT: bigint;
732
654
  * @returns `true` if the node is considered a component definition.
733
655
  */
734
656
  export declare function isFunctionComponentDefinition(context: RuleContext, node: TSESTreeFunction, hint: bigint): boolean;
735
- //#endregion
736
- //#region src/function-component-collector.d.ts
737
657
  export declare namespace getFunctionComponentCollector {
738
658
  /** The options for {@link getFunctionComponentCollector}. */
739
659
  type Options = {
@@ -755,8 +675,6 @@ export declare namespace getFunctionComponentCollector {
755
675
  * @returns The api and visitor of the collector.
756
676
  */
757
677
  export declare function getFunctionComponentCollector(context: RuleContext, options?: getFunctionComponentCollector.Options): getFunctionComponentCollector.ReturnType;
758
- //#endregion
759
- //#region src/hook-collector.d.ts
760
678
  export declare namespace getHookCollector {
761
679
  /** The api and visitor pair returned by {@link getHookCollector}. */
762
680
  type ReturnType = {
@@ -772,8 +690,6 @@ export declare namespace getHookCollector {
772
690
  * @returns The api and visitor of the collector.
773
691
  */
774
692
  export declare function getHookCollector(context: RuleContext): getHookCollector.ReturnType;
775
- //#endregion
776
- //#region src/jsx.d.ts
777
693
  /**
778
694
  * BitFlags for configuring JSX detection behavior.
779
695
  *
@@ -846,8 +762,6 @@ export declare const DEFAULT_JSX_DETECTION_HINT: JSXDetectionHint;
846
762
  * ```
847
763
  */
848
764
  export declare function isJSXLike(context: RuleContext, node: TSESTree.Node | null, hint?: JSXDetectionHint): boolean;
849
- //#endregion
850
- //#region src/jsx-config.d.ts
851
765
  /**
852
766
  * Resolved JSX configuration derived from compiler options and / or pragma
853
767
  * annotations found in the source file.
@@ -896,8 +810,6 @@ export declare function getJSXConfigFromAnnotation(context: RuleContext): JSXCon
896
810
  * @returns Fully‑populated, merged `JSXConfig`.
897
811
  */
898
812
  export declare function getJSXConfig(context: RuleContext): Required<JSXConfig>;
899
- //#endregion
900
- //#region src/type-is.d.ts
901
813
  /**
902
814
  * Check if the type is a boolean literal type.
903
815
  * @param type The type to check.
@@ -1063,8 +975,6 @@ export declare const isTruthyStringType: (type: ts.Type) => boolean;
1063
975
  * @internal
1064
976
  */
1065
977
  export declare const isUnknownType: (type: ts.Type) => boolean;
1066
- //#endregion
1067
- //#region src/type-name.d.ts
1068
978
  /**
1069
979
  * Get the fully qualified name of a symbol, handling cases that `ts.TypeChecker.getFullyQualifiedName` does not handle (ex: `export as namespace preact`).
1070
980
  * @param checker The TypeScript type checker.
@@ -1072,8 +982,6 @@ export declare const isUnknownType: (type: ts.Type) => boolean;
1072
982
  * @returns The fully qualified name of the symbol.
1073
983
  */
1074
984
  export declare function getFullyQualifiedNameEx(checker: ts.TypeChecker, symbol: ts.Symbol): string;
1075
- //#endregion
1076
- //#region src/type-variant.d.ts
1077
985
  /** Represents the variant of a type for boolean expression analysis. */
1078
986
  export type TypeVariant = "any" | "bigint" | "boolean" | "enum" | "never" | "nullish" | "number" | "object" | "string" | "unknown" | "falsy bigint" | "falsy boolean" | "falsy number" | "falsy string" | "truthy bigint" | "truthy boolean" | "truthy number" | "truthy string";
1079
987
  /**
@@ -1083,5 +991,4 @@ export type TypeVariant = "any" | "bigint" | "boolean" | "enum" | "never" | "nul
1083
991
  * @remarks Ported from https://github.com/typescript-eslint/typescript-eslint/blob/eb736bbfc22554694400e6a4f97051d845d32e0b/packages/eslint-plugin/src/rules/strict-boolean-expressions.ts#L826 with some enhancements.
1084
992
  * @internal
1085
993
  */
1086
- export declare function getTypeVariants(types: ts.Type[]): Set<TypeVariant>;
1087
- //#endregion
994
+ export declare function getTypeVariants(types: ts.Type[]): Set<TypeVariant>;
package/dist/index.js CHANGED
@@ -1,12 +1,13 @@
1
1
  import { Check, Extract, Traverse } from "@eslint-react/ast";
2
2
  import { getText } from "@eslint-react/eslint";
3
3
  import { AST_NODE_TYPES } from "@typescript-eslint/types";
4
+ import { isCreateElementChildrenArgument } from "@eslint-react/jsx";
4
5
  import { RE_ANNOTATION_JSX, RE_ANNOTATION_JSX_FRAG, RE_ANNOTATION_JSX_IMPORT_SOURCE, RE_ANNOTATION_JSX_RUNTIME, RE_COMPONENT_NAME, RE_COMPONENT_NAME_LOOSE } from "@eslint-react/shared";
5
6
  import { resolve } from "@eslint-react/var";
6
7
  import { findVariable } from "@typescript-eslint/utils/ast-utils";
7
8
  import { P, isMatching, match } from "ts-pattern";
8
9
  import ts from "typescript";
9
- //#region src/api.ts
10
+ // src/api.ts
10
11
  function isAPI(api) {
11
12
  function impl(context, node) {
12
13
  if (node == null) return false;
@@ -94,15 +95,13 @@ const isUseRefCall = isAPICall("useRef");
94
95
  const isUseStateCall = isAPICall("useState");
95
96
  const isUseSyncExternalStoreCall = isAPICall("useSyncExternalStore");
96
97
  const isUseTransitionCall = isAPICall("useTransition");
97
- //#endregion
98
- //#region src/class.ts
98
+ // src/class.ts
99
99
  function getClassId(node) {
100
100
  if (node.id != null) return node.id;
101
101
  if (node.parent.type === AST_NODE_TYPES.VariableDeclarator) return node.parent.id;
102
102
  return null;
103
103
  }
104
- //#endregion
105
- //#region ../../.pkgs/eff/dist/index.js
104
+ // ../../.pkgs/eff/dist/index.js
106
105
  const pipeArguments = (self, args) => {
107
106
  switch (args.length) {
108
107
  case 0: return self;
@@ -201,8 +200,7 @@ dual(2, (self, predicate) => {
201
200
  while (idx < len && predicate(input[idx], idx)) idx++;
202
201
  return input.slice(0, idx);
203
202
  });
204
- //#endregion
205
- //#region src/class-component.ts
203
+ // src/class-component.ts
206
204
  function getStaticKeyName(key, computed) {
207
205
  if (!computed && Check.isIdentifier(key)) return key.name;
208
206
  if (key.type === AST_NODE_TYPES.Literal && isString(key.value)) return key.value;
@@ -222,7 +220,7 @@ function isClassComponent(node) {
222
220
  return false;
223
221
  }
224
222
  function isPureComponent(node) {
225
- if (hasProperty(node, "superClass") && node.superClass != null) {
223
+ if (node.superClass != null) {
226
224
  const re = /^PureComponent$/u;
227
225
  switch (true) {
228
226
  case Check.isIdentifier(node.superClass): return re.test(node.superClass.name);
@@ -269,8 +267,7 @@ function isThisSetStateCall(node) {
269
267
  const callee = Extract.unwrap(node.callee);
270
268
  return callee.type === AST_NODE_TYPES.MemberExpression && Extract.unwrap(callee.object).type === AST_NODE_TYPES.ThisExpression && Extract.getCalleeName(node) === "setState";
271
269
  }
272
- //#endregion
273
- //#region src/class-component-collector.ts
270
+ // src/class-component-collector.ts
274
271
  function getClassComponentCollector(context) {
275
272
  const components = /* @__PURE__ */ new Map();
276
273
  const collect = (node) => {
@@ -300,45 +297,7 @@ function getClassComponentCollector(context) {
300
297
  }
301
298
  };
302
299
  }
303
- //#endregion
304
- //#region src/create-element.ts
305
- function getCreateElementTypeArgument(context, node) {
306
- if (!isCreateElementCall(context, node)) return null;
307
- return node.arguments[0] ?? null;
308
- }
309
- function getCreateElementPropsObject(context, node) {
310
- if (!isCreateElementCall(context, node)) return null;
311
- const propsArg = node.arguments[1];
312
- if (propsArg == null) return null;
313
- const expr = Extract.unwrap(propsArg);
314
- return expr.type === AST_NODE_TYPES.ObjectExpression ? expr : null;
315
- }
316
- function getCreateElementChildrenArguments(context, node) {
317
- if (!isCreateElementCall(context, node)) return [];
318
- return node.arguments.slice(2);
319
- }
320
- function getCreateElementProp(context, node, name) {
321
- const propsObject = getCreateElementPropsObject(context, node);
322
- if (propsObject == null) return null;
323
- for (const prop of propsObject.properties) if (prop.type === AST_NODE_TYPES.Property && Extract.getPropertyName(prop, "max") === name) return prop;
324
- return null;
325
- }
326
- function isCreateElementChildrenArgument(context, node) {
327
- let parent = node.parent;
328
- while (Check.isTypeExpression(parent)) parent = parent.parent;
329
- return parent?.type === AST_NODE_TYPES.CallExpression && isCreateElementCall(context, parent) && parent.arguments.slice(2).some((arg) => Extract.unwrap(arg) === Extract.unwrap(node));
330
- }
331
- function isInsideCreateElementProps(context, node) {
332
- const call = Traverse.findParent(node, isCreateElementCall(context));
333
- if (call == null) return false;
334
- const prop = Traverse.findParent(node, Check.isObjectExpression);
335
- if (prop == null) return false;
336
- const propsArg = call.arguments[1];
337
- if (propsArg == null) return false;
338
- return prop === Extract.unwrap(propsArg);
339
- }
340
- //#endregion
341
- //#region src/function.ts
300
+ // src/function.ts
342
301
  function getFunctionId(node) {
343
302
  switch (true) {
344
303
  case hasProperty(node, "id") && node.id != null: return node.id;
@@ -438,8 +397,7 @@ const SEL_FUNCTION_DISPLAY_NAME_ASSIGNMENT = [
438
397
  "[left.computed=true][left.property.type='Literal'][left.property.value='displayName']",
439
398
  ")"
440
399
  ].join("");
441
- //#endregion
442
- //#region src/jsx.ts
400
+ // src/jsx.ts
443
401
  const JSXDetectionHint = {
444
402
  None: 0n,
445
403
  DoNotIncludeJSXWithNullValue: 1n << 0n,
@@ -494,8 +452,7 @@ function isJSXLike(context, node, hint = DEFAULT_JSX_DETECTION_HINT) {
494
452
  }
495
453
  return visit(node);
496
454
  }
497
- //#endregion
498
- //#region src/function-component.ts
455
+ // src/function-component.ts
499
456
  const FunctionComponentFlag = {
500
457
  None: 0n,
501
458
  PureComponent: 1n << 0n,
@@ -510,11 +467,9 @@ function getFunctionComponentFlagFromInitPath(initPath) {
510
467
  return flag;
511
468
  }
512
469
  function isFunctionComponentWrapperCall(context, node) {
513
- if (node.type !== AST_NODE_TYPES.CallExpression) return false;
514
470
  return isMemoCall(context, node) || isForwardRefCall(context, node);
515
471
  }
516
472
  function isFunctionComponentWrapperCallback(context, node) {
517
- if (!Check.isFunction(node)) return false;
518
473
  let argument = node;
519
474
  let parent = node.parent;
520
475
  while (Check.isTypeExpression(parent)) {
@@ -602,8 +557,7 @@ function isFunctionComponentDefinition(context, node, hint) {
602
557
  if (significantParent == null) return true;
603
558
  return significantParent.type !== AST_NODE_TYPES.JSXExpressionContainer;
604
559
  }
605
- //#endregion
606
- //#region src/hook.ts
560
+ // src/hook.ts
607
561
  function isHookName(name) {
608
562
  return name === "use" || /^use[A-Z0-9]/.test(name);
609
563
  }
@@ -615,11 +569,9 @@ function isHookId(id) {
615
569
  }
616
570
  }
617
571
  function isHookTag(tag) {
618
- if (tag == null) return false;
619
572
  return isHookId(Extract.unwrap(tag));
620
573
  }
621
574
  function isHookDefinition(node) {
622
- if (node == null) return false;
623
575
  const id = getFunctionId(node);
624
576
  switch (id?.type) {
625
577
  case AST_NODE_TYPES.Identifier: return isHookName(id.name);
@@ -628,35 +580,26 @@ function isHookDefinition(node) {
628
580
  }
629
581
  }
630
582
  function isHookCall(node) {
631
- if (node == null) return false;
632
- if (node.type !== AST_NODE_TYPES.CallExpression) return false;
633
583
  const name = Extract.getCalleeName(node);
634
584
  if (name == null) return false;
635
585
  return isHookName(name);
636
586
  }
637
587
  function isUseRefLikeCall(node, additionalRefHooks = { test: constFalse }) {
638
- if (node == null) return false;
639
- if (node.type !== AST_NODE_TYPES.CallExpression) return false;
640
588
  const name = Extract.getCalleeName(node);
641
589
  if (name == null) return false;
642
590
  return name === "useRef" || additionalRefHooks.test(name);
643
591
  }
644
592
  function isUseStateLikeCall(node, additionalStateHooks = { test: constFalse }) {
645
- if (node == null) return false;
646
- if (node.type !== AST_NODE_TYPES.CallExpression) return false;
647
593
  const name = Extract.getCalleeName(node);
648
594
  if (name == null) return false;
649
595
  return name === "useState" || additionalStateHooks.test(name);
650
596
  }
651
597
  function isUseEffectLikeCall(node, additionalEffectHooks = { test: constFalse }) {
652
- if (node == null) return false;
653
- if (node.type !== AST_NODE_TYPES.CallExpression) return false;
654
598
  const name = Extract.getCalleeName(node);
655
599
  if (name == null) return false;
656
600
  return /^use\w*Effect$/u.test(name) || additionalEffectHooks.test(name);
657
601
  }
658
602
  function isUseEffectSetupCallback(node) {
659
- if (node == null) return false;
660
603
  const expr = Extract.unwrap(node);
661
604
  const call = Traverse.findParent(expr, not(Check.isTypeOrChainExpression));
662
605
  if (call?.type !== AST_NODE_TYPES.CallExpression) return false;
@@ -665,7 +608,6 @@ function isUseEffectSetupCallback(node) {
665
608
  return Extract.unwrap(arg0) === expr && isUseEffectLikeCall(call);
666
609
  }
667
610
  function isUseEffectCleanupCallback(node) {
668
- if (node == null) return false;
669
611
  const expr = Extract.unwrap(node);
670
612
  const func = Traverse.findParent(expr, Check.isFunction);
671
613
  if (func == null || !isUseEffectSetupCallback(func)) return false;
@@ -673,8 +615,7 @@ function isUseEffectCleanupCallback(node) {
673
615
  if (stat != null) return stat.argument != null && Extract.unwrap(stat.argument) === expr;
674
616
  return Check.isFunction(expr) && func.type === AST_NODE_TYPES.ArrowFunctionExpression && Extract.unwrap(func.body) === expr;
675
617
  }
676
- //#endregion
677
- //#region src/function-component-collector.ts
618
+ // src/function-component-collector.ts
678
619
  function getFunctionComponentCollector(context, options = {}) {
679
620
  const { collectDisplayName = false, hint = DEFAULT_COMPONENT_DETECTION_HINT } = options;
680
621
  const functionEntries = [];
@@ -765,8 +706,7 @@ function getFunctionComponentCollector(context, options = {}) {
765
706
  }
766
707
  };
767
708
  }
768
- //#endregion
769
- //#region src/hook-collector.ts
709
+ // src/hook-collector.ts
770
710
  function getHookCollector(context) {
771
711
  const functionEntries = [];
772
712
  const hooks = /* @__PURE__ */ new Map();
@@ -828,8 +768,7 @@ function getHookCollector(context) {
828
768
  }
829
769
  };
830
770
  }
831
- //#endregion
832
- //#region src/jsx-config.ts
771
+ // src/jsx-config.ts
833
772
  const annotationCache = /* @__PURE__ */ new WeakMap();
834
773
  const mergedCache = /* @__PURE__ */ new WeakMap();
835
774
  function getJSXConfigFromCompilerOptions(context) {
@@ -875,8 +814,7 @@ function getJSXConfig(context) {
875
814
  mergedCache.set(context.sourceCode, merged);
876
815
  return merged;
877
816
  }
878
- //#endregion
879
- //#region src/type-is.ts
817
+ // src/type-is.ts
880
818
  function isFlagSet(allFlags, flag) {
881
819
  return (allFlags & flag) !== 0;
882
820
  }
@@ -903,8 +841,7 @@ const isTruthyBigIntType = (type) => type.isLiteral() && isMatching({ value: { b
903
841
  const isTruthyNumberType = (type) => type.isNumberLiteral() && type.value !== 0;
904
842
  const isTruthyStringType = (type) => type.isStringLiteral() && type.value !== "";
905
843
  const isUnknownType = (type) => isTypeFlagSet(type, ts.TypeFlags.Unknown);
906
- //#endregion
907
- //#region src/type-name.ts
844
+ // src/type-name.ts
908
845
  function getFullyQualifiedNameEx(checker, symbol) {
909
846
  let name = symbol.name;
910
847
  let parent = symbol.declarations?.at(0)?.parent;
@@ -948,8 +885,7 @@ function getFullyQualifiedNameEx(checker, symbol) {
948
885
  if (name.startsWith(`${namespace}.`)) return name;
949
886
  return `${namespace}.${name}`;
950
887
  }
951
- //#endregion
952
- //#region src/type-variant.ts
888
+ // src/type-variant.ts
953
889
  function getTypeVariants(types) {
954
890
  const variants = /* @__PURE__ */ new Set();
955
891
  if (types.some(isUnknownType)) {
@@ -985,5 +921,4 @@ function getTypeVariants(types) {
985
921
  if (types.some(isNeverType)) variants.add("never");
986
922
  return variants;
987
923
  }
988
- //#endregion
989
- export { DEFAULT_COMPONENT_DETECTION_HINT, DEFAULT_JSX_DETECTION_HINT, FunctionComponentDetectionHint, FunctionComponentFlag, JSXDetectionHint, SEL_FUNCTION_DISPLAY_NAME_ASSIGNMENT, getClassComponentCollector, getClassId, getCreateElementChildrenArguments, getCreateElementProp, getCreateElementPropsObject, getCreateElementTypeArgument, getFullyQualifiedNameEx, getFunctionComponentCollector, getFunctionComponentFlagFromInitPath, getFunctionComponentId, getFunctionDirectives, getFunctionId, getFunctionInitPath, getHookCollector, getJSXConfig, getJSXConfigFromAnnotation, getJSXConfigFromCompilerOptions, getTypeVariants, isAPI, isAPICall, isAnyType, isBigIntType, isBooleanLiteralType, isBooleanType, isCaptureOwnerStack, isCaptureOwnerStackCall, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCloneElement, isCloneElementCall, isComponentDidCatch, isComponentDidMount, isComponentDidUpdate, isComponentWillMount, isComponentWillReceiveProps, isComponentWillUnmount, isComponentWillUpdate, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateElementChildrenArgument, isCreateRef, isCreateRefCall, isEnumType, isFalseLiteralType, isFalsyBigIntType, isFalsyNumberType, isFalsyStringType, isForwardRef, isForwardRefCall, isFunctionComponentDefinition, isFunctionComponentName, isFunctionComponentNameLoose, isFunctionComponentWrapperCall, isFunctionComponentWrapperCallback, isFunctionEmpty, isFunctionHasCallInInitPath, isFunctionHasDirective, isFunctionWithLooseComponentName, isGetChildContext, isGetDefaultProps, isGetDerivedStateFromError, isGetDerivedStateFromProps, isGetInitialState, isGetSnapshotBeforeUpdate, isHookCall, isHookDefinition, isHookId, isHookName, isHookTag, isInsideCreateElementProps, isJSXLike, isLazy, isLazyCall, isMemo, isMemoCall, isNeverType, isNullishType, isNumberType, isObjectType, isPureComponent, isRender, isRenderMethodCallback, isRenderMethodLike, isShouldComponentUpdate, isStringType, isThisSetStateCall, isTrueLiteralType, isTruthyBigIntType, isTruthyNumberType, isTruthyStringType, isUnknownType, isUnsafeComponentWillMount, isUnsafeComponentWillReceiveProps, isUnsafeComponentWillUpdate, isUse, isUseActionState, isUseActionStateCall, isUseCall, isUseCallback, isUseCallbackCall, isUseContext, isUseContextCall, isUseDebugValue, isUseDebugValueCall, isUseDeferredValue, isUseDeferredValueCall, isUseEffect, isUseEffectCall, isUseEffectCleanupCallback, isUseEffectLikeCall, isUseEffectSetupCallback, isUseFormStatus, isUseFormStatusCall, isUseId, isUseIdCall, isUseImperativeHandle, isUseImperativeHandleCall, isUseInsertionEffect, isUseInsertionEffectCall, isUseLayoutEffect, isUseLayoutEffectCall, isUseMemo, isUseMemoCall, isUseOptimistic, isUseOptimisticCall, isUseReducer, isUseReducerCall, isUseRef, isUseRefCall, isUseRefLikeCall, isUseState, isUseStateCall, isUseStateLikeCall, isUseSyncExternalStore, isUseSyncExternalStoreCall, isUseTransition, isUseTransitionCall };
924
+ export { DEFAULT_COMPONENT_DETECTION_HINT, DEFAULT_JSX_DETECTION_HINT, FunctionComponentDetectionHint, FunctionComponentFlag, JSXDetectionHint, SEL_FUNCTION_DISPLAY_NAME_ASSIGNMENT, getClassComponentCollector, getClassId, getFullyQualifiedNameEx, getFunctionComponentCollector, getFunctionComponentFlagFromInitPath, getFunctionComponentId, getFunctionDirectives, getFunctionId, getFunctionInitPath, getHookCollector, getJSXConfig, getJSXConfigFromAnnotation, getJSXConfigFromCompilerOptions, getTypeVariants, isAPI, isAPICall, isAnyType, isBigIntType, isBooleanLiteralType, isBooleanType, isCaptureOwnerStack, isCaptureOwnerStackCall, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCloneElement, isCloneElementCall, isComponentDidCatch, isComponentDidMount, isComponentDidUpdate, isComponentWillMount, isComponentWillReceiveProps, isComponentWillUnmount, isComponentWillUpdate, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isEnumType, isFalseLiteralType, isFalsyBigIntType, isFalsyNumberType, isFalsyStringType, isForwardRef, isForwardRefCall, isFunctionComponentDefinition, isFunctionComponentName, isFunctionComponentNameLoose, isFunctionComponentWrapperCall, isFunctionComponentWrapperCallback, isFunctionEmpty, isFunctionHasCallInInitPath, isFunctionHasDirective, isFunctionWithLooseComponentName, isGetChildContext, isGetDefaultProps, isGetDerivedStateFromError, isGetDerivedStateFromProps, isGetInitialState, isGetSnapshotBeforeUpdate, isHookCall, isHookDefinition, isHookId, isHookName, isHookTag, isJSXLike, isLazy, isLazyCall, isMemo, isMemoCall, isNeverType, isNullishType, isNumberType, isObjectType, isPureComponent, isRender, isRenderMethodCallback, isRenderMethodLike, isShouldComponentUpdate, isStringType, isThisSetStateCall, isTrueLiteralType, isTruthyBigIntType, isTruthyNumberType, isTruthyStringType, isUnknownType, isUnsafeComponentWillMount, isUnsafeComponentWillReceiveProps, isUnsafeComponentWillUpdate, isUse, isUseActionState, isUseActionStateCall, isUseCall, isUseCallback, isUseCallbackCall, isUseContext, isUseContextCall, isUseDebugValue, isUseDebugValueCall, isUseDeferredValue, isUseDeferredValueCall, isUseEffect, isUseEffectCall, isUseEffectCleanupCallback, isUseEffectLikeCall, isUseEffectSetupCallback, isUseFormStatus, isUseFormStatusCall, isUseId, isUseIdCall, isUseImperativeHandle, isUseImperativeHandleCall, isUseInsertionEffect, isUseInsertionEffectCall, isUseLayoutEffect, isUseLayoutEffectCall, isUseMemo, isUseMemoCall, isUseOptimistic, isUseOptimisticCall, isUseReducer, isUseReducerCall, isUseRef, isUseRefCall, isUseRefLikeCall, isUseState, isUseStateCall, isUseStateLikeCall, isUseSyncExternalStore, isUseSyncExternalStoreCall, isUseTransition, isUseTransitionCall };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eslint-react/core",
3
- "version": "5.28.8",
3
+ "version": "5.30.0-beta.1",
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": {
@@ -29,10 +29,11 @@
29
29
  "dist"
30
30
  ],
31
31
  "dependencies": {
32
- "@eslint-react/ast": "5.28.8",
33
- "@eslint-react/eslint": "5.28.8",
34
- "@eslint-react/shared": "5.28.8",
35
- "@eslint-react/var": "5.28.8",
32
+ "@eslint-react/ast": "5.30.0-beta.1",
33
+ "@eslint-react/eslint": "5.30.0-beta.1",
34
+ "@eslint-react/jsx": "5.30.0-beta.1",
35
+ "@eslint-react/shared": "5.30.0-beta.1",
36
+ "@eslint-react/var": "5.30.0-beta.1",
36
37
  "@typescript-eslint/types": "^8.72.0",
37
38
  "@typescript-eslint/utils": "^8.72.0",
38
39
  "ts-pattern": "^5.9.2"
@@ -46,7 +47,7 @@
46
47
  "@typescript-eslint/typescript-estree": "^8.72.0",
47
48
  "dedent": "^1.7.2",
48
49
  "eslint": "^10.13.0",
49
- "tsdown": "^0.23.1",
50
+ "tsdown": "^0.23.2",
50
51
  "typescript": "6.0.3",
51
52
  "vitest": "^5.0.5"
52
53
  },