@eslint-react/core 2.0.0-beta.4 → 2.0.0-beta.41

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.
Files changed (3) hide show
  1. package/dist/index.d.ts +129 -9
  2. package/dist/index.js +88 -13
  3. package/package.json +12 -12
package/dist/index.d.ts CHANGED
@@ -1,11 +1,13 @@
1
1
  import { RuleContext } from '@eslint-react/kit';
2
2
  import { TSESTree } from '@typescript-eslint/types';
3
- import { ESLintUtils, TSESTree as TSESTree$1 } from '@typescript-eslint/utils';
4
3
  import * as AST from '@eslint-react/ast';
5
4
  import { unit } from '@eslint-react/eff';
5
+ import { ESLintUtils, TSESTree as TSESTree$1 } from '@typescript-eslint/utils';
6
6
  import * as birecord from 'birecord';
7
7
  import { Scope } from '@typescript-eslint/scope-manager';
8
8
  import * as VAR from '@eslint-react/var';
9
+ import ts from 'typescript';
10
+ export { isFalseLiteralType, isTrueLiteralType } from 'ts-api-utils';
9
11
 
10
12
  /**
11
13
  * Determines whether inside `createElement`'s children.
@@ -331,6 +333,15 @@ declare function isComponentWrapperCallLoose(context: RuleContext, node: TSESTre
331
333
 
332
334
  type EffectKind = "useEffect" | "useLayoutEffect" | "useInsertionEffect";
333
335
 
336
+ /**
337
+ * Checks if the given node is inside a `vi.mock` callback.
338
+ * @param context RuleContext
339
+ * @param node The node to check
340
+ * @returns `true` if the node is inside a `vi.mock` callback, otherwise `false`.
341
+ * @internal
342
+ */
343
+ declare function isInViMockCallback(context: RuleContext, node: TSESTree.Node): boolean;
344
+
334
345
  interface Hook extends SemanticNode {
335
346
  id: TSESTree.Identifier | unit;
336
347
  node: AST.TSESTreeFunction;
@@ -454,6 +465,9 @@ declare function isJsxLike(code: {
454
465
  getScope: (node: TSESTree$1.Node) => Scope;
455
466
  }, node: TSESTree$1.Node | unit | null, hint?: JSXDetectionHint): boolean;
456
467
 
468
+ declare function isHostElement(context: RuleContext, node: TSESTree.Node): boolean;
469
+ declare function isFragmentElement(context: RuleContext, node: TSESTree.Node): node is TSESTree.JSXElement;
470
+
457
471
  /**
458
472
  * Get the stringified type of a JSX element
459
473
  * @param context The ESLint rule context
@@ -474,11 +488,6 @@ declare function hasEveryAttribute(context: RuleContext, names: string[], attrib
474
488
  */
475
489
  declare function findParentAttribute(node: TSESTree.Node, test?: (node: TSESTree.JSXAttribute) => boolean): TSESTree.JSXAttribute | unit;
476
490
 
477
- declare function isHostElement(context: RuleContext, node: TSESTree.Node): boolean;
478
- declare function isKeyedElement(context: RuleContext, node: TSESTree.Node, initialScope?: Scope): boolean;
479
- declare function isFragmentElement(context: RuleContext, node: TSESTree.Node | null | unit, allowJSXFragment?: false): node is TSESTree.JSXElement;
480
- declare function isFragmentElement(context: RuleContext, node: TSESTree.Node | null | unit, allowJSXFragment?: true): node is TSESTree.JSXElement | TSESTree.JSXFragment;
481
-
482
491
  /**
483
492
  * Get the stringified representation of a JSX node
484
493
  * @param node The JSX node
@@ -486,15 +495,126 @@ declare function isFragmentElement(context: RuleContext, node: TSESTree.Node | n
486
495
  */
487
496
  declare function stringifyJsx(node: TSESTree$1.JSXIdentifier | TSESTree$1.JSXMemberExpression | TSESTree$1.JSXNamespacedName | TSESTree$1.JSXOpeningElement | TSESTree$1.JSXClosingElement | TSESTree$1.JSXOpeningFragment | TSESTree$1.JSXClosingFragment | TSESTree$1.JSXText): string;
488
497
 
498
+ /** @internal */
499
+ declare const isAnyType: (type: ts.Type) => boolean;
500
+ /** @internal */
501
+ declare const isBigIntType: (type: ts.Type) => boolean;
502
+ /** @internal */
503
+ declare const isBooleanType: (type: ts.Type) => boolean;
504
+ /** @internal */
505
+ declare const isEnumType: (type: ts.Type) => boolean;
506
+ /** @internal */
507
+ declare const isFalsyBigIntType: (type: ts.Type) => type is ts.LiteralType & {
508
+ freshType: ts.FreshableType;
509
+ regularType: ts.FreshableType;
510
+ flags: ts.TypeFlags;
511
+ symbol: ts.Symbol;
512
+ pattern?: ts.DestructuringPattern;
513
+ aliasSymbol?: ts.Symbol;
514
+ aliasTypeArguments?: readonly ts.Type[];
515
+ getFlags: () => ts.TypeFlags;
516
+ getSymbol: () => ts.Symbol | undefined;
517
+ getProperties: () => ts.Symbol[];
518
+ getProperty: (propertyName: string) => ts.Symbol | undefined;
519
+ getApparentProperties: () => ts.Symbol[];
520
+ getCallSignatures: () => readonly ts.Signature[];
521
+ getConstructSignatures: () => readonly ts.Signature[];
522
+ getStringIndexType: () => ts.Type | undefined;
523
+ getNumberIndexType: () => ts.Type | undefined;
524
+ getBaseTypes: () => ts.BaseType[] | undefined;
525
+ getNonNullableType: () => ts.Type;
526
+ getConstraint: () => ts.Type | undefined;
527
+ getDefault: () => ts.Type | undefined;
528
+ isUnion: () => this is ts.UnionType;
529
+ isIntersection: () => this is ts.IntersectionType;
530
+ isUnionOrIntersection: () => this is ts.UnionOrIntersectionType;
531
+ isLiteral: () => this is ts.LiteralType;
532
+ isStringLiteral: () => this is ts.StringLiteralType;
533
+ isNumberLiteral: () => this is ts.NumberLiteralType;
534
+ isTypeParameter: () => this is ts.TypeParameter;
535
+ isClassOrInterface: () => this is ts.InterfaceType;
536
+ isClass: () => this is ts.InterfaceType;
537
+ isIndexType: () => this is ts.IndexType;
538
+ value: {
539
+ negative: boolean;
540
+ base10Value: "0";
541
+ };
542
+ };
543
+ /** @internal */
544
+ declare const isFalsyNumberType: (type: ts.Type) => boolean;
545
+ /** @internal */
546
+ declare const isFalsyStringType: (type: ts.Type) => boolean;
547
+ /** @internal */
548
+ declare const isNeverType: (type: ts.Type) => boolean;
549
+ /** @internal */
550
+ declare const isNullishType: (type: ts.Type) => boolean;
551
+ /** @internal */
552
+ declare const isNumberType: (type: ts.Type) => boolean;
553
+ /** @internal */
554
+ declare const isObjectType: (type: ts.Type) => boolean;
555
+ /** @internal */
556
+ declare const isStringType: (type: ts.Type) => boolean;
557
+ /** @internal */
558
+ declare const isTruthyBigIntType: (type: ts.Type) => type is ts.LiteralType & {
559
+ freshType: ts.FreshableType;
560
+ regularType: ts.FreshableType;
561
+ flags: ts.TypeFlags;
562
+ symbol: ts.Symbol;
563
+ pattern?: ts.DestructuringPattern;
564
+ aliasSymbol?: ts.Symbol;
565
+ aliasTypeArguments?: readonly ts.Type[];
566
+ getFlags: () => ts.TypeFlags;
567
+ getSymbol: () => ts.Symbol | undefined;
568
+ getProperties: () => ts.Symbol[];
569
+ getProperty: (propertyName: string) => ts.Symbol | undefined;
570
+ getApparentProperties: () => ts.Symbol[];
571
+ getCallSignatures: () => readonly ts.Signature[];
572
+ getConstructSignatures: () => readonly ts.Signature[];
573
+ getStringIndexType: () => ts.Type | undefined;
574
+ getNumberIndexType: () => ts.Type | undefined;
575
+ getBaseTypes: () => ts.BaseType[] | undefined;
576
+ getNonNullableType: () => ts.Type;
577
+ getConstraint: () => ts.Type | undefined;
578
+ getDefault: () => ts.Type | undefined;
579
+ isUnion: () => this is ts.UnionType;
580
+ isIntersection: () => this is ts.IntersectionType;
581
+ isUnionOrIntersection: () => this is ts.UnionOrIntersectionType;
582
+ isLiteral: () => this is ts.LiteralType;
583
+ isStringLiteral: () => this is ts.StringLiteralType;
584
+ isNumberLiteral: () => this is ts.NumberLiteralType;
585
+ isTypeParameter: () => this is ts.TypeParameter;
586
+ isClassOrInterface: () => this is ts.InterfaceType;
587
+ isClass: () => this is ts.InterfaceType;
588
+ isIndexType: () => this is ts.IndexType;
589
+ value: ts.PseudoBigInt;
590
+ };
591
+ /** @internal */
592
+ declare const isTruthyNumberType: (type: ts.Type) => boolean;
593
+ /** @internal */
594
+ declare const isTruthyStringType: (type: ts.Type) => boolean;
595
+ /** @internal */
596
+ declare const isUnknownType: (type: ts.Type) => boolean;
597
+
598
+ 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";
599
+ /**
600
+ * Ported from https://github.com/typescript-eslint/typescript-eslint/blob/eb736bbfc22554694400e6a4f97051d845d32e0b/packages/eslint-plugin/src/rules/strict-boolean-expressions.ts#L826 with some enhancements
601
+ * Get the variants of an array of types.
602
+ * @param types The types to get the variants of
603
+ * @returns The variants of the types
604
+ * @internal
605
+ */
606
+ declare function getTypeVariants(types: ts.Type[]): Set<TypeVariant>;
607
+
489
608
  /** @internal */
490
609
  declare function getInstanceId(node: TSESTree.Node, prev?: TSESTree.Node): TSESTree.ArrayExpression | TSESTree.ArrayPattern | TSESTree.ArrowFunctionExpression | TSESTree.AssignmentExpression | TSESTree.AwaitExpression | TSESTree.BinaryExpression | 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.UnaryExpression | TSESTree.UpdateExpression | TSESTree.YieldExpression | undefined;
491
610
 
492
611
  /**
493
- * Check if an identifier is initialized from react
612
+ * Check if an identifier name is initialized from react
494
613
  * @param name The top-level identifier's name
495
614
  * @param importSource The import source to check against
496
615
  * @param initialScope Initial scope to search for the identifier
497
- * @returns Whether the identifier is initialized from react
616
+ * @returns Whether the identifier name is initialized from react
617
+ * @internal
498
618
  */
499
619
  declare function isInitializedFromReact(name: string, importSource: string, initialScope: Scope): boolean;
500
620
 
@@ -542,4 +662,4 @@ declare const isForwardRefCall: isReactAPICall.ReturnType;
542
662
  declare const isMemoCall: isReactAPICall.ReturnType;
543
663
  declare const isLazyCall: isReactAPICall.ReturnType;
544
664
 
545
- export { type ClassComponent, type Component, ComponentDetectionHint, type ComponentEffectPhaseKind, ComponentFlag, type ComponentKind, type ComponentLifecyclePhaseKind, type ComponentPhaseKind, ComponentPhaseRelevance, type ComponentStateKind, DEFAULT_COMPONENT_DETECTION_HINT, DEFAULT_JSX_DETECTION_HINT, type EffectKind, type FunctionComponent, type Hook, JSXDetectionHint, REACT_BUILTIN_HOOK_NAMES, type SemanticEntry, type SemanticNode, findParentAttribute, getAttribute, getAttributeName, getAttributeValue, getComponentFlagFromInitPath, getComponentNameFromId, getElementType, getFunctionComponentId, getInstanceId, hasAnyAttribute, hasAttribute, hasEveryAttribute, hasNoneOrLooseComponentName, isAssignmentToThisState, isCaptureOwnerStack, isCaptureOwnerStackCall, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOfCreateElement, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCloneElement, isCloneElementCall, isComponentDidCatch, isComponentDidMount, isComponentDidUpdate, isComponentName, isComponentNameLoose, isComponentWillMount, isComponentWillReceiveProps, isComponentWillUnmount, isComponentWillUpdate, isComponentWrapperCall, isComponentWrapperCallLoose, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRef, isForwardRefCall, isFragmentElement, isFunctionOfRender, isFunctionOfRenderMethod, isGetChildContext, isGetDefaultProps, isGetDerivedStateFromError, isGetDerivedStateFromProps, isGetInitialState, isGetSnapshotBeforeUpdate, isHostElement, isInitializedFromReact, isInstanceIdEqual, isInversePhase, isJsxLike, isJsxText, isKeyedElement, isLazy, isLazyCall, isMemo, isMemoCall, isPureComponent, isReactAPI, isReactAPICall, isReactHook, isReactHookCall, isReactHookCallWithName, isReactHookCallWithNameAlias, isReactHookCallWithNameLoose, isReactHookId, isReactHookName, isRenderFunctionLoose, isRenderLike, isRenderMethodLike, isRenderPropLoose, isShouldComponentUpdate, isThisSetState, isUnsafeComponentWillMount, isUnsafeComponentWillReceiveProps, isUnsafeComponentWillUpdate, isUseActionStateCall, isUseCall, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectCallLoose, isUseFormStatusCall, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseOptimisticCall, isUseReducerCall, isUseRefCall, isUseStateCall, isUseSyncExternalStoreCall, isUseTransitionCall, isValidComponentDefinition, stringifyJsx, useComponentCollector, useComponentCollectorLegacy, useHookCollector };
665
+ export { type ClassComponent, type Component, ComponentDetectionHint, type ComponentEffectPhaseKind, ComponentFlag, type ComponentKind, type ComponentLifecyclePhaseKind, type ComponentPhaseKind, ComponentPhaseRelevance, type ComponentStateKind, DEFAULT_COMPONENT_DETECTION_HINT, DEFAULT_JSX_DETECTION_HINT, type EffectKind, type FunctionComponent, type Hook, JSXDetectionHint, REACT_BUILTIN_HOOK_NAMES, type SemanticEntry, type SemanticNode, type TypeVariant, findParentAttribute, getAttribute, getAttributeName, getAttributeValue, getComponentFlagFromInitPath, getComponentNameFromId, getElementType, getFunctionComponentId, getInstanceId, getTypeVariants, hasAnyAttribute, hasAttribute, hasEveryAttribute, hasNoneOrLooseComponentName, isAnyType, isAssignmentToThisState, isBigIntType, isBooleanType, isCaptureOwnerStack, isCaptureOwnerStackCall, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOfCreateElement, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCloneElement, isCloneElementCall, isComponentDidCatch, isComponentDidMount, isComponentDidUpdate, isComponentName, isComponentNameLoose, isComponentWillMount, isComponentWillReceiveProps, isComponentWillUnmount, isComponentWillUpdate, isComponentWrapperCall, isComponentWrapperCallLoose, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isEnumType, isFalsyBigIntType, isFalsyNumberType, isFalsyStringType, isForwardRef, isForwardRefCall, isFragmentElement, isFunctionOfRender, isFunctionOfRenderMethod, isGetChildContext, isGetDefaultProps, isGetDerivedStateFromError, isGetDerivedStateFromProps, isGetInitialState, isGetSnapshotBeforeUpdate, isHostElement, isInViMockCallback, isInitializedFromReact, isInstanceIdEqual, isInversePhase, isJsxLike, isJsxText, isLazy, isLazyCall, isMemo, isMemoCall, isNeverType, isNullishType, isNumberType, isObjectType, isPureComponent, isReactAPI, isReactAPICall, isReactHook, isReactHookCall, isReactHookCallWithName, isReactHookCallWithNameAlias, isReactHookCallWithNameLoose, isReactHookId, isReactHookName, isRenderFunctionLoose, isRenderLike, isRenderMethodLike, isRenderPropLoose, isShouldComponentUpdate, isStringType, isThisSetState, isTruthyBigIntType, isTruthyNumberType, isTruthyStringType, isUnknownType, isUnsafeComponentWillMount, isUnsafeComponentWillReceiveProps, isUnsafeComponentWillUpdate, isUseActionStateCall, isUseCall, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectCallLoose, isUseFormStatusCall, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseOptimisticCall, isUseReducerCall, isUseRefCall, isUseStateCall, isUseSyncExternalStoreCall, isUseTransitionCall, isValidComponentDefinition, stringifyJsx, useComponentCollector, useComponentCollectorLegacy, useHookCollector };
package/dist/index.js CHANGED
@@ -6,6 +6,9 @@ import { coerceSettings, DEFAULT_ESLINT_REACT_SETTINGS, getId } from '@eslint-re
6
6
  import * as VAR3 from '@eslint-react/var';
7
7
  import { isMatching, P, match } from 'ts-pattern';
8
8
  import birecord from 'birecord';
9
+ import { isTypeFlagSet, isFalseLiteralType, isTrueLiteralType } from 'ts-api-utils';
10
+ export { isFalseLiteralType, isTrueLiteralType } from 'ts-api-utils';
11
+ import ts from 'typescript';
9
12
 
10
13
  // src/component/component-children.ts
11
14
  function isReactAPI(api) {
@@ -504,6 +507,15 @@ function getElementType(context, node) {
504
507
  return stringifyJsx(node.openingElement.name);
505
508
  }
506
509
 
510
+ // src/jsx/jsx-element-is.ts
511
+ function isHostElement(context, node) {
512
+ return node.type === AST_NODE_TYPES.JSXElement && node.openingElement.name.type === AST_NODE_TYPES.JSXIdentifier && /^[a-z]/u.test(node.openingElement.name.name);
513
+ }
514
+ function isFragmentElement(context, node) {
515
+ if (node.type !== AST_NODE_TYPES.JSXElement) return false;
516
+ return getElementType(context, node).split(".").at(-1) === "Fragment";
517
+ }
518
+
507
519
  // src/jsx/jsx-has.ts
508
520
  function hasAttribute(context, name, attributes, initialScope) {
509
521
  return getAttribute(context, name, attributes, initialScope) != null;
@@ -520,18 +532,6 @@ function findParentAttribute(node, test = constTrue) {
520
532
  };
521
533
  return AST14.findParentNode(node, guard);
522
534
  }
523
- function isHostElement(context, node) {
524
- return node.type === AST_NODE_TYPES.JSXElement && node.openingElement.name.type === AST_NODE_TYPES.JSXIdentifier && /^[a-z]/u.test(node.openingElement.name.name);
525
- }
526
- function isKeyedElement(context, node, initialScope) {
527
- return node.type === AST_NODE_TYPES.JSXElement && hasAttribute(context, "key", node.openingElement.attributes, initialScope);
528
- }
529
- function isFragmentElement(context, node, allowJSXFragment = false) {
530
- if (node == null) return false;
531
- if (node.type !== AST_NODE_TYPES.JSXElement && node.type !== AST_NODE_TYPES.JSXFragment) return false;
532
- if (node.type === AST_NODE_TYPES.JSXFragment) return allowJSXFragment;
533
- return getElementType(context, node).split(".").at(-1) === "Fragment";
534
- }
535
535
 
536
536
  // src/component/component-detection-hint.ts
537
537
  var ComponentDetectionHint = {
@@ -961,5 +961,80 @@ function isAssignmentToThisState(node) {
961
961
  const { left } = node;
962
962
  return left.type === AST_NODE_TYPES.MemberExpression && AST14.isThisExpression(left.object) && AST14.getPropertyName(left.property) === "state";
963
963
  }
964
+ function isInViMockCallback(context, node) {
965
+ const found = AST14.findParentNode(node, (n) => {
966
+ if (!AST14.isFunction(n)) return false;
967
+ return n.parent.type === AST_NODE_TYPES.CallExpression && n.parent.callee.type === AST_NODE_TYPES.MemberExpression && n.parent.callee.object.type === AST_NODE_TYPES.Identifier && n.parent.callee.object.name === "vi" && n.parent.callee.property.type === AST_NODE_TYPES.Identifier && n.parent.callee.property.name === "mock" && n.parent.arguments[1] === n;
968
+ });
969
+ return found != null;
970
+ }
971
+ var isAnyType = (type) => isTypeFlagSet(type, ts.TypeFlags.TypeParameter | ts.TypeFlags.Any);
972
+ var isBigIntType = (type) => isTypeFlagSet(type, ts.TypeFlags.BigIntLike);
973
+ var isBooleanType = (type) => isTypeFlagSet(type, ts.TypeFlags.BooleanLike);
974
+ var isEnumType = (type) => isTypeFlagSet(type, ts.TypeFlags.EnumLike);
975
+ var isFalsyBigIntType = (type) => type.isLiteral() && isMatching({ value: { base10Value: "0" } }, type);
976
+ var isFalsyNumberType = (type) => type.isNumberLiteral() && type.value === 0;
977
+ var isFalsyStringType = (type) => type.isStringLiteral() && type.value === "";
978
+ var isNeverType = (type) => isTypeFlagSet(type, ts.TypeFlags.Never);
979
+ var isNullishType = (type) => isTypeFlagSet(type, ts.TypeFlags.Null | ts.TypeFlags.Undefined | ts.TypeFlags.VoidLike);
980
+ var isNumberType = (type) => isTypeFlagSet(type, ts.TypeFlags.NumberLike);
981
+ var isObjectType = (type) => !isTypeFlagSet(
982
+ type,
983
+ ts.TypeFlags.Null | ts.TypeFlags.Undefined | ts.TypeFlags.VoidLike | ts.TypeFlags.BooleanLike | ts.TypeFlags.StringLike | ts.TypeFlags.NumberLike | ts.TypeFlags.BigIntLike | ts.TypeFlags.TypeParameter | ts.TypeFlags.Any | ts.TypeFlags.Unknown | ts.TypeFlags.Never
984
+ );
985
+ var isStringType = (type) => isTypeFlagSet(type, ts.TypeFlags.StringLike);
986
+ var isTruthyBigIntType = (type) => type.isLiteral() && isMatching({ value: { base10Value: P.not("0") } }, type);
987
+ var isTruthyNumberType = (type) => type.isNumberLiteral() && type.value !== 0;
988
+ var isTruthyStringType = (type) => type.isStringLiteral() && type.value !== "";
989
+ var isUnknownType = (type) => isTypeFlagSet(type, ts.TypeFlags.Unknown);
990
+ function getTypeVariants(types) {
991
+ const variants = /* @__PURE__ */ new Set();
992
+ if (types.some(isUnknownType)) {
993
+ variants.add("unknown");
994
+ return variants;
995
+ }
996
+ if (types.some(isNullishType)) {
997
+ variants.add("nullish");
998
+ }
999
+ const booleans = types.filter(isBooleanType);
1000
+ const boolean0 = booleans[0];
1001
+ if (booleans.length === 1 && boolean0 != null) {
1002
+ if (isFalseLiteralType(boolean0)) {
1003
+ variants.add("falsy boolean");
1004
+ } else if (isTrueLiteralType(boolean0)) {
1005
+ variants.add("truthy boolean");
1006
+ }
1007
+ } else if (booleans.length === 2) {
1008
+ variants.add("boolean");
1009
+ }
1010
+ const strings = types.filter(isStringType);
1011
+ if (strings.length > 0) {
1012
+ const evaluated = match(strings).when((types2) => types2.every(isTruthyStringType), () => "truthy string").when((types2) => types2.every(isFalsyStringType), () => "falsy string").otherwise(() => "string");
1013
+ variants.add(evaluated);
1014
+ }
1015
+ const bigints = types.filter(isBigIntType);
1016
+ if (bigints.length > 0) {
1017
+ const evaluated = match(bigints).when((types2) => types2.every(isTruthyBigIntType), () => "truthy bigint").when((types2) => types2.every(isFalsyBigIntType), () => "falsy bigint").otherwise(() => "bigint");
1018
+ variants.add(evaluated);
1019
+ }
1020
+ const numbers = types.filter(isNumberType);
1021
+ if (numbers.length > 0) {
1022
+ const evaluated = match(numbers).when((types2) => types2.every(isTruthyNumberType), () => "truthy number").when((types2) => types2.every(isFalsyNumberType), () => "falsy number").otherwise(() => "number");
1023
+ variants.add(evaluated);
1024
+ }
1025
+ if (types.some(isEnumType)) {
1026
+ variants.add("enum");
1027
+ }
1028
+ if (types.some(isObjectType)) {
1029
+ variants.add("object");
1030
+ }
1031
+ if (types.some(isAnyType)) {
1032
+ variants.add("any");
1033
+ }
1034
+ if (types.some(isNeverType)) {
1035
+ variants.add("never");
1036
+ }
1037
+ return variants;
1038
+ }
964
1039
 
965
- export { ComponentDetectionHint, ComponentFlag, ComponentPhaseRelevance, DEFAULT_COMPONENT_DETECTION_HINT, DEFAULT_JSX_DETECTION_HINT, JSXDetectionHint, REACT_BUILTIN_HOOK_NAMES, findParentAttribute, getAttribute, getAttributeName, getAttributeValue, getComponentFlagFromInitPath, getComponentNameFromId, getElementType, getFunctionComponentId, getInstanceId, hasAnyAttribute, hasAttribute, hasEveryAttribute, hasNoneOrLooseComponentName, isAssignmentToThisState, isCaptureOwnerStack, isCaptureOwnerStackCall, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOfCreateElement, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCloneElement, isCloneElementCall, isComponentDidCatch, isComponentDidMount, isComponentDidUpdate, isComponentName, isComponentNameLoose, isComponentWillMount, isComponentWillReceiveProps, isComponentWillUnmount, isComponentWillUpdate, isComponentWrapperCall, isComponentWrapperCallLoose, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRef, isForwardRefCall, isFragmentElement, isFunctionOfRender, isFunctionOfRenderMethod, isGetChildContext, isGetDefaultProps, isGetDerivedStateFromError, isGetDerivedStateFromProps, isGetInitialState, isGetSnapshotBeforeUpdate, isHostElement, isInitializedFromReact, isInstanceIdEqual, isInversePhase, isJsxLike, isJsxText, isKeyedElement, isLazy, isLazyCall, isMemo, isMemoCall, isPureComponent, isReactAPI, isReactAPICall, isReactHook, isReactHookCall, isReactHookCallWithName, isReactHookCallWithNameAlias, isReactHookCallWithNameLoose, isReactHookId, isReactHookName, isRenderFunctionLoose, isRenderLike, isRenderMethodLike, isRenderPropLoose, isShouldComponentUpdate, isThisSetState, isUnsafeComponentWillMount, isUnsafeComponentWillReceiveProps, isUnsafeComponentWillUpdate, isUseActionStateCall, isUseCall, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectCallLoose, isUseFormStatusCall, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseOptimisticCall, isUseReducerCall, isUseRefCall, isUseStateCall, isUseSyncExternalStoreCall, isUseTransitionCall, isValidComponentDefinition, stringifyJsx, useComponentCollector, useComponentCollectorLegacy, useHookCollector };
1040
+ export { ComponentDetectionHint, ComponentFlag, ComponentPhaseRelevance, DEFAULT_COMPONENT_DETECTION_HINT, DEFAULT_JSX_DETECTION_HINT, JSXDetectionHint, REACT_BUILTIN_HOOK_NAMES, findParentAttribute, getAttribute, getAttributeName, getAttributeValue, getComponentFlagFromInitPath, getComponentNameFromId, getElementType, getFunctionComponentId, getInstanceId, getTypeVariants, hasAnyAttribute, hasAttribute, hasEveryAttribute, hasNoneOrLooseComponentName, isAnyType, isAssignmentToThisState, isBigIntType, isBooleanType, isCaptureOwnerStack, isCaptureOwnerStackCall, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOfCreateElement, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCloneElement, isCloneElementCall, isComponentDidCatch, isComponentDidMount, isComponentDidUpdate, isComponentName, isComponentNameLoose, isComponentWillMount, isComponentWillReceiveProps, isComponentWillUnmount, isComponentWillUpdate, isComponentWrapperCall, isComponentWrapperCallLoose, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isEnumType, isFalsyBigIntType, isFalsyNumberType, isFalsyStringType, isForwardRef, isForwardRefCall, isFragmentElement, isFunctionOfRender, isFunctionOfRenderMethod, isGetChildContext, isGetDefaultProps, isGetDerivedStateFromError, isGetDerivedStateFromProps, isGetInitialState, isGetSnapshotBeforeUpdate, isHostElement, isInViMockCallback, isInitializedFromReact, isInstanceIdEqual, isInversePhase, isJsxLike, isJsxText, isLazy, isLazyCall, isMemo, isMemoCall, isNeverType, isNullishType, isNumberType, isObjectType, isPureComponent, isReactAPI, isReactAPICall, isReactHook, isReactHookCall, isReactHookCallWithName, isReactHookCallWithNameAlias, isReactHookCallWithNameLoose, isReactHookId, isReactHookName, isRenderFunctionLoose, isRenderLike, isRenderMethodLike, isRenderPropLoose, isShouldComponentUpdate, isStringType, isThisSetState, isTruthyBigIntType, isTruthyNumberType, isTruthyStringType, isUnknownType, isUnsafeComponentWillMount, isUnsafeComponentWillReceiveProps, isUnsafeComponentWillUpdate, isUseActionStateCall, isUseCall, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectCallLoose, isUseFormStatusCall, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseOptimisticCall, isUseReducerCall, isUseRefCall, isUseStateCall, isUseSyncExternalStoreCall, isUseTransitionCall, isValidComponentDefinition, stringifyJsx, useComponentCollector, useComponentCollectorLegacy, useHookCollector };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eslint-react/core",
3
- "version": "2.0.0-beta.4",
3
+ "version": "2.0.0-beta.41",
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": {
@@ -27,24 +27,24 @@
27
27
  "./package.json"
28
28
  ],
29
29
  "dependencies": {
30
- "@typescript-eslint/scope-manager": "^8.35.0",
31
- "@typescript-eslint/type-utils": "^8.35.0",
32
- "@typescript-eslint/types": "^8.35.0",
33
- "@typescript-eslint/utils": "^8.35.0",
30
+ "@typescript-eslint/scope-manager": "^8.40.0",
31
+ "@typescript-eslint/type-utils": "^8.40.0",
32
+ "@typescript-eslint/types": "^8.40.0",
33
+ "@typescript-eslint/utils": "^8.40.0",
34
34
  "birecord": "^0.1.1",
35
- "ts-pattern": "^5.7.1",
36
- "@eslint-react/ast": "2.0.0-beta.4",
37
- "@eslint-react/eff": "2.0.0-beta.4",
38
- "@eslint-react/kit": "2.0.0-beta.4",
39
- "@eslint-react/shared": "2.0.0-beta.4",
40
- "@eslint-react/var": "2.0.0-beta.4"
35
+ "ts-api-utils": "^2.1.0",
36
+ "ts-pattern": "^5.8.0",
37
+ "@eslint-react/eff": "2.0.0-beta.41",
38
+ "@eslint-react/kit": "2.0.0-beta.41",
39
+ "@eslint-react/ast": "2.0.0-beta.41",
40
+ "@eslint-react/var": "2.0.0-beta.41",
41
+ "@eslint-react/shared": "2.0.0-beta.41"
41
42
  },
42
43
  "devDependencies": {
43
44
  "tsup": "^8.5.0",
44
45
  "@local/configs": "0.0.0"
45
46
  },
46
47
  "engines": {
47
- "bun": ">=1.0.15",
48
48
  "node": ">=20.19.0"
49
49
  },
50
50
  "scripts": {