eslint-plugin-react-x 2.0.7-beta.2 → 2.0.7-beta.3
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.js +15 -29
- package/package.json +9 -9
package/dist/index.js
CHANGED
|
@@ -134,7 +134,7 @@ const settings = { ...settings$1 };
|
|
|
134
134
|
//#endregion
|
|
135
135
|
//#region package.json
|
|
136
136
|
var name = "eslint-plugin-react-x";
|
|
137
|
-
var version = "2.0.7-beta.
|
|
137
|
+
var version = "2.0.7-beta.3";
|
|
138
138
|
|
|
139
139
|
//#endregion
|
|
140
140
|
//#region src/utils/create-rule.ts
|
|
@@ -1241,8 +1241,7 @@ function create$37(context) {
|
|
|
1241
1241
|
if (object.type !== AST_NODE_TYPES.Identifier) return;
|
|
1242
1242
|
if (property.type !== AST_NODE_TYPES.Identifier || property.name !== "defaultProps") return;
|
|
1243
1243
|
if (!isComponentNameLoose(object.name)) return;
|
|
1244
|
-
const
|
|
1245
|
-
const variableNode = getVariableDefinitionNode(variable, 0);
|
|
1244
|
+
const variableNode = getVariableDefinitionNode(findVariable(object.name, context.sourceCode.getScope(node)), 0);
|
|
1246
1245
|
if (variableNode == null) return;
|
|
1247
1246
|
if (!AST.isFunction(variableNode)) return;
|
|
1248
1247
|
context.report({
|
|
@@ -1423,8 +1422,7 @@ function create$34(context, [option]) {
|
|
|
1423
1422
|
if ("excludedNodes" in forbiddenPropItem && forbiddenPropItem.excludedNodes.includes(nodeName)) continue;
|
|
1424
1423
|
if ("includedNodes" in forbiddenPropItem && !forbiddenPropItem.includedNodes.includes(nodeName)) continue;
|
|
1425
1424
|
}
|
|
1426
|
-
|
|
1427
|
-
if (toRegExp(forbiddenProp).test(name$4)) context.report({
|
|
1425
|
+
if (toRegExp(typeof forbiddenPropItem === "string" ? forbiddenPropItem : forbiddenPropItem.prop).test(name$4)) context.report({
|
|
1428
1426
|
messageId,
|
|
1429
1427
|
node: attr,
|
|
1430
1428
|
data: { name: name$4 }
|
|
@@ -1630,8 +1628,7 @@ function create$31(context) {
|
|
|
1630
1628
|
node: left,
|
|
1631
1629
|
data: { value: context.sourceCode.getText(left) }
|
|
1632
1630
|
};
|
|
1633
|
-
const
|
|
1634
|
-
const leftTypeVariants = getTypeVariants(unionConstituents(leftType));
|
|
1631
|
+
const leftTypeVariants = getTypeVariants(unionConstituents(getConstrainedTypeAtLocation(services, left)));
|
|
1635
1632
|
if (Array.from(leftTypeVariants.values()).every((type) => allowedVariants.some((allowed) => allowed === type))) return getReportDescriptor(right);
|
|
1636
1633
|
return {
|
|
1637
1634
|
messageId: "noLeakedConditionalRendering",
|
|
@@ -1930,8 +1927,7 @@ var no_nested_component_definitions_default = createRule({
|
|
|
1930
1927
|
defaultOptions: []
|
|
1931
1928
|
});
|
|
1932
1929
|
function create$26(context) {
|
|
1933
|
-
const
|
|
1934
|
-
const collector = useComponentCollector(context, { hint });
|
|
1930
|
+
const collector = useComponentCollector(context, { hint: ComponentDetectionHint.SkipArrayMapArgument | ComponentDetectionHint.SkipNullLiteral | ComponentDetectionHint.SkipUndefined | ComponentDetectionHint.SkipBooleanLiteral | ComponentDetectionHint.SkipStringLiteral | ComponentDetectionHint.SkipNumberLiteral | ComponentDetectionHint.StrictLogical | ComponentDetectionHint.StrictConditional });
|
|
1935
1931
|
const collectorLegacy = useComponentCollectorLegacy();
|
|
1936
1932
|
return {
|
|
1937
1933
|
...collector.listeners,
|
|
@@ -2110,8 +2106,7 @@ function create$24(context) {
|
|
|
2110
2106
|
if (object.type !== AST_NODE_TYPES.Identifier) return;
|
|
2111
2107
|
if (property.type !== AST_NODE_TYPES.Identifier || property.name !== "propTypes") return;
|
|
2112
2108
|
if (!isComponentNameLoose(object.name)) return;
|
|
2113
|
-
const
|
|
2114
|
-
const variableNode = getVariableDefinitionNode(variable, 0);
|
|
2109
|
+
const variableNode = getVariableDefinitionNode(findVariable(object.name, context.sourceCode.getScope(node)), 0);
|
|
2115
2110
|
if (variableNode != null && (AST.isFunction(variableNode) || isClassComponent(variableNode))) context.report({
|
|
2116
2111
|
messageId: "noPropTypes",
|
|
2117
2112
|
node: property
|
|
@@ -2409,8 +2404,7 @@ function create$17(context) {
|
|
|
2409
2404
|
const [arg0, arg1] = node.arguments;
|
|
2410
2405
|
if (arg0 == null || arg1 == null) return;
|
|
2411
2406
|
if (!match(arg1).with({ type: AST_NODE_TYPES.ArrayExpression }, (n) => n.elements.length === 0).with({ type: AST_NODE_TYPES.Identifier }, (n) => {
|
|
2412
|
-
const
|
|
2413
|
-
const variableNode = getVariableDefinitionNode(variable, 0);
|
|
2407
|
+
const variableNode = getVariableDefinitionNode(findVariable(n.name, initialScope), 0);
|
|
2414
2408
|
if (variableNode?.type !== AST_NODE_TYPES.ArrayExpression) return false;
|
|
2415
2409
|
return variableNode.elements.length === 0;
|
|
2416
2410
|
}).otherwise(() => false)) return;
|
|
@@ -2418,14 +2412,12 @@ function create$17(context) {
|
|
|
2418
2412
|
if (n.body.type === AST_NODE_TYPES.ArrowFunctionExpression) return n.body;
|
|
2419
2413
|
return n;
|
|
2420
2414
|
}).with({ type: AST_NODE_TYPES.FunctionExpression }, identity).with({ type: AST_NODE_TYPES.Identifier }, (n) => {
|
|
2421
|
-
const
|
|
2422
|
-
const variableNode = getVariableDefinitionNode(variable, 0);
|
|
2415
|
+
const variableNode = getVariableDefinitionNode(findVariable(n.name, initialScope), 0);
|
|
2423
2416
|
if (variableNode?.type !== AST_NODE_TYPES.ArrowFunctionExpression && variableNode?.type !== AST_NODE_TYPES.FunctionExpression) return null;
|
|
2424
2417
|
return variableNode;
|
|
2425
2418
|
}).otherwise(() => null);
|
|
2426
2419
|
if (arg0Node == null) return;
|
|
2427
|
-
|
|
2428
|
-
if (!getChildScopes(arg0NodeScope).flatMap((x) => x.references).some((x) => x.resolved?.scope.block === component)) context.report({
|
|
2420
|
+
if (!getChildScopes(context.sourceCode.getScope(arg0Node)).flatMap((x) => x.references).some((x) => x.resolved?.scope.block === component)) context.report({
|
|
2429
2421
|
messageId: "noUnnecessaryUseCallback",
|
|
2430
2422
|
node
|
|
2431
2423
|
});
|
|
@@ -2461,8 +2453,7 @@ function create$16(context) {
|
|
|
2461
2453
|
if (arg0 == null || arg1 == null) return;
|
|
2462
2454
|
if (AST.isFunction(arg0) && [...AST.getNestedCallExpressions(arg0.body), ...AST.getNestedNewExpressions(arg0.body)].length > 0) return;
|
|
2463
2455
|
if (!match(arg1).with({ type: AST_NODE_TYPES.ArrayExpression }, (n) => n.elements.length === 0).with({ type: AST_NODE_TYPES.Identifier }, (n) => {
|
|
2464
|
-
const
|
|
2465
|
-
const variableNode = getVariableDefinitionNode(variable, 0);
|
|
2456
|
+
const variableNode = getVariableDefinitionNode(findVariable(n.name, initialScope), 0);
|
|
2466
2457
|
if (variableNode?.type !== AST_NODE_TYPES.ArrayExpression) return false;
|
|
2467
2458
|
return variableNode.elements.length === 0;
|
|
2468
2459
|
}).otherwise(() => false)) return;
|
|
@@ -2470,14 +2461,12 @@ function create$16(context) {
|
|
|
2470
2461
|
if (n.body.type === AST_NODE_TYPES.ArrowFunctionExpression) return n.body;
|
|
2471
2462
|
return n;
|
|
2472
2463
|
}).with({ type: AST_NODE_TYPES.FunctionExpression }, identity).with({ type: AST_NODE_TYPES.Identifier }, (n) => {
|
|
2473
|
-
const
|
|
2474
|
-
const variableNode = getVariableDefinitionNode(variable, 0);
|
|
2464
|
+
const variableNode = getVariableDefinitionNode(findVariable(n.name, initialScope), 0);
|
|
2475
2465
|
if (variableNode?.type !== AST_NODE_TYPES.ArrowFunctionExpression && variableNode?.type !== AST_NODE_TYPES.FunctionExpression) return null;
|
|
2476
2466
|
return variableNode;
|
|
2477
2467
|
}).otherwise(() => null);
|
|
2478
2468
|
if (arg0Node == null) return;
|
|
2479
|
-
|
|
2480
|
-
if (!getChildScopes(arg0NodeScope).flatMap((x) => x.references).some((x) => x.resolved?.scope.block === component)) context.report({
|
|
2469
|
+
if (!getChildScopes(context.sourceCode.getScope(arg0Node)).flatMap((x) => x.references).some((x) => x.resolved?.scope.block === component)) context.report({
|
|
2481
2470
|
messageId: "noUnnecessaryUseMemo",
|
|
2482
2471
|
node
|
|
2483
2472
|
});
|
|
@@ -2672,8 +2661,7 @@ function create$11(context) {
|
|
|
2672
2661
|
const value = attribute.value;
|
|
2673
2662
|
if (value?.type !== AST_NODE_TYPES.JSXExpressionContainer) return;
|
|
2674
2663
|
const valueExpression = value.expression;
|
|
2675
|
-
const
|
|
2676
|
-
const construction = getConstruction(valueExpression, initialScope);
|
|
2664
|
+
const construction = getConstruction(valueExpression, context.sourceCode.getScope(valueExpression));
|
|
2677
2665
|
if (construction == null) return;
|
|
2678
2666
|
if (isReactHookCall(construction.node)) return;
|
|
2679
2667
|
getOrElseUpdate(constructions, functionEntry.node, () => []).push(construction);
|
|
@@ -2742,8 +2730,7 @@ function create$10(context) {
|
|
|
2742
2730
|
if (prop.type !== AST_NODE_TYPES.Property || prop.value.type !== AST_NODE_TYPES.AssignmentPattern) continue;
|
|
2743
2731
|
const { value } = prop;
|
|
2744
2732
|
const { right } = value;
|
|
2745
|
-
const
|
|
2746
|
-
const construction = getConstruction(value, initialScope, ConstructionDetectionHint.StrictCallExpression);
|
|
2733
|
+
const construction = getConstruction(value, context.sourceCode.getScope(value), ConstructionDetectionHint.StrictCallExpression);
|
|
2747
2734
|
if (construction == null) continue;
|
|
2748
2735
|
if (isReactHookCall(construction.node)) continue;
|
|
2749
2736
|
const forbiddenType = AST.toDelimiterFormat(right);
|
|
@@ -3502,8 +3489,7 @@ function create$1(context) {
|
|
|
3502
3489
|
if (component.name == null) continue;
|
|
3503
3490
|
const [props] = component.node.params;
|
|
3504
3491
|
if (props == null) continue;
|
|
3505
|
-
|
|
3506
|
-
if (isTypeReadonlyLoose(services, propsType)) continue;
|
|
3492
|
+
if (isTypeReadonlyLoose(services, getConstrainedTypeAtLocation(services, props))) continue;
|
|
3507
3493
|
context.report({
|
|
3508
3494
|
messageId: "preferReadOnlyProps",
|
|
3509
3495
|
node: props
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-react-x",
|
|
3
|
-
"version": "2.0.7-beta.
|
|
3
|
+
"version": "2.0.7-beta.3",
|
|
4
4
|
"description": "A set of composable ESLint rules for for libraries and frameworks that use React as a UI runtime.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -43,16 +43,16 @@
|
|
|
43
43
|
"string-ts": "^2.2.1",
|
|
44
44
|
"ts-api-utils": "^2.1.0",
|
|
45
45
|
"ts-pattern": "^5.8.0",
|
|
46
|
-
"@eslint-react/ast": "2.0.7-beta.
|
|
47
|
-
"@eslint-react/core": "2.0.7-beta.
|
|
48
|
-
"@eslint-react/eff": "2.0.7-beta.
|
|
49
|
-
"@eslint-react/kit": "2.0.7-beta.
|
|
50
|
-
"@eslint-react/
|
|
51
|
-
"@eslint-react/
|
|
46
|
+
"@eslint-react/ast": "2.0.7-beta.3",
|
|
47
|
+
"@eslint-react/core": "2.0.7-beta.3",
|
|
48
|
+
"@eslint-react/eff": "2.0.7-beta.3",
|
|
49
|
+
"@eslint-react/kit": "2.0.7-beta.3",
|
|
50
|
+
"@eslint-react/var": "2.0.7-beta.3",
|
|
51
|
+
"@eslint-react/shared": "2.0.7-beta.3"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"@types/react": "^19.2.
|
|
55
|
-
"@types/react-dom": "^19.2.
|
|
54
|
+
"@types/react": "^19.2.2",
|
|
55
|
+
"@types/react-dom": "^19.2.1",
|
|
56
56
|
"tsdown": "^0.15.6",
|
|
57
57
|
"@local/configs": "0.0.0"
|
|
58
58
|
},
|