eslint-plugin-react-x 2.3.10-next.4 → 2.3.11-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.js +41 -62
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -34,7 +34,7 @@ var __export = (all, symbols) => {
|
|
|
34
34
|
//#endregion
|
|
35
35
|
//#region package.json
|
|
36
36
|
var name$6 = "eslint-plugin-react-x";
|
|
37
|
-
var version = "2.3.
|
|
37
|
+
var version = "2.3.11-beta.0";
|
|
38
38
|
|
|
39
39
|
//#endregion
|
|
40
40
|
//#region src/utils/create-rule.ts
|
|
@@ -946,8 +946,7 @@ function create$44(context) {
|
|
|
946
946
|
return {
|
|
947
947
|
...listeners,
|
|
948
948
|
"Program:exit"(program) {
|
|
949
|
-
const
|
|
950
|
-
for (const { name: name$7 = "anonymous", node: component } of components.values()) {
|
|
949
|
+
for (const { name: name$7 = "anonymous", node: component } of ctx.getAllComponents(program)) {
|
|
951
950
|
if (component.body.body.some((m) => isComponentDidCatch(m) || isGetDerivedStateFromError(m))) continue;
|
|
952
951
|
context.report({
|
|
953
952
|
messageId: "noClassComponent",
|
|
@@ -1011,8 +1010,7 @@ function create$42(context) {
|
|
|
1011
1010
|
return {
|
|
1012
1011
|
...listeners,
|
|
1013
1012
|
"Program:exit"(program) {
|
|
1014
|
-
const
|
|
1015
|
-
for (const { node: component } of components.values()) {
|
|
1013
|
+
for (const { node: component } of ctx.getAllComponents(program)) {
|
|
1016
1014
|
const { body } = component.body;
|
|
1017
1015
|
for (const member of body) if (isComponentWillMount(member)) context.report({
|
|
1018
1016
|
messageId: "noComponentWillMount",
|
|
@@ -1052,8 +1050,7 @@ function create$41(context) {
|
|
|
1052
1050
|
return {
|
|
1053
1051
|
...listeners,
|
|
1054
1052
|
"Program:exit"(program) {
|
|
1055
|
-
const
|
|
1056
|
-
for (const { node: component } of components.values()) {
|
|
1053
|
+
for (const { node: component } of ctx.getAllComponents(program)) {
|
|
1057
1054
|
const { body } = component.body;
|
|
1058
1055
|
for (const member of body) if (isComponentWillReceiveProps(member)) context.report({
|
|
1059
1056
|
messageId: "noComponentWillReceiveProps",
|
|
@@ -1093,8 +1090,7 @@ function create$40(context) {
|
|
|
1093
1090
|
return {
|
|
1094
1091
|
...listeners,
|
|
1095
1092
|
"Program:exit"(program) {
|
|
1096
|
-
const
|
|
1097
|
-
for (const { node: component } of components.values()) {
|
|
1093
|
+
for (const { node: component } of ctx.getAllComponents(program)) {
|
|
1098
1094
|
const { body } = component.body;
|
|
1099
1095
|
for (const member of body) if (isComponentWillUpdate(member)) context.report({
|
|
1100
1096
|
messageId: "noComponentWillUpdate",
|
|
@@ -1561,18 +1557,15 @@ function create$31(context) {
|
|
|
1561
1557
|
return {
|
|
1562
1558
|
...listeners,
|
|
1563
1559
|
"Program:exit"(program) {
|
|
1564
|
-
const
|
|
1565
|
-
|
|
1560
|
+
for (const { node, displayName, flag } of ctx.getAllComponents(program)) {
|
|
1561
|
+
const id = AST.getFunctionId(node);
|
|
1566
1562
|
const isMemoOrForwardRef = (flag & (ComponentFlag.ForwardRef | ComponentFlag.Memo)) > 0n;
|
|
1567
|
-
if (
|
|
1563
|
+
if (id != null) continue;
|
|
1568
1564
|
if (!isMemoOrForwardRef) continue;
|
|
1569
|
-
if (displayName == null) {
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
node: id ?? node
|
|
1574
|
-
});
|
|
1575
|
-
}
|
|
1565
|
+
if (displayName == null) context.report({
|
|
1566
|
+
messageId: "noMissingComponentDisplayName",
|
|
1567
|
+
node
|
|
1568
|
+
});
|
|
1576
1569
|
}
|
|
1577
1570
|
}
|
|
1578
1571
|
};
|
|
@@ -1815,21 +1808,21 @@ var no_nested_component_definitions_default = createRule({
|
|
|
1815
1808
|
defaultOptions: []
|
|
1816
1809
|
});
|
|
1817
1810
|
function create$27(context) {
|
|
1818
|
-
const
|
|
1819
|
-
const
|
|
1811
|
+
const fCollector = useComponentCollector(context, { hint: ComponentDetectionHint.SkipArrayMapArgument | ComponentDetectionHint.SkipNullLiteral | ComponentDetectionHint.SkipUndefined | ComponentDetectionHint.SkipBooleanLiteral | ComponentDetectionHint.SkipStringLiteral | ComponentDetectionHint.SkipNumberLiteral | ComponentDetectionHint.StrictLogical | ComponentDetectionHint.StrictConditional });
|
|
1812
|
+
const cCollector = useComponentCollectorLegacy();
|
|
1820
1813
|
return {
|
|
1821
|
-
...
|
|
1822
|
-
...
|
|
1814
|
+
...fCollector.listeners,
|
|
1815
|
+
...cCollector.listeners,
|
|
1823
1816
|
"Program:exit"(program) {
|
|
1824
|
-
const
|
|
1825
|
-
const
|
|
1817
|
+
const fComponents = [...fCollector.ctx.getAllComponents(program)];
|
|
1818
|
+
const cComponents = [...cCollector.ctx.getAllComponents(program)];
|
|
1826
1819
|
const isFunctionComponent = (node) => {
|
|
1827
|
-
return AST.isFunction(node) &&
|
|
1820
|
+
return AST.isFunction(node) && fComponents.some((component) => component.node === node);
|
|
1828
1821
|
};
|
|
1829
1822
|
const isClassComponent$1 = (node) => {
|
|
1830
|
-
return AST.isClass(node) &&
|
|
1823
|
+
return AST.isClass(node) && cComponents.some((component) => component.node === node);
|
|
1831
1824
|
};
|
|
1832
|
-
for (const { name: name$7, node: component } of
|
|
1825
|
+
for (const { name: name$7, node: component } of fComponents) {
|
|
1833
1826
|
if (name$7 == null) continue;
|
|
1834
1827
|
if (isDirectValueOfRenderPropertyLoose(component)) continue;
|
|
1835
1828
|
if (isInsideJSXAttributeValue(component)) {
|
|
@@ -1875,7 +1868,7 @@ function create$27(context) {
|
|
|
1875
1868
|
}
|
|
1876
1869
|
});
|
|
1877
1870
|
}
|
|
1878
|
-
for (const { name: name$7 = "unknown", node: component } of
|
|
1871
|
+
for (const { name: name$7 = "unknown", node: component } of cComponents) {
|
|
1879
1872
|
if (AST.findParentNode(component, (n) => isClassComponent$1(n) || isFunctionComponent(n)) == null) continue;
|
|
1880
1873
|
context.report({
|
|
1881
1874
|
messageId: "noNestedComponentDefinitions",
|
|
@@ -1951,8 +1944,8 @@ function create$26(context) {
|
|
|
1951
1944
|
if (lazyCall != null) lazyComponentDeclarations.add(lazyCall);
|
|
1952
1945
|
},
|
|
1953
1946
|
"Program:exit"(program) {
|
|
1954
|
-
const functionComponents =
|
|
1955
|
-
const classComponents =
|
|
1947
|
+
const functionComponents = collector.ctx.getAllComponents(program);
|
|
1948
|
+
const classComponents = collectorLegacy.ctx.getAllComponents(program);
|
|
1956
1949
|
for (const lazy of lazyComponentDeclarations) if (AST.findParentNode(lazy, (n) => {
|
|
1957
1950
|
if (AST.isJSX(n)) return true;
|
|
1958
1951
|
if (n.type === AST_NODE_TYPES.CallExpression) return isReactHookCall(n) || isCreateElementCall(context, n) || isCreateContextCall(context, n);
|
|
@@ -2038,8 +2031,7 @@ function create$24(context) {
|
|
|
2038
2031
|
return {
|
|
2039
2032
|
...listeners,
|
|
2040
2033
|
"Program:exit"(program) {
|
|
2041
|
-
const
|
|
2042
|
-
for (const { name: name$7 = "PureComponent", node: component, flag } of components.values()) {
|
|
2034
|
+
for (const { name: name$7 = "PureComponent", node: component, flag } of ctx.getAllComponents(program)) {
|
|
2043
2035
|
if ((flag & ComponentFlag.PureComponent) === 0n) continue;
|
|
2044
2036
|
const { body } = component.body;
|
|
2045
2037
|
for (const member of body) if (isShouldComponentUpdate(member)) context.report({
|
|
@@ -2449,8 +2441,7 @@ function create$16(context) {
|
|
|
2449
2441
|
return {
|
|
2450
2442
|
...listeners,
|
|
2451
2443
|
"Program:exit"(program) {
|
|
2452
|
-
const
|
|
2453
|
-
for (const { id, name: name$7, node, hookCalls } of allHooks.values()) {
|
|
2444
|
+
for (const { id, name: name$7, node, hookCalls } of ctx.getAllHooks(program)) {
|
|
2454
2445
|
if (hookCalls.length > 0) continue;
|
|
2455
2446
|
if (AST.isFunctionEmpty(node)) continue;
|
|
2456
2447
|
if (WELL_KNOWN_HOOKS.includes(name$7)) continue;
|
|
@@ -2490,8 +2481,7 @@ function create$15(context) {
|
|
|
2490
2481
|
return {
|
|
2491
2482
|
...listeners,
|
|
2492
2483
|
"Program:exit"(program) {
|
|
2493
|
-
const
|
|
2494
|
-
for (const { node: component } of components.values()) {
|
|
2484
|
+
for (const { node: component } of ctx.getAllComponents(program)) {
|
|
2495
2485
|
const { body } = component.body;
|
|
2496
2486
|
for (const member of body) if (isUnsafeComponentWillMount(member)) context.report({
|
|
2497
2487
|
messageId: "noUnsafeComponentWillMount",
|
|
@@ -2526,8 +2516,7 @@ function create$14(context) {
|
|
|
2526
2516
|
return {
|
|
2527
2517
|
...listeners,
|
|
2528
2518
|
"Program:exit"(program) {
|
|
2529
|
-
const
|
|
2530
|
-
for (const { node: component } of components.values()) {
|
|
2519
|
+
for (const { node: component } of ctx.getAllComponents(program)) {
|
|
2531
2520
|
const { body } = component.body;
|
|
2532
2521
|
for (const member of body) if (isUnsafeComponentWillReceiveProps(member)) context.report({
|
|
2533
2522
|
messageId: "noUnsafeComponentWillReceiveProps",
|
|
@@ -2562,8 +2551,7 @@ function create$13(context) {
|
|
|
2562
2551
|
return {
|
|
2563
2552
|
...listeners,
|
|
2564
2553
|
"Program:exit"(program) {
|
|
2565
|
-
const
|
|
2566
|
-
for (const { node: component } of components.values()) {
|
|
2554
|
+
for (const { node: component } of ctx.getAllComponents(program)) {
|
|
2567
2555
|
const { body } = component.body;
|
|
2568
2556
|
for (const member of body) if (isUnsafeComponentWillUpdate(member)) context.report({
|
|
2569
2557
|
messageId: "noUnsafeComponentWillUpdate",
|
|
@@ -2616,8 +2604,7 @@ function create$12(context) {
|
|
|
2616
2604
|
getOrElseUpdate(constructions, functionEntry.node, () => []).push(construction);
|
|
2617
2605
|
},
|
|
2618
2606
|
"Program:exit"(program) {
|
|
2619
|
-
const
|
|
2620
|
-
for (const { node: component } of components) for (const construction of constructions.get(component) ?? []) {
|
|
2607
|
+
for (const { node: component } of ctx.getAllComponents(program)) for (const construction of constructions.get(component) ?? []) {
|
|
2621
2608
|
const { kind, node: constructionNode } = construction;
|
|
2622
2609
|
const suggestion = kind === "function" ? "Consider wrapping it in a useCallback hook." : "Consider wrapping it in a useMemo hook.";
|
|
2623
2610
|
context.report({
|
|
@@ -2686,8 +2673,7 @@ function create$11(context, [options]) {
|
|
|
2686
2673
|
getOrElseUpdate(declarators, functionEntry.node, () => []).push(node);
|
|
2687
2674
|
},
|
|
2688
2675
|
"Program:exit"(program) {
|
|
2689
|
-
const
|
|
2690
|
-
for (const { node: component } of components.values()) {
|
|
2676
|
+
for (const { node: component } of ctx.getAllComponents(program)) {
|
|
2691
2677
|
const { params } = component;
|
|
2692
2678
|
const [props] = params;
|
|
2693
2679
|
if (props == null) continue;
|
|
@@ -2862,10 +2848,9 @@ function create$9(context) {
|
|
|
2862
2848
|
...listeners,
|
|
2863
2849
|
"Program:exit"(program) {
|
|
2864
2850
|
const checker = services.program.getTypeChecker();
|
|
2865
|
-
const components = ctx.getAllComponents(program);
|
|
2866
2851
|
const totalDeclaredProps = /* @__PURE__ */ new Set();
|
|
2867
2852
|
const totalUsedProps = /* @__PURE__ */ new Set();
|
|
2868
|
-
for (const
|
|
2853
|
+
for (const component of ctx.getAllComponents(program)) {
|
|
2869
2854
|
const [props] = component.node.params;
|
|
2870
2855
|
if (props == null) continue;
|
|
2871
2856
|
const usedPropKeys = /* @__PURE__ */ new Set();
|
|
@@ -3347,23 +3332,23 @@ var prefer_destructuring_assignment_default = createRule({
|
|
|
3347
3332
|
});
|
|
3348
3333
|
function create$4(context) {
|
|
3349
3334
|
const { ctx, listeners } = useComponentCollector(context);
|
|
3350
|
-
const
|
|
3335
|
+
const exprs = [];
|
|
3351
3336
|
return {
|
|
3352
3337
|
...listeners,
|
|
3353
3338
|
MemberExpression(node) {
|
|
3354
3339
|
if (isMemberExpressionWithObjectName(node)) {
|
|
3355
3340
|
const scope = context.sourceCode.getScope(node);
|
|
3356
|
-
|
|
3341
|
+
exprs.push([scope, node]);
|
|
3357
3342
|
}
|
|
3358
3343
|
},
|
|
3359
3344
|
"Program:exit"(program) {
|
|
3360
|
-
const
|
|
3345
|
+
const componentBlocks = new Set(ctx.getAllComponents(program).map((component) => component.node));
|
|
3361
3346
|
function isFunctionComponent(block) {
|
|
3362
3347
|
if (!AST.isFunction(block)) return false;
|
|
3363
3348
|
const id = AST.getFunctionId(block);
|
|
3364
|
-
return id != null && isComponentNameLoose(id.name) &&
|
|
3349
|
+
return id != null && isComponentNameLoose(id.name) && componentBlocks.has(block);
|
|
3365
3350
|
}
|
|
3366
|
-
for (const [initialScope,
|
|
3351
|
+
for (const [initialScope, expr] of exprs) {
|
|
3367
3352
|
let scope = initialScope;
|
|
3368
3353
|
let isComponent = isFunctionComponent(scope.block);
|
|
3369
3354
|
while (!isComponent && scope.upper != null && scope.upper !== scope) {
|
|
@@ -3373,18 +3358,13 @@ function create$4(context) {
|
|
|
3373
3358
|
if (!isComponent) continue;
|
|
3374
3359
|
const component = scope.block;
|
|
3375
3360
|
if (!("params" in component)) continue;
|
|
3376
|
-
const
|
|
3377
|
-
const isMatch = (node) => node != null && node.type === AST_NODE_TYPES.Identifier && node.name ===
|
|
3361
|
+
const props = component.params.at(0);
|
|
3362
|
+
const isMatch = (node) => node != null && node.type === AST_NODE_TYPES.Identifier && node.name === expr.object.name;
|
|
3378
3363
|
if (isMatch(props)) context.report({
|
|
3379
3364
|
messageId: "preferDestructuringAssignment",
|
|
3380
|
-
node:
|
|
3365
|
+
node: expr,
|
|
3381
3366
|
data: { name: "props" }
|
|
3382
3367
|
});
|
|
3383
|
-
if (isMatch(ctx$1)) context.report({
|
|
3384
|
-
messageId: "preferDestructuringAssignment",
|
|
3385
|
-
node: memberExpression,
|
|
3386
|
-
data: { name: "context" }
|
|
3387
|
-
});
|
|
3388
3368
|
}
|
|
3389
3369
|
}
|
|
3390
3370
|
};
|
|
@@ -3456,8 +3436,7 @@ function create$2(context) {
|
|
|
3456
3436
|
return {
|
|
3457
3437
|
...listeners,
|
|
3458
3438
|
"Program:exit"(program) {
|
|
3459
|
-
const
|
|
3460
|
-
for (const [, component] of components) {
|
|
3439
|
+
for (const component of ctx.getAllComponents(program)) {
|
|
3461
3440
|
const [props] = component.node.params;
|
|
3462
3441
|
if (component.id == null || component.name == null) continue;
|
|
3463
3442
|
if (props == null) continue;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-react-x",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.11-beta.0",
|
|
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",
|
|
@@ -46,16 +46,16 @@
|
|
|
46
46
|
"string-ts": "^2.3.1",
|
|
47
47
|
"ts-api-utils": "^2.1.0",
|
|
48
48
|
"ts-pattern": "^5.9.0",
|
|
49
|
-
"@eslint-react/ast": "2.3.
|
|
50
|
-
"@eslint-react/
|
|
51
|
-
"@eslint-react/
|
|
52
|
-
"@eslint-react/
|
|
53
|
-
"@eslint-react/
|
|
49
|
+
"@eslint-react/ast": "2.3.11-beta.0",
|
|
50
|
+
"@eslint-react/shared": "2.3.11-beta.0",
|
|
51
|
+
"@eslint-react/eff": "2.3.11-beta.0",
|
|
52
|
+
"@eslint-react/var": "2.3.11-beta.0",
|
|
53
|
+
"@eslint-react/core": "2.3.11-beta.0"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@types/react": "^19.2.7",
|
|
57
57
|
"@types/react-dom": "^19.2.3",
|
|
58
|
-
"tsdown": "^0.17.0-beta.
|
|
58
|
+
"tsdown": "^0.17.0-beta.5",
|
|
59
59
|
"@local/configs": "0.0.0"
|
|
60
60
|
},
|
|
61
61
|
"peerDependencies": {
|