@eslint-react/core 3.0.0-next.32 → 3.0.0-next.33
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 +62 -48
- package/dist/index.js +97 -97
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
|
@@ -108,19 +108,6 @@ declare const ComponentDetectionHint: {
|
|
|
108
108
|
* Default component detection hint
|
|
109
109
|
*/
|
|
110
110
|
declare const DEFAULT_COMPONENT_DETECTION_HINT: bigint;
|
|
111
|
-
/**
|
|
112
|
-
* Check whether given node is a render method of a class component
|
|
113
|
-
* @example
|
|
114
|
-
* ```tsx
|
|
115
|
-
* class Component extends React.Component {
|
|
116
|
-
* renderHeader = () => <div />;
|
|
117
|
-
* renderFooter = () => <div />;
|
|
118
|
-
* }
|
|
119
|
-
* ```
|
|
120
|
-
* @param node The AST node to check
|
|
121
|
-
* @returns `true` if node is a render function, `false` if not
|
|
122
|
-
*/
|
|
123
|
-
declare function isRenderMethodLike(node: TSESTree.Node): node is ast.TSESTreeMethodOrProperty;
|
|
124
111
|
/**
|
|
125
112
|
* Unsafe check whether given node is a render function
|
|
126
113
|
* ```tsx
|
|
@@ -359,18 +346,77 @@ declare namespace useComponentCollectorLegacy {
|
|
|
359
346
|
* @returns The ctx and visitor of the collector
|
|
360
347
|
*/
|
|
361
348
|
declare function useComponentCollectorLegacy(context: RuleContext): useComponentCollectorLegacy.ReturnType;
|
|
349
|
+
//#endregion
|
|
350
|
+
//#region src/component/component-detection-legacy.d.ts
|
|
351
|
+
declare const isRender: (node: TSESTree.Node) => node is ast.TSESTreeMethodOrProperty;
|
|
352
|
+
declare const isComponentDidCatch: (node: TSESTree.Node) => node is ast.TSESTreeMethodOrProperty;
|
|
353
|
+
declare const isComponentDidMount: (node: TSESTree.Node) => node is ast.TSESTreeMethodOrProperty;
|
|
354
|
+
declare const isComponentDidUpdate: (node: TSESTree.Node) => node is ast.TSESTreeMethodOrProperty;
|
|
355
|
+
declare const isComponentWillMount: (node: TSESTree.Node) => node is ast.TSESTreeMethodOrProperty;
|
|
356
|
+
declare const isComponentWillReceiveProps: (node: TSESTree.Node) => node is ast.TSESTreeMethodOrProperty;
|
|
357
|
+
declare const isComponentWillUnmount: (node: TSESTree.Node) => node is ast.TSESTreeMethodOrProperty;
|
|
358
|
+
declare const isComponentWillUpdate: (node: TSESTree.Node) => node is ast.TSESTreeMethodOrProperty;
|
|
359
|
+
declare const isGetChildContext: (node: TSESTree.Node) => node is ast.TSESTreeMethodOrProperty;
|
|
360
|
+
declare const isGetInitialState: (node: TSESTree.Node) => node is ast.TSESTreeMethodOrProperty;
|
|
361
|
+
declare const isGetSnapshotBeforeUpdate: (node: TSESTree.Node) => node is ast.TSESTreeMethodOrProperty;
|
|
362
|
+
declare const isShouldComponentUpdate: (node: TSESTree.Node) => node is ast.TSESTreeMethodOrProperty;
|
|
363
|
+
declare const isUnsafeComponentWillMount: (node: TSESTree.Node) => node is ast.TSESTreeMethodOrProperty;
|
|
364
|
+
declare const isUnsafeComponentWillReceiveProps: (node: TSESTree.Node) => node is ast.TSESTreeMethodOrProperty;
|
|
365
|
+
declare const isUnsafeComponentWillUpdate: (node: TSESTree.Node) => node is ast.TSESTreeMethodOrProperty;
|
|
366
|
+
declare const isGetDefaultProps: (node: TSESTree.Node) => node is ast.TSESTreeMethodOrProperty;
|
|
367
|
+
declare const isGetDerivedStateFromProps: (node: TSESTree.Node) => node is ast.TSESTreeMethodOrProperty;
|
|
368
|
+
declare const isGetDerivedStateFromError: (node: TSESTree.Node) => node is ast.TSESTreeMethodOrProperty;
|
|
369
|
+
/**
|
|
370
|
+
* Check if the given node is a componentDidMount callback
|
|
371
|
+
* @param node The node to check
|
|
372
|
+
* @returns True if the node is a componentDidMount callback, false otherwise
|
|
373
|
+
*/
|
|
374
|
+
declare function isComponentDidMountCallback(node: TSESTree.Node): boolean;
|
|
375
|
+
/**
|
|
376
|
+
* Check if the given node is a componentWillUnmount callback
|
|
377
|
+
* @param node The node to check
|
|
378
|
+
* @returns True if the node is a componentWillUnmount callback, false otherwise
|
|
379
|
+
*/
|
|
380
|
+
declare function isComponentWillUnmountCallback(node: TSESTree.Node): boolean;
|
|
381
|
+
/**
|
|
382
|
+
* Check whether given node is a render method of a class component
|
|
383
|
+
* @example
|
|
384
|
+
* ```tsx
|
|
385
|
+
* class Component extends React.Component {
|
|
386
|
+
* renderHeader = () => <div />;
|
|
387
|
+
* renderFooter = () => <div />;
|
|
388
|
+
* }
|
|
389
|
+
* ```
|
|
390
|
+
* @param node The AST node to check
|
|
391
|
+
* @returns `true` if node is a render function, `false` if not
|
|
392
|
+
*/
|
|
393
|
+
declare function isRenderMethodLike(node: TSESTree.Node): node is ast.TSESTreeMethodOrProperty;
|
|
394
|
+
/**
|
|
395
|
+
* Check if the given node is a function within a render method of a class component
|
|
396
|
+
*
|
|
397
|
+
* @param node The AST node to check
|
|
398
|
+
* @returns `true` if the node is a render function inside a class component
|
|
399
|
+
*
|
|
400
|
+
* @example
|
|
401
|
+
* ```tsx
|
|
402
|
+
* class Component extends React.Component {
|
|
403
|
+
* renderHeader = () => <div />; // Returns true
|
|
404
|
+
* }
|
|
405
|
+
* ```
|
|
406
|
+
*/
|
|
407
|
+
declare function isRenderMethodCallback(node: ast.TSESTreeFunction): boolean;
|
|
362
408
|
/**
|
|
363
409
|
* Check whether the given node is a this.setState() call
|
|
364
410
|
* @param node The node to check
|
|
365
411
|
* @internal
|
|
366
412
|
*/
|
|
367
|
-
declare function isThisSetState(node: TSESTree
|
|
413
|
+
declare function isThisSetState(node: TSESTree.CallExpression): boolean;
|
|
368
414
|
/**
|
|
369
415
|
* Check whether the given node is an assignment to this.state
|
|
370
416
|
* @param node The node to check
|
|
371
417
|
* @internal
|
|
372
418
|
*/
|
|
373
|
-
declare function isAssignmentToThisState(node: TSESTree
|
|
419
|
+
declare function isAssignmentToThisState(node: TSESTree.AssignmentExpression): boolean;
|
|
374
420
|
//#endregion
|
|
375
421
|
//#region src/component/component-flag.d.ts
|
|
376
422
|
/**
|
|
@@ -414,38 +460,6 @@ declare function isClassComponent(node: TSESTree.Node): node is ast.TSESTreeClas
|
|
|
414
460
|
*/
|
|
415
461
|
declare function isPureComponent(node: TSESTree.Node): boolean;
|
|
416
462
|
//#endregion
|
|
417
|
-
//#region src/component/component-method.d.ts
|
|
418
|
-
declare const isRender: (node: TSESTree.Node) => node is ast.TSESTreeMethodOrProperty;
|
|
419
|
-
declare const isComponentDidCatch: (node: TSESTree.Node) => node is ast.TSESTreeMethodOrProperty;
|
|
420
|
-
declare const isComponentDidMount: (node: TSESTree.Node) => node is ast.TSESTreeMethodOrProperty;
|
|
421
|
-
declare const isComponentDidUpdate: (node: TSESTree.Node) => node is ast.TSESTreeMethodOrProperty;
|
|
422
|
-
declare const isComponentWillMount: (node: TSESTree.Node) => node is ast.TSESTreeMethodOrProperty;
|
|
423
|
-
declare const isComponentWillReceiveProps: (node: TSESTree.Node) => node is ast.TSESTreeMethodOrProperty;
|
|
424
|
-
declare const isComponentWillUnmount: (node: TSESTree.Node) => node is ast.TSESTreeMethodOrProperty;
|
|
425
|
-
declare const isComponentWillUpdate: (node: TSESTree.Node) => node is ast.TSESTreeMethodOrProperty;
|
|
426
|
-
declare const isGetChildContext: (node: TSESTree.Node) => node is ast.TSESTreeMethodOrProperty;
|
|
427
|
-
declare const isGetInitialState: (node: TSESTree.Node) => node is ast.TSESTreeMethodOrProperty;
|
|
428
|
-
declare const isGetSnapshotBeforeUpdate: (node: TSESTree.Node) => node is ast.TSESTreeMethodOrProperty;
|
|
429
|
-
declare const isShouldComponentUpdate: (node: TSESTree.Node) => node is ast.TSESTreeMethodOrProperty;
|
|
430
|
-
declare const isUnsafeComponentWillMount: (node: TSESTree.Node) => node is ast.TSESTreeMethodOrProperty;
|
|
431
|
-
declare const isUnsafeComponentWillReceiveProps: (node: TSESTree.Node) => node is ast.TSESTreeMethodOrProperty;
|
|
432
|
-
declare const isUnsafeComponentWillUpdate: (node: TSESTree.Node) => node is ast.TSESTreeMethodOrProperty;
|
|
433
|
-
declare const isGetDefaultProps: (node: TSESTree.Node) => node is ast.TSESTreeMethodOrProperty;
|
|
434
|
-
declare const isGetDerivedStateFromProps: (node: TSESTree.Node) => node is ast.TSESTreeMethodOrProperty;
|
|
435
|
-
declare const isGetDerivedStateFromError: (node: TSESTree.Node) => node is ast.TSESTreeMethodOrProperty;
|
|
436
|
-
/**
|
|
437
|
-
* Check if the given node is a componentDidMount callback
|
|
438
|
-
* @param node The node to check
|
|
439
|
-
* @returns True if the node is a componentDidMount callback, false otherwise
|
|
440
|
-
*/
|
|
441
|
-
declare function isComponentDidMountCallback(node: TSESTree.Node): boolean;
|
|
442
|
-
/**
|
|
443
|
-
* Check if the given node is a componentWillUnmount callback
|
|
444
|
-
* @param node The node to check
|
|
445
|
-
* @returns True if the node is a componentWillUnmount callback, false otherwise
|
|
446
|
-
*/
|
|
447
|
-
declare function isComponentWillUnmountCallback(node: TSESTree.Node): boolean;
|
|
448
|
-
//#endregion
|
|
449
463
|
//#region src/component/component-name.d.ts
|
|
450
464
|
/**
|
|
451
465
|
* Check if a string matches the strict component name pattern
|
|
@@ -906,4 +920,4 @@ declare function getRefInit(name: string, initialScope: Scope): TSESTree$1.Expre
|
|
|
906
920
|
*/
|
|
907
921
|
declare function isRefLikeName(name: string): boolean;
|
|
908
922
|
//#endregion
|
|
909
|
-
export { ClassComponentSemanticNode, ClientFunctionSemanticNode, ComponentDetectionHint, ComponentFlag, ComponentKind, ComponentSemanticNode, DEFAULT_COMPONENT_DETECTION_HINT, DEFAULT_JSX_DETECTION_HINT, FindEnclosingComponentOrHookFilter, FunctionComponentSemanticNode, FunctionKind, FunctionSemanticNode, HookSemanticNode, JsxAttributeValue, JsxConfig, JsxDetectionHint, JsxEmit, REACT_BUILTIN_HOOK_NAMES, SemanticFunc, SemanticNode, ServerFunctionSemanticNode, findEnclosingComponentOrHook, findParentJsxAttribute, getComponentFlagFromInitPath, getFunctionComponentId, getJsxAttribute, getJsxAttributeName, getJsxConfigFromAnnotation, getJsxConfigFromContext, getJsxElementType, getRefInit, isAssignmentToThisState, isCaptureOwnerStack, isCaptureOwnerStackCall, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCloneElement, isCloneElementCall, isComponentDefinition, isComponentDidCatch, isComponentDidMount, isComponentDidMountCallback, isComponentDidUpdate, isComponentName, isComponentNameLoose, isComponentWillMount, isComponentWillReceiveProps, isComponentWillUnmount, isComponentWillUnmountCallback, isComponentWillUpdate, isComponentWrapperCall, isComponentWrapperCallLoose, isComponentWrapperCallback, isComponentWrapperCallbackLoose, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRef, isForwardRefCall, isFunctionWithLooseComponentName, isGetChildContext, isGetDefaultProps, isGetDerivedStateFromError, isGetDerivedStateFromProps, isGetInitialState, isGetSnapshotBeforeUpdate, isHook, isHookCall, isHookCallWithName, isHookId, isHookName, isInitializedFromReact, isInitializedFromReactNative, isInitializedFromRef, isInsideComponentOrHook, isJsxFragmentElement, isJsxHostElement, isJsxLike, isJsxText, isLazy, isLazyCall, isMemo, isMemoCall, isPureComponent, isReactAPI, isReactAPICall, isRefId, isRefLikeName, isRender, isRenderFunctionLoose, isRenderMethodLike, isRenderPropLoose, isShouldComponentUpdate, isThisSetState, isUnsafeComponentWillMount, isUnsafeComponentWillReceiveProps, isUnsafeComponentWillUpdate, isUseActionStateCall, isUseCall, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectCleanupCallback, isUseEffectLikeCall, isUseEffectSetupCallback, isUseFormStatusCall, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseOptimisticCall, isUseReducerCall, isUseRefCall, isUseStateCall, isUseStateLikeCall, isUseSyncExternalStoreCall, isUseTransitionCall, resolveJsxAttributeValue, stringifyJsx, useComponentCollector, useComponentCollectorLegacy, useHookCollector };
|
|
923
|
+
export { ClassComponentSemanticNode, ClientFunctionSemanticNode, ComponentDetectionHint, ComponentFlag, ComponentKind, ComponentSemanticNode, DEFAULT_COMPONENT_DETECTION_HINT, DEFAULT_JSX_DETECTION_HINT, FindEnclosingComponentOrHookFilter, FunctionComponentSemanticNode, FunctionKind, FunctionSemanticNode, HookSemanticNode, JsxAttributeValue, JsxConfig, JsxDetectionHint, JsxEmit, REACT_BUILTIN_HOOK_NAMES, SemanticFunc, SemanticNode, ServerFunctionSemanticNode, findEnclosingComponentOrHook, findParentJsxAttribute, getComponentFlagFromInitPath, getFunctionComponentId, getJsxAttribute, getJsxAttributeName, getJsxConfigFromAnnotation, getJsxConfigFromContext, getJsxElementType, getRefInit, isAssignmentToThisState, isCaptureOwnerStack, isCaptureOwnerStackCall, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCloneElement, isCloneElementCall, isComponentDefinition, isComponentDidCatch, isComponentDidMount, isComponentDidMountCallback, isComponentDidUpdate, isComponentName, isComponentNameLoose, isComponentWillMount, isComponentWillReceiveProps, isComponentWillUnmount, isComponentWillUnmountCallback, isComponentWillUpdate, isComponentWrapperCall, isComponentWrapperCallLoose, isComponentWrapperCallback, isComponentWrapperCallbackLoose, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRef, isForwardRefCall, isFunctionWithLooseComponentName, isGetChildContext, isGetDefaultProps, isGetDerivedStateFromError, isGetDerivedStateFromProps, isGetInitialState, isGetSnapshotBeforeUpdate, isHook, isHookCall, isHookCallWithName, isHookId, isHookName, isInitializedFromReact, isInitializedFromReactNative, isInitializedFromRef, isInsideComponentOrHook, isJsxFragmentElement, isJsxHostElement, isJsxLike, isJsxText, isLazy, isLazyCall, isMemo, isMemoCall, isPureComponent, isReactAPI, isReactAPICall, isRefId, isRefLikeName, isRender, isRenderFunctionLoose, isRenderMethodCallback, isRenderMethodLike, isRenderPropLoose, isShouldComponentUpdate, isThisSetState, isUnsafeComponentWillMount, isUnsafeComponentWillReceiveProps, isUnsafeComponentWillUpdate, isUseActionStateCall, isUseCall, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectCleanupCallback, isUseEffectLikeCall, isUseEffectSetupCallback, isUseFormStatusCall, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseOptimisticCall, isUseReducerCall, isUseRefCall, isUseStateCall, isUseStateLikeCall, isUseSyncExternalStoreCall, isUseTransitionCall, resolveJsxAttributeValue, stringifyJsx, useComponentCollector, useComponentCollectorLegacy, useHookCollector };
|
package/dist/index.js
CHANGED
|
@@ -698,6 +698,102 @@ function isPureComponent(node) {
|
|
|
698
698
|
return false;
|
|
699
699
|
}
|
|
700
700
|
|
|
701
|
+
//#endregion
|
|
702
|
+
//#region src/component/component-detection-legacy.ts
|
|
703
|
+
/**
|
|
704
|
+
* Create a lifecycle method checker function
|
|
705
|
+
* @param methodName The lifecycle method name
|
|
706
|
+
* @param isStatic Whether the method is static
|
|
707
|
+
*/
|
|
708
|
+
function createLifecycleChecker(methodName, isStatic = false) {
|
|
709
|
+
return (node) => ast.isMethodOrProperty(node) && node.static === isStatic && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === methodName;
|
|
710
|
+
}
|
|
711
|
+
const isRender = createLifecycleChecker("render");
|
|
712
|
+
const isComponentDidCatch = createLifecycleChecker("componentDidCatch");
|
|
713
|
+
const isComponentDidMount = createLifecycleChecker("componentDidMount");
|
|
714
|
+
const isComponentDidUpdate = createLifecycleChecker("componentDidUpdate");
|
|
715
|
+
const isComponentWillMount = createLifecycleChecker("componentWillMount");
|
|
716
|
+
const isComponentWillReceiveProps = createLifecycleChecker("componentWillReceiveProps");
|
|
717
|
+
const isComponentWillUnmount = createLifecycleChecker("componentWillUnmount");
|
|
718
|
+
const isComponentWillUpdate = createLifecycleChecker("componentWillUpdate");
|
|
719
|
+
const isGetChildContext = createLifecycleChecker("getChildContext");
|
|
720
|
+
const isGetInitialState = createLifecycleChecker("getInitialState");
|
|
721
|
+
const isGetSnapshotBeforeUpdate = createLifecycleChecker("getSnapshotBeforeUpdate");
|
|
722
|
+
const isShouldComponentUpdate = createLifecycleChecker("shouldComponentUpdate");
|
|
723
|
+
const isUnsafeComponentWillMount = createLifecycleChecker("UNSAFE_componentWillMount");
|
|
724
|
+
const isUnsafeComponentWillReceiveProps = createLifecycleChecker("UNSAFE_componentWillReceiveProps");
|
|
725
|
+
const isUnsafeComponentWillUpdate = createLifecycleChecker("UNSAFE_componentWillUpdate");
|
|
726
|
+
const isGetDefaultProps = createLifecycleChecker("getDefaultProps", true);
|
|
727
|
+
const isGetDerivedStateFromProps = createLifecycleChecker("getDerivedStateFromProps", true);
|
|
728
|
+
const isGetDerivedStateFromError = createLifecycleChecker("getDerivedStateFromError", true);
|
|
729
|
+
/**
|
|
730
|
+
* Check if the given node is a componentDidMount callback
|
|
731
|
+
* @param node The node to check
|
|
732
|
+
* @returns True if the node is a componentDidMount callback, false otherwise
|
|
733
|
+
*/
|
|
734
|
+
function isComponentDidMountCallback(node) {
|
|
735
|
+
return ast.isFunction(node) && isComponentDidMount(node.parent) && node.parent.value === node;
|
|
736
|
+
}
|
|
737
|
+
/**
|
|
738
|
+
* Check if the given node is a componentWillUnmount callback
|
|
739
|
+
* @param node The node to check
|
|
740
|
+
* @returns True if the node is a componentWillUnmount callback, false otherwise
|
|
741
|
+
*/
|
|
742
|
+
function isComponentWillUnmountCallback(node) {
|
|
743
|
+
return ast.isFunction(node) && isComponentWillUnmount(node.parent) && node.parent.value === node;
|
|
744
|
+
}
|
|
745
|
+
/**
|
|
746
|
+
* Check whether given node is a render method of a class component
|
|
747
|
+
* @example
|
|
748
|
+
* ```tsx
|
|
749
|
+
* class Component extends React.Component {
|
|
750
|
+
* renderHeader = () => <div />;
|
|
751
|
+
* renderFooter = () => <div />;
|
|
752
|
+
* }
|
|
753
|
+
* ```
|
|
754
|
+
* @param node The AST node to check
|
|
755
|
+
* @returns `true` if node is a render function, `false` if not
|
|
756
|
+
*/
|
|
757
|
+
function isRenderMethodLike(node) {
|
|
758
|
+
return ast.isMethodOrProperty(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name.startsWith("render") && node.parent.parent.type === AST_NODE_TYPES.ClassDeclaration;
|
|
759
|
+
}
|
|
760
|
+
/**
|
|
761
|
+
* Check if the given node is a function within a render method of a class component
|
|
762
|
+
*
|
|
763
|
+
* @param node The AST node to check
|
|
764
|
+
* @returns `true` if the node is a render function inside a class component
|
|
765
|
+
*
|
|
766
|
+
* @example
|
|
767
|
+
* ```tsx
|
|
768
|
+
* class Component extends React.Component {
|
|
769
|
+
* renderHeader = () => <div />; // Returns true
|
|
770
|
+
* }
|
|
771
|
+
* ```
|
|
772
|
+
*/
|
|
773
|
+
function isRenderMethodCallback(node) {
|
|
774
|
+
const parent = node.parent;
|
|
775
|
+
const greatGrandparent = parent.parent?.parent;
|
|
776
|
+
return greatGrandparent != null && isRenderMethodLike(parent) && isClassComponent(greatGrandparent);
|
|
777
|
+
}
|
|
778
|
+
/**
|
|
779
|
+
* Check whether the given node is a this.setState() call
|
|
780
|
+
* @param node The node to check
|
|
781
|
+
* @internal
|
|
782
|
+
*/
|
|
783
|
+
function isThisSetState(node) {
|
|
784
|
+
const { callee } = node;
|
|
785
|
+
return callee.type === AST_NODE_TYPES.MemberExpression && ast.isThisExpressionLoose(callee.object) && callee.property.type === AST_NODE_TYPES.Identifier && callee.property.name === "setState";
|
|
786
|
+
}
|
|
787
|
+
/**
|
|
788
|
+
* Check whether the given node is an assignment to this.state
|
|
789
|
+
* @param node The node to check
|
|
790
|
+
* @internal
|
|
791
|
+
*/
|
|
792
|
+
function isAssignmentToThisState(node) {
|
|
793
|
+
const { left } = node;
|
|
794
|
+
return left.type === AST_NODE_TYPES.MemberExpression && ast.isThisExpressionLoose(left.object) && ast.getPropertyName(left.property) === "state";
|
|
795
|
+
}
|
|
796
|
+
|
|
701
797
|
//#endregion
|
|
702
798
|
//#region src/component/component-wrapper.ts
|
|
703
799
|
/**
|
|
@@ -813,39 +909,6 @@ const ComponentDetectionHint = {
|
|
|
813
909
|
*/
|
|
814
910
|
const DEFAULT_COMPONENT_DETECTION_HINT = 0n | ComponentDetectionHint.DoNotIncludeJsxWithBigIntValue | ComponentDetectionHint.DoNotIncludeJsxWithBooleanValue | ComponentDetectionHint.DoNotIncludeJsxWithNumberValue | ComponentDetectionHint.DoNotIncludeJsxWithStringValue | ComponentDetectionHint.DoNotIncludeJsxWithUndefinedValue | ComponentDetectionHint.DoNotIncludeFunctionDefinedAsArrayFlatMapCallback | ComponentDetectionHint.DoNotIncludeFunctionDefinedAsArrayMapCallback | ComponentDetectionHint.DoNotIncludeFunctionDefinedInArrayExpression | ComponentDetectionHint.DoNotIncludeFunctionDefinedInArrayPattern | ComponentDetectionHint.RequireAllArrayElementsToBeJsx | ComponentDetectionHint.RequireBothBranchesOfConditionalExpressionToBeJsx | ComponentDetectionHint.RequireBothSidesOfLogicalExpressionToBeJsx;
|
|
815
911
|
/**
|
|
816
|
-
* Check whether given node is a render method of a class component
|
|
817
|
-
* @example
|
|
818
|
-
* ```tsx
|
|
819
|
-
* class Component extends React.Component {
|
|
820
|
-
* renderHeader = () => <div />;
|
|
821
|
-
* renderFooter = () => <div />;
|
|
822
|
-
* }
|
|
823
|
-
* ```
|
|
824
|
-
* @param node The AST node to check
|
|
825
|
-
* @returns `true` if node is a render function, `false` if not
|
|
826
|
-
*/
|
|
827
|
-
function isRenderMethodLike(node) {
|
|
828
|
-
return ast.isMethodOrProperty(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name.startsWith("render") && node.parent.parent.type === AST_NODE_TYPES.ClassDeclaration;
|
|
829
|
-
}
|
|
830
|
-
/**
|
|
831
|
-
* Check if the given node is a function within a render method of a class component
|
|
832
|
-
*
|
|
833
|
-
* @param node The AST node to check
|
|
834
|
-
* @returns `true` if the node is a render function inside a class component
|
|
835
|
-
*
|
|
836
|
-
* @example
|
|
837
|
-
* ```tsx
|
|
838
|
-
* class Component extends React.Component {
|
|
839
|
-
* renderHeader = () => <div />; // Returns true
|
|
840
|
-
* }
|
|
841
|
-
* ```
|
|
842
|
-
*/
|
|
843
|
-
function isRenderMethodCallback(node) {
|
|
844
|
-
const parent = node.parent;
|
|
845
|
-
const greatGrandparent = parent.parent?.parent;
|
|
846
|
-
return greatGrandparent != null && isRenderMethodLike(parent) && isClassComponent(greatGrandparent);
|
|
847
|
-
}
|
|
848
|
-
/**
|
|
849
912
|
* Unsafe check whether given node is a render function
|
|
850
913
|
* ```tsx
|
|
851
914
|
* const renderRow = () => <div />
|
|
@@ -1136,69 +1199,6 @@ function useComponentCollectorLegacy(context) {
|
|
|
1136
1199
|
}
|
|
1137
1200
|
};
|
|
1138
1201
|
}
|
|
1139
|
-
/**
|
|
1140
|
-
* Check whether the given node is a this.setState() call
|
|
1141
|
-
* @param node The node to check
|
|
1142
|
-
* @internal
|
|
1143
|
-
*/
|
|
1144
|
-
function isThisSetState(node) {
|
|
1145
|
-
const { callee } = node;
|
|
1146
|
-
return callee.type === AST_NODE_TYPES$1.MemberExpression && ast.isThisExpressionLoose(callee.object) && callee.property.type === AST_NODE_TYPES$1.Identifier && callee.property.name === "setState";
|
|
1147
|
-
}
|
|
1148
|
-
/**
|
|
1149
|
-
* Check whether the given node is an assignment to this.state
|
|
1150
|
-
* @param node The node to check
|
|
1151
|
-
* @internal
|
|
1152
|
-
*/
|
|
1153
|
-
function isAssignmentToThisState(node) {
|
|
1154
|
-
const { left } = node;
|
|
1155
|
-
return left.type === AST_NODE_TYPES$1.MemberExpression && ast.isThisExpressionLoose(left.object) && ast.getPropertyName(left.property) === "state";
|
|
1156
|
-
}
|
|
1157
|
-
|
|
1158
|
-
//#endregion
|
|
1159
|
-
//#region src/component/component-method.ts
|
|
1160
|
-
/**
|
|
1161
|
-
* Create a lifecycle method checker function
|
|
1162
|
-
* @param methodName The lifecycle method name
|
|
1163
|
-
* @param isStatic Whether the method is static
|
|
1164
|
-
*/
|
|
1165
|
-
function createLifecycleChecker(methodName, isStatic = false) {
|
|
1166
|
-
return (node) => ast.isMethodOrProperty(node) && node.static === isStatic && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === methodName;
|
|
1167
|
-
}
|
|
1168
|
-
const isRender = createLifecycleChecker("render");
|
|
1169
|
-
const isComponentDidCatch = createLifecycleChecker("componentDidCatch");
|
|
1170
|
-
const isComponentDidMount = createLifecycleChecker("componentDidMount");
|
|
1171
|
-
const isComponentDidUpdate = createLifecycleChecker("componentDidUpdate");
|
|
1172
|
-
const isComponentWillMount = createLifecycleChecker("componentWillMount");
|
|
1173
|
-
const isComponentWillReceiveProps = createLifecycleChecker("componentWillReceiveProps");
|
|
1174
|
-
const isComponentWillUnmount = createLifecycleChecker("componentWillUnmount");
|
|
1175
|
-
const isComponentWillUpdate = createLifecycleChecker("componentWillUpdate");
|
|
1176
|
-
const isGetChildContext = createLifecycleChecker("getChildContext");
|
|
1177
|
-
const isGetInitialState = createLifecycleChecker("getInitialState");
|
|
1178
|
-
const isGetSnapshotBeforeUpdate = createLifecycleChecker("getSnapshotBeforeUpdate");
|
|
1179
|
-
const isShouldComponentUpdate = createLifecycleChecker("shouldComponentUpdate");
|
|
1180
|
-
const isUnsafeComponentWillMount = createLifecycleChecker("UNSAFE_componentWillMount");
|
|
1181
|
-
const isUnsafeComponentWillReceiveProps = createLifecycleChecker("UNSAFE_componentWillReceiveProps");
|
|
1182
|
-
const isUnsafeComponentWillUpdate = createLifecycleChecker("UNSAFE_componentWillUpdate");
|
|
1183
|
-
const isGetDefaultProps = createLifecycleChecker("getDefaultProps", true);
|
|
1184
|
-
const isGetDerivedStateFromProps = createLifecycleChecker("getDerivedStateFromProps", true);
|
|
1185
|
-
const isGetDerivedStateFromError = createLifecycleChecker("getDerivedStateFromError", true);
|
|
1186
|
-
/**
|
|
1187
|
-
* Check if the given node is a componentDidMount callback
|
|
1188
|
-
* @param node The node to check
|
|
1189
|
-
* @returns True if the node is a componentDidMount callback, false otherwise
|
|
1190
|
-
*/
|
|
1191
|
-
function isComponentDidMountCallback(node) {
|
|
1192
|
-
return ast.isFunction(node) && isComponentDidMount(node.parent) && node.parent.value === node;
|
|
1193
|
-
}
|
|
1194
|
-
/**
|
|
1195
|
-
* Check if the given node is a componentWillUnmount callback
|
|
1196
|
-
* @param node The node to check
|
|
1197
|
-
* @returns True if the node is a componentWillUnmount callback, false otherwise
|
|
1198
|
-
*/
|
|
1199
|
-
function isComponentWillUnmountCallback(node) {
|
|
1200
|
-
return ast.isFunction(node) && isComponentWillUnmount(node.parent) && node.parent.value === node;
|
|
1201
|
-
}
|
|
1202
1202
|
|
|
1203
1203
|
//#endregion
|
|
1204
1204
|
//#region src/hierarchy/find-enclosing-component-or-hook.ts
|
|
@@ -1281,4 +1281,4 @@ function getRefInit(name, initialScope) {
|
|
|
1281
1281
|
}
|
|
1282
1282
|
|
|
1283
1283
|
//#endregion
|
|
1284
|
-
export { ComponentDetectionHint, ComponentFlag, DEFAULT_COMPONENT_DETECTION_HINT, DEFAULT_JSX_DETECTION_HINT, JsxDetectionHint, JsxEmit, REACT_BUILTIN_HOOK_NAMES, findEnclosingComponentOrHook, findParentJsxAttribute, getComponentFlagFromInitPath, getFunctionComponentId, getJsxAttribute, getJsxAttributeName, getJsxConfigFromAnnotation, getJsxConfigFromContext, getJsxElementType, getRefInit, isAssignmentToThisState, isCaptureOwnerStack, isCaptureOwnerStackCall, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCloneElement, isCloneElementCall, isComponentDefinition, isComponentDidCatch, isComponentDidMount, isComponentDidMountCallback, isComponentDidUpdate, isComponentName, isComponentNameLoose, isComponentWillMount, isComponentWillReceiveProps, isComponentWillUnmount, isComponentWillUnmountCallback, isComponentWillUpdate, isComponentWrapperCall, isComponentWrapperCallLoose, isComponentWrapperCallback, isComponentWrapperCallbackLoose, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRef, isForwardRefCall, isFunctionWithLooseComponentName, isGetChildContext, isGetDefaultProps, isGetDerivedStateFromError, isGetDerivedStateFromProps, isGetInitialState, isGetSnapshotBeforeUpdate, isHook, isHookCall, isHookCallWithName, isHookId, isHookName, isInitializedFromReact, isInitializedFromReactNative, isInitializedFromRef, isInsideComponentOrHook, isJsxFragmentElement, isJsxHostElement, isJsxLike, isJsxText, isLazy, isLazyCall, isMemo, isMemoCall, isPureComponent, isReactAPI, isReactAPICall, isRefId, isRefLikeName, isRender, isRenderFunctionLoose, isRenderMethodLike, isRenderPropLoose, isShouldComponentUpdate, isThisSetState, isUnsafeComponentWillMount, isUnsafeComponentWillReceiveProps, isUnsafeComponentWillUpdate, isUseActionStateCall, isUseCall, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectCleanupCallback, isUseEffectLikeCall, isUseEffectSetupCallback, isUseFormStatusCall, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseOptimisticCall, isUseReducerCall, isUseRefCall, isUseStateCall, isUseStateLikeCall, isUseSyncExternalStoreCall, isUseTransitionCall, resolveJsxAttributeValue, stringifyJsx, useComponentCollector, useComponentCollectorLegacy, useHookCollector };
|
|
1284
|
+
export { ComponentDetectionHint, ComponentFlag, DEFAULT_COMPONENT_DETECTION_HINT, DEFAULT_JSX_DETECTION_HINT, JsxDetectionHint, JsxEmit, REACT_BUILTIN_HOOK_NAMES, findEnclosingComponentOrHook, findParentJsxAttribute, getComponentFlagFromInitPath, getFunctionComponentId, getJsxAttribute, getJsxAttributeName, getJsxConfigFromAnnotation, getJsxConfigFromContext, getJsxElementType, getRefInit, isAssignmentToThisState, isCaptureOwnerStack, isCaptureOwnerStackCall, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCloneElement, isCloneElementCall, isComponentDefinition, isComponentDidCatch, isComponentDidMount, isComponentDidMountCallback, isComponentDidUpdate, isComponentName, isComponentNameLoose, isComponentWillMount, isComponentWillReceiveProps, isComponentWillUnmount, isComponentWillUnmountCallback, isComponentWillUpdate, isComponentWrapperCall, isComponentWrapperCallLoose, isComponentWrapperCallback, isComponentWrapperCallbackLoose, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRef, isForwardRefCall, isFunctionWithLooseComponentName, isGetChildContext, isGetDefaultProps, isGetDerivedStateFromError, isGetDerivedStateFromProps, isGetInitialState, isGetSnapshotBeforeUpdate, isHook, isHookCall, isHookCallWithName, isHookId, isHookName, isInitializedFromReact, isInitializedFromReactNative, isInitializedFromRef, isInsideComponentOrHook, isJsxFragmentElement, isJsxHostElement, isJsxLike, isJsxText, isLazy, isLazyCall, isMemo, isMemoCall, isPureComponent, isReactAPI, isReactAPICall, isRefId, isRefLikeName, isRender, isRenderFunctionLoose, isRenderMethodCallback, isRenderMethodLike, isRenderPropLoose, isShouldComponentUpdate, isThisSetState, isUnsafeComponentWillMount, isUnsafeComponentWillReceiveProps, isUnsafeComponentWillUpdate, isUseActionStateCall, isUseCall, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectCleanupCallback, isUseEffectLikeCall, isUseEffectSetupCallback, isUseFormStatusCall, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseOptimisticCall, isUseReducerCall, isUseRefCall, isUseStateCall, isUseStateLikeCall, 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": "3.0.0-next.
|
|
3
|
+
"version": "3.0.0-next.33",
|
|
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": {
|
|
@@ -34,10 +34,10 @@
|
|
|
34
34
|
"@typescript-eslint/types": "canary",
|
|
35
35
|
"@typescript-eslint/utils": "canary",
|
|
36
36
|
"ts-pattern": "^5.9.0",
|
|
37
|
-
"@eslint-react/ast": "3.0.0-next.
|
|
38
|
-
"@eslint-react/eff": "3.0.0-next.
|
|
39
|
-
"@eslint-react/
|
|
40
|
-
"@eslint-react/
|
|
37
|
+
"@eslint-react/ast": "3.0.0-next.33",
|
|
38
|
+
"@eslint-react/eff": "3.0.0-next.33",
|
|
39
|
+
"@eslint-react/shared": "3.0.0-next.33",
|
|
40
|
+
"@eslint-react/var": "3.0.0-next.33"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"tsdown": "^0.20.3",
|