@eslint-react/core 2.11.2 → 2.12.0-next.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 +28 -46
- package/dist/index.js +39 -39
- package/package.json +6 -6
package/dist/index.d.ts
CHANGED
|
@@ -84,42 +84,24 @@ type ComponentDetectionHint = bigint;
|
|
|
84
84
|
* Hints for component collector
|
|
85
85
|
*/
|
|
86
86
|
declare const ComponentDetectionHint: {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
readonly
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
*/
|
|
94
|
-
readonly SkipClassMethod: bigint;
|
|
95
|
-
/**
|
|
96
|
-
* Skip function component defined on class property
|
|
97
|
-
*/
|
|
98
|
-
readonly SkipClassProperty: bigint;
|
|
99
|
-
/**
|
|
100
|
-
* Skip function component defined in array pattern
|
|
101
|
-
*/
|
|
102
|
-
readonly SkipArrayPattern: bigint;
|
|
103
|
-
/**
|
|
104
|
-
* Skip function component defined in array expression
|
|
105
|
-
*/
|
|
106
|
-
readonly SkipArrayExpression: bigint;
|
|
107
|
-
/**
|
|
108
|
-
* Skip function component defined as array map callback
|
|
109
|
-
*/
|
|
110
|
-
readonly SkipArrayMapCallback: bigint;
|
|
87
|
+
readonly DoNotIncludeFunctionDefinedOnObjectMethod: bigint;
|
|
88
|
+
readonly DoNotIncludeFunctionDefinedOnClassMethod: bigint;
|
|
89
|
+
readonly DoNotIncludeFunctionDefinedOnClassProperty: bigint;
|
|
90
|
+
readonly DoNotIncludeFunctionDefinedInArrayPattern: bigint;
|
|
91
|
+
readonly DoNotIncludeFunctionDefinedInArrayExpression: bigint;
|
|
92
|
+
readonly DoNotIncludeFunctionDefinedAsArrayMapCallback: bigint;
|
|
111
93
|
readonly None: 0n;
|
|
112
|
-
readonly
|
|
113
|
-
readonly
|
|
114
|
-
readonly
|
|
115
|
-
readonly
|
|
116
|
-
readonly
|
|
117
|
-
readonly
|
|
118
|
-
readonly
|
|
119
|
-
readonly
|
|
120
|
-
readonly
|
|
121
|
-
readonly
|
|
122
|
-
readonly
|
|
94
|
+
readonly DoNotIncludeJsxWithNullValue: bigint;
|
|
95
|
+
readonly DoNotIncludeJsxWithNumberValue: bigint;
|
|
96
|
+
readonly DoNotIncludeJsxWithBigIntValue: bigint;
|
|
97
|
+
readonly DoNotIncludeJsxWithStringValue: bigint;
|
|
98
|
+
readonly DoNotIncludeJsxWithBooleanValue: bigint;
|
|
99
|
+
readonly DoNotIncludeJsxWithUndefinedValue: bigint;
|
|
100
|
+
readonly DoNotIncludeJsxWithEmptyArrayValue: bigint;
|
|
101
|
+
readonly DoNotIncludeJsxWithCreateElementValue: bigint;
|
|
102
|
+
readonly RequireAllArrayElementsToBeJsx: bigint;
|
|
103
|
+
readonly RequireBothSidesOfLogicalExpressionToBeJsx: bigint;
|
|
104
|
+
readonly RequireBothBranchesOfConditionalExpressionToBeJsx: bigint;
|
|
123
105
|
};
|
|
124
106
|
/**
|
|
125
107
|
* Default component detection hint
|
|
@@ -815,17 +797,17 @@ declare function getJsxConfigFromAnnotation(context: RuleContext): JsxConfig;
|
|
|
815
797
|
type JsxDetectionHint = bigint;
|
|
816
798
|
declare const JsxDetectionHint: {
|
|
817
799
|
readonly None: 0n;
|
|
818
|
-
readonly
|
|
819
|
-
readonly
|
|
820
|
-
readonly
|
|
821
|
-
readonly
|
|
822
|
-
readonly
|
|
823
|
-
readonly
|
|
824
|
-
readonly
|
|
825
|
-
readonly
|
|
826
|
-
readonly
|
|
827
|
-
readonly
|
|
828
|
-
readonly
|
|
800
|
+
readonly DoNotIncludeJsxWithNullValue: bigint;
|
|
801
|
+
readonly DoNotIncludeJsxWithNumberValue: bigint;
|
|
802
|
+
readonly DoNotIncludeJsxWithBigIntValue: bigint;
|
|
803
|
+
readonly DoNotIncludeJsxWithStringValue: bigint;
|
|
804
|
+
readonly DoNotIncludeJsxWithBooleanValue: bigint;
|
|
805
|
+
readonly DoNotIncludeJsxWithUndefinedValue: bigint;
|
|
806
|
+
readonly DoNotIncludeJsxWithEmptyArrayValue: bigint;
|
|
807
|
+
readonly DoNotIncludeJsxWithCreateElementValue: bigint;
|
|
808
|
+
readonly RequireAllArrayElementsToBeJsx: bigint;
|
|
809
|
+
readonly RequireBothSidesOfLogicalExpressionToBeJsx: bigint;
|
|
810
|
+
readonly RequireBothBranchesOfConditionalExpressionToBeJsx: bigint;
|
|
829
811
|
};
|
|
830
812
|
/**
|
|
831
813
|
* Default JSX detection configuration
|
package/dist/index.js
CHANGED
|
@@ -513,23 +513,23 @@ function getJsxConfigFromAnnotation(context) {
|
|
|
513
513
|
//#region src/jsx/jsx-detection.ts
|
|
514
514
|
const JsxDetectionHint = {
|
|
515
515
|
None: 0n,
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
516
|
+
DoNotIncludeJsxWithNullValue: 1n << 0n,
|
|
517
|
+
DoNotIncludeJsxWithNumberValue: 1n << 1n,
|
|
518
|
+
DoNotIncludeJsxWithBigIntValue: 1n << 2n,
|
|
519
|
+
DoNotIncludeJsxWithStringValue: 1n << 3n,
|
|
520
|
+
DoNotIncludeJsxWithBooleanValue: 1n << 4n,
|
|
521
|
+
DoNotIncludeJsxWithUndefinedValue: 1n << 5n,
|
|
522
|
+
DoNotIncludeJsxWithEmptyArrayValue: 1n << 6n,
|
|
523
|
+
DoNotIncludeJsxWithCreateElementValue: 1n << 7n,
|
|
524
|
+
RequireAllArrayElementsToBeJsx: 1n << 8n,
|
|
525
|
+
RequireBothSidesOfLogicalExpressionToBeJsx: 1n << 9n,
|
|
526
|
+
RequireBothBranchesOfConditionalExpressionToBeJsx: 1n << 10n
|
|
527
527
|
};
|
|
528
528
|
/**
|
|
529
529
|
* Default JSX detection configuration
|
|
530
530
|
* Skips undefined and boolean literals (common in React)
|
|
531
531
|
*/
|
|
532
|
-
const DEFAULT_JSX_DETECTION_HINT = 0n | JsxDetectionHint.
|
|
532
|
+
const DEFAULT_JSX_DETECTION_HINT = 0n | JsxDetectionHint.DoNotIncludeJsxWithNumberValue | JsxDetectionHint.DoNotIncludeJsxWithBigIntValue | JsxDetectionHint.DoNotIncludeJsxWithBooleanValue | JsxDetectionHint.DoNotIncludeJsxWithStringValue | JsxDetectionHint.DoNotIncludeJsxWithUndefinedValue;
|
|
533
533
|
/**
|
|
534
534
|
* Check if a node is a `JSXText` or a `Literal` node
|
|
535
535
|
* @param node The AST node to check
|
|
@@ -555,26 +555,26 @@ function isJsxLike(code, node, hint = DEFAULT_JSX_DETECTION_HINT) {
|
|
|
555
555
|
switch (node.type) {
|
|
556
556
|
case AST_NODE_TYPES.Literal:
|
|
557
557
|
switch (typeof node.value) {
|
|
558
|
-
case "boolean": return !(hint & JsxDetectionHint.
|
|
559
|
-
case "string": return !(hint & JsxDetectionHint.
|
|
560
|
-
case "number": return !(hint & JsxDetectionHint.
|
|
561
|
-
case "bigint": return !(hint & JsxDetectionHint.
|
|
558
|
+
case "boolean": return !(hint & JsxDetectionHint.DoNotIncludeJsxWithBooleanValue);
|
|
559
|
+
case "string": return !(hint & JsxDetectionHint.DoNotIncludeJsxWithStringValue);
|
|
560
|
+
case "number": return !(hint & JsxDetectionHint.DoNotIncludeJsxWithNumberValue);
|
|
561
|
+
case "bigint": return !(hint & JsxDetectionHint.DoNotIncludeJsxWithBigIntValue);
|
|
562
562
|
}
|
|
563
|
-
if (node.value == null) return !(hint & JsxDetectionHint.
|
|
563
|
+
if (node.value == null) return !(hint & JsxDetectionHint.DoNotIncludeJsxWithNullValue);
|
|
564
564
|
return false;
|
|
565
|
-
case AST_NODE_TYPES.TemplateLiteral: return !(hint & JsxDetectionHint.
|
|
565
|
+
case AST_NODE_TYPES.TemplateLiteral: return !(hint & JsxDetectionHint.DoNotIncludeJsxWithStringValue);
|
|
566
566
|
case AST_NODE_TYPES.ArrayExpression:
|
|
567
|
-
if (node.elements.length === 0) return !(hint & JsxDetectionHint.
|
|
568
|
-
if (hint & JsxDetectionHint.
|
|
567
|
+
if (node.elements.length === 0) return !(hint & JsxDetectionHint.DoNotIncludeJsxWithEmptyArrayValue);
|
|
568
|
+
if (hint & JsxDetectionHint.RequireAllArrayElementsToBeJsx) return node.elements.every((n) => isJsxLike(code, n, hint));
|
|
569
569
|
return node.elements.some((n) => isJsxLike(code, n, hint));
|
|
570
570
|
case AST_NODE_TYPES.LogicalExpression:
|
|
571
|
-
if (hint & JsxDetectionHint.
|
|
571
|
+
if (hint & JsxDetectionHint.RequireBothSidesOfLogicalExpressionToBeJsx) return isJsxLike(code, node.left, hint) && isJsxLike(code, node.right, hint);
|
|
572
572
|
return isJsxLike(code, node.left, hint) || isJsxLike(code, node.right, hint);
|
|
573
573
|
case AST_NODE_TYPES.ConditionalExpression: {
|
|
574
574
|
function leftHasJSX(node) {
|
|
575
575
|
if (Array.isArray(node.consequent)) {
|
|
576
|
-
if (node.consequent.length === 0) return !(hint & JsxDetectionHint.
|
|
577
|
-
if (hint & JsxDetectionHint.
|
|
576
|
+
if (node.consequent.length === 0) return !(hint & JsxDetectionHint.DoNotIncludeJsxWithEmptyArrayValue);
|
|
577
|
+
if (hint & JsxDetectionHint.RequireAllArrayElementsToBeJsx) return node.consequent.every((n) => isJsxLike(code, n, hint));
|
|
578
578
|
return node.consequent.some((n) => isJsxLike(code, n, hint));
|
|
579
579
|
}
|
|
580
580
|
return isJsxLike(code, node.consequent, hint);
|
|
@@ -582,12 +582,12 @@ function isJsxLike(code, node, hint = DEFAULT_JSX_DETECTION_HINT) {
|
|
|
582
582
|
function rightHasJSX(node) {
|
|
583
583
|
return isJsxLike(code, node.alternate, hint);
|
|
584
584
|
}
|
|
585
|
-
if (hint & JsxDetectionHint.
|
|
585
|
+
if (hint & JsxDetectionHint.RequireBothBranchesOfConditionalExpressionToBeJsx) return leftHasJSX(node) && rightHasJSX(node);
|
|
586
586
|
return leftHasJSX(node) || rightHasJSX(node);
|
|
587
587
|
}
|
|
588
588
|
case AST_NODE_TYPES.SequenceExpression: return isJsxLike(code, node.expressions.at(-1), hint);
|
|
589
589
|
case AST_NODE_TYPES.CallExpression:
|
|
590
|
-
if (hint & JsxDetectionHint.
|
|
590
|
+
if (hint & JsxDetectionHint.DoNotIncludeJsxWithCreateElementValue) return false;
|
|
591
591
|
switch (node.callee.type) {
|
|
592
592
|
case AST_NODE_TYPES.Identifier: return node.callee.name === "createElement";
|
|
593
593
|
case AST_NODE_TYPES.MemberExpression: return node.callee.property.type === AST_NODE_TYPES.Identifier && node.callee.property.name === "createElement";
|
|
@@ -595,7 +595,7 @@ function isJsxLike(code, node, hint = DEFAULT_JSX_DETECTION_HINT) {
|
|
|
595
595
|
return false;
|
|
596
596
|
case AST_NODE_TYPES.Identifier: {
|
|
597
597
|
const { name } = node;
|
|
598
|
-
if (name === "undefined") return !(hint & JsxDetectionHint.
|
|
598
|
+
if (name === "undefined") return !(hint & JsxDetectionHint.DoNotIncludeJsxWithUndefinedValue);
|
|
599
599
|
if (ast.isJSXTagNameExpression(node)) return true;
|
|
600
600
|
return isJsxLike(code, getVariableDefinitionNode(findVariable(name, code.getScope(node)), 0), hint);
|
|
601
601
|
}
|
|
@@ -672,17 +672,17 @@ function findParentJsxAttribute(node, test = constTrue) {
|
|
|
672
672
|
*/
|
|
673
673
|
const ComponentDetectionHint = {
|
|
674
674
|
...JsxDetectionHint,
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
675
|
+
DoNotIncludeFunctionDefinedOnObjectMethod: 1n << 64n,
|
|
676
|
+
DoNotIncludeFunctionDefinedOnClassMethod: 1n << 65n,
|
|
677
|
+
DoNotIncludeFunctionDefinedOnClassProperty: 1n << 66n,
|
|
678
|
+
DoNotIncludeFunctionDefinedInArrayPattern: 1n << 67n,
|
|
679
|
+
DoNotIncludeFunctionDefinedInArrayExpression: 1n << 68n,
|
|
680
|
+
DoNotIncludeFunctionDefinedAsArrayMapCallback: 1n << 69n
|
|
681
681
|
};
|
|
682
682
|
/**
|
|
683
683
|
* Default component detection hint
|
|
684
684
|
*/
|
|
685
|
-
const DEFAULT_COMPONENT_DETECTION_HINT = 0n | ComponentDetectionHint.
|
|
685
|
+
const DEFAULT_COMPONENT_DETECTION_HINT = 0n | ComponentDetectionHint.DoNotIncludeJsxWithBigIntValue | ComponentDetectionHint.DoNotIncludeJsxWithBooleanValue | ComponentDetectionHint.DoNotIncludeJsxWithNumberValue | ComponentDetectionHint.DoNotIncludeJsxWithStringValue | ComponentDetectionHint.DoNotIncludeJsxWithUndefinedValue | ComponentDetectionHint.DoNotIncludeFunctionDefinedAsArrayMapCallback | ComponentDetectionHint.DoNotIncludeFunctionDefinedInArrayExpression | ComponentDetectionHint.DoNotIncludeFunctionDefinedInArrayPattern | ComponentDetectionHint.RequireAllArrayElementsToBeJsx | ComponentDetectionHint.RequireBothBranchesOfConditionalExpressionToBeJsx | ComponentDetectionHint.RequireBothSidesOfLogicalExpressionToBeJsx;
|
|
686
686
|
|
|
687
687
|
//#endregion
|
|
688
688
|
//#region src/component/component-is.ts
|
|
@@ -859,12 +859,12 @@ function isRenderMethodCallback(node) {
|
|
|
859
859
|
*/
|
|
860
860
|
function shouldExcludeBasedOnHint(node, hint) {
|
|
861
861
|
switch (true) {
|
|
862
|
-
case hint & ComponentDetectionHint.
|
|
863
|
-
case hint & ComponentDetectionHint.
|
|
864
|
-
case hint & ComponentDetectionHint.
|
|
865
|
-
case hint & ComponentDetectionHint.
|
|
866
|
-
case hint & ComponentDetectionHint.
|
|
867
|
-
case hint & ComponentDetectionHint.
|
|
862
|
+
case hint & ComponentDetectionHint.DoNotIncludeFunctionDefinedOnObjectMethod && ast.isOneOf([AST_NODE_TYPES.ArrowFunctionExpression, AST_NODE_TYPES.FunctionExpression])(node) && node.parent.type === AST_NODE_TYPES.Property && node.parent.parent.type === AST_NODE_TYPES.ObjectExpression: return true;
|
|
863
|
+
case hint & ComponentDetectionHint.DoNotIncludeFunctionDefinedOnClassMethod && ast.isOneOf([AST_NODE_TYPES.ArrowFunctionExpression, AST_NODE_TYPES.FunctionExpression])(node) && node.parent.type === AST_NODE_TYPES.MethodDefinition: return true;
|
|
864
|
+
case hint & ComponentDetectionHint.DoNotIncludeFunctionDefinedOnClassProperty && ast.isOneOf([AST_NODE_TYPES.ArrowFunctionExpression, AST_NODE_TYPES.FunctionExpression])(node) && node.parent.type === AST_NODE_TYPES.Property: return true;
|
|
865
|
+
case hint & ComponentDetectionHint.DoNotIncludeFunctionDefinedInArrayPattern && node.parent.type === AST_NODE_TYPES.ArrayPattern: return true;
|
|
866
|
+
case hint & ComponentDetectionHint.DoNotIncludeFunctionDefinedInArrayExpression && node.parent.type === AST_NODE_TYPES.ArrayExpression: return true;
|
|
867
|
+
case hint & ComponentDetectionHint.DoNotIncludeFunctionDefinedAsArrayMapCallback && node.parent.type === AST_NODE_TYPES.CallExpression && node.parent.callee.type === AST_NODE_TYPES.MemberExpression && node.parent.callee.property.type === AST_NODE_TYPES.Identifier && node.parent.callee.property.name === "map": return true;
|
|
868
868
|
}
|
|
869
869
|
return false;
|
|
870
870
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/core",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.12.0-next.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": {
|
|
@@ -34,17 +34,17 @@
|
|
|
34
34
|
"@typescript-eslint/types": "^8.54.0",
|
|
35
35
|
"@typescript-eslint/utils": "^8.54.0",
|
|
36
36
|
"ts-pattern": "^5.9.0",
|
|
37
|
-
"@eslint-react/
|
|
38
|
-
"@eslint-react/
|
|
39
|
-
"@eslint-react/
|
|
40
|
-
"@eslint-react/
|
|
37
|
+
"@eslint-react/eff": "2.12.0-next.0",
|
|
38
|
+
"@eslint-react/ast": "2.12.0-next.0",
|
|
39
|
+
"@eslint-react/shared": "2.12.0-next.0",
|
|
40
|
+
"@eslint-react/var": "2.12.0-next.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"tsdown": "^0.20.3",
|
|
44
44
|
"@local/configs": "0.0.0"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
|
-
"eslint": "^8.57.0 || ^9.0.0",
|
|
47
|
+
"eslint": "^8.57.0 || ^9.0.0 || ^10.0.0",
|
|
48
48
|
"typescript": ">=4.8.4 <6.0.0"
|
|
49
49
|
},
|
|
50
50
|
"engines": {
|