@eslint-react/core 2.4.0-next.9 → 2.4.1-beta.0
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 +14 -15
- package/dist/index.js +22 -48
- package/package.json +9 -9
package/dist/index.d.ts
CHANGED
|
@@ -729,24 +729,23 @@ declare function getInstanceId(node: TSESTree.Node, prev?: TSESTree.Node): TSEST
|
|
|
729
729
|
//#endregion
|
|
730
730
|
//#region src/utils/is-from-react.d.ts
|
|
731
731
|
/**
|
|
732
|
-
*
|
|
733
|
-
* @param name The
|
|
734
|
-
* @param
|
|
735
|
-
* @param
|
|
736
|
-
* @returns
|
|
732
|
+
* Checks if a variable is initialized from React import
|
|
733
|
+
* @param name The variable name
|
|
734
|
+
* @param initialScope The initial scope
|
|
735
|
+
* @param importSource Alternative import source of React (e.g., "preact/compat")
|
|
736
|
+
* @returns True if the variable is initialized from React import
|
|
737
737
|
*/
|
|
738
|
-
declare function isInitializedFromReact(name: string,
|
|
738
|
+
declare function isInitializedFromReact(name: string, initialScope: Scope, importSource?: string): boolean;
|
|
739
739
|
//#endregion
|
|
740
|
-
//#region src/utils/is-from-
|
|
740
|
+
//#region src/utils/is-from-react-native.d.ts
|
|
741
741
|
/**
|
|
742
|
-
*
|
|
743
|
-
* @param name The
|
|
744
|
-
* @param
|
|
745
|
-
* @param
|
|
746
|
-
* @returns
|
|
747
|
-
* @internal
|
|
742
|
+
* Checks if a variable is initialized from React Native import
|
|
743
|
+
* @param name The variable name
|
|
744
|
+
* @param initialScope The initial scope
|
|
745
|
+
* @param importSource Alternative import source of React Native (e.g., "react-native-web")
|
|
746
|
+
* @returns True if the variable is initialized from React Native import
|
|
748
747
|
*/
|
|
749
|
-
declare function
|
|
748
|
+
declare function isInitializedFromReactNative(name: string, initialScope: Scope, importSource?: string): boolean;
|
|
750
749
|
//#endregion
|
|
751
750
|
//#region src/utils/is-instance-id-equal.d.ts
|
|
752
751
|
/** @internal */
|
|
@@ -804,4 +803,4 @@ declare const isForwardRefCall: isReactAPICall.ReturnType;
|
|
|
804
803
|
declare const isMemoCall: isReactAPICall.ReturnType;
|
|
805
804
|
declare const isLazyCall: isReactAPICall.ReturnType;
|
|
806
805
|
//#endregion
|
|
807
|
-
export { ClassComponent, Component, ComponentDetectionHint, ComponentEffectPhaseKind, ComponentFlag, ComponentKind, ComponentLifecyclePhaseKind, ComponentPhaseKind, ComponentPhaseRelevance, DEFAULT_COMPONENT_DETECTION_HINT, DEFAULT_JSX_DETECTION_HINT, FunctionComponent, Hook, JsxAttributeValue, JsxConfig, JsxDetectionHint, JsxEmit, REACT_BUILTIN_HOOK_NAMES, SemanticEntry, SemanticNode, findParentJsxAttribute, getComponentFlagFromInitPath, getComponentNameFromId, getFunctionComponentId, getInstanceId, getJsxAttribute, getJsxAttributeName, getJsxConfigFromAnnotation, getJsxConfigFromContext, getJsxElementType, getPhaseKindOfFunction, hasNoneOrLooseComponentName, isAssignmentToThisState, isCaptureOwnerStack, isCaptureOwnerStackCall, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCloneElement, isCloneElementCall, isComponentDefinition, isComponentDidCatch, isComponentDidMount, isComponentDidUpdate, isComponentName, isComponentNameLoose, isComponentWillMount, isComponentWillReceiveProps, isComponentWillUnmount, isComponentWillUpdate, isComponentWrapperCall, isComponentWrapperCallLoose, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRef, isForwardRefCall, isFunctionOfComponentDidMount, isFunctionOfComponentWillUnmount, isFunctionOfUseEffectCleanup, isFunctionOfUseEffectSetup, isGetChildContext, isGetDefaultProps, isGetDerivedStateFromError, isGetDerivedStateFromProps, isGetInitialState, isGetSnapshotBeforeUpdate, isInitializedFromReact,
|
|
806
|
+
export { ClassComponent, Component, ComponentDetectionHint, ComponentEffectPhaseKind, ComponentFlag, ComponentKind, ComponentLifecyclePhaseKind, ComponentPhaseKind, ComponentPhaseRelevance, DEFAULT_COMPONENT_DETECTION_HINT, DEFAULT_JSX_DETECTION_HINT, FunctionComponent, Hook, JsxAttributeValue, JsxConfig, JsxDetectionHint, JsxEmit, REACT_BUILTIN_HOOK_NAMES, SemanticEntry, SemanticNode, findParentJsxAttribute, getComponentFlagFromInitPath, getComponentNameFromId, getFunctionComponentId, getInstanceId, getJsxAttribute, getJsxAttributeName, getJsxConfigFromAnnotation, getJsxConfigFromContext, getJsxElementType, getPhaseKindOfFunction, hasNoneOrLooseComponentName, isAssignmentToThisState, isCaptureOwnerStack, isCaptureOwnerStackCall, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCloneElement, isCloneElementCall, isComponentDefinition, isComponentDidCatch, isComponentDidMount, isComponentDidUpdate, isComponentName, isComponentNameLoose, isComponentWillMount, isComponentWillReceiveProps, isComponentWillUnmount, isComponentWillUpdate, isComponentWrapperCall, isComponentWrapperCallLoose, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRef, isForwardRefCall, isFunctionOfComponentDidMount, isFunctionOfComponentWillUnmount, isFunctionOfUseEffectCleanup, isFunctionOfUseEffectSetup, isGetChildContext, isGetDefaultProps, isGetDerivedStateFromError, isGetDerivedStateFromProps, isGetInitialState, isGetSnapshotBeforeUpdate, isInitializedFromReact, isInitializedFromReactNative, isInstanceIdEqual, isInversePhase, isJsxFragmentElement, isJsxHostElement, isJsxLike, isJsxText, isLazy, isLazyCall, isMemo, isMemoCall, isPureComponent, isReactAPI, isReactAPICall, isReactHook, isReactHookCall, isReactHookCallWithName, isReactHookCallWithNameAlias, isReactHookId, isReactHookName, isRender, isRenderFunctionLoose, isRenderMethodLike, isRenderPropLoose, isShouldComponentUpdate, isThisSetState, isUnsafeComponentWillMount, isUnsafeComponentWillReceiveProps, isUnsafeComponentWillUpdate, isUseActionStateCall, isUseCall, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectLikeCall, isUseFormStatusCall, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseOptimisticCall, isUseReducerCall, isUseRefCall, isUseStateCall, isUseSyncExternalStoreCall, isUseTransitionCall, resolveJsxAttributeValue, stringifyJsx, useComponentCollector, useComponentCollectorLegacy, useHookCollector };
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import * as AST from "@eslint-react/ast";
|
|
|
2
2
|
import { constFalse, constTrue, dual, flip, getOrElseUpdate, identity, unit } from "@eslint-react/eff";
|
|
3
3
|
import { IdGenerator, 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";
|
|
4
4
|
import { AST_NODE_TYPES } from "@typescript-eslint/types";
|
|
5
|
-
import { findProperty, findVariable, getVariableDefinitionNode, isNodeValueEqual } from "@eslint-react/var";
|
|
5
|
+
import { findImportSource, findProperty, findVariable, getVariableDefinitionNode, isNodeValueEqual } from "@eslint-react/var";
|
|
6
6
|
import { getStaticValue } from "@typescript-eslint/utils/ast-utils";
|
|
7
7
|
import { P, isMatching, match } from "ts-pattern";
|
|
8
8
|
import { AST_NODE_TYPES as AST_NODE_TYPES$1 } from "@typescript-eslint/utils";
|
|
@@ -585,59 +585,33 @@ function getInstanceId(node, prev) {
|
|
|
585
585
|
}
|
|
586
586
|
|
|
587
587
|
//#endregion
|
|
588
|
-
//#region src/utils/is-from-
|
|
589
|
-
/**
|
|
590
|
-
* Get the arguments of a require expression
|
|
591
|
-
* @param node The node to match
|
|
592
|
-
* @returns The require expression arguments or undefined if the node is not a require expression
|
|
593
|
-
*/
|
|
594
|
-
function getRequireExpressionArguments(node) {
|
|
595
|
-
return match(node).with({
|
|
596
|
-
type: AST_NODE_TYPES.CallExpression,
|
|
597
|
-
arguments: P.select(),
|
|
598
|
-
callee: {
|
|
599
|
-
type: AST_NODE_TYPES.Identifier,
|
|
600
|
-
name: "require"
|
|
601
|
-
}
|
|
602
|
-
}, identity).with({
|
|
603
|
-
type: AST_NODE_TYPES.MemberExpression,
|
|
604
|
-
object: P.select()
|
|
605
|
-
}, getRequireExpressionArguments).otherwise(() => null);
|
|
606
|
-
}
|
|
588
|
+
//#region src/utils/is-from-react.ts
|
|
607
589
|
/**
|
|
608
|
-
*
|
|
609
|
-
* @param name The
|
|
610
|
-
* @param
|
|
611
|
-
* @param
|
|
612
|
-
* @returns
|
|
613
|
-
* @internal
|
|
590
|
+
* Checks if a variable is initialized from React import
|
|
591
|
+
* @param name The variable name
|
|
592
|
+
* @param initialScope The initial scope
|
|
593
|
+
* @param importSource Alternative import source of React (e.g., "preact/compat")
|
|
594
|
+
* @returns True if the variable is initialized from React import
|
|
614
595
|
*/
|
|
615
|
-
function
|
|
616
|
-
|
|
617
|
-
if (latestDef == null) return false;
|
|
618
|
-
const { node, parent } = latestDef;
|
|
619
|
-
if (node.type === AST_NODE_TYPES.VariableDeclarator && node.init != null) {
|
|
620
|
-
const { init } = node;
|
|
621
|
-
if (init.type === AST_NODE_TYPES.MemberExpression && init.object.type === AST_NODE_TYPES.Identifier) return isInitializedFromSource(init.object.name, source, initialScope);
|
|
622
|
-
if (init.type === AST_NODE_TYPES.Identifier) return isInitializedFromSource(init.name, source, initialScope);
|
|
623
|
-
const arg0 = getRequireExpressionArguments(init)?.[0];
|
|
624
|
-
if (arg0 == null || !AST.isLiteral(arg0, "string")) return false;
|
|
625
|
-
return arg0.value === source || arg0.value.startsWith(`${source}/`);
|
|
626
|
-
}
|
|
627
|
-
return parent?.type === AST_NODE_TYPES.ImportDeclaration && parent.source.value === source;
|
|
596
|
+
function isInitializedFromReact(name, initialScope, importSource = "react") {
|
|
597
|
+
return name.toLowerCase() === "react" || Boolean(findImportSource(name, initialScope)?.startsWith(importSource));
|
|
628
598
|
}
|
|
629
599
|
|
|
630
600
|
//#endregion
|
|
631
|
-
//#region src/utils/is-from-react.ts
|
|
601
|
+
//#region src/utils/is-from-react-native.ts
|
|
632
602
|
/**
|
|
633
|
-
*
|
|
634
|
-
* @param name The
|
|
635
|
-
* @param
|
|
636
|
-
* @param
|
|
637
|
-
* @returns
|
|
603
|
+
* Checks if a variable is initialized from React Native import
|
|
604
|
+
* @param name The variable name
|
|
605
|
+
* @param initialScope The initial scope
|
|
606
|
+
* @param importSource Alternative import source of React Native (e.g., "react-native-web")
|
|
607
|
+
* @returns True if the variable is initialized from React Native import
|
|
638
608
|
*/
|
|
639
|
-
function
|
|
640
|
-
return
|
|
609
|
+
function isInitializedFromReactNative(name, initialScope, importSource = "react-native") {
|
|
610
|
+
return [
|
|
611
|
+
"react_native",
|
|
612
|
+
"reactnative",
|
|
613
|
+
"rn"
|
|
614
|
+
].includes(name.toLowerCase()) || Boolean(findImportSource(name, initialScope)?.startsWith(importSource));
|
|
641
615
|
}
|
|
642
616
|
|
|
643
617
|
//#endregion
|
|
@@ -1245,4 +1219,4 @@ function isDeclaredInRenderPropLoose(node) {
|
|
|
1245
1219
|
}
|
|
1246
1220
|
|
|
1247
1221
|
//#endregion
|
|
1248
|
-
export { ComponentDetectionHint, ComponentFlag, ComponentPhaseRelevance, DEFAULT_COMPONENT_DETECTION_HINT, DEFAULT_JSX_DETECTION_HINT, JsxDetectionHint, JsxEmit, REACT_BUILTIN_HOOK_NAMES, findParentJsxAttribute, getComponentFlagFromInitPath, getComponentNameFromId, getFunctionComponentId, getInstanceId, getJsxAttribute, getJsxAttributeName, getJsxConfigFromAnnotation, getJsxConfigFromContext, getJsxElementType, getPhaseKindOfFunction, hasNoneOrLooseComponentName, isAssignmentToThisState, isCaptureOwnerStack, isCaptureOwnerStackCall, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCloneElement, isCloneElementCall, isComponentDefinition, isComponentDidCatch, isComponentDidMount, isComponentDidUpdate, isComponentName, isComponentNameLoose, isComponentWillMount, isComponentWillReceiveProps, isComponentWillUnmount, isComponentWillUpdate, isComponentWrapperCall, isComponentWrapperCallLoose, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRef, isForwardRefCall, isFunctionOfComponentDidMount, isFunctionOfComponentWillUnmount, isFunctionOfUseEffectCleanup, isFunctionOfUseEffectSetup, isGetChildContext, isGetDefaultProps, isGetDerivedStateFromError, isGetDerivedStateFromProps, isGetInitialState, isGetSnapshotBeforeUpdate, isInitializedFromReact,
|
|
1222
|
+
export { ComponentDetectionHint, ComponentFlag, ComponentPhaseRelevance, DEFAULT_COMPONENT_DETECTION_HINT, DEFAULT_JSX_DETECTION_HINT, JsxDetectionHint, JsxEmit, REACT_BUILTIN_HOOK_NAMES, findParentJsxAttribute, getComponentFlagFromInitPath, getComponentNameFromId, getFunctionComponentId, getInstanceId, getJsxAttribute, getJsxAttributeName, getJsxConfigFromAnnotation, getJsxConfigFromContext, getJsxElementType, getPhaseKindOfFunction, hasNoneOrLooseComponentName, isAssignmentToThisState, isCaptureOwnerStack, isCaptureOwnerStackCall, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCloneElement, isCloneElementCall, isComponentDefinition, isComponentDidCatch, isComponentDidMount, isComponentDidUpdate, isComponentName, isComponentNameLoose, isComponentWillMount, isComponentWillReceiveProps, isComponentWillUnmount, isComponentWillUpdate, isComponentWrapperCall, isComponentWrapperCallLoose, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRef, isForwardRefCall, isFunctionOfComponentDidMount, isFunctionOfComponentWillUnmount, isFunctionOfUseEffectCleanup, isFunctionOfUseEffectSetup, isGetChildContext, isGetDefaultProps, isGetDerivedStateFromError, isGetDerivedStateFromProps, isGetInitialState, isGetSnapshotBeforeUpdate, isInitializedFromReact, isInitializedFromReactNative, isInstanceIdEqual, isInversePhase, isJsxFragmentElement, isJsxHostElement, isJsxLike, isJsxText, isLazy, isLazyCall, isMemo, isMemoCall, isPureComponent, isReactAPI, isReactAPICall, isReactHook, isReactHookCall, isReactHookCallWithName, isReactHookCallWithNameAlias, isReactHookId, isReactHookName, isRender, isRenderFunctionLoose, isRenderMethodLike, isRenderPropLoose, isShouldComponentUpdate, isThisSetState, isUnsafeComponentWillMount, isUnsafeComponentWillReceiveProps, isUnsafeComponentWillUpdate, isUseActionStateCall, isUseCall, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectLikeCall, isUseFormStatusCall, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseOptimisticCall, isUseReducerCall, isUseRefCall, isUseStateCall, isUseSyncExternalStoreCall, isUseTransitionCall, resolveJsxAttributeValue, stringifyJsx, useComponentCollector, useComponentCollectorLegacy, useHookCollector };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/core",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.1-beta.0",
|
|
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": {
|
|
@@ -30,18 +30,18 @@
|
|
|
30
30
|
"./package.json"
|
|
31
31
|
],
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@typescript-eslint/scope-manager": "^8.50.
|
|
34
|
-
"@typescript-eslint/types": "^8.50.
|
|
35
|
-
"@typescript-eslint/utils": "^8.50.
|
|
33
|
+
"@typescript-eslint/scope-manager": "^8.50.1",
|
|
34
|
+
"@typescript-eslint/types": "^8.50.1",
|
|
35
|
+
"@typescript-eslint/utils": "^8.50.1",
|
|
36
36
|
"birecord": "^0.1.1",
|
|
37
37
|
"ts-pattern": "^5.9.0",
|
|
38
|
-
"@eslint-react/
|
|
39
|
-
"@eslint-react/
|
|
40
|
-
"@eslint-react/
|
|
41
|
-
"@eslint-react/
|
|
38
|
+
"@eslint-react/ast": "2.4.1-beta.0",
|
|
39
|
+
"@eslint-react/shared": "2.4.1-beta.0",
|
|
40
|
+
"@eslint-react/var": "2.4.1-beta.0",
|
|
41
|
+
"@eslint-react/eff": "2.4.1-beta.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"tsdown": "^0.18.
|
|
44
|
+
"tsdown": "^0.18.2",
|
|
45
45
|
"@local/configs": "0.0.0"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|