@eslint-react/core 5.17.0 → 5.17.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +33 -2
- package/dist/index.js +143 -67
- package/package.json +8 -8
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { TSESTreeClass, TSESTreeDirective, TSESTreeFunction, TSESTreeMethodOrPropertyDefinition } from "@eslint-react/ast";
|
|
2
2
|
import { TSESTree } from "@typescript-eslint/types";
|
|
3
|
-
import { JsxDetectionHint } from "@eslint-react/jsx";
|
|
4
3
|
import { RegExpLike } from "@eslint-react/shared";
|
|
5
4
|
import ts from "typescript";
|
|
6
5
|
import { RuleContext } from "@eslint-react/eslint";
|
|
@@ -599,6 +598,38 @@ declare namespace getHookCollector {
|
|
|
599
598
|
declare function getHookCollector(context: RuleContext): getHookCollector.ReturnType;
|
|
600
599
|
//#endregion
|
|
601
600
|
//#region src/jsx.d.ts
|
|
601
|
+
/**
|
|
602
|
+
* BitFlags for configuring JSX detection behavior.
|
|
603
|
+
*
|
|
604
|
+
* Used by `isJsxLike` to control which AST node kinds are considered
|
|
605
|
+
* "JSX-like". Combine flags with the `|` operator.
|
|
606
|
+
*/
|
|
607
|
+
type JsxDetectionHint = bigint;
|
|
608
|
+
/**
|
|
609
|
+
* Hints for JSX detection.
|
|
610
|
+
*/
|
|
611
|
+
declare const JsxDetectionHint: {
|
|
612
|
+
readonly None: 0n;
|
|
613
|
+
readonly DoNotIncludeJsxWithNullValue: bigint;
|
|
614
|
+
readonly DoNotIncludeJsxWithNumberValue: bigint;
|
|
615
|
+
readonly DoNotIncludeJsxWithBigIntValue: bigint;
|
|
616
|
+
readonly DoNotIncludeJsxWithStringValue: bigint;
|
|
617
|
+
readonly DoNotIncludeJsxWithBooleanValue: bigint;
|
|
618
|
+
readonly DoNotIncludeJsxWithUndefinedValue: bigint;
|
|
619
|
+
readonly DoNotIncludeJsxWithEmptyArrayValue: bigint;
|
|
620
|
+
readonly DoNotIncludeJsxWithCreateElementValue: bigint;
|
|
621
|
+
readonly RequireAllArrayElementsToBeJsx: bigint;
|
|
622
|
+
readonly RequireBothSidesOfLogicalExpressionToBeJsx: bigint;
|
|
623
|
+
readonly RequireBothBranchesOfConditionalExpressionToBeJsx: bigint;
|
|
624
|
+
};
|
|
625
|
+
/**
|
|
626
|
+
* Default JSX detection hint.
|
|
627
|
+
*
|
|
628
|
+
* Skips number, bigint, boolean, string, and undefined literals,
|
|
629
|
+
* the value types that are commonly returned alongside JSX in React
|
|
630
|
+
* components but are not themselves renderable elements.
|
|
631
|
+
*/
|
|
632
|
+
declare const DEFAULT_JSX_DETECTION_HINT: JsxDetectionHint;
|
|
602
633
|
/**
|
|
603
634
|
* Determine whether a node represents JSX-like content based on heuristics.
|
|
604
635
|
*
|
|
@@ -799,4 +830,4 @@ type TypeVariant = "any" | "bigint" | "boolean" | "enum" | "never" | "nullish" |
|
|
|
799
830
|
*/
|
|
800
831
|
declare function getTypeVariants(types: ts.Type[]): Set<TypeVariant>;
|
|
801
832
|
//#endregion
|
|
802
|
-
export { ClassComponentSemanticNode, ClientFunctionSemanticNode, DEFAULT_COMPONENT_DETECTION_HINT, FunctionComponentDetectionHint, FunctionComponentFlag, FunctionComponentSemanticNode, FunctionDisplayNameAssignment, FunctionID, FunctionInitPath, FunctionKind, FunctionSemanticNode, HookCall, HookSemanticNode, JsxConfig, REACT_BUILTIN_HOOK_NAMES, SEL_FUNCTION_DISPLAY_NAME_ASSIGNMENT, SemanticFunc, SemanticNode, ServerFunctionSemanticNode, TypeVariant, getClassComponentCollector, getClassId, getFullyQualifiedNameEx, getFunctionComponentCollector, getFunctionComponentFlagFromInitPath, getFunctionComponentId, getFunctionDirectives, getFunctionId, getFunctionInitPath, getHookCollector, getJsxConfig, getJsxConfigFromAnnotation, getJsxConfigFromCompilerOptions, getTypeVariants, isAPI, isAPICall, isAnyType, isAssignmentToThisState, 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, isUseState, isUseStateCall, isUseStateLikeCall, isUseSyncExternalStore, isUseSyncExternalStoreCall, isUseTransition, isUseTransitionCall };
|
|
833
|
+
export { ClassComponentSemanticNode, ClientFunctionSemanticNode, DEFAULT_COMPONENT_DETECTION_HINT, DEFAULT_JSX_DETECTION_HINT, FunctionComponentDetectionHint, FunctionComponentFlag, FunctionComponentSemanticNode, FunctionDisplayNameAssignment, FunctionID, FunctionInitPath, FunctionKind, FunctionSemanticNode, HookCall, HookSemanticNode, JsxConfig, JsxDetectionHint, REACT_BUILTIN_HOOK_NAMES, SEL_FUNCTION_DISPLAY_NAME_ASSIGNMENT, SemanticFunc, SemanticNode, ServerFunctionSemanticNode, TypeVariant, getClassComponentCollector, getClassId, getFullyQualifiedNameEx, getFunctionComponentCollector, getFunctionComponentFlagFromInitPath, getFunctionComponentId, getFunctionDirectives, getFunctionId, getFunctionInitPath, getHookCollector, getJsxConfig, getJsxConfigFromAnnotation, getJsxConfigFromCompilerOptions, getTypeVariants, isAPI, isAPICall, isAnyType, isAssignmentToThisState, 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, isUseState, isUseStateCall, isUseStateLikeCall, isUseSyncExternalStore, isUseSyncExternalStoreCall, isUseTransition, isUseTransitionCall };
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Check, Extract, Traverse } from "@eslint-react/ast";
|
|
2
2
|
import { AST_NODE_TYPES } from "@typescript-eslint/types";
|
|
3
3
|
import { randomBytes } from "node:crypto";
|
|
4
|
-
import { DEFAULT_JSX_DETECTION_HINT, JsxDetectionHint } from "@eslint-react/jsx";
|
|
5
4
|
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";
|
|
6
5
|
import { resolve } from "@eslint-react/var";
|
|
7
6
|
import ts from "typescript";
|
|
@@ -427,6 +426,58 @@ const absurd = (_) => {
|
|
|
427
426
|
* @since 2.0.0
|
|
428
427
|
*/
|
|
429
428
|
const hole = cast(absurd);
|
|
429
|
+
/**
|
|
430
|
+
* Drops the longest prefix of elements from an array that satisfy the given predicate.
|
|
431
|
+
*
|
|
432
|
+
* Supports both data-first and data-last (`pipe`-friendly) call styles.
|
|
433
|
+
*
|
|
434
|
+
* @param pred - The predicate to test each element with.
|
|
435
|
+
* @returns A new array without the matching prefix.
|
|
436
|
+
* @example
|
|
437
|
+
* ```ts
|
|
438
|
+
* import * as assert from "node:assert"
|
|
439
|
+
* import { dropWhile, pipe } from "@local/eff"
|
|
440
|
+
*
|
|
441
|
+
* // data-first
|
|
442
|
+
* assert.deepStrictEqual(dropWhile([1, 2, 3, 2, 1], (n: number) => n < 3), [3, 2, 1])
|
|
443
|
+
*
|
|
444
|
+
* // data-last
|
|
445
|
+
* assert.deepStrictEqual(pipe([1, 2, 3, 2, 1], dropWhile((n: number) => n < 3)), [3, 2, 1])
|
|
446
|
+
* ```
|
|
447
|
+
* @category array
|
|
448
|
+
*/
|
|
449
|
+
const dropWhile = dual(2, (xs, pred) => {
|
|
450
|
+
const len = xs.length;
|
|
451
|
+
let idx = 0;
|
|
452
|
+
while (idx < len && pred(xs[idx])) idx++;
|
|
453
|
+
return xs.slice(idx);
|
|
454
|
+
});
|
|
455
|
+
/**
|
|
456
|
+
* Takes the longest prefix of elements from an array that satisfy the given predicate.
|
|
457
|
+
*
|
|
458
|
+
* Supports both data-first and data-last (`pipe`-friendly) call styles.
|
|
459
|
+
*
|
|
460
|
+
* @param pred - The predicate to test each element with.
|
|
461
|
+
* @returns A new array containing only the matching prefix.
|
|
462
|
+
* @example
|
|
463
|
+
* ```ts
|
|
464
|
+
* import * as assert from "node:assert"
|
|
465
|
+
* import { pipe, takeWhile } from "@local/eff"
|
|
466
|
+
*
|
|
467
|
+
* // data-first
|
|
468
|
+
* assert.deepStrictEqual(takeWhile([1, 2, 3, 2, 1], (n: number) => n < 3), [1, 2])
|
|
469
|
+
*
|
|
470
|
+
* // data-last
|
|
471
|
+
* assert.deepStrictEqual(pipe([1, 2, 3, 2, 1], takeWhile((n: number) => n < 3)), [1, 2])
|
|
472
|
+
* ```
|
|
473
|
+
* @category array
|
|
474
|
+
*/
|
|
475
|
+
const takeWhile = dual(2, (xs, pred) => {
|
|
476
|
+
const len = xs.length;
|
|
477
|
+
let idx = 0;
|
|
478
|
+
while (idx < len && pred(xs[idx])) idx++;
|
|
479
|
+
return xs.slice(0, idx);
|
|
480
|
+
});
|
|
430
481
|
|
|
431
482
|
//#endregion
|
|
432
483
|
//#region src/api.ts
|
|
@@ -810,6 +861,96 @@ const SEL_FUNCTION_DISPLAY_NAME_ASSIGNMENT = [
|
|
|
810
861
|
"[left.property.name='displayName']"
|
|
811
862
|
].join("");
|
|
812
863
|
|
|
864
|
+
//#endregion
|
|
865
|
+
//#region src/jsx.ts
|
|
866
|
+
/**
|
|
867
|
+
* Hints for JSX detection.
|
|
868
|
+
*/
|
|
869
|
+
const JsxDetectionHint = {
|
|
870
|
+
None: 0n,
|
|
871
|
+
DoNotIncludeJsxWithNullValue: 1n << 0n,
|
|
872
|
+
DoNotIncludeJsxWithNumberValue: 1n << 1n,
|
|
873
|
+
DoNotIncludeJsxWithBigIntValue: 1n << 2n,
|
|
874
|
+
DoNotIncludeJsxWithStringValue: 1n << 3n,
|
|
875
|
+
DoNotIncludeJsxWithBooleanValue: 1n << 4n,
|
|
876
|
+
DoNotIncludeJsxWithUndefinedValue: 1n << 5n,
|
|
877
|
+
DoNotIncludeJsxWithEmptyArrayValue: 1n << 6n,
|
|
878
|
+
DoNotIncludeJsxWithCreateElementValue: 1n << 7n,
|
|
879
|
+
RequireAllArrayElementsToBeJsx: 1n << 8n,
|
|
880
|
+
RequireBothSidesOfLogicalExpressionToBeJsx: 1n << 9n,
|
|
881
|
+
RequireBothBranchesOfConditionalExpressionToBeJsx: 1n << 10n
|
|
882
|
+
};
|
|
883
|
+
/**
|
|
884
|
+
* Default JSX detection hint.
|
|
885
|
+
*
|
|
886
|
+
* Skips number, bigint, boolean, string, and undefined literals,
|
|
887
|
+
* the value types that are commonly returned alongside JSX in React
|
|
888
|
+
* components but are not themselves renderable elements.
|
|
889
|
+
*/
|
|
890
|
+
const DEFAULT_JSX_DETECTION_HINT = 0n | JsxDetectionHint.DoNotIncludeJsxWithNumberValue | JsxDetectionHint.DoNotIncludeJsxWithBigIntValue | JsxDetectionHint.DoNotIncludeJsxWithBooleanValue | JsxDetectionHint.DoNotIncludeJsxWithStringValue | JsxDetectionHint.DoNotIncludeJsxWithUndefinedValue;
|
|
891
|
+
/**
|
|
892
|
+
* Determine whether a node represents JSX-like content based on heuristics.
|
|
893
|
+
*
|
|
894
|
+
* The detection behaviour is configurable through {@link JsxDetectionHint}
|
|
895
|
+
* bit-flags so that callers can opt individual value kinds in or out.
|
|
896
|
+
*
|
|
897
|
+
* Identifiers are resolved to their definitions via scope analysis;
|
|
898
|
+
* circular definitions (e.g. `var a = b; var b = a;`) are detected and
|
|
899
|
+
* treated as not JSX-like instead of recursing indefinitely.
|
|
900
|
+
*
|
|
901
|
+
* @param context The ESLint rule context (needed for variable resolution).
|
|
902
|
+
* @param node The AST node to analyse.
|
|
903
|
+
* @param hint Optional bit-flags to adjust detection behaviour. Defaults to {@link DEFAULT_JSX_DETECTION_HINT}.
|
|
904
|
+
* @returns Whether the node is considered JSX-like.
|
|
905
|
+
*
|
|
906
|
+
* @example
|
|
907
|
+
* ```ts
|
|
908
|
+
* import { isJsxLike } from "@eslint-react/core";
|
|
909
|
+
*
|
|
910
|
+
* if (isJsxLike(context, node)) {
|
|
911
|
+
* // node looks like it evaluates to a React element
|
|
912
|
+
* }
|
|
913
|
+
* ```
|
|
914
|
+
*/
|
|
915
|
+
function isJsxLike(context, node, hint = DEFAULT_JSX_DETECTION_HINT) {
|
|
916
|
+
const seen = /* @__PURE__ */ new Set();
|
|
917
|
+
function visit(node) {
|
|
918
|
+
if (node == null) return false;
|
|
919
|
+
if (Check.isJSX(node)) return true;
|
|
920
|
+
switch (node.type) {
|
|
921
|
+
case AST_NODE_TYPES.Literal:
|
|
922
|
+
switch (typeof node.value) {
|
|
923
|
+
case "boolean": return !(hint & JsxDetectionHint.DoNotIncludeJsxWithBooleanValue);
|
|
924
|
+
case "string": return !(hint & JsxDetectionHint.DoNotIncludeJsxWithStringValue);
|
|
925
|
+
case "number": return !(hint & JsxDetectionHint.DoNotIncludeJsxWithNumberValue);
|
|
926
|
+
case "bigint": return !(hint & JsxDetectionHint.DoNotIncludeJsxWithBigIntValue);
|
|
927
|
+
}
|
|
928
|
+
return node.value == null && !(hint & JsxDetectionHint.DoNotIncludeJsxWithNullValue);
|
|
929
|
+
case AST_NODE_TYPES.TemplateLiteral: return !(hint & JsxDetectionHint.DoNotIncludeJsxWithStringValue);
|
|
930
|
+
case AST_NODE_TYPES.ArrayExpression:
|
|
931
|
+
if (node.elements.length === 0) return !(hint & JsxDetectionHint.DoNotIncludeJsxWithEmptyArrayValue);
|
|
932
|
+
return hint & JsxDetectionHint.RequireAllArrayElementsToBeJsx ? node.elements.every(visit) : node.elements.some(visit);
|
|
933
|
+
case AST_NODE_TYPES.LogicalExpression:
|
|
934
|
+
if (hint & JsxDetectionHint.RequireBothSidesOfLogicalExpressionToBeJsx) return visit(node.left) && visit(node.right);
|
|
935
|
+
return visit(node.left) || visit(node.right);
|
|
936
|
+
case AST_NODE_TYPES.ConditionalExpression:
|
|
937
|
+
if (hint & JsxDetectionHint.RequireBothBranchesOfConditionalExpressionToBeJsx) return visit(node.consequent) && visit(node.alternate);
|
|
938
|
+
return visit(node.consequent) || visit(node.alternate);
|
|
939
|
+
case AST_NODE_TYPES.SequenceExpression: return visit(node.expressions.at(-1) ?? null);
|
|
940
|
+
case AST_NODE_TYPES.CallExpression:
|
|
941
|
+
if (hint & JsxDetectionHint.DoNotIncludeJsxWithCreateElementValue) return false;
|
|
942
|
+
return Extract.getCalleeName(node) === "createElement";
|
|
943
|
+
case AST_NODE_TYPES.Identifier:
|
|
944
|
+
if (node.name === "undefined") return !(hint & JsxDetectionHint.DoNotIncludeJsxWithUndefinedValue);
|
|
945
|
+
if (seen.has(node)) return false;
|
|
946
|
+
seen.add(node);
|
|
947
|
+
return visit(resolve(context, node));
|
|
948
|
+
}
|
|
949
|
+
return false;
|
|
950
|
+
}
|
|
951
|
+
return visit(node);
|
|
952
|
+
}
|
|
953
|
+
|
|
813
954
|
//#endregion
|
|
814
955
|
//#region src/function-component.ts
|
|
815
956
|
/**
|
|
@@ -1114,71 +1255,6 @@ function isUseEffectCleanupCallback(node) {
|
|
|
1114
1255
|
return isUseEffectSetupCallback(enclosingFunction);
|
|
1115
1256
|
}
|
|
1116
1257
|
|
|
1117
|
-
//#endregion
|
|
1118
|
-
//#region src/jsx.ts
|
|
1119
|
-
/**
|
|
1120
|
-
* Determine whether a node represents JSX-like content based on heuristics.
|
|
1121
|
-
*
|
|
1122
|
-
* The detection behaviour is configurable through {@link JsxDetectionHint}
|
|
1123
|
-
* bit-flags so that callers can opt individual value kinds in or out.
|
|
1124
|
-
*
|
|
1125
|
-
* Identifiers are resolved to their definitions via scope analysis;
|
|
1126
|
-
* circular definitions (e.g. `var a = b; var b = a;`) are detected and
|
|
1127
|
-
* treated as not JSX-like instead of recursing indefinitely.
|
|
1128
|
-
*
|
|
1129
|
-
* @param context The ESLint rule context (needed for variable resolution).
|
|
1130
|
-
* @param node The AST node to analyse.
|
|
1131
|
-
* @param hint Optional bit-flags to adjust detection behaviour. Defaults to {@link DEFAULT_JSX_DETECTION_HINT}.
|
|
1132
|
-
* @returns Whether the node is considered JSX-like.
|
|
1133
|
-
*
|
|
1134
|
-
* @example
|
|
1135
|
-
* ```ts
|
|
1136
|
-
* import { isJsxLike } from "@eslint-react/core";
|
|
1137
|
-
*
|
|
1138
|
-
* if (isJsxLike(context, node)) {
|
|
1139
|
-
* // node looks like it evaluates to a React element
|
|
1140
|
-
* }
|
|
1141
|
-
* ```
|
|
1142
|
-
*/
|
|
1143
|
-
function isJsxLike(context, node, hint = DEFAULT_JSX_DETECTION_HINT) {
|
|
1144
|
-
const seen = /* @__PURE__ */ new Set();
|
|
1145
|
-
function visit(node) {
|
|
1146
|
-
if (node == null) return false;
|
|
1147
|
-
if (Check.isJSX(node)) return true;
|
|
1148
|
-
switch (node.type) {
|
|
1149
|
-
case AST_NODE_TYPES.Literal:
|
|
1150
|
-
switch (typeof node.value) {
|
|
1151
|
-
case "boolean": return !(hint & JsxDetectionHint.DoNotIncludeJsxWithBooleanValue);
|
|
1152
|
-
case "string": return !(hint & JsxDetectionHint.DoNotIncludeJsxWithStringValue);
|
|
1153
|
-
case "number": return !(hint & JsxDetectionHint.DoNotIncludeJsxWithNumberValue);
|
|
1154
|
-
case "bigint": return !(hint & JsxDetectionHint.DoNotIncludeJsxWithBigIntValue);
|
|
1155
|
-
}
|
|
1156
|
-
return node.value == null && !(hint & JsxDetectionHint.DoNotIncludeJsxWithNullValue);
|
|
1157
|
-
case AST_NODE_TYPES.TemplateLiteral: return !(hint & JsxDetectionHint.DoNotIncludeJsxWithStringValue);
|
|
1158
|
-
case AST_NODE_TYPES.ArrayExpression:
|
|
1159
|
-
if (node.elements.length === 0) return !(hint & JsxDetectionHint.DoNotIncludeJsxWithEmptyArrayValue);
|
|
1160
|
-
return hint & JsxDetectionHint.RequireAllArrayElementsToBeJsx ? node.elements.every(visit) : node.elements.some(visit);
|
|
1161
|
-
case AST_NODE_TYPES.LogicalExpression:
|
|
1162
|
-
if (hint & JsxDetectionHint.RequireBothSidesOfLogicalExpressionToBeJsx) return visit(node.left) && visit(node.right);
|
|
1163
|
-
return visit(node.left) || visit(node.right);
|
|
1164
|
-
case AST_NODE_TYPES.ConditionalExpression:
|
|
1165
|
-
if (hint & JsxDetectionHint.RequireBothBranchesOfConditionalExpressionToBeJsx) return visit(node.consequent) && visit(node.alternate);
|
|
1166
|
-
return visit(node.consequent) || visit(node.alternate);
|
|
1167
|
-
case AST_NODE_TYPES.SequenceExpression: return visit(node.expressions.at(-1) ?? null);
|
|
1168
|
-
case AST_NODE_TYPES.CallExpression:
|
|
1169
|
-
if (hint & JsxDetectionHint.DoNotIncludeJsxWithCreateElementValue) return false;
|
|
1170
|
-
return Extract.getCalleeName(node) === "createElement";
|
|
1171
|
-
case AST_NODE_TYPES.Identifier:
|
|
1172
|
-
if (node.name === "undefined") return !(hint & JsxDetectionHint.DoNotIncludeJsxWithUndefinedValue);
|
|
1173
|
-
if (seen.has(node)) return false;
|
|
1174
|
-
seen.add(node);
|
|
1175
|
-
return visit(resolve(context, node));
|
|
1176
|
-
}
|
|
1177
|
-
return false;
|
|
1178
|
-
}
|
|
1179
|
-
return visit(node);
|
|
1180
|
-
}
|
|
1181
|
-
|
|
1182
1258
|
//#endregion
|
|
1183
1259
|
//#region src/function-component-collector.ts
|
|
1184
1260
|
/**
|
|
@@ -1582,4 +1658,4 @@ function getTypeVariants(types) {
|
|
|
1582
1658
|
}
|
|
1583
1659
|
|
|
1584
1660
|
//#endregion
|
|
1585
|
-
export { DEFAULT_COMPONENT_DETECTION_HINT, FunctionComponentDetectionHint, FunctionComponentFlag, REACT_BUILTIN_HOOK_NAMES, SEL_FUNCTION_DISPLAY_NAME_ASSIGNMENT, getClassComponentCollector, getClassId, getFullyQualifiedNameEx, getFunctionComponentCollector, getFunctionComponentFlagFromInitPath, getFunctionComponentId, getFunctionDirectives, getFunctionId, getFunctionInitPath, getHookCollector, getJsxConfig, getJsxConfigFromAnnotation, getJsxConfigFromCompilerOptions, getTypeVariants, isAPI, isAPICall, isAnyType, isAssignmentToThisState, 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, isUseState, isUseStateCall, isUseStateLikeCall, isUseSyncExternalStore, isUseSyncExternalStoreCall, isUseTransition, isUseTransitionCall };
|
|
1661
|
+
export { DEFAULT_COMPONENT_DETECTION_HINT, DEFAULT_JSX_DETECTION_HINT, FunctionComponentDetectionHint, FunctionComponentFlag, JsxDetectionHint, REACT_BUILTIN_HOOK_NAMES, SEL_FUNCTION_DISPLAY_NAME_ASSIGNMENT, getClassComponentCollector, getClassId, getFullyQualifiedNameEx, getFunctionComponentCollector, getFunctionComponentFlagFromInitPath, getFunctionComponentId, getFunctionDirectives, getFunctionId, getFunctionInitPath, getHookCollector, getJsxConfig, getJsxConfigFromAnnotation, getJsxConfigFromCompilerOptions, getTypeVariants, isAPI, isAPICall, isAnyType, isAssignmentToThisState, 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, 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.17.
|
|
3
|
+
"version": "5.17.2",
|
|
4
4
|
"description": "ESLint React's ESLint utility module for static analysis of React core APIs and patterns.",
|
|
5
5
|
"homepage": "https://github.com/Rel1cx/eslint-react",
|
|
6
6
|
"bugs": {
|
|
@@ -33,21 +33,21 @@
|
|
|
33
33
|
"@typescript-eslint/types": "^8.64.0",
|
|
34
34
|
"@typescript-eslint/utils": "^8.64.0",
|
|
35
35
|
"ts-pattern": "^5.9.0",
|
|
36
|
-
"@eslint-react/
|
|
37
|
-
"@eslint-react/
|
|
38
|
-
"@eslint-react/
|
|
39
|
-
"@eslint-react/
|
|
40
|
-
"@eslint-react/eslint": "5.17.0"
|
|
36
|
+
"@eslint-react/ast": "5.17.2",
|
|
37
|
+
"@eslint-react/shared": "5.17.2",
|
|
38
|
+
"@eslint-react/var": "5.17.2",
|
|
39
|
+
"@eslint-react/eslint": "5.17.2"
|
|
41
40
|
},
|
|
42
41
|
"devDependencies": {
|
|
43
42
|
"@typescript-eslint/parser": "^8.64.0",
|
|
44
43
|
"@typescript-eslint/typescript-estree": "^8.64.0",
|
|
45
44
|
"eslint": "^10.7.0",
|
|
46
|
-
"tsdown": "^0.22.
|
|
45
|
+
"tsdown": "^0.22.9",
|
|
47
46
|
"typescript": "6.0.3",
|
|
48
47
|
"vitest": "^4.1.10",
|
|
48
|
+
"@local/configs": "0.0.0",
|
|
49
49
|
"@local/eff": "0.0.0",
|
|
50
|
-
"@local/
|
|
50
|
+
"@local/testkit": "0.0.0"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
53
|
"eslint": "*",
|