eslint-plugin-react-x 1.23.3-next.4 → 1.23.3-next.6
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 +91 -85
- package/dist/index.mjs +93 -87
- package/package.json +9 -9
package/dist/index.js
CHANGED
|
@@ -42,7 +42,7 @@ var ts__default = /*#__PURE__*/_interopDefault(ts);
|
|
|
42
42
|
|
|
43
43
|
// package.json
|
|
44
44
|
var name = "eslint-plugin-react-x";
|
|
45
|
-
var version = "1.23.3-next.
|
|
45
|
+
var version = "1.23.3-next.6";
|
|
46
46
|
var createRule = shared.createRuleForPlugin("x");
|
|
47
47
|
|
|
48
48
|
// src/rules/avoid-shorthand-boolean.ts
|
|
@@ -66,7 +66,7 @@ var avoid_shorthand_boolean_default = createRule({
|
|
|
66
66
|
name: RULE_NAME,
|
|
67
67
|
create(context) {
|
|
68
68
|
function getReportDescriptor(node) {
|
|
69
|
-
return node.value ? eff.O.none() : eff.O.some({
|
|
69
|
+
return node.value != null ? eff.O.none() : eff.O.some({
|
|
70
70
|
messageId: "avoidShorthandBoolean",
|
|
71
71
|
node,
|
|
72
72
|
data: {
|
|
@@ -136,11 +136,11 @@ var ensure_forward_ref_using_ref_default = createRule({
|
|
|
136
136
|
return;
|
|
137
137
|
}
|
|
138
138
|
const [component] = node.arguments;
|
|
139
|
-
if (
|
|
139
|
+
if (component == null || !AST11__namespace.isFunction(component)) {
|
|
140
140
|
return;
|
|
141
141
|
}
|
|
142
142
|
const [_, ref] = component.params;
|
|
143
|
-
if (ref) {
|
|
143
|
+
if (ref != null) {
|
|
144
144
|
return;
|
|
145
145
|
}
|
|
146
146
|
context.report({
|
|
@@ -221,15 +221,15 @@ var no_access_state_in_setstate_default = createRule({
|
|
|
221
221
|
return;
|
|
222
222
|
}
|
|
223
223
|
const [currClass, isComponent] = classStack.at(-1) ?? [];
|
|
224
|
-
if (
|
|
224
|
+
if (currClass == null || !isComponent) {
|
|
225
225
|
return;
|
|
226
226
|
}
|
|
227
227
|
const [currMethod, isStatic] = methodStack.at(-1) ?? [];
|
|
228
|
-
if (
|
|
228
|
+
if (currMethod == null || isStatic) {
|
|
229
229
|
return;
|
|
230
230
|
}
|
|
231
231
|
const [setState, hasThisState] = setStateStack.at(-1) ?? [];
|
|
232
|
-
if (
|
|
232
|
+
if (setState == null || hasThisState) {
|
|
233
233
|
return;
|
|
234
234
|
}
|
|
235
235
|
if (!eff.O.exists(getName(node.property), (name2) => name2 === "state")) {
|
|
@@ -251,18 +251,18 @@ var no_access_state_in_setstate_default = createRule({
|
|
|
251
251
|
},
|
|
252
252
|
VariableDeclarator(node) {
|
|
253
253
|
const [currClass, isComponent] = classStack.at(-1) ?? [];
|
|
254
|
-
if (
|
|
254
|
+
if (currClass == null || !isComponent) {
|
|
255
255
|
return;
|
|
256
256
|
}
|
|
257
257
|
const [currMethod, isStatic] = methodStack.at(-1) ?? [];
|
|
258
|
-
if (
|
|
258
|
+
if (currMethod == null || isStatic) {
|
|
259
259
|
return;
|
|
260
260
|
}
|
|
261
261
|
const [setState, hasThisState] = setStateStack.at(-1) ?? [];
|
|
262
|
-
if (
|
|
262
|
+
if (setState == null || hasThisState) {
|
|
263
263
|
return;
|
|
264
264
|
}
|
|
265
|
-
if (!(node.init && AST11__namespace.isThisExpression(node.init) && node.id.type === types.AST_NODE_TYPES.ObjectPattern)) {
|
|
265
|
+
if (!(node.init != null && AST11__namespace.isThisExpression(node.init) && node.id.type === types.AST_NODE_TYPES.ObjectPattern)) {
|
|
266
266
|
return;
|
|
267
267
|
}
|
|
268
268
|
const hasState = node.id.properties.some((prop) => {
|
|
@@ -299,16 +299,6 @@ var iteratorFunctionIndexParamPosition = /* @__PURE__ */ new Map([
|
|
|
299
299
|
["reduceRight", 2],
|
|
300
300
|
["some", 1]
|
|
301
301
|
]);
|
|
302
|
-
var isToStringCall = tsPattern.isMatching({
|
|
303
|
-
type: types.AST_NODE_TYPES.CallExpression,
|
|
304
|
-
callee: {
|
|
305
|
-
type: types.AST_NODE_TYPES.MemberExpression,
|
|
306
|
-
property: {
|
|
307
|
-
type: types.AST_NODE_TYPES.Identifier,
|
|
308
|
-
name: "toString"
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
});
|
|
312
302
|
function isReactChildrenMethod(name2) {
|
|
313
303
|
return reactChildrenMethod.some((method) => method === name2);
|
|
314
304
|
}
|
|
@@ -343,7 +333,7 @@ function getMapIndexParamName(node, context) {
|
|
|
343
333
|
return eff.O.none();
|
|
344
334
|
}
|
|
345
335
|
const callbackArg = node.arguments[isUsingReactChildren(node, context) ? 1 : 0];
|
|
346
|
-
if (
|
|
336
|
+
if (callbackArg == null) {
|
|
347
337
|
return eff.O.none();
|
|
348
338
|
}
|
|
349
339
|
if (!AST11__namespace.isOneOf([types.AST_NODE_TYPES.ArrowFunctionExpression, types.AST_NODE_TYPES.FunctionExpression])(callbackArg)) {
|
|
@@ -358,7 +348,7 @@ function getMapIndexParamName(node, context) {
|
|
|
358
348
|
return eff.O.none();
|
|
359
349
|
}
|
|
360
350
|
const param = params.at(indexParamPosition);
|
|
361
|
-
return param && "name" in param ? eff.O.some(param.name) : eff.O.none();
|
|
351
|
+
return param != null && "name" in param ? eff.O.some(param.name) : eff.O.none();
|
|
362
352
|
}
|
|
363
353
|
var no_array_index_key_default = createRule({
|
|
364
354
|
meta: {
|
|
@@ -375,40 +365,57 @@ var no_array_index_key_default = createRule({
|
|
|
375
365
|
name: RULE_NAME5,
|
|
376
366
|
create(context) {
|
|
377
367
|
const indexParamNames = [];
|
|
378
|
-
const isCreateOrCloneElementCall = eff.or(core.isCreateElementCall(context), core.isCloneElementCall(context));
|
|
379
368
|
function isArrayIndex(node) {
|
|
380
369
|
return node.type === types.AST_NODE_TYPES.Identifier && indexParamNames.some(eff.O.exists((name2) => name2 === node.name));
|
|
381
370
|
}
|
|
382
|
-
function
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
if (
|
|
390
|
-
return [
|
|
371
|
+
function isCreateOrCloneElementCall(node) {
|
|
372
|
+
return core.isCreateElementCall(node, context) || core.isCloneElementCall(node, context);
|
|
373
|
+
}
|
|
374
|
+
function getReportDescriptors(node) {
|
|
375
|
+
switch (node.type) {
|
|
376
|
+
// key={bar}
|
|
377
|
+
case types.AST_NODE_TYPES.Identifier: {
|
|
378
|
+
if (indexParamNames.some(eff.O.exists((name2) => name2 === node.name))) {
|
|
379
|
+
return [{
|
|
380
|
+
messageId: "noArrayIndexKey",
|
|
381
|
+
node
|
|
382
|
+
}];
|
|
391
383
|
}
|
|
392
|
-
return acc;
|
|
393
|
-
}, []);
|
|
394
|
-
}
|
|
395
|
-
if (isToStringCall(node)) {
|
|
396
|
-
if (!("object" in node.callee && isArrayIndex(node.callee.object))) {
|
|
397
384
|
return [];
|
|
398
385
|
}
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
386
|
+
// key={`foo-${bar}`} or key={'foo' + bar}
|
|
387
|
+
case types.AST_NODE_TYPES.TemplateLiteral:
|
|
388
|
+
case types.AST_NODE_TYPES.BinaryExpression: {
|
|
389
|
+
const descriptors = [];
|
|
390
|
+
const expressions = node.type === types.AST_NODE_TYPES.TemplateLiteral ? node.expressions : AST11__namespace.getIdentifiersFromBinaryExpression(node);
|
|
391
|
+
for (const expression of expressions) {
|
|
392
|
+
if (isArrayIndex(expression)) {
|
|
393
|
+
descriptors.push({
|
|
394
|
+
messageId: "noArrayIndexKey",
|
|
395
|
+
node: expression
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
return descriptors;
|
|
400
|
+
}
|
|
401
|
+
// key={bar.toString()} or key={String(bar)}
|
|
402
|
+
case types.AST_NODE_TYPES.CallExpression: {
|
|
403
|
+
switch (true) {
|
|
404
|
+
// key={bar.toString()}
|
|
405
|
+
case (node.callee.type === types.AST_NODE_TYPES.MemberExpression && node.callee.property.type === types.AST_NODE_TYPES.Identifier && node.callee.property.name === "toString" && isArrayIndex(node.callee.object)): {
|
|
406
|
+
return [{
|
|
407
|
+
messageId: "noArrayIndexKey",
|
|
408
|
+
node: node.callee.object
|
|
409
|
+
}];
|
|
410
|
+
}
|
|
411
|
+
// key={String(bar)}
|
|
412
|
+
case (node.callee.type === types.AST_NODE_TYPES.Identifier && node.callee.name === "String" && node.arguments[0] != null && isArrayIndex(node.arguments[0])): {
|
|
413
|
+
return [{
|
|
414
|
+
messageId: "noArrayIndexKey",
|
|
415
|
+
node: node.arguments[0]
|
|
416
|
+
}];
|
|
417
|
+
}
|
|
418
|
+
}
|
|
412
419
|
}
|
|
413
420
|
}
|
|
414
421
|
return [];
|
|
@@ -433,7 +440,7 @@ var no_array_index_key_default = createRule({
|
|
|
433
440
|
if (!("value" in prop)) {
|
|
434
441
|
continue;
|
|
435
442
|
}
|
|
436
|
-
const descriptors =
|
|
443
|
+
const descriptors = getReportDescriptors(prop.value);
|
|
437
444
|
for (const descriptor of descriptors) {
|
|
438
445
|
context.report(descriptor);
|
|
439
446
|
}
|
|
@@ -449,11 +456,10 @@ var no_array_index_key_default = createRule({
|
|
|
449
456
|
if (indexParamNames.length === 0) {
|
|
450
457
|
return;
|
|
451
458
|
}
|
|
452
|
-
|
|
453
|
-
if (value?.type !== types.AST_NODE_TYPES.JSXExpressionContainer) {
|
|
459
|
+
if (node.value?.type !== types.AST_NODE_TYPES.JSXExpressionContainer) {
|
|
454
460
|
return;
|
|
455
461
|
}
|
|
456
|
-
const descriptors =
|
|
462
|
+
const descriptors = getReportDescriptors(node.value.expression);
|
|
457
463
|
for (const descriptor of descriptors) {
|
|
458
464
|
context.report(descriptor);
|
|
459
465
|
}
|
|
@@ -1017,7 +1023,7 @@ var no_context_provider_default = createRule({
|
|
|
1017
1023
|
const providerName = elementName.replace(/\.Provider$/, "");
|
|
1018
1024
|
const openingElement = node.openingElement;
|
|
1019
1025
|
const closingElement = node.closingElement;
|
|
1020
|
-
if (
|
|
1026
|
+
if (closingElement == null) {
|
|
1021
1027
|
return fixer.replaceText(openingElement.name, providerName);
|
|
1022
1028
|
}
|
|
1023
1029
|
return [
|
|
@@ -1259,7 +1265,7 @@ var no_duplicate_key_default = createRule({
|
|
|
1259
1265
|
function isKeyValueEqual(a, b) {
|
|
1260
1266
|
const aValue = a.value;
|
|
1261
1267
|
const bValue = b.value;
|
|
1262
|
-
if (aValue
|
|
1268
|
+
if (aValue == null || bValue == null) {
|
|
1263
1269
|
return false;
|
|
1264
1270
|
}
|
|
1265
1271
|
return AST11__namespace.isNodeEqual(aValue, bValue);
|
|
@@ -1367,7 +1373,7 @@ var no_forward_ref_default = createRule({
|
|
|
1367
1373
|
function getFix(node, context) {
|
|
1368
1374
|
return (fixer) => {
|
|
1369
1375
|
const [componentNode] = node.arguments;
|
|
1370
|
-
if (
|
|
1376
|
+
if (componentNode == null || !AST11__namespace.isFunction(componentNode)) {
|
|
1371
1377
|
return [];
|
|
1372
1378
|
}
|
|
1373
1379
|
return [
|
|
@@ -1388,7 +1394,7 @@ function getComponentPropsFixes(node, typeArguments, fixer, context) {
|
|
|
1388
1394
|
const getText = (node2) => context.sourceCode.getText(node2);
|
|
1389
1395
|
const [arg0, arg1] = node.params;
|
|
1390
1396
|
const [typeArg0, typeArg1] = typeArguments;
|
|
1391
|
-
if (
|
|
1397
|
+
if (arg0 == null) {
|
|
1392
1398
|
return [];
|
|
1393
1399
|
}
|
|
1394
1400
|
const fixedArg0Text = tsPattern.match(arg0).with({ type: types.AST_NODE_TYPES.Identifier }, (n) => eff.O.some(`...${n.name}`)).with({ type: types.AST_NODE_TYPES.ObjectPattern }, (n) => eff.O.some(n.properties.map(getText).join(", "))).otherwise(eff.O.none);
|
|
@@ -1398,7 +1404,7 @@ function getComponentPropsFixes(node, typeArguments, fixer, context) {
|
|
|
1398
1404
|
}
|
|
1399
1405
|
const fixedPropsText = fixedArg0Text.value;
|
|
1400
1406
|
const fixedRefText = fixedArg1Text.value;
|
|
1401
|
-
if (
|
|
1407
|
+
if (typeArg0 == null || typeArg1 == null) {
|
|
1402
1408
|
return [
|
|
1403
1409
|
fixer.replaceText(
|
|
1404
1410
|
arg0,
|
|
@@ -1409,7 +1415,7 @@ function getComponentPropsFixes(node, typeArguments, fixer, context) {
|
|
|
1409
1415
|
"}"
|
|
1410
1416
|
].join(" ")
|
|
1411
1417
|
),
|
|
1412
|
-
...arg1 ? [fixer.remove(arg1), fixer.removeRange([arg0.range[1], arg1.range[0]])]
|
|
1418
|
+
...arg1 == null ? [] : [fixer.remove(arg1), fixer.removeRange([arg0.range[1], arg1.range[0]])]
|
|
1413
1419
|
];
|
|
1414
1420
|
}
|
|
1415
1421
|
return [
|
|
@@ -1428,7 +1434,7 @@ function getComponentPropsFixes(node, typeArguments, fixer, context) {
|
|
|
1428
1434
|
"}"
|
|
1429
1435
|
].join(" ")
|
|
1430
1436
|
),
|
|
1431
|
-
...arg1 ? [fixer.remove(arg1), fixer.removeRange([arg0.range[1], arg1.range[0]])]
|
|
1437
|
+
...arg1 == null ? [] : [fixer.remove(arg1), fixer.removeRange([arg0.range[1], arg1.range[0]])]
|
|
1432
1438
|
];
|
|
1433
1439
|
}
|
|
1434
1440
|
var RULE_NAME26 = "no-implicit-key";
|
|
@@ -1504,7 +1510,7 @@ function inspectVariantTypes(types) {
|
|
|
1504
1510
|
}
|
|
1505
1511
|
const booleans = types.filter(tsHelpers.isBooleanType);
|
|
1506
1512
|
switch (true) {
|
|
1507
|
-
case (booleans.length === 1 &&
|
|
1513
|
+
case (booleans.length === 1 && booleans[0] != null): {
|
|
1508
1514
|
const [first] = booleans;
|
|
1509
1515
|
const evaluated = eff.F.pipe(
|
|
1510
1516
|
tsPattern.match(first).when(tsApiUtils.isTrueLiteralType, () => eff.O.some("truthy boolean")).when(tsApiUtils.isFalseLiteralType, () => eff.O.some("falsy boolean")).otherwise(eff.O.none)
|
|
@@ -1663,7 +1669,7 @@ var no_missing_component_display_name_default = createRule({
|
|
|
1663
1669
|
"Program:exit"(node) {
|
|
1664
1670
|
const components = ctx.getAllComponents(node);
|
|
1665
1671
|
for (const { node: node2, displayName, flag } of components.values()) {
|
|
1666
|
-
const isMemoOrForwardRef =
|
|
1672
|
+
const isMemoOrForwardRef = (flag & (core.ERFunctionComponentFlag.ForwardRef | core.ERFunctionComponentFlag.Memo)) > 0n;
|
|
1667
1673
|
if (eff.O.isSome(AST11__namespace.getFunctionIdentifier(node2))) {
|
|
1668
1674
|
continue;
|
|
1669
1675
|
}
|
|
@@ -1745,7 +1751,7 @@ var no_missing_key_default = createRule({
|
|
|
1745
1751
|
}
|
|
1746
1752
|
function checkBlockStatement(node) {
|
|
1747
1753
|
return AST11__namespace.getNestedReturnStatements(node).reduce((acc, statement) => {
|
|
1748
|
-
if (
|
|
1754
|
+
if (statement.argument == null) {
|
|
1749
1755
|
return acc;
|
|
1750
1756
|
}
|
|
1751
1757
|
const mbDescriptor = checkIteratorElement(statement.argument);
|
|
@@ -2021,7 +2027,7 @@ var no_redundant_should_component_update_default = createRule({
|
|
|
2021
2027
|
"Program:exit"(node) {
|
|
2022
2028
|
const components = ctx.getAllComponents(node);
|
|
2023
2029
|
for (const { name: name2, node: component, flag } of components.values()) {
|
|
2024
|
-
if (
|
|
2030
|
+
if ((flag & core.ERClassComponentFlag.PureComponent) === 0n) {
|
|
2025
2031
|
continue;
|
|
2026
2032
|
}
|
|
2027
2033
|
const { body } = component.body;
|
|
@@ -2493,7 +2499,7 @@ var no_unstable_default_props_default = createRule({
|
|
|
2493
2499
|
for (const { node: component } of components.values()) {
|
|
2494
2500
|
const { params } = component;
|
|
2495
2501
|
const [props] = params;
|
|
2496
|
-
if (
|
|
2502
|
+
if (props == null) {
|
|
2497
2503
|
continue;
|
|
2498
2504
|
}
|
|
2499
2505
|
const properties = tsPattern.match(props).with({ type: types.AST_NODE_TYPES.ObjectPattern }, ({ properties: properties2 }) => properties2).with({ type: types.AST_NODE_TYPES.Identifier }, ({ name: name2 }) => {
|
|
@@ -2605,13 +2611,13 @@ var no_unused_class_component_members_default = createRule({
|
|
|
2605
2611
|
}
|
|
2606
2612
|
function classExit() {
|
|
2607
2613
|
const currentClass = classStack.pop();
|
|
2608
|
-
if (
|
|
2614
|
+
if (currentClass == null || !core.isClassComponent(currentClass)) {
|
|
2609
2615
|
return;
|
|
2610
2616
|
}
|
|
2611
2617
|
const className = eff.O.map(AST11__namespace.getClassIdentifier(currentClass), (id) => id.name);
|
|
2612
2618
|
const defs = propertyDefs.get(currentClass);
|
|
2613
2619
|
const usages = propertyUsages.get(currentClass);
|
|
2614
|
-
if (
|
|
2620
|
+
if (defs == null) {
|
|
2615
2621
|
return;
|
|
2616
2622
|
}
|
|
2617
2623
|
for (const def of defs) {
|
|
@@ -2635,7 +2641,7 @@ var no_unused_class_component_members_default = createRule({
|
|
|
2635
2641
|
function methodEnter(node) {
|
|
2636
2642
|
methodStack.push(node);
|
|
2637
2643
|
const currentClass = classStack.at(-1);
|
|
2638
|
-
if (
|
|
2644
|
+
if (currentClass == null || !core.isClassComponent(currentClass)) {
|
|
2639
2645
|
return;
|
|
2640
2646
|
}
|
|
2641
2647
|
if (node.static) {
|
|
@@ -2656,7 +2662,7 @@ var no_unused_class_component_members_default = createRule({
|
|
|
2656
2662
|
MemberExpression(node) {
|
|
2657
2663
|
const currentClass = classStack.at(-1);
|
|
2658
2664
|
const currentMethod = methodStack.at(-1);
|
|
2659
|
-
if (
|
|
2665
|
+
if (currentClass == null || currentMethod == null) {
|
|
2660
2666
|
return;
|
|
2661
2667
|
}
|
|
2662
2668
|
if (!core.isClassComponent(currentClass) || currentMethod.static) {
|
|
@@ -2678,13 +2684,13 @@ var no_unused_class_component_members_default = createRule({
|
|
|
2678
2684
|
VariableDeclarator(node) {
|
|
2679
2685
|
const currentClass = classStack.at(-1);
|
|
2680
2686
|
const currentMethod = methodStack.at(-1);
|
|
2681
|
-
if (
|
|
2687
|
+
if (currentClass == null || currentMethod == null) {
|
|
2682
2688
|
return;
|
|
2683
2689
|
}
|
|
2684
2690
|
if (!core.isClassComponent(currentClass) || currentMethod.static) {
|
|
2685
2691
|
return;
|
|
2686
2692
|
}
|
|
2687
|
-
if (node.init && AST11__namespace.isThisExpression(node.init) && node.id.type === types.AST_NODE_TYPES.ObjectPattern) {
|
|
2693
|
+
if (node.init != null && AST11__namespace.isThisExpression(node.init) && node.id.type === types.AST_NODE_TYPES.ObjectPattern) {
|
|
2688
2694
|
for (const prop of node.id.properties) {
|
|
2689
2695
|
if (prop.type === types.AST_NODE_TYPES.Property && AST11__namespace.isKeyLiteralLike(prop, prop.key)) {
|
|
2690
2696
|
const mbName = getName3(prop.key);
|
|
@@ -2755,7 +2761,7 @@ var no_unused_state_default = createRule({
|
|
|
2755
2761
|
}
|
|
2756
2762
|
function classExit() {
|
|
2757
2763
|
const currentClass = classStack.pop();
|
|
2758
|
-
if (
|
|
2764
|
+
if (currentClass == null || !core.isClassComponent(currentClass)) {
|
|
2759
2765
|
return;
|
|
2760
2766
|
}
|
|
2761
2767
|
const className = eff.O.map(AST11__namespace.getClassIdentifier(currentClass), (id) => id.name);
|
|
@@ -2774,7 +2780,7 @@ var no_unused_state_default = createRule({
|
|
|
2774
2780
|
function methodEnter(node) {
|
|
2775
2781
|
methodStack.push(node);
|
|
2776
2782
|
const currentClass = classStack.at(-1);
|
|
2777
|
-
if (
|
|
2783
|
+
if (currentClass == null || !core.isClassComponent(currentClass)) {
|
|
2778
2784
|
return;
|
|
2779
2785
|
}
|
|
2780
2786
|
if (node.static) {
|
|
@@ -2803,11 +2809,11 @@ var no_unused_state_default = createRule({
|
|
|
2803
2809
|
return;
|
|
2804
2810
|
}
|
|
2805
2811
|
const currentClass = classStack.at(-1);
|
|
2806
|
-
if (
|
|
2812
|
+
if (currentClass == null || !core.isClassComponent(currentClass)) {
|
|
2807
2813
|
return;
|
|
2808
2814
|
}
|
|
2809
2815
|
const currentConstructor = constructorStack.at(-1);
|
|
2810
|
-
if (
|
|
2816
|
+
if (currentConstructor == null || !currentClass.body.body.includes(currentConstructor)) {
|
|
2811
2817
|
return;
|
|
2812
2818
|
}
|
|
2813
2819
|
const [_, isUsed] = stateDefs.get(currentClass) ?? [eff.O.none(), false];
|
|
@@ -2825,11 +2831,11 @@ var no_unused_state_default = createRule({
|
|
|
2825
2831
|
return;
|
|
2826
2832
|
}
|
|
2827
2833
|
const currentClass = classStack.at(-1);
|
|
2828
|
-
if (
|
|
2834
|
+
if (currentClass == null || !core.isClassComponent(currentClass)) {
|
|
2829
2835
|
return;
|
|
2830
2836
|
}
|
|
2831
2837
|
const currentMethod = methodStack.at(-1);
|
|
2832
|
-
if (
|
|
2838
|
+
if (currentMethod == null || currentMethod.static) {
|
|
2833
2839
|
return;
|
|
2834
2840
|
}
|
|
2835
2841
|
if (currentMethod === constructorStack.at(-1)) {
|
|
@@ -2849,11 +2855,11 @@ var no_unused_state_default = createRule({
|
|
|
2849
2855
|
"PropertyDefinition:exit": methodExit,
|
|
2850
2856
|
VariableDeclarator(node) {
|
|
2851
2857
|
const currentClass = classStack.at(-1);
|
|
2852
|
-
if (
|
|
2858
|
+
if (currentClass == null || !core.isClassComponent(currentClass)) {
|
|
2853
2859
|
return;
|
|
2854
2860
|
}
|
|
2855
2861
|
const currentMethod = methodStack.at(-1);
|
|
2856
|
-
if (
|
|
2862
|
+
if (currentMethod == null || currentMethod.static) {
|
|
2857
2863
|
return;
|
|
2858
2864
|
}
|
|
2859
2865
|
if (currentMethod === constructorStack.at(-1)) {
|
|
@@ -2862,7 +2868,7 @@ var no_unused_state_default = createRule({
|
|
|
2862
2868
|
if (!currentClass.body.body.includes(currentMethod)) {
|
|
2863
2869
|
return;
|
|
2864
2870
|
}
|
|
2865
|
-
if (!(node.init && AST11__namespace.isThisExpression(node.init) && node.id.type === types.AST_NODE_TYPES.ObjectPattern)) {
|
|
2871
|
+
if (!(node.init != null && AST11__namespace.isThisExpression(node.init) && node.id.type === types.AST_NODE_TYPES.ObjectPattern)) {
|
|
2866
2872
|
return;
|
|
2867
2873
|
}
|
|
2868
2874
|
const hasState = node.id.properties.some((prop) => {
|
|
@@ -3008,7 +3014,7 @@ var prefer_destructuring_assignment_default = createRule({
|
|
|
3008
3014
|
for (const [initialScope, memberExpression] of memberExpressionWithNames) {
|
|
3009
3015
|
let scope = initialScope;
|
|
3010
3016
|
let isComponent = isFunctionComponent(scope.block);
|
|
3011
|
-
while (!isComponent && scope.upper && scope.upper !== scope) {
|
|
3017
|
+
while (!isComponent && scope.upper != null && scope.upper !== scope) {
|
|
3012
3018
|
scope = scope.upper;
|
|
3013
3019
|
isComponent = isFunctionComponent(scope.block);
|
|
3014
3020
|
}
|
|
@@ -3134,7 +3140,7 @@ var prefer_read_only_props_default = createRule({
|
|
|
3134
3140
|
const components = ctx.getAllComponents(node);
|
|
3135
3141
|
for (const [_, component] of components) {
|
|
3136
3142
|
const [props] = component.node.params;
|
|
3137
|
-
if (
|
|
3143
|
+
if (props == null) {
|
|
3138
3144
|
continue;
|
|
3139
3145
|
}
|
|
3140
3146
|
const propsType = typeUtils.getConstrainedTypeAtLocation(services, props);
|
|
@@ -3223,7 +3229,7 @@ var prefer_shorthand_fragment_default = createRule({
|
|
|
3223
3229
|
node,
|
|
3224
3230
|
fix: (fixer) => {
|
|
3225
3231
|
const { closingElement, openingElement } = node;
|
|
3226
|
-
if (
|
|
3232
|
+
if (closingElement == null) {
|
|
3227
3233
|
return [];
|
|
3228
3234
|
}
|
|
3229
3235
|
return [
|
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { F, O,
|
|
1
|
+
import { F, O, isString, not, or, isNullable } from '@eslint-react/eff';
|
|
2
2
|
import * as JSX7 from '@eslint-react/jsx';
|
|
3
3
|
import { createRuleForPlugin, getSettingsFromContext, unsafeDecodeSettings } from '@eslint-react/shared';
|
|
4
4
|
import * as AST11 from '@eslint-react/ast';
|
|
5
|
-
import { isForwardRefCall, isThisSetState, isClassComponent,
|
|
5
|
+
import { isForwardRefCall, isThisSetState, isClassComponent, isChildrenCount, isChildrenForEach, isChildrenMap, isChildrenOnly, isChildrenToArray, useComponentCollectorLegacy, isCloneElementCall, isCreateRefCall, isComponentName, useComponentCollector, ERFunctionComponentFlag, isChildrenToArrayCall, ERComponentHint, isDirectValueOfRenderPropertyLoose, isDeclaredInRenderPropLoose, isInsideCreateElementProps, isInsideRenderMethod, ERClassComponentFlag, isReactHookCall, isCreateElementCall, isInitializedFromReact } from '@eslint-react/core';
|
|
6
6
|
import { AST_NODE_TYPES } from '@typescript-eslint/types';
|
|
7
7
|
import { isMatching, match, P } from 'ts-pattern';
|
|
8
8
|
import { compare } from 'compare-versions';
|
|
@@ -15,7 +15,7 @@ import { getTypeImmutability, isUnknown, isImmutable, isReadonlyShallow, isReado
|
|
|
15
15
|
|
|
16
16
|
// package.json
|
|
17
17
|
var name = "eslint-plugin-react-x";
|
|
18
|
-
var version = "1.23.3-next.
|
|
18
|
+
var version = "1.23.3-next.6";
|
|
19
19
|
var createRule = createRuleForPlugin("x");
|
|
20
20
|
|
|
21
21
|
// src/rules/avoid-shorthand-boolean.ts
|
|
@@ -39,7 +39,7 @@ var avoid_shorthand_boolean_default = createRule({
|
|
|
39
39
|
name: RULE_NAME,
|
|
40
40
|
create(context) {
|
|
41
41
|
function getReportDescriptor(node) {
|
|
42
|
-
return node.value ? O.none() : O.some({
|
|
42
|
+
return node.value != null ? O.none() : O.some({
|
|
43
43
|
messageId: "avoidShorthandBoolean",
|
|
44
44
|
node,
|
|
45
45
|
data: {
|
|
@@ -109,11 +109,11 @@ var ensure_forward_ref_using_ref_default = createRule({
|
|
|
109
109
|
return;
|
|
110
110
|
}
|
|
111
111
|
const [component] = node.arguments;
|
|
112
|
-
if (
|
|
112
|
+
if (component == null || !AST11.isFunction(component)) {
|
|
113
113
|
return;
|
|
114
114
|
}
|
|
115
115
|
const [_, ref] = component.params;
|
|
116
|
-
if (ref) {
|
|
116
|
+
if (ref != null) {
|
|
117
117
|
return;
|
|
118
118
|
}
|
|
119
119
|
context.report({
|
|
@@ -194,15 +194,15 @@ var no_access_state_in_setstate_default = createRule({
|
|
|
194
194
|
return;
|
|
195
195
|
}
|
|
196
196
|
const [currClass, isComponent] = classStack.at(-1) ?? [];
|
|
197
|
-
if (
|
|
197
|
+
if (currClass == null || !isComponent) {
|
|
198
198
|
return;
|
|
199
199
|
}
|
|
200
200
|
const [currMethod, isStatic] = methodStack.at(-1) ?? [];
|
|
201
|
-
if (
|
|
201
|
+
if (currMethod == null || isStatic) {
|
|
202
202
|
return;
|
|
203
203
|
}
|
|
204
204
|
const [setState, hasThisState] = setStateStack.at(-1) ?? [];
|
|
205
|
-
if (
|
|
205
|
+
if (setState == null || hasThisState) {
|
|
206
206
|
return;
|
|
207
207
|
}
|
|
208
208
|
if (!O.exists(getName(node.property), (name2) => name2 === "state")) {
|
|
@@ -224,18 +224,18 @@ var no_access_state_in_setstate_default = createRule({
|
|
|
224
224
|
},
|
|
225
225
|
VariableDeclarator(node) {
|
|
226
226
|
const [currClass, isComponent] = classStack.at(-1) ?? [];
|
|
227
|
-
if (
|
|
227
|
+
if (currClass == null || !isComponent) {
|
|
228
228
|
return;
|
|
229
229
|
}
|
|
230
230
|
const [currMethod, isStatic] = methodStack.at(-1) ?? [];
|
|
231
|
-
if (
|
|
231
|
+
if (currMethod == null || isStatic) {
|
|
232
232
|
return;
|
|
233
233
|
}
|
|
234
234
|
const [setState, hasThisState] = setStateStack.at(-1) ?? [];
|
|
235
|
-
if (
|
|
235
|
+
if (setState == null || hasThisState) {
|
|
236
236
|
return;
|
|
237
237
|
}
|
|
238
|
-
if (!(node.init && AST11.isThisExpression(node.init) && node.id.type === AST_NODE_TYPES.ObjectPattern)) {
|
|
238
|
+
if (!(node.init != null && AST11.isThisExpression(node.init) && node.id.type === AST_NODE_TYPES.ObjectPattern)) {
|
|
239
239
|
return;
|
|
240
240
|
}
|
|
241
241
|
const hasState = node.id.properties.some((prop) => {
|
|
@@ -272,16 +272,6 @@ var iteratorFunctionIndexParamPosition = /* @__PURE__ */ new Map([
|
|
|
272
272
|
["reduceRight", 2],
|
|
273
273
|
["some", 1]
|
|
274
274
|
]);
|
|
275
|
-
var isToStringCall = isMatching({
|
|
276
|
-
type: AST_NODE_TYPES.CallExpression,
|
|
277
|
-
callee: {
|
|
278
|
-
type: AST_NODE_TYPES.MemberExpression,
|
|
279
|
-
property: {
|
|
280
|
-
type: AST_NODE_TYPES.Identifier,
|
|
281
|
-
name: "toString"
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
});
|
|
285
275
|
function isReactChildrenMethod(name2) {
|
|
286
276
|
return reactChildrenMethod.some((method) => method === name2);
|
|
287
277
|
}
|
|
@@ -316,7 +306,7 @@ function getMapIndexParamName(node, context) {
|
|
|
316
306
|
return O.none();
|
|
317
307
|
}
|
|
318
308
|
const callbackArg = node.arguments[isUsingReactChildren(node, context) ? 1 : 0];
|
|
319
|
-
if (
|
|
309
|
+
if (callbackArg == null) {
|
|
320
310
|
return O.none();
|
|
321
311
|
}
|
|
322
312
|
if (!AST11.isOneOf([AST_NODE_TYPES.ArrowFunctionExpression, AST_NODE_TYPES.FunctionExpression])(callbackArg)) {
|
|
@@ -331,7 +321,7 @@ function getMapIndexParamName(node, context) {
|
|
|
331
321
|
return O.none();
|
|
332
322
|
}
|
|
333
323
|
const param = params.at(indexParamPosition);
|
|
334
|
-
return param && "name" in param ? O.some(param.name) : O.none();
|
|
324
|
+
return param != null && "name" in param ? O.some(param.name) : O.none();
|
|
335
325
|
}
|
|
336
326
|
var no_array_index_key_default = createRule({
|
|
337
327
|
meta: {
|
|
@@ -348,40 +338,57 @@ var no_array_index_key_default = createRule({
|
|
|
348
338
|
name: RULE_NAME5,
|
|
349
339
|
create(context) {
|
|
350
340
|
const indexParamNames = [];
|
|
351
|
-
const isCreateOrCloneElementCall = or(isCreateElementCall(context), isCloneElementCall(context));
|
|
352
341
|
function isArrayIndex(node) {
|
|
353
342
|
return node.type === AST_NODE_TYPES.Identifier && indexParamNames.some(O.exists((name2) => name2 === node.name));
|
|
354
343
|
}
|
|
355
|
-
function
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
if (
|
|
363
|
-
return [
|
|
344
|
+
function isCreateOrCloneElementCall(node) {
|
|
345
|
+
return isCreateElementCall(node, context) || isCloneElementCall(node, context);
|
|
346
|
+
}
|
|
347
|
+
function getReportDescriptors(node) {
|
|
348
|
+
switch (node.type) {
|
|
349
|
+
// key={bar}
|
|
350
|
+
case AST_NODE_TYPES.Identifier: {
|
|
351
|
+
if (indexParamNames.some(O.exists((name2) => name2 === node.name))) {
|
|
352
|
+
return [{
|
|
353
|
+
messageId: "noArrayIndexKey",
|
|
354
|
+
node
|
|
355
|
+
}];
|
|
364
356
|
}
|
|
365
|
-
return acc;
|
|
366
|
-
}, []);
|
|
367
|
-
}
|
|
368
|
-
if (isToStringCall(node)) {
|
|
369
|
-
if (!("object" in node.callee && isArrayIndex(node.callee.object))) {
|
|
370
357
|
return [];
|
|
371
358
|
}
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
359
|
+
// key={`foo-${bar}`} or key={'foo' + bar}
|
|
360
|
+
case AST_NODE_TYPES.TemplateLiteral:
|
|
361
|
+
case AST_NODE_TYPES.BinaryExpression: {
|
|
362
|
+
const descriptors = [];
|
|
363
|
+
const expressions = node.type === AST_NODE_TYPES.TemplateLiteral ? node.expressions : AST11.getIdentifiersFromBinaryExpression(node);
|
|
364
|
+
for (const expression of expressions) {
|
|
365
|
+
if (isArrayIndex(expression)) {
|
|
366
|
+
descriptors.push({
|
|
367
|
+
messageId: "noArrayIndexKey",
|
|
368
|
+
node: expression
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
return descriptors;
|
|
373
|
+
}
|
|
374
|
+
// key={bar.toString()} or key={String(bar)}
|
|
375
|
+
case AST_NODE_TYPES.CallExpression: {
|
|
376
|
+
switch (true) {
|
|
377
|
+
// key={bar.toString()}
|
|
378
|
+
case (node.callee.type === AST_NODE_TYPES.MemberExpression && node.callee.property.type === AST_NODE_TYPES.Identifier && node.callee.property.name === "toString" && isArrayIndex(node.callee.object)): {
|
|
379
|
+
return [{
|
|
380
|
+
messageId: "noArrayIndexKey",
|
|
381
|
+
node: node.callee.object
|
|
382
|
+
}];
|
|
383
|
+
}
|
|
384
|
+
// key={String(bar)}
|
|
385
|
+
case (node.callee.type === AST_NODE_TYPES.Identifier && node.callee.name === "String" && node.arguments[0] != null && isArrayIndex(node.arguments[0])): {
|
|
386
|
+
return [{
|
|
387
|
+
messageId: "noArrayIndexKey",
|
|
388
|
+
node: node.arguments[0]
|
|
389
|
+
}];
|
|
390
|
+
}
|
|
391
|
+
}
|
|
385
392
|
}
|
|
386
393
|
}
|
|
387
394
|
return [];
|
|
@@ -406,7 +413,7 @@ var no_array_index_key_default = createRule({
|
|
|
406
413
|
if (!("value" in prop)) {
|
|
407
414
|
continue;
|
|
408
415
|
}
|
|
409
|
-
const descriptors =
|
|
416
|
+
const descriptors = getReportDescriptors(prop.value);
|
|
410
417
|
for (const descriptor of descriptors) {
|
|
411
418
|
context.report(descriptor);
|
|
412
419
|
}
|
|
@@ -422,11 +429,10 @@ var no_array_index_key_default = createRule({
|
|
|
422
429
|
if (indexParamNames.length === 0) {
|
|
423
430
|
return;
|
|
424
431
|
}
|
|
425
|
-
|
|
426
|
-
if (value?.type !== AST_NODE_TYPES.JSXExpressionContainer) {
|
|
432
|
+
if (node.value?.type !== AST_NODE_TYPES.JSXExpressionContainer) {
|
|
427
433
|
return;
|
|
428
434
|
}
|
|
429
|
-
const descriptors =
|
|
435
|
+
const descriptors = getReportDescriptors(node.value.expression);
|
|
430
436
|
for (const descriptor of descriptors) {
|
|
431
437
|
context.report(descriptor);
|
|
432
438
|
}
|
|
@@ -990,7 +996,7 @@ var no_context_provider_default = createRule({
|
|
|
990
996
|
const providerName = elementName.replace(/\.Provider$/, "");
|
|
991
997
|
const openingElement = node.openingElement;
|
|
992
998
|
const closingElement = node.closingElement;
|
|
993
|
-
if (
|
|
999
|
+
if (closingElement == null) {
|
|
994
1000
|
return fixer.replaceText(openingElement.name, providerName);
|
|
995
1001
|
}
|
|
996
1002
|
return [
|
|
@@ -1232,7 +1238,7 @@ var no_duplicate_key_default = createRule({
|
|
|
1232
1238
|
function isKeyValueEqual(a, b) {
|
|
1233
1239
|
const aValue = a.value;
|
|
1234
1240
|
const bValue = b.value;
|
|
1235
|
-
if (aValue
|
|
1241
|
+
if (aValue == null || bValue == null) {
|
|
1236
1242
|
return false;
|
|
1237
1243
|
}
|
|
1238
1244
|
return AST11.isNodeEqual(aValue, bValue);
|
|
@@ -1340,7 +1346,7 @@ var no_forward_ref_default = createRule({
|
|
|
1340
1346
|
function getFix(node, context) {
|
|
1341
1347
|
return (fixer) => {
|
|
1342
1348
|
const [componentNode] = node.arguments;
|
|
1343
|
-
if (
|
|
1349
|
+
if (componentNode == null || !AST11.isFunction(componentNode)) {
|
|
1344
1350
|
return [];
|
|
1345
1351
|
}
|
|
1346
1352
|
return [
|
|
@@ -1361,7 +1367,7 @@ function getComponentPropsFixes(node, typeArguments, fixer, context) {
|
|
|
1361
1367
|
const getText = (node2) => context.sourceCode.getText(node2);
|
|
1362
1368
|
const [arg0, arg1] = node.params;
|
|
1363
1369
|
const [typeArg0, typeArg1] = typeArguments;
|
|
1364
|
-
if (
|
|
1370
|
+
if (arg0 == null) {
|
|
1365
1371
|
return [];
|
|
1366
1372
|
}
|
|
1367
1373
|
const fixedArg0Text = match(arg0).with({ type: AST_NODE_TYPES.Identifier }, (n) => O.some(`...${n.name}`)).with({ type: AST_NODE_TYPES.ObjectPattern }, (n) => O.some(n.properties.map(getText).join(", "))).otherwise(O.none);
|
|
@@ -1371,7 +1377,7 @@ function getComponentPropsFixes(node, typeArguments, fixer, context) {
|
|
|
1371
1377
|
}
|
|
1372
1378
|
const fixedPropsText = fixedArg0Text.value;
|
|
1373
1379
|
const fixedRefText = fixedArg1Text.value;
|
|
1374
|
-
if (
|
|
1380
|
+
if (typeArg0 == null || typeArg1 == null) {
|
|
1375
1381
|
return [
|
|
1376
1382
|
fixer.replaceText(
|
|
1377
1383
|
arg0,
|
|
@@ -1382,7 +1388,7 @@ function getComponentPropsFixes(node, typeArguments, fixer, context) {
|
|
|
1382
1388
|
"}"
|
|
1383
1389
|
].join(" ")
|
|
1384
1390
|
),
|
|
1385
|
-
...arg1 ? [fixer.remove(arg1), fixer.removeRange([arg0.range[1], arg1.range[0]])]
|
|
1391
|
+
...arg1 == null ? [] : [fixer.remove(arg1), fixer.removeRange([arg0.range[1], arg1.range[0]])]
|
|
1386
1392
|
];
|
|
1387
1393
|
}
|
|
1388
1394
|
return [
|
|
@@ -1401,7 +1407,7 @@ function getComponentPropsFixes(node, typeArguments, fixer, context) {
|
|
|
1401
1407
|
"}"
|
|
1402
1408
|
].join(" ")
|
|
1403
1409
|
),
|
|
1404
|
-
...arg1 ? [fixer.remove(arg1), fixer.removeRange([arg0.range[1], arg1.range[0]])]
|
|
1410
|
+
...arg1 == null ? [] : [fixer.remove(arg1), fixer.removeRange([arg0.range[1], arg1.range[0]])]
|
|
1405
1411
|
];
|
|
1406
1412
|
}
|
|
1407
1413
|
var RULE_NAME26 = "no-implicit-key";
|
|
@@ -1477,7 +1483,7 @@ function inspectVariantTypes(types) {
|
|
|
1477
1483
|
}
|
|
1478
1484
|
const booleans = types.filter(tsHelpers.isBooleanType);
|
|
1479
1485
|
switch (true) {
|
|
1480
|
-
case (booleans.length === 1 &&
|
|
1486
|
+
case (booleans.length === 1 && booleans[0] != null): {
|
|
1481
1487
|
const [first] = booleans;
|
|
1482
1488
|
const evaluated = F.pipe(
|
|
1483
1489
|
match(first).when(isTrueLiteralType, () => O.some("truthy boolean")).when(isFalseLiteralType, () => O.some("falsy boolean")).otherwise(O.none)
|
|
@@ -1636,7 +1642,7 @@ var no_missing_component_display_name_default = createRule({
|
|
|
1636
1642
|
"Program:exit"(node) {
|
|
1637
1643
|
const components = ctx.getAllComponents(node);
|
|
1638
1644
|
for (const { node: node2, displayName, flag } of components.values()) {
|
|
1639
|
-
const isMemoOrForwardRef =
|
|
1645
|
+
const isMemoOrForwardRef = (flag & (ERFunctionComponentFlag.ForwardRef | ERFunctionComponentFlag.Memo)) > 0n;
|
|
1640
1646
|
if (O.isSome(AST11.getFunctionIdentifier(node2))) {
|
|
1641
1647
|
continue;
|
|
1642
1648
|
}
|
|
@@ -1718,7 +1724,7 @@ var no_missing_key_default = createRule({
|
|
|
1718
1724
|
}
|
|
1719
1725
|
function checkBlockStatement(node) {
|
|
1720
1726
|
return AST11.getNestedReturnStatements(node).reduce((acc, statement) => {
|
|
1721
|
-
if (
|
|
1727
|
+
if (statement.argument == null) {
|
|
1722
1728
|
return acc;
|
|
1723
1729
|
}
|
|
1724
1730
|
const mbDescriptor = checkIteratorElement(statement.argument);
|
|
@@ -1994,7 +2000,7 @@ var no_redundant_should_component_update_default = createRule({
|
|
|
1994
2000
|
"Program:exit"(node) {
|
|
1995
2001
|
const components = ctx.getAllComponents(node);
|
|
1996
2002
|
for (const { name: name2, node: component, flag } of components.values()) {
|
|
1997
|
-
if (
|
|
2003
|
+
if ((flag & ERClassComponentFlag.PureComponent) === 0n) {
|
|
1998
2004
|
continue;
|
|
1999
2005
|
}
|
|
2000
2006
|
const { body } = component.body;
|
|
@@ -2466,7 +2472,7 @@ var no_unstable_default_props_default = createRule({
|
|
|
2466
2472
|
for (const { node: component } of components.values()) {
|
|
2467
2473
|
const { params } = component;
|
|
2468
2474
|
const [props] = params;
|
|
2469
|
-
if (
|
|
2475
|
+
if (props == null) {
|
|
2470
2476
|
continue;
|
|
2471
2477
|
}
|
|
2472
2478
|
const properties = match(props).with({ type: AST_NODE_TYPES.ObjectPattern }, ({ properties: properties2 }) => properties2).with({ type: AST_NODE_TYPES.Identifier }, ({ name: name2 }) => {
|
|
@@ -2578,13 +2584,13 @@ var no_unused_class_component_members_default = createRule({
|
|
|
2578
2584
|
}
|
|
2579
2585
|
function classExit() {
|
|
2580
2586
|
const currentClass = classStack.pop();
|
|
2581
|
-
if (
|
|
2587
|
+
if (currentClass == null || !isClassComponent(currentClass)) {
|
|
2582
2588
|
return;
|
|
2583
2589
|
}
|
|
2584
2590
|
const className = O.map(AST11.getClassIdentifier(currentClass), (id) => id.name);
|
|
2585
2591
|
const defs = propertyDefs.get(currentClass);
|
|
2586
2592
|
const usages = propertyUsages.get(currentClass);
|
|
2587
|
-
if (
|
|
2593
|
+
if (defs == null) {
|
|
2588
2594
|
return;
|
|
2589
2595
|
}
|
|
2590
2596
|
for (const def of defs) {
|
|
@@ -2608,7 +2614,7 @@ var no_unused_class_component_members_default = createRule({
|
|
|
2608
2614
|
function methodEnter(node) {
|
|
2609
2615
|
methodStack.push(node);
|
|
2610
2616
|
const currentClass = classStack.at(-1);
|
|
2611
|
-
if (
|
|
2617
|
+
if (currentClass == null || !isClassComponent(currentClass)) {
|
|
2612
2618
|
return;
|
|
2613
2619
|
}
|
|
2614
2620
|
if (node.static) {
|
|
@@ -2629,7 +2635,7 @@ var no_unused_class_component_members_default = createRule({
|
|
|
2629
2635
|
MemberExpression(node) {
|
|
2630
2636
|
const currentClass = classStack.at(-1);
|
|
2631
2637
|
const currentMethod = methodStack.at(-1);
|
|
2632
|
-
if (
|
|
2638
|
+
if (currentClass == null || currentMethod == null) {
|
|
2633
2639
|
return;
|
|
2634
2640
|
}
|
|
2635
2641
|
if (!isClassComponent(currentClass) || currentMethod.static) {
|
|
@@ -2651,13 +2657,13 @@ var no_unused_class_component_members_default = createRule({
|
|
|
2651
2657
|
VariableDeclarator(node) {
|
|
2652
2658
|
const currentClass = classStack.at(-1);
|
|
2653
2659
|
const currentMethod = methodStack.at(-1);
|
|
2654
|
-
if (
|
|
2660
|
+
if (currentClass == null || currentMethod == null) {
|
|
2655
2661
|
return;
|
|
2656
2662
|
}
|
|
2657
2663
|
if (!isClassComponent(currentClass) || currentMethod.static) {
|
|
2658
2664
|
return;
|
|
2659
2665
|
}
|
|
2660
|
-
if (node.init && AST11.isThisExpression(node.init) && node.id.type === AST_NODE_TYPES.ObjectPattern) {
|
|
2666
|
+
if (node.init != null && AST11.isThisExpression(node.init) && node.id.type === AST_NODE_TYPES.ObjectPattern) {
|
|
2661
2667
|
for (const prop of node.id.properties) {
|
|
2662
2668
|
if (prop.type === AST_NODE_TYPES.Property && AST11.isKeyLiteralLike(prop, prop.key)) {
|
|
2663
2669
|
const mbName = getName3(prop.key);
|
|
@@ -2728,7 +2734,7 @@ var no_unused_state_default = createRule({
|
|
|
2728
2734
|
}
|
|
2729
2735
|
function classExit() {
|
|
2730
2736
|
const currentClass = classStack.pop();
|
|
2731
|
-
if (
|
|
2737
|
+
if (currentClass == null || !isClassComponent(currentClass)) {
|
|
2732
2738
|
return;
|
|
2733
2739
|
}
|
|
2734
2740
|
const className = O.map(AST11.getClassIdentifier(currentClass), (id) => id.name);
|
|
@@ -2747,7 +2753,7 @@ var no_unused_state_default = createRule({
|
|
|
2747
2753
|
function methodEnter(node) {
|
|
2748
2754
|
methodStack.push(node);
|
|
2749
2755
|
const currentClass = classStack.at(-1);
|
|
2750
|
-
if (
|
|
2756
|
+
if (currentClass == null || !isClassComponent(currentClass)) {
|
|
2751
2757
|
return;
|
|
2752
2758
|
}
|
|
2753
2759
|
if (node.static) {
|
|
@@ -2776,11 +2782,11 @@ var no_unused_state_default = createRule({
|
|
|
2776
2782
|
return;
|
|
2777
2783
|
}
|
|
2778
2784
|
const currentClass = classStack.at(-1);
|
|
2779
|
-
if (
|
|
2785
|
+
if (currentClass == null || !isClassComponent(currentClass)) {
|
|
2780
2786
|
return;
|
|
2781
2787
|
}
|
|
2782
2788
|
const currentConstructor = constructorStack.at(-1);
|
|
2783
|
-
if (
|
|
2789
|
+
if (currentConstructor == null || !currentClass.body.body.includes(currentConstructor)) {
|
|
2784
2790
|
return;
|
|
2785
2791
|
}
|
|
2786
2792
|
const [_, isUsed] = stateDefs.get(currentClass) ?? [O.none(), false];
|
|
@@ -2798,11 +2804,11 @@ var no_unused_state_default = createRule({
|
|
|
2798
2804
|
return;
|
|
2799
2805
|
}
|
|
2800
2806
|
const currentClass = classStack.at(-1);
|
|
2801
|
-
if (
|
|
2807
|
+
if (currentClass == null || !isClassComponent(currentClass)) {
|
|
2802
2808
|
return;
|
|
2803
2809
|
}
|
|
2804
2810
|
const currentMethod = methodStack.at(-1);
|
|
2805
|
-
if (
|
|
2811
|
+
if (currentMethod == null || currentMethod.static) {
|
|
2806
2812
|
return;
|
|
2807
2813
|
}
|
|
2808
2814
|
if (currentMethod === constructorStack.at(-1)) {
|
|
@@ -2822,11 +2828,11 @@ var no_unused_state_default = createRule({
|
|
|
2822
2828
|
"PropertyDefinition:exit": methodExit,
|
|
2823
2829
|
VariableDeclarator(node) {
|
|
2824
2830
|
const currentClass = classStack.at(-1);
|
|
2825
|
-
if (
|
|
2831
|
+
if (currentClass == null || !isClassComponent(currentClass)) {
|
|
2826
2832
|
return;
|
|
2827
2833
|
}
|
|
2828
2834
|
const currentMethod = methodStack.at(-1);
|
|
2829
|
-
if (
|
|
2835
|
+
if (currentMethod == null || currentMethod.static) {
|
|
2830
2836
|
return;
|
|
2831
2837
|
}
|
|
2832
2838
|
if (currentMethod === constructorStack.at(-1)) {
|
|
@@ -2835,7 +2841,7 @@ var no_unused_state_default = createRule({
|
|
|
2835
2841
|
if (!currentClass.body.body.includes(currentMethod)) {
|
|
2836
2842
|
return;
|
|
2837
2843
|
}
|
|
2838
|
-
if (!(node.init && AST11.isThisExpression(node.init) && node.id.type === AST_NODE_TYPES.ObjectPattern)) {
|
|
2844
|
+
if (!(node.init != null && AST11.isThisExpression(node.init) && node.id.type === AST_NODE_TYPES.ObjectPattern)) {
|
|
2839
2845
|
return;
|
|
2840
2846
|
}
|
|
2841
2847
|
const hasState = node.id.properties.some((prop) => {
|
|
@@ -2981,7 +2987,7 @@ var prefer_destructuring_assignment_default = createRule({
|
|
|
2981
2987
|
for (const [initialScope, memberExpression] of memberExpressionWithNames) {
|
|
2982
2988
|
let scope = initialScope;
|
|
2983
2989
|
let isComponent = isFunctionComponent(scope.block);
|
|
2984
|
-
while (!isComponent && scope.upper && scope.upper !== scope) {
|
|
2990
|
+
while (!isComponent && scope.upper != null && scope.upper !== scope) {
|
|
2985
2991
|
scope = scope.upper;
|
|
2986
2992
|
isComponent = isFunctionComponent(scope.block);
|
|
2987
2993
|
}
|
|
@@ -3107,7 +3113,7 @@ var prefer_read_only_props_default = createRule({
|
|
|
3107
3113
|
const components = ctx.getAllComponents(node);
|
|
3108
3114
|
for (const [_, component] of components) {
|
|
3109
3115
|
const [props] = component.node.params;
|
|
3110
|
-
if (
|
|
3116
|
+
if (props == null) {
|
|
3111
3117
|
continue;
|
|
3112
3118
|
}
|
|
3113
3119
|
const propsType = getConstrainedTypeAtLocation(services, props);
|
|
@@ -3196,7 +3202,7 @@ var prefer_shorthand_fragment_default = createRule({
|
|
|
3196
3202
|
node,
|
|
3197
3203
|
fix: (fixer) => {
|
|
3198
3204
|
const { closingElement, openingElement } = node;
|
|
3199
|
-
if (
|
|
3205
|
+
if (closingElement == null) {
|
|
3200
3206
|
return [];
|
|
3201
3207
|
}
|
|
3202
3208
|
return [
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-react-x",
|
|
3
|
-
"version": "1.23.3-next.
|
|
3
|
+
"version": "1.23.3-next.6",
|
|
4
4
|
"description": "A set of composable ESLint rules for libraries and frameworks that use React as a UI runtime.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -48,16 +48,16 @@
|
|
|
48
48
|
"is-immutable-type": "^5.0.1",
|
|
49
49
|
"string-ts": "^2.2.0",
|
|
50
50
|
"ts-pattern": "^5.6.0",
|
|
51
|
-
"@eslint-react/ast": "1.23.3-next.
|
|
52
|
-
"@eslint-react/core": "1.23.3-next.
|
|
53
|
-
"@eslint-react/jsx": "1.23.3-next.
|
|
54
|
-
"@eslint-react/eff": "1.23.3-next.
|
|
55
|
-
"@eslint-react/shared": "1.23.3-next.
|
|
56
|
-
"@eslint-react/
|
|
57
|
-
"@eslint-react/
|
|
51
|
+
"@eslint-react/ast": "1.23.3-next.6",
|
|
52
|
+
"@eslint-react/core": "1.23.3-next.6",
|
|
53
|
+
"@eslint-react/jsx": "1.23.3-next.6",
|
|
54
|
+
"@eslint-react/eff": "1.23.3-next.6",
|
|
55
|
+
"@eslint-react/shared": "1.23.3-next.6",
|
|
56
|
+
"@eslint-react/var": "1.23.3-next.6",
|
|
57
|
+
"@eslint-react/types": "1.23.3-next.6"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
|
-
"@types/react": "^19.0.
|
|
60
|
+
"@types/react": "^19.0.4",
|
|
61
61
|
"@types/react-dom": "^19.0.2",
|
|
62
62
|
"ts-api-utils": "^2.0.0",
|
|
63
63
|
"tsup": "^8.3.5",
|