@eslint-react/core 2.3.13-next.1 → 2.3.13-next.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 +37 -22
- package/dist/index.js +44 -24
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
|
@@ -220,13 +220,15 @@ declare namespace useComponentCollectorLegacy {
|
|
|
220
220
|
declare function useComponentCollectorLegacy(): useComponentCollectorLegacy.ReturnType;
|
|
221
221
|
/**
|
|
222
222
|
* Check whether the given node is a this.setState() call
|
|
223
|
-
* @param node
|
|
223
|
+
* @param node The node to check
|
|
224
|
+
* @param node
|
|
224
225
|
* @internal
|
|
225
226
|
*/
|
|
226
227
|
declare function isThisSetState(node: TSESTree$1.CallExpression): boolean;
|
|
227
228
|
/**
|
|
228
229
|
* Check whether the given node is an assignment to this.state
|
|
229
|
-
* @param node
|
|
230
|
+
* @param node The node to check
|
|
231
|
+
* @param node
|
|
230
232
|
* @internal
|
|
231
233
|
*/
|
|
232
234
|
declare function isAssignmentToThisState(node: TSESTree$1.AssignmentExpression): boolean;
|
|
@@ -235,9 +237,12 @@ declare function isAssignmentToThisState(node: TSESTree$1.AssignmentExpression):
|
|
|
235
237
|
/**
|
|
236
238
|
* Determines if a function node represents a valid React component definition
|
|
237
239
|
*
|
|
238
|
-
* @param context
|
|
239
|
-
* @param node
|
|
240
|
-
* @param hint
|
|
240
|
+
* @param context The rule context
|
|
241
|
+
* @param node The function node to analyze
|
|
242
|
+
* @param hint Component detection hints (bit flags) to customize detection logic
|
|
243
|
+
* @param context
|
|
244
|
+
* @param node
|
|
245
|
+
* @param hint
|
|
241
246
|
* @returns `true` if the node is considered a component definition
|
|
242
247
|
*/
|
|
243
248
|
declare function isComponentDefinition(context: RuleContext, node: AST.TSESTreeFunction, hint: bigint): boolean;
|
|
@@ -292,23 +297,23 @@ declare function isFunctionOfComponentWillUnmount(node: TSESTree.Node): boolean;
|
|
|
292
297
|
//#region src/component/component-name.d.ts
|
|
293
298
|
/**
|
|
294
299
|
* Check if a string matches the strict component name pattern
|
|
295
|
-
* @param name
|
|
300
|
+
* @param name The name to check
|
|
296
301
|
*/
|
|
297
302
|
declare function isComponentName(name: string): boolean;
|
|
298
303
|
/**
|
|
299
304
|
* Check if a string matches the loose component name pattern
|
|
300
|
-
* @param name
|
|
305
|
+
* @param name The name to check
|
|
301
306
|
*/
|
|
302
307
|
declare function isComponentNameLoose(name: string): boolean;
|
|
303
308
|
/**
|
|
304
309
|
* Get component name from an identifier or identifier sequence (e.g., MemberExpression)
|
|
305
|
-
* @param id
|
|
310
|
+
* @param id The identifier or identifier sequence
|
|
306
311
|
*/
|
|
307
312
|
declare function getComponentNameFromId(id: TSESTree.Identifier | TSESTree.Identifier[] | unit): string | undefined;
|
|
308
313
|
/**
|
|
309
314
|
* Check if the function has no name or a loose component name
|
|
310
|
-
* @param context
|
|
311
|
-
* @param fn
|
|
315
|
+
* @param context The rule context
|
|
316
|
+
* @param fn The function node
|
|
312
317
|
*/
|
|
313
318
|
declare function hasNoneOrLooseComponentName(context: RuleContext, fn: AST.TSESTreeFunction): boolean;
|
|
314
319
|
//#endregion
|
|
@@ -547,7 +552,7 @@ declare function resolveJsxAttributeValue(context: RuleContext, attribute: AST.T
|
|
|
547
552
|
readonly toStatic: () => string | number | bigint | boolean | RegExp | null;
|
|
548
553
|
} | {
|
|
549
554
|
readonly kind: "expression";
|
|
550
|
-
readonly node: TSESTree.
|
|
555
|
+
readonly node: TSESTree.JSXEmptyExpression | TSESTree.Expression;
|
|
551
556
|
readonly toStatic: () => unknown;
|
|
552
557
|
} | {
|
|
553
558
|
readonly kind: "element";
|
|
@@ -555,7 +560,7 @@ declare function resolveJsxAttributeValue(context: RuleContext, attribute: AST.T
|
|
|
555
560
|
readonly toStatic: () => undefined;
|
|
556
561
|
} | {
|
|
557
562
|
readonly kind: "spreadChild";
|
|
558
|
-
readonly node: TSESTree.
|
|
563
|
+
readonly node: TSESTree.JSXEmptyExpression | TSESTree.Expression;
|
|
559
564
|
readonly toStatic: () => undefined;
|
|
560
565
|
} | {
|
|
561
566
|
readonly kind: "spreadProps";
|
|
@@ -645,8 +650,8 @@ declare function isJsxLike(code: {
|
|
|
645
650
|
* Determines if a JSX element is a host element
|
|
646
651
|
* Host elements in React start with lowercase letters (e.g., div, span)
|
|
647
652
|
*
|
|
648
|
-
* @param context
|
|
649
|
-
* @param node
|
|
653
|
+
* @param context ESLint rule context
|
|
654
|
+
* @param node AST node to check
|
|
650
655
|
* @returns boolean indicating if the element is a host element
|
|
651
656
|
*/
|
|
652
657
|
declare function isJsxHostElement(context: RuleContext, node: TSESTree.Node): boolean;
|
|
@@ -654,8 +659,8 @@ declare function isJsxHostElement(context: RuleContext, node: TSESTree.Node): bo
|
|
|
654
659
|
* Determines if a JSX element is a React Fragment
|
|
655
660
|
* Fragments can be imported from React and used like <Fragment> or <React.Fragment>
|
|
656
661
|
*
|
|
657
|
-
* @param context
|
|
658
|
-
* @param node
|
|
662
|
+
* @param context ESLint rule context
|
|
663
|
+
* @param node AST node to check
|
|
659
664
|
* @returns boolean indicating if the element is a Fragment with type narrowing
|
|
660
665
|
*/
|
|
661
666
|
declare function isJsxFragmentElement(context: RuleContext, node: TSESTree.Node): node is TSESTree.JSXElement;
|
|
@@ -666,8 +671,8 @@ declare function isJsxFragmentElement(context: RuleContext, node: TSESTree.Node)
|
|
|
666
671
|
* For JSX elements, returns the stringified name (e.g., "div", "Button", "React.Fragment")
|
|
667
672
|
* For JSX fragments, returns an empty string
|
|
668
673
|
*
|
|
669
|
-
* @param context
|
|
670
|
-
* @param node
|
|
674
|
+
* @param context ESLint rule context
|
|
675
|
+
* @param node JSX element or fragment node
|
|
671
676
|
* @returns String representation of the element type
|
|
672
677
|
*/
|
|
673
678
|
declare function getJsxElementType(context: RuleContext, node: TSESTree.JSXElement | TSESTree.JSXFragment): string;
|
|
@@ -676,8 +681,8 @@ declare function getJsxElementType(context: RuleContext, node: TSESTree.JSXEleme
|
|
|
676
681
|
/**
|
|
677
682
|
* Traverses up the AST to find a parent JSX attribute node that matches a given test
|
|
678
683
|
*
|
|
679
|
-
* @param node
|
|
680
|
-
* @param test
|
|
684
|
+
* @param node The starting AST node
|
|
685
|
+
* @param test Optional predicate function to test if the attribute meets criteria
|
|
681
686
|
* Defaults to always returning true (matches any attribute)
|
|
682
687
|
* @returns The first matching JSX attribute node found when traversing upwards, or undefined
|
|
683
688
|
*/
|
|
@@ -687,7 +692,7 @@ declare function findParentJsxAttribute(node: TSESTree.Node, test?: (node: TSEST
|
|
|
687
692
|
/**
|
|
688
693
|
* Incomplete but sufficient stringification of JSX nodes for common use cases
|
|
689
694
|
*
|
|
690
|
-
* @param node
|
|
695
|
+
* @param node JSX node from TypeScript ESTree
|
|
691
696
|
* @returns String representation of the JSX node
|
|
692
697
|
*/
|
|
693
698
|
declare function stringifyJsx(node: TSESTree$1.JSXIdentifier | TSESTree$1.JSXNamespacedName | TSESTree$1.JSXMemberExpression | TSESTree$1.JSXOpeningElement | TSESTree$1.JSXClosingElement | TSESTree$1.JSXOpeningFragment | TSESTree$1.JSXClosingFragment | TSESTree$1.JSXText): string;
|
|
@@ -700,7 +705,7 @@ declare function stringifyJsx(node: TSESTree$1.JSXIdentifier | TSESTree$1.JSXNam
|
|
|
700
705
|
* @param prev The previous AST node in the traversal (used for context)
|
|
701
706
|
* @internal
|
|
702
707
|
*/
|
|
703
|
-
declare function getInstanceId(node: TSESTree.Node, prev?: TSESTree.Node): TSESTree.
|
|
708
|
+
declare function getInstanceId(node: TSESTree.Node, prev?: TSESTree.Node): TSESTree.ArrayExpression | TSESTree.ArrayPattern | TSESTree.ArrowFunctionExpression | TSESTree.AssignmentExpression | TSESTree.AwaitExpression | TSESTree.PrivateInExpression | TSESTree.SymmetricBinaryExpression | TSESTree.CallExpression | TSESTree.ChainExpression | TSESTree.ClassExpression | TSESTree.ConditionalExpression | TSESTree.FunctionExpression | TSESTree.Identifier | TSESTree.ImportExpression | TSESTree.JSXElement | TSESTree.JSXFragment | TSESTree.BigIntLiteral | TSESTree.BooleanLiteral | TSESTree.NullLiteral | TSESTree.NumberLiteral | TSESTree.RegExpLiteral | TSESTree.StringLiteral | TSESTree.LogicalExpression | TSESTree.MemberExpressionComputedName | TSESTree.MemberExpressionNonComputedName | TSESTree.MetaProperty | TSESTree.NewExpression | TSESTree.ObjectExpression | TSESTree.ObjectPattern | TSESTree.PrivateIdentifier | TSESTree.SequenceExpression | TSESTree.Super | TSESTree.TaggedTemplateExpression | TSESTree.TemplateLiteral | TSESTree.ThisExpression | TSESTree.TSAsExpression | TSESTree.TSInstantiationExpression | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion | TSESTree.UnaryExpressionBitwiseNot | TSESTree.UnaryExpressionDelete | TSESTree.UnaryExpressionMinus | TSESTree.UnaryExpressionNot | TSESTree.UnaryExpressionPlus | TSESTree.UnaryExpressionTypeof | TSESTree.UnaryExpressionVoid | TSESTree.UpdateExpression | TSESTree.YieldExpression | undefined;
|
|
704
709
|
//#endregion
|
|
705
710
|
//#region src/utils/is-from-react.d.ts
|
|
706
711
|
/**
|
|
@@ -734,6 +739,11 @@ declare namespace isReactAPI {
|
|
|
734
739
|
(context: RuleContext): (node: unit | null | TSESTree.Node) => node is TSESTree.MemberExpression | TSESTree.Identifier;
|
|
735
740
|
};
|
|
736
741
|
}
|
|
742
|
+
/**
|
|
743
|
+
* Checks if the node is a React API identifier or member expression
|
|
744
|
+
* @param api The React API name to check against (e.g., "useState", "React.memo")
|
|
745
|
+
* @returns A predicate function to check if a node matches the API
|
|
746
|
+
*/
|
|
737
747
|
declare function isReactAPI(api: string): isReactAPI.ReturnType;
|
|
738
748
|
declare namespace isReactAPICall {
|
|
739
749
|
type ReturnType = {
|
|
@@ -741,6 +751,11 @@ declare namespace isReactAPICall {
|
|
|
741
751
|
(context: RuleContext): (node: unit | null | TSESTree.Node) => node is TSESTree.CallExpression;
|
|
742
752
|
};
|
|
743
753
|
}
|
|
754
|
+
/**
|
|
755
|
+
* Checks if the node is a call expression to a specific React API
|
|
756
|
+
* @param api The React API name to check against
|
|
757
|
+
* @returns A predicate function to check if a node is a call to the API
|
|
758
|
+
*/
|
|
744
759
|
declare function isReactAPICall(api: string): isReactAPICall.ReturnType;
|
|
745
760
|
declare const isCaptureOwnerStack: isReactAPI.ReturnType;
|
|
746
761
|
declare const isChildrenCount: isReactAPI.ReturnType;
|
package/dist/index.js
CHANGED
|
@@ -214,7 +214,7 @@ function isFunctionOfUseEffectCleanup(node) {
|
|
|
214
214
|
/**
|
|
215
215
|
* Incomplete but sufficient stringification of JSX nodes for common use cases
|
|
216
216
|
*
|
|
217
|
-
* @param node
|
|
217
|
+
* @param node JSX node from TypeScript ESTree
|
|
218
218
|
* @returns String representation of the JSX node
|
|
219
219
|
*/
|
|
220
220
|
function stringifyJsx(node) {
|
|
@@ -492,8 +492,8 @@ function isJsxLike(code, node, hint = DEFAULT_JSX_DETECTION_HINT) {
|
|
|
492
492
|
* For JSX elements, returns the stringified name (e.g., "div", "Button", "React.Fragment")
|
|
493
493
|
* For JSX fragments, returns an empty string
|
|
494
494
|
*
|
|
495
|
-
* @param context
|
|
496
|
-
* @param node
|
|
495
|
+
* @param context ESLint rule context
|
|
496
|
+
* @param node JSX element or fragment node
|
|
497
497
|
* @returns String representation of the element type
|
|
498
498
|
*/
|
|
499
499
|
function getJsxElementType(context, node) {
|
|
@@ -507,8 +507,8 @@ function getJsxElementType(context, node) {
|
|
|
507
507
|
* Determines if a JSX element is a host element
|
|
508
508
|
* Host elements in React start with lowercase letters (e.g., div, span)
|
|
509
509
|
*
|
|
510
|
-
* @param context
|
|
511
|
-
* @param node
|
|
510
|
+
* @param context ESLint rule context
|
|
511
|
+
* @param node AST node to check
|
|
512
512
|
* @returns boolean indicating if the element is a host element
|
|
513
513
|
*/
|
|
514
514
|
function isJsxHostElement(context, node) {
|
|
@@ -518,8 +518,8 @@ function isJsxHostElement(context, node) {
|
|
|
518
518
|
* Determines if a JSX element is a React Fragment
|
|
519
519
|
* Fragments can be imported from React and used like <Fragment> or <React.Fragment>
|
|
520
520
|
*
|
|
521
|
-
* @param context
|
|
522
|
-
* @param node
|
|
521
|
+
* @param context ESLint rule context
|
|
522
|
+
* @param node AST node to check
|
|
523
523
|
* @returns boolean indicating if the element is a Fragment with type narrowing
|
|
524
524
|
*/
|
|
525
525
|
function isJsxFragmentElement(context, node) {
|
|
@@ -532,8 +532,8 @@ function isJsxFragmentElement(context, node) {
|
|
|
532
532
|
/**
|
|
533
533
|
* Traverses up the AST to find a parent JSX attribute node that matches a given test
|
|
534
534
|
*
|
|
535
|
-
* @param node
|
|
536
|
-
* @param test
|
|
535
|
+
* @param node The starting AST node
|
|
536
|
+
* @param test Optional predicate function to test if the attribute meets criteria
|
|
537
537
|
* Defaults to always returning true (matches any attribute)
|
|
538
538
|
* @returns The first matching JSX attribute node found when traversing upwards, or undefined
|
|
539
539
|
*/
|
|
@@ -629,6 +629,11 @@ function isInstanceIdEqual(context, a, b) {
|
|
|
629
629
|
|
|
630
630
|
//#endregion
|
|
631
631
|
//#region src/utils/is-react-api.ts
|
|
632
|
+
/**
|
|
633
|
+
* Checks if the node is a React API identifier or member expression
|
|
634
|
+
* @param api The React API name to check against (e.g., "useState", "React.memo")
|
|
635
|
+
* @returns A predicate function to check if a node matches the API
|
|
636
|
+
*/
|
|
632
637
|
function isReactAPI(api) {
|
|
633
638
|
const func = (context, node) => {
|
|
634
639
|
if (node == null) return false;
|
|
@@ -640,6 +645,11 @@ function isReactAPI(api) {
|
|
|
640
645
|
};
|
|
641
646
|
return dual(2, func);
|
|
642
647
|
}
|
|
648
|
+
/**
|
|
649
|
+
* Checks if the node is a call expression to a specific React API
|
|
650
|
+
* @param api The React API name to check against
|
|
651
|
+
* @returns A predicate function to check if a node is a call to the API
|
|
652
|
+
*/
|
|
643
653
|
function isReactAPICall(api) {
|
|
644
654
|
const func = (context, node) => {
|
|
645
655
|
if (node == null) return false;
|
|
@@ -771,7 +781,8 @@ const FUNCTION_PATTERNS = {
|
|
|
771
781
|
/**
|
|
772
782
|
* Checks if the given node is a function within a render method of a class component.
|
|
773
783
|
*
|
|
774
|
-
* @param node
|
|
784
|
+
* @param node The AST node to check
|
|
785
|
+
* @param node
|
|
775
786
|
* @returns `true` if the node is a render function inside a class component
|
|
776
787
|
*
|
|
777
788
|
* @example
|
|
@@ -789,8 +800,10 @@ function isFunctionOfRenderMethod(node) {
|
|
|
789
800
|
/**
|
|
790
801
|
* Checks if a function node should be excluded based on provided detection hints
|
|
791
802
|
*
|
|
792
|
-
* @param node
|
|
793
|
-
* @param hint
|
|
803
|
+
* @param node The function node to check
|
|
804
|
+
* @param hint Component detection hints as bit flags
|
|
805
|
+
* @param node
|
|
806
|
+
* @param hint
|
|
794
807
|
* @returns `true` if the function matches an exclusion hint
|
|
795
808
|
*/
|
|
796
809
|
function shouldExcludeBasedOnHint(node, hint) {
|
|
@@ -803,8 +816,10 @@ function shouldExcludeBasedOnHint(node, hint) {
|
|
|
803
816
|
/**
|
|
804
817
|
* Determines if the node is an argument within `createElement`'s children list (3rd argument onwards)
|
|
805
818
|
*
|
|
806
|
-
* @param context
|
|
807
|
-
* @param node
|
|
819
|
+
* @param context The rule context
|
|
820
|
+
* @param node The AST node to check
|
|
821
|
+
* @param context
|
|
822
|
+
* @param node
|
|
808
823
|
* @returns `true` if the node is passed as a child to `createElement`
|
|
809
824
|
*/
|
|
810
825
|
function isChildrenOfCreateElement(context, node) {
|
|
@@ -816,9 +831,12 @@ function isChildrenOfCreateElement(context, node) {
|
|
|
816
831
|
/**
|
|
817
832
|
* Determines if a function node represents a valid React component definition
|
|
818
833
|
*
|
|
819
|
-
* @param context
|
|
820
|
-
* @param node
|
|
821
|
-
* @param hint
|
|
834
|
+
* @param context The rule context
|
|
835
|
+
* @param node The function node to analyze
|
|
836
|
+
* @param hint Component detection hints (bit flags) to customize detection logic
|
|
837
|
+
* @param context
|
|
838
|
+
* @param node
|
|
839
|
+
* @param hint
|
|
822
840
|
* @returns `true` if the node is considered a component definition
|
|
823
841
|
*/
|
|
824
842
|
function isComponentDefinition(context, node, hint) {
|
|
@@ -892,21 +910,21 @@ function getComponentFlagFromInitPath(initPath) {
|
|
|
892
910
|
//#region src/component/component-name.ts
|
|
893
911
|
/**
|
|
894
912
|
* Check if a string matches the strict component name pattern
|
|
895
|
-
* @param name
|
|
913
|
+
* @param name The name to check
|
|
896
914
|
*/
|
|
897
915
|
function isComponentName(name) {
|
|
898
916
|
return RE_COMPONENT_NAME.test(name);
|
|
899
917
|
}
|
|
900
918
|
/**
|
|
901
919
|
* Check if a string matches the loose component name pattern
|
|
902
|
-
* @param name
|
|
920
|
+
* @param name The name to check
|
|
903
921
|
*/
|
|
904
922
|
function isComponentNameLoose(name) {
|
|
905
923
|
return RE_COMPONENT_NAME_LOOSE.test(name);
|
|
906
924
|
}
|
|
907
925
|
/**
|
|
908
926
|
* Get component name from an identifier or identifier sequence (e.g., MemberExpression)
|
|
909
|
-
* @param id
|
|
927
|
+
* @param id The identifier or identifier sequence
|
|
910
928
|
*/
|
|
911
929
|
function getComponentNameFromId(id) {
|
|
912
930
|
if (id == null) return unit;
|
|
@@ -914,8 +932,8 @@ function getComponentNameFromId(id) {
|
|
|
914
932
|
}
|
|
915
933
|
/**
|
|
916
934
|
* Check if the function has no name or a loose component name
|
|
917
|
-
* @param context
|
|
918
|
-
* @param fn
|
|
935
|
+
* @param context The rule context
|
|
936
|
+
* @param fn The function node
|
|
919
937
|
*/
|
|
920
938
|
function hasNoneOrLooseComponentName(context, fn) {
|
|
921
939
|
const id = getFunctionComponentId(context, fn);
|
|
@@ -1064,7 +1082,8 @@ function useComponentCollectorLegacy() {
|
|
|
1064
1082
|
}
|
|
1065
1083
|
/**
|
|
1066
1084
|
* Check whether the given node is a this.setState() call
|
|
1067
|
-
* @param node
|
|
1085
|
+
* @param node The node to check
|
|
1086
|
+
* @param node
|
|
1068
1087
|
* @internal
|
|
1069
1088
|
*/
|
|
1070
1089
|
function isThisSetState(node) {
|
|
@@ -1073,7 +1092,8 @@ function isThisSetState(node) {
|
|
|
1073
1092
|
}
|
|
1074
1093
|
/**
|
|
1075
1094
|
* Check whether the given node is an assignment to this.state
|
|
1076
|
-
* @param node
|
|
1095
|
+
* @param node The node to check
|
|
1096
|
+
* @param node
|
|
1077
1097
|
* @internal
|
|
1078
1098
|
*/
|
|
1079
1099
|
function isAssignmentToThisState(node) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/core",
|
|
3
|
-
"version": "2.3.13-next.
|
|
3
|
+
"version": "2.3.13-next.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": {
|
|
@@ -35,10 +35,10 @@
|
|
|
35
35
|
"@typescript-eslint/utils": "^8.48.1",
|
|
36
36
|
"birecord": "^0.1.1",
|
|
37
37
|
"ts-pattern": "^5.9.0",
|
|
38
|
-
"@eslint-react/ast": "2.3.13-next.
|
|
39
|
-
"@eslint-react/
|
|
40
|
-
"@eslint-react/var": "2.3.13-next.
|
|
41
|
-
"@eslint-react/
|
|
38
|
+
"@eslint-react/ast": "2.3.13-next.2",
|
|
39
|
+
"@eslint-react/shared": "2.3.13-next.2",
|
|
40
|
+
"@eslint-react/var": "2.3.13-next.2",
|
|
41
|
+
"@eslint-react/eff": "2.3.13-next.2"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
44
|
"eslint": "^8.57.0 || ^9.0.0",
|