eslint-plugin-react-x 1.40.4-next.0 → 1.40.4-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.js +82 -99
- package/dist/index.mjs +81 -98
- package/package.json +8 -8
package/dist/index.js
CHANGED
|
@@ -9,7 +9,7 @@ var VAR2 = require('@eslint-react/var');
|
|
|
9
9
|
var tsPattern = require('ts-pattern');
|
|
10
10
|
var kit = require('@eslint-react/kit');
|
|
11
11
|
var ts = require('typescript');
|
|
12
|
-
var
|
|
12
|
+
var AST8 = require('@eslint-react/ast');
|
|
13
13
|
var ER21 = require('@eslint-react/core');
|
|
14
14
|
var compareVersions = require('compare-versions');
|
|
15
15
|
var typeUtils = require('@typescript-eslint/type-utils');
|
|
@@ -39,7 +39,7 @@ function _interopNamespace(e) {
|
|
|
39
39
|
var JSX8__namespace = /*#__PURE__*/_interopNamespace(JSX8);
|
|
40
40
|
var VAR2__namespace = /*#__PURE__*/_interopNamespace(VAR2);
|
|
41
41
|
var ts__default = /*#__PURE__*/_interopDefault(ts);
|
|
42
|
-
var
|
|
42
|
+
var AST8__namespace = /*#__PURE__*/_interopNamespace(AST8);
|
|
43
43
|
var ER21__namespace = /*#__PURE__*/_interopNamespace(ER21);
|
|
44
44
|
|
|
45
45
|
var __defProp = Object.defineProperty;
|
|
@@ -141,7 +141,7 @@ var settings3 = {
|
|
|
141
141
|
|
|
142
142
|
// package.json
|
|
143
143
|
var name4 = "eslint-plugin-react-x";
|
|
144
|
-
var version = "1.40.4-next.
|
|
144
|
+
var version = "1.40.4-next.2";
|
|
145
145
|
var createRule = utils.ESLintUtils.RuleCreator(shared.getDocsUrl("x"));
|
|
146
146
|
|
|
147
147
|
// src/rules/avoid-shorthand-boolean.ts
|
|
@@ -452,7 +452,7 @@ function create7(context) {
|
|
|
452
452
|
classEntries.pop();
|
|
453
453
|
},
|
|
454
454
|
MemberExpression(node) {
|
|
455
|
-
if (!
|
|
455
|
+
if (!AST8__namespace.isThisExpression(node.object)) {
|
|
456
456
|
return;
|
|
457
457
|
}
|
|
458
458
|
const [currClass, isComponent = false] = classEntries.at(-1) ?? [];
|
|
@@ -467,7 +467,7 @@ function create7(context) {
|
|
|
467
467
|
if (setState == null || hasThisState) {
|
|
468
468
|
return;
|
|
469
469
|
}
|
|
470
|
-
if (
|
|
470
|
+
if (AST8__namespace.getPropertyName(node.property) !== "state") {
|
|
471
471
|
return;
|
|
472
472
|
}
|
|
473
473
|
context.report({ messageId: "noAccessStateInSetstate", node });
|
|
@@ -497,11 +497,11 @@ function create7(context) {
|
|
|
497
497
|
if (setState == null || hasThisState) {
|
|
498
498
|
return;
|
|
499
499
|
}
|
|
500
|
-
if (node.init == null || !
|
|
500
|
+
if (node.init == null || !AST8__namespace.isThisExpression(node.init) || node.id.type !== types.AST_NODE_TYPES.ObjectPattern) {
|
|
501
501
|
return;
|
|
502
502
|
}
|
|
503
503
|
const hasState = node.id.properties.some(
|
|
504
|
-
(prop) => prop.type === types.AST_NODE_TYPES.Property && isKeyLiteral(prop, prop.key) &&
|
|
504
|
+
(prop) => prop.type === types.AST_NODE_TYPES.Property && isKeyLiteral(prop, prop.key) && AST8__namespace.getPropertyName(prop.key) === "state"
|
|
505
505
|
);
|
|
506
506
|
if (!hasState) {
|
|
507
507
|
return;
|
|
@@ -543,18 +543,18 @@ function getMapIndexParamName(context, node) {
|
|
|
543
543
|
return eff._;
|
|
544
544
|
}
|
|
545
545
|
const { name: name5 } = callee.property;
|
|
546
|
-
if (!
|
|
546
|
+
if (!AST8__namespace.ITERATOR_FUNCTION_INDEX_PARAM_POSITION.has(name5)) {
|
|
547
547
|
return eff._;
|
|
548
548
|
}
|
|
549
549
|
const callbackArg = node.arguments[isUsingReactChildren(context, node) ? 1 : 0];
|
|
550
550
|
if (callbackArg == null) {
|
|
551
551
|
return eff._;
|
|
552
552
|
}
|
|
553
|
-
if (!
|
|
553
|
+
if (!AST8__namespace.isOneOf([types.AST_NODE_TYPES.ArrowFunctionExpression, types.AST_NODE_TYPES.FunctionExpression])(callbackArg)) {
|
|
554
554
|
return eff._;
|
|
555
555
|
}
|
|
556
556
|
const { params } = callbackArg;
|
|
557
|
-
const indexParamPosition =
|
|
557
|
+
const indexParamPosition = AST8__namespace.ITERATOR_FUNCTION_INDEX_PARAM_POSITION.get(name5);
|
|
558
558
|
if (indexParamPosition == null) {
|
|
559
559
|
return eff._;
|
|
560
560
|
}
|
|
@@ -966,14 +966,14 @@ var no_comment_textnodes_default = createRule({
|
|
|
966
966
|
});
|
|
967
967
|
function create17(context) {
|
|
968
968
|
function hasCommentLike(node) {
|
|
969
|
-
if (
|
|
969
|
+
if (AST8__namespace.isOneOf([types.AST_NODE_TYPES.JSXAttribute, types.AST_NODE_TYPES.JSXExpressionContainer])(node.parent)) {
|
|
970
970
|
return false;
|
|
971
971
|
}
|
|
972
972
|
const rawValue = context.sourceCode.getText(node);
|
|
973
973
|
return /^\s*\/(?:\/|\*)/mu.test(rawValue);
|
|
974
974
|
}
|
|
975
975
|
const visitorFunction = (node) => {
|
|
976
|
-
if (!
|
|
976
|
+
if (!AST8__namespace.isOneOf([types.AST_NODE_TYPES.JSXElement, types.AST_NODE_TYPES.JSXFragment])(node.parent)) {
|
|
977
977
|
return;
|
|
978
978
|
}
|
|
979
979
|
if (!hasCommentLike(node)) {
|
|
@@ -1015,10 +1015,10 @@ var no_complex_conditional_rendering_default = createRule({
|
|
|
1015
1015
|
function create18(context) {
|
|
1016
1016
|
const visitorFunction = (node) => {
|
|
1017
1017
|
const jsxExpContainer = node.parent?.parent;
|
|
1018
|
-
if (!
|
|
1018
|
+
if (!AST8__namespace.is(types.AST_NODE_TYPES.JSXExpressionContainer)(jsxExpContainer)) {
|
|
1019
1019
|
return;
|
|
1020
1020
|
}
|
|
1021
|
-
if (!
|
|
1021
|
+
if (!AST8__namespace.isOneOf([types.AST_NODE_TYPES.JSXElement, types.AST_NODE_TYPES.JSXFragment])(jsxExpContainer.parent)) {
|
|
1022
1022
|
return;
|
|
1023
1023
|
}
|
|
1024
1024
|
if (!jsxExpContainer.parent.children.includes(jsxExpContainer)) {
|
|
@@ -1041,9 +1041,6 @@ var RULE_NAME19 = "no-component-will-mount";
|
|
|
1041
1041
|
var RULE_FEATURES19 = [
|
|
1042
1042
|
"MOD"
|
|
1043
1043
|
];
|
|
1044
|
-
function isComponentWillMount(node) {
|
|
1045
|
-
return AST11__namespace.isMethodOrProperty(node) && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentWillMount";
|
|
1046
|
-
}
|
|
1047
1044
|
var no_component_will_mount_default = createRule({
|
|
1048
1045
|
meta: {
|
|
1049
1046
|
type: "problem",
|
|
@@ -1071,7 +1068,7 @@ function create19(context) {
|
|
|
1071
1068
|
for (const { node: component } of components.values()) {
|
|
1072
1069
|
const { body } = component.body;
|
|
1073
1070
|
for (const member of body) {
|
|
1074
|
-
if (isComponentWillMount(member)) {
|
|
1071
|
+
if (ER21__namespace.isComponentWillMount(member)) {
|
|
1075
1072
|
context.report({
|
|
1076
1073
|
messageId: "noComponentWillMount",
|
|
1077
1074
|
node: member,
|
|
@@ -1092,9 +1089,6 @@ var RULE_NAME20 = "no-component-will-receive-props";
|
|
|
1092
1089
|
var RULE_FEATURES20 = [
|
|
1093
1090
|
"MOD"
|
|
1094
1091
|
];
|
|
1095
|
-
function isComponentWillUpdate(node) {
|
|
1096
|
-
return AST11__namespace.isMethodOrProperty(node) && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentWillReceiveProps";
|
|
1097
|
-
}
|
|
1098
1092
|
var no_component_will_receive_props_default = createRule({
|
|
1099
1093
|
meta: {
|
|
1100
1094
|
type: "problem",
|
|
@@ -1122,7 +1116,7 @@ function create20(context) {
|
|
|
1122
1116
|
for (const { node: component } of components.values()) {
|
|
1123
1117
|
const { body } = component.body;
|
|
1124
1118
|
for (const member of body) {
|
|
1125
|
-
if (
|
|
1119
|
+
if (ER21__namespace.isComponentWillReceiveProps(member)) {
|
|
1126
1120
|
context.report({
|
|
1127
1121
|
messageId: "noComponentWillReceiveProps",
|
|
1128
1122
|
node: member,
|
|
@@ -1143,9 +1137,6 @@ var RULE_NAME21 = "no-component-will-update";
|
|
|
1143
1137
|
var RULE_FEATURES21 = [
|
|
1144
1138
|
"MOD"
|
|
1145
1139
|
];
|
|
1146
|
-
function isComponentWillUpdate2(node) {
|
|
1147
|
-
return AST11__namespace.isMethodOrProperty(node) && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentWillUpdate";
|
|
1148
|
-
}
|
|
1149
1140
|
var no_component_will_update_default = createRule({
|
|
1150
1141
|
meta: {
|
|
1151
1142
|
type: "problem",
|
|
@@ -1173,7 +1164,7 @@ function create21(context) {
|
|
|
1173
1164
|
for (const { node: component } of components.values()) {
|
|
1174
1165
|
const { body } = component.body;
|
|
1175
1166
|
for (const member of body) {
|
|
1176
|
-
if (
|
|
1167
|
+
if (ER21__namespace.isComponentWillUpdate(member)) {
|
|
1177
1168
|
context.report({
|
|
1178
1169
|
messageId: "noComponentWillUpdate",
|
|
1179
1170
|
node: member,
|
|
@@ -1264,7 +1255,7 @@ var no_create_ref_default = createRule({
|
|
|
1264
1255
|
function create23(context) {
|
|
1265
1256
|
return {
|
|
1266
1257
|
CallExpression(node) {
|
|
1267
|
-
if (ER21__namespace.isCreateRefCall(context, node) &&
|
|
1258
|
+
if (ER21__namespace.isCreateRefCall(context, node) && AST8__namespace.findParentNode(node, ER21__namespace.isClassComponent) == null) {
|
|
1268
1259
|
context.report({ messageId: "noCreateRef", node });
|
|
1269
1260
|
}
|
|
1270
1261
|
}
|
|
@@ -1308,7 +1299,7 @@ function create24(context) {
|
|
|
1308
1299
|
const variable = VAR2__namespace.findVariable(object.name, context.sourceCode.getScope(node));
|
|
1309
1300
|
const variableNode = VAR2__namespace.getVariableInitNode(variable, 0);
|
|
1310
1301
|
if (variableNode == null) return;
|
|
1311
|
-
if (!
|
|
1302
|
+
if (!AST8__namespace.isFunction(variableNode) && !ER21__namespace.isClassComponent(variableNode)) return;
|
|
1312
1303
|
context.report({ messageId: "noDefaultProps", node: property });
|
|
1313
1304
|
},
|
|
1314
1305
|
PropertyDefinition(node) {
|
|
@@ -1325,7 +1316,7 @@ function create24(context) {
|
|
|
1325
1316
|
var RULE_NAME25 = "no-direct-mutation-state";
|
|
1326
1317
|
var RULE_FEATURES25 = [];
|
|
1327
1318
|
function isConstructorFunction(node) {
|
|
1328
|
-
return
|
|
1319
|
+
return AST8__namespace.isOneOf([types.AST_NODE_TYPES.FunctionDeclaration, types.AST_NODE_TYPES.FunctionExpression])(node) && AST8__namespace.isMethodOrProperty(node.parent) && node.parent.key.type === types.AST_NODE_TYPES.Identifier && node.parent.key.name === "constructor";
|
|
1329
1320
|
}
|
|
1330
1321
|
var no_direct_mutation_state_default = createRule({
|
|
1331
1322
|
meta: {
|
|
@@ -1347,15 +1338,15 @@ function create25(context) {
|
|
|
1347
1338
|
return {
|
|
1348
1339
|
AssignmentExpression(node) {
|
|
1349
1340
|
if (!ER21__namespace.isAssignmentToThisState(node)) return;
|
|
1350
|
-
const parentClass =
|
|
1341
|
+
const parentClass = AST8__namespace.findParentNode(
|
|
1351
1342
|
node,
|
|
1352
|
-
|
|
1343
|
+
AST8__namespace.isOneOf([
|
|
1353
1344
|
types.AST_NODE_TYPES.ClassDeclaration,
|
|
1354
1345
|
types.AST_NODE_TYPES.ClassExpression
|
|
1355
1346
|
])
|
|
1356
1347
|
);
|
|
1357
1348
|
if (parentClass == null) return;
|
|
1358
|
-
if (ER21__namespace.isClassComponent(parentClass) && context.sourceCode.getScope(node).block !==
|
|
1349
|
+
if (ER21__namespace.isClassComponent(parentClass) && context.sourceCode.getScope(node).block !== AST8__namespace.findParentNode(node, isConstructorFunction)) {
|
|
1359
1350
|
context.report({
|
|
1360
1351
|
messageId: "noDirectMutationState",
|
|
1361
1352
|
node
|
|
@@ -1393,7 +1384,7 @@ function create26(context) {
|
|
|
1393
1384
|
if (aValue == null || bValue == null) {
|
|
1394
1385
|
return false;
|
|
1395
1386
|
}
|
|
1396
|
-
return
|
|
1387
|
+
return AST8__namespace.isNodeEqual(aValue, bValue);
|
|
1397
1388
|
}
|
|
1398
1389
|
return {
|
|
1399
1390
|
"JSXAttribute[name.name='key']"(node) {
|
|
@@ -1412,12 +1403,12 @@ function create26(context) {
|
|
|
1412
1403
|
break;
|
|
1413
1404
|
}
|
|
1414
1405
|
default: {
|
|
1415
|
-
const call =
|
|
1416
|
-
const iter =
|
|
1417
|
-
if (!
|
|
1406
|
+
const call = AST8__namespace.findParentNode(jsxElement, AST8__namespace.isArrayMapCallLoose);
|
|
1407
|
+
const iter = AST8__namespace.findParentNode(jsxElement, (n) => n === call || AST8__namespace.isFunction(n));
|
|
1408
|
+
if (!AST8__namespace.isFunction(iter)) return;
|
|
1418
1409
|
const arg0 = call?.arguments[0];
|
|
1419
1410
|
if (call == null || arg0 == null) return;
|
|
1420
|
-
if (
|
|
1411
|
+
if (AST8__namespace.getEcmaExpression(arg0) !== iter) {
|
|
1421
1412
|
return;
|
|
1422
1413
|
}
|
|
1423
1414
|
keyedEntries.set(call, {
|
|
@@ -1491,7 +1482,7 @@ function create27(context) {
|
|
|
1491
1482
|
function getFix(context, node) {
|
|
1492
1483
|
return (fixer) => {
|
|
1493
1484
|
const [componentNode] = node.arguments;
|
|
1494
|
-
if (componentNode == null || !
|
|
1485
|
+
if (componentNode == null || !AST8__namespace.isFunction(componentNode)) {
|
|
1495
1486
|
return [];
|
|
1496
1487
|
}
|
|
1497
1488
|
return [
|
|
@@ -1705,7 +1696,7 @@ function create29(context) {
|
|
|
1705
1696
|
const services = utils.ESLintUtils.getParserServices(context, false);
|
|
1706
1697
|
function getReportDescriptor(node) {
|
|
1707
1698
|
if (node == null) return eff._;
|
|
1708
|
-
return tsPattern.match(node).when(
|
|
1699
|
+
return tsPattern.match(node).when(AST8__namespace.isJSX, () => eff._).with({ type: types.AST_NODE_TYPES.LogicalExpression, operator: "&&" }, ({ left, right }) => {
|
|
1709
1700
|
const isLeftUnaryNot = left.type === types.AST_NODE_TYPES.UnaryExpression && left.operator === "!";
|
|
1710
1701
|
if (isLeftUnaryNot) {
|
|
1711
1702
|
return getReportDescriptor(right);
|
|
@@ -1781,7 +1772,7 @@ function create30(context) {
|
|
|
1781
1772
|
const components = ctx.getAllComponents(node);
|
|
1782
1773
|
for (const { node: node2, displayName, flag } of components.values()) {
|
|
1783
1774
|
const isMemoOrForwardRef = (flag & (ER21__namespace.ComponentFlag.ForwardRef | ER21__namespace.ComponentFlag.Memo)) > 0n;
|
|
1784
|
-
if (
|
|
1775
|
+
if (AST8__namespace.getFunctionIdentifier(node2) != null) {
|
|
1785
1776
|
continue;
|
|
1786
1777
|
}
|
|
1787
1778
|
if (!isMemoOrForwardRef) {
|
|
@@ -1918,7 +1909,7 @@ function create32(context) {
|
|
|
1918
1909
|
}
|
|
1919
1910
|
function checkBlockStatement(node) {
|
|
1920
1911
|
const descriptors = [];
|
|
1921
|
-
for (const statement of
|
|
1912
|
+
for (const statement of AST8__namespace.getNestedReturnStatements(node)) {
|
|
1922
1913
|
if (statement.argument == null) continue;
|
|
1923
1914
|
const descriptor = checkIteratorElement(statement.argument);
|
|
1924
1915
|
if (descriptor != null) descriptors.push(descriptor);
|
|
@@ -1930,7 +1921,7 @@ function create32(context) {
|
|
|
1930
1921
|
if (state.isWithinChildrenToArray) {
|
|
1931
1922
|
return;
|
|
1932
1923
|
}
|
|
1933
|
-
const elements = node.elements.filter(
|
|
1924
|
+
const elements = node.elements.filter(AST8__namespace.is(types.AST_NODE_TYPES.JSXElement));
|
|
1934
1925
|
if (elements.length === 0) {
|
|
1935
1926
|
return;
|
|
1936
1927
|
}
|
|
@@ -1949,12 +1940,12 @@ function create32(context) {
|
|
|
1949
1940
|
if (state.isWithinChildrenToArray) {
|
|
1950
1941
|
return;
|
|
1951
1942
|
}
|
|
1952
|
-
const isMapCall =
|
|
1943
|
+
const isMapCall = AST8__namespace.isArrayMapCallLoose(node);
|
|
1953
1944
|
if (!isMapCall && !isArrayFromCall(node)) {
|
|
1954
1945
|
return;
|
|
1955
1946
|
}
|
|
1956
1947
|
const fn = node.arguments[isMapCall ? 0 : 1];
|
|
1957
|
-
if (!
|
|
1948
|
+
if (!AST8__namespace.isFunction(fn)) {
|
|
1958
1949
|
return;
|
|
1959
1950
|
}
|
|
1960
1951
|
if (fn.body.type === types.AST_NODE_TYPES.BlockStatement) {
|
|
@@ -2018,10 +2009,10 @@ function create33(context) {
|
|
|
2018
2009
|
...collectorLegacy.ctx.getAllComponents(node).values()
|
|
2019
2010
|
];
|
|
2020
2011
|
const isFunctionComponent = (node2) => {
|
|
2021
|
-
return
|
|
2012
|
+
return AST8__namespace.isFunction(node2) && functionComponents.some((component) => component.node === node2);
|
|
2022
2013
|
};
|
|
2023
2014
|
const isClassComponent11 = (node2) => {
|
|
2024
|
-
return
|
|
2015
|
+
return AST8__namespace.isClass(node2) && classComponents.some((component) => component.node === node2);
|
|
2025
2016
|
};
|
|
2026
2017
|
for (const { name: name5, node: component } of functionComponents) {
|
|
2027
2018
|
if (name5 == null) continue;
|
|
@@ -2050,7 +2041,7 @@ function create33(context) {
|
|
|
2050
2041
|
});
|
|
2051
2042
|
continue;
|
|
2052
2043
|
}
|
|
2053
|
-
const parentComponent =
|
|
2044
|
+
const parentComponent = AST8__namespace.findParentNode(component, isFunctionComponent);
|
|
2054
2045
|
if (parentComponent != null && !ER21__namespace.isDirectValueOfRenderPropertyLoose(parentComponent)) {
|
|
2055
2046
|
context.report({
|
|
2056
2047
|
messageId: "noNestedComponentDefinitions",
|
|
@@ -2074,7 +2065,7 @@ function create33(context) {
|
|
|
2074
2065
|
}
|
|
2075
2066
|
}
|
|
2076
2067
|
for (const { name: name5 = "unknown", node: component } of classComponents) {
|
|
2077
|
-
if (
|
|
2068
|
+
if (AST8__namespace.findParentNode(component, (n) => isClassComponent11(n) || isFunctionComponent(n)) == null) {
|
|
2078
2069
|
continue;
|
|
2079
2070
|
}
|
|
2080
2071
|
context.report({
|
|
@@ -2093,9 +2084,9 @@ function isInsideJSXAttributeValue(node) {
|
|
|
2093
2084
|
return node.parent.type === types.AST_NODE_TYPES.JSXAttribute || JSX8__namespace.findParentAttribute(node, (n) => n.value?.type === types.AST_NODE_TYPES.JSXExpressionContainer) != null;
|
|
2094
2085
|
}
|
|
2095
2086
|
function isInsideCreateElementProps(context, node) {
|
|
2096
|
-
const call =
|
|
2087
|
+
const call = AST8__namespace.findParentNode(node, ER21__namespace.isCreateElementCall(context));
|
|
2097
2088
|
if (call == null) return false;
|
|
2098
|
-
const prop =
|
|
2089
|
+
const prop = AST8__namespace.findParentNode(node, AST8__namespace.is(types.AST_NODE_TYPES.ObjectExpression));
|
|
2099
2090
|
if (prop == null) return false;
|
|
2100
2091
|
return prop === call.arguments[1];
|
|
2101
2092
|
}
|
|
@@ -2138,7 +2129,7 @@ function create34(context) {
|
|
|
2138
2129
|
}
|
|
2139
2130
|
const variable = VAR2__namespace.findVariable(object.name, context.sourceCode.getScope(node));
|
|
2140
2131
|
const variableNode = VAR2__namespace.getVariableInitNode(variable, 0);
|
|
2141
|
-
if (variableNode != null && (
|
|
2132
|
+
if (variableNode != null && (AST8__namespace.isFunction(variableNode) || ER21__namespace.isClassComponent(variableNode))) {
|
|
2142
2133
|
context.report({ messageId: "noPropTypes", node: property });
|
|
2143
2134
|
}
|
|
2144
2135
|
},
|
|
@@ -2156,7 +2147,7 @@ function create34(context) {
|
|
|
2156
2147
|
var RULE_NAME35 = "no-redundant-should-component-update";
|
|
2157
2148
|
var RULE_FEATURES35 = [];
|
|
2158
2149
|
function isShouldComponentUpdate(node) {
|
|
2159
|
-
return
|
|
2150
|
+
return AST8__namespace.isMethodOrProperty(node) && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "shouldComponentUpdate";
|
|
2160
2151
|
}
|
|
2161
2152
|
var no_redundant_should_component_update_default = createRule({
|
|
2162
2153
|
meta: {
|
|
@@ -2203,9 +2194,6 @@ function create35(context) {
|
|
|
2203
2194
|
}
|
|
2204
2195
|
var RULE_NAME36 = "no-set-state-in-component-did-mount";
|
|
2205
2196
|
var RULE_FEATURES36 = [];
|
|
2206
|
-
function isComponentDidMount(node) {
|
|
2207
|
-
return AST11__namespace.isMethodOrProperty(node) && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentDidMount";
|
|
2208
|
-
}
|
|
2209
2197
|
var no_set_state_in_component_did_mount_default = createRule({
|
|
2210
2198
|
meta: {
|
|
2211
2199
|
type: "problem",
|
|
@@ -2229,8 +2217,8 @@ function create36(context) {
|
|
|
2229
2217
|
if (!ER21__namespace.isThisSetState(node)) {
|
|
2230
2218
|
return;
|
|
2231
2219
|
}
|
|
2232
|
-
const clazz =
|
|
2233
|
-
const method =
|
|
2220
|
+
const clazz = AST8__namespace.findParentNode(node, ER21__namespace.isClassComponent);
|
|
2221
|
+
const method = AST8__namespace.findParentNode(node, (n) => n === clazz || ER21__namespace.isComponentDidMount(n));
|
|
2234
2222
|
if (clazz == null || method == null || method === clazz) return;
|
|
2235
2223
|
const methodScope = context.sourceCode.getScope(method);
|
|
2236
2224
|
const upperScope = context.sourceCode.getScope(node).upper;
|
|
@@ -2245,9 +2233,6 @@ function create36(context) {
|
|
|
2245
2233
|
}
|
|
2246
2234
|
var RULE_NAME37 = "no-set-state-in-component-did-update";
|
|
2247
2235
|
var RULE_FEATURES37 = [];
|
|
2248
|
-
function isComponentDidUpdate(node) {
|
|
2249
|
-
return AST11__namespace.isMethodOrProperty(node) && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentDidUpdate";
|
|
2250
|
-
}
|
|
2251
2236
|
var no_set_state_in_component_did_update_default = createRule({
|
|
2252
2237
|
meta: {
|
|
2253
2238
|
type: "problem",
|
|
@@ -2271,8 +2256,8 @@ function create37(context) {
|
|
|
2271
2256
|
if (!ER21__namespace.isThisSetState(node)) {
|
|
2272
2257
|
return;
|
|
2273
2258
|
}
|
|
2274
|
-
const clazz =
|
|
2275
|
-
const method =
|
|
2259
|
+
const clazz = AST8__namespace.findParentNode(node, ER21__namespace.isClassComponent);
|
|
2260
|
+
const method = AST8__namespace.findParentNode(node, (n) => n === clazz || ER21__namespace.isComponentDidUpdate(n));
|
|
2276
2261
|
if (clazz == null || method == null || method === clazz) return;
|
|
2277
2262
|
const methodScope = context.sourceCode.getScope(method);
|
|
2278
2263
|
const upperScope = context.sourceCode.getScope(node).upper;
|
|
@@ -2287,9 +2272,6 @@ function create37(context) {
|
|
|
2287
2272
|
}
|
|
2288
2273
|
var RULE_NAME38 = "no-set-state-in-component-will-update";
|
|
2289
2274
|
var RULE_FEATURES38 = [];
|
|
2290
|
-
function isComponentWillUpdate3(node) {
|
|
2291
|
-
return AST11__namespace.isMethodOrProperty(node) && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentWillUpdate";
|
|
2292
|
-
}
|
|
2293
2275
|
var no_set_state_in_component_will_update_default = createRule({
|
|
2294
2276
|
meta: {
|
|
2295
2277
|
type: "problem",
|
|
@@ -2313,8 +2295,8 @@ function create38(context) {
|
|
|
2313
2295
|
if (!ER21__namespace.isThisSetState(node)) {
|
|
2314
2296
|
return;
|
|
2315
2297
|
}
|
|
2316
|
-
const clazz =
|
|
2317
|
-
const method =
|
|
2298
|
+
const clazz = AST8__namespace.findParentNode(node, ER21__namespace.isClassComponent);
|
|
2299
|
+
const method = AST8__namespace.findParentNode(node, (n) => n === clazz || ER21__namespace.isComponentWillUpdate(n));
|
|
2318
2300
|
if (clazz == null || method == null || method === clazz) return;
|
|
2319
2301
|
const methodScope = context.sourceCode.getScope(method);
|
|
2320
2302
|
const upperScope = context.sourceCode.getScope(node).upper;
|
|
@@ -2375,7 +2357,7 @@ function create39(context) {
|
|
|
2375
2357
|
var RULE_NAME40 = "no-unsafe-component-will-mount";
|
|
2376
2358
|
var RULE_FEATURES40 = [];
|
|
2377
2359
|
function isUnsafeComponentWillMount(node) {
|
|
2378
|
-
return
|
|
2360
|
+
return AST8__namespace.isMethodOrProperty(node) && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "UNSAFE_componentWillMount";
|
|
2379
2361
|
}
|
|
2380
2362
|
var no_unsafe_component_will_mount_default = createRule({
|
|
2381
2363
|
meta: {
|
|
@@ -2417,7 +2399,7 @@ function create40(context) {
|
|
|
2417
2399
|
var RULE_NAME41 = "no-unsafe-component-will-receive-props";
|
|
2418
2400
|
var RULE_FEATURES41 = [];
|
|
2419
2401
|
function isUnsafeComponentWillReceiveProps(node) {
|
|
2420
|
-
return
|
|
2402
|
+
return AST8__namespace.isMethodOrProperty(node) && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "UNSAFE_componentWillReceiveProps";
|
|
2421
2403
|
}
|
|
2422
2404
|
var no_unsafe_component_will_receive_props_default = createRule({
|
|
2423
2405
|
meta: {
|
|
@@ -2461,7 +2443,7 @@ function create41(context) {
|
|
|
2461
2443
|
var RULE_NAME42 = "no-unsafe-component-will-update";
|
|
2462
2444
|
var RULE_FEATURES42 = [];
|
|
2463
2445
|
function isUnsafeComponentWillUpdate(node) {
|
|
2464
|
-
return
|
|
2446
|
+
return AST8__namespace.isMethodOrProperty(node) && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "UNSAFE_componentWillUpdate";
|
|
2465
2447
|
}
|
|
2466
2448
|
var no_unsafe_component_will_update_default = createRule({
|
|
2467
2449
|
meta: {
|
|
@@ -2540,7 +2522,7 @@ function create43(context) {
|
|
|
2540
2522
|
if (value?.type !== types.AST_NODE_TYPES.JSXExpressionContainer) return;
|
|
2541
2523
|
const valueExpression = value.expression;
|
|
2542
2524
|
const initialScope = context.sourceCode.getScope(valueExpression);
|
|
2543
|
-
const construction = VAR2__namespace.
|
|
2525
|
+
const construction = VAR2__namespace.getConstructionDetectionResult(valueExpression, initialScope);
|
|
2544
2526
|
if (construction == null) return;
|
|
2545
2527
|
if (ER21__namespace.isReactHookCall(construction.node)) {
|
|
2546
2528
|
return;
|
|
@@ -2557,7 +2539,7 @@ function create43(context) {
|
|
|
2557
2539
|
messageId: "unstableContextValue",
|
|
2558
2540
|
node: constructionNode,
|
|
2559
2541
|
data: {
|
|
2560
|
-
type:
|
|
2542
|
+
type: AST8__namespace.toReadableNodeType(constructionNode),
|
|
2561
2543
|
suggestion
|
|
2562
2544
|
}
|
|
2563
2545
|
});
|
|
@@ -2614,10 +2596,10 @@ function create44(context) {
|
|
|
2614
2596
|
const { value } = prop;
|
|
2615
2597
|
const { right } = value;
|
|
2616
2598
|
const initialScope = context.sourceCode.getScope(value);
|
|
2617
|
-
const construction = VAR2__namespace.
|
|
2599
|
+
const construction = VAR2__namespace.getConstructionDetectionResult(
|
|
2618
2600
|
value,
|
|
2619
2601
|
initialScope,
|
|
2620
|
-
VAR2__namespace.
|
|
2602
|
+
VAR2__namespace.ConstructionDetectionHint.StrictCallExpression
|
|
2621
2603
|
);
|
|
2622
2604
|
if (construction == null) {
|
|
2623
2605
|
continue;
|
|
@@ -2625,7 +2607,7 @@ function create44(context) {
|
|
|
2625
2607
|
if (ER21__namespace.isReactHookCall(construction.node)) {
|
|
2626
2608
|
continue;
|
|
2627
2609
|
}
|
|
2628
|
-
const forbiddenType =
|
|
2610
|
+
const forbiddenType = AST8__namespace.toReadableNodeType(right);
|
|
2629
2611
|
context.report({
|
|
2630
2612
|
messageId: "noUnstableDefaultProps",
|
|
2631
2613
|
node: right,
|
|
@@ -2703,14 +2685,14 @@ function create45(context) {
|
|
|
2703
2685
|
if (currentClass == null || !ER21__namespace.isClassComponent(currentClass)) {
|
|
2704
2686
|
return;
|
|
2705
2687
|
}
|
|
2706
|
-
const className =
|
|
2688
|
+
const className = AST8__namespace.getClassIdentifier(currentClass)?.name;
|
|
2707
2689
|
const defs = propertyDefs.get(currentClass);
|
|
2708
2690
|
const usages = propertyUsages.get(currentClass);
|
|
2709
2691
|
if (defs == null) {
|
|
2710
2692
|
return;
|
|
2711
2693
|
}
|
|
2712
2694
|
for (const def of defs) {
|
|
2713
|
-
const methodName =
|
|
2695
|
+
const methodName = AST8__namespace.getPropertyName(def);
|
|
2714
2696
|
if (methodName == null) {
|
|
2715
2697
|
continue;
|
|
2716
2698
|
}
|
|
@@ -2757,14 +2739,14 @@ function create45(context) {
|
|
|
2757
2739
|
if (!ER21__namespace.isClassComponent(currentClass) || currentMethod.static) {
|
|
2758
2740
|
return;
|
|
2759
2741
|
}
|
|
2760
|
-
if (!
|
|
2742
|
+
if (!AST8__namespace.isThisExpression(node.object) || !isKeyLiteral2(node, node.property)) {
|
|
2761
2743
|
return;
|
|
2762
2744
|
}
|
|
2763
2745
|
if (node.parent.type === types.AST_NODE_TYPES.AssignmentExpression && node.parent.left === node) {
|
|
2764
2746
|
propertyDefs.get(currentClass)?.add(node.property);
|
|
2765
2747
|
return;
|
|
2766
2748
|
}
|
|
2767
|
-
const propertyName =
|
|
2749
|
+
const propertyName = AST8__namespace.getPropertyName(node.property);
|
|
2768
2750
|
if (propertyName != null) {
|
|
2769
2751
|
propertyUsages.get(currentClass)?.add(propertyName);
|
|
2770
2752
|
}
|
|
@@ -2782,10 +2764,10 @@ function create45(context) {
|
|
|
2782
2764
|
if (!ER21__namespace.isClassComponent(currentClass) || currentMethod.static) {
|
|
2783
2765
|
return;
|
|
2784
2766
|
}
|
|
2785
|
-
if (node.init != null &&
|
|
2767
|
+
if (node.init != null && AST8__namespace.isThisExpression(node.init) && node.id.type === types.AST_NODE_TYPES.ObjectPattern) {
|
|
2786
2768
|
for (const prop of node.id.properties) {
|
|
2787
2769
|
if (prop.type === types.AST_NODE_TYPES.Property && isKeyLiteral2(prop, prop.key)) {
|
|
2788
|
-
const keyName =
|
|
2770
|
+
const keyName = AST8__namespace.getPropertyName(prop.key);
|
|
2789
2771
|
if (keyName != null) {
|
|
2790
2772
|
propertyUsages.get(currentClass)?.add(keyName);
|
|
2791
2773
|
}
|
|
@@ -2829,7 +2811,7 @@ function create46(context) {
|
|
|
2829
2811
|
if (currentClass == null || !ER21__namespace.isClassComponent(currentClass)) {
|
|
2830
2812
|
return;
|
|
2831
2813
|
}
|
|
2832
|
-
const className =
|
|
2814
|
+
const className = AST8__namespace.getClassIdentifier(currentClass)?.name;
|
|
2833
2815
|
const { node: defNode, isUsed = false } = stateDefs.get(currentClass) ?? {};
|
|
2834
2816
|
if (defNode == null || isUsed) {
|
|
2835
2817
|
return;
|
|
@@ -2855,7 +2837,7 @@ function create46(context) {
|
|
|
2855
2837
|
}
|
|
2856
2838
|
return;
|
|
2857
2839
|
}
|
|
2858
|
-
if (
|
|
2840
|
+
if (AST8__namespace.getPropertyName(node.key) === "state") {
|
|
2859
2841
|
stateDefs.set(currentClass, { node: node.key, isUsed: false });
|
|
2860
2842
|
}
|
|
2861
2843
|
}
|
|
@@ -2889,10 +2871,10 @@ function create46(context) {
|
|
|
2889
2871
|
ClassExpression: classEnter,
|
|
2890
2872
|
"ClassExpression:exit": classExit,
|
|
2891
2873
|
MemberExpression(node) {
|
|
2892
|
-
if (!
|
|
2874
|
+
if (!AST8__namespace.isThisExpression(node.object)) {
|
|
2893
2875
|
return;
|
|
2894
2876
|
}
|
|
2895
|
-
if (
|
|
2877
|
+
if (AST8__namespace.getPropertyName(node.property) !== "state") {
|
|
2896
2878
|
return;
|
|
2897
2879
|
}
|
|
2898
2880
|
const currentClass = classEntries.at(-1);
|
|
@@ -2933,12 +2915,12 @@ function create46(context) {
|
|
|
2933
2915
|
if (!currentClass.body.body.includes(currentMethod)) {
|
|
2934
2916
|
return;
|
|
2935
2917
|
}
|
|
2936
|
-
if (node.init == null || !
|
|
2918
|
+
if (node.init == null || !AST8__namespace.isThisExpression(node.init) || node.id.type !== types.AST_NODE_TYPES.ObjectPattern) {
|
|
2937
2919
|
return;
|
|
2938
2920
|
}
|
|
2939
2921
|
const hasState = node.id.properties.some((prop) => {
|
|
2940
2922
|
if (prop.type === types.AST_NODE_TYPES.Property && isKeyLiteral3(prop, prop.key)) {
|
|
2941
|
-
return
|
|
2923
|
+
return AST8__namespace.getPropertyName(prop.key) === "state";
|
|
2942
2924
|
}
|
|
2943
2925
|
return false;
|
|
2944
2926
|
});
|
|
@@ -3074,7 +3056,7 @@ function create48(context) {
|
|
|
3074
3056
|
return;
|
|
3075
3057
|
}
|
|
3076
3058
|
const [component] = node.arguments;
|
|
3077
|
-
if (component == null || !
|
|
3059
|
+
if (component == null || !AST8__namespace.isFunction(component)) {
|
|
3078
3060
|
return;
|
|
3079
3061
|
}
|
|
3080
3062
|
const ref = component.params[1];
|
|
@@ -3169,7 +3151,7 @@ function checkNode(context, node, allowExpressions) {
|
|
|
3169
3151
|
});
|
|
3170
3152
|
return;
|
|
3171
3153
|
}
|
|
3172
|
-
const isChildElement =
|
|
3154
|
+
const isChildElement = AST8__namespace.isOneOf([types.AST_NODE_TYPES.JSXElement, types.AST_NODE_TYPES.JSXFragment])(node.parent);
|
|
3173
3155
|
switch (true) {
|
|
3174
3156
|
// <Foo content={<>ee eeee eeee ...</>} />
|
|
3175
3157
|
case (allowExpressions && !isChildElement && node.children.length === 1 && JSX8__namespace.isJsxText(node.children.at(0))): {
|
|
@@ -3233,7 +3215,7 @@ function canFix(node) {
|
|
|
3233
3215
|
if (node.children.length === 0) {
|
|
3234
3216
|
return false;
|
|
3235
3217
|
}
|
|
3236
|
-
if (node.children.some((child) => JSX8__namespace.isJsxText(child) && !isWhiteSpace(child) ||
|
|
3218
|
+
if (node.children.some((child) => JSX8__namespace.isJsxText(child) && !isWhiteSpace(child) || AST8__namespace.is(types.AST_NODE_TYPES.JSXExpressionContainer)(child))) {
|
|
3237
3219
|
return false;
|
|
3238
3220
|
}
|
|
3239
3221
|
return true;
|
|
@@ -3275,10 +3257,10 @@ function create50(context) {
|
|
|
3275
3257
|
...ctx.getAllComponents(node).values()
|
|
3276
3258
|
];
|
|
3277
3259
|
function isFunctionComponent(block) {
|
|
3278
|
-
if (!
|
|
3260
|
+
if (!AST8__namespace.isFunction(block)) {
|
|
3279
3261
|
return false;
|
|
3280
3262
|
}
|
|
3281
|
-
const id =
|
|
3263
|
+
const id = AST8__namespace.getFunctionIdentifier(block);
|
|
3282
3264
|
return id != null && ER21__namespace.isComponentNameLoose(id.name) && components.some((component) => component.node === block);
|
|
3283
3265
|
}
|
|
3284
3266
|
for (const [initialScope, memberExpression] of memberExpressionWithNames) {
|
|
@@ -3349,25 +3331,26 @@ function create51(context) {
|
|
|
3349
3331
|
messageId: "preferReactNamespaceImport",
|
|
3350
3332
|
node: hasOtherSpecifiers ? node : node.parent,
|
|
3351
3333
|
data: { importSource },
|
|
3352
|
-
// TODO: Use `settings.languagePreference` to determine what code style to use in the fixer (e.g. single or double quotes)
|
|
3353
3334
|
fix(fixer) {
|
|
3335
|
+
const importDeclarationText = context.sourceCode.getText(node.parent);
|
|
3336
|
+
const semi = importDeclarationText.endsWith(";") ? ";" : "";
|
|
3354
3337
|
const quote = node.parent.source.raw.at(0) ?? "'";
|
|
3355
3338
|
const isTypeImport = node.parent.importKind === "type";
|
|
3356
3339
|
const importStringPrefix = `import${isTypeImport ? " type" : ""}`;
|
|
3357
3340
|
const importSourceQuoted = `${quote}${importSource}${quote}`;
|
|
3358
|
-
const sourceCode = context.sourceCode.getText(node.parent);
|
|
3359
|
-
const semiColon = sourceCode.endsWith(";") ? ";" : "";
|
|
3360
3341
|
if (!hasOtherSpecifiers) {
|
|
3361
3342
|
return fixer.replaceText(
|
|
3362
3343
|
node.parent,
|
|
3363
|
-
`${importStringPrefix} * as ${node.local.name} from ${importSourceQuoted}${
|
|
3344
|
+
`${importStringPrefix} * as ${node.local.name} from ${importSourceQuoted}${semi}`
|
|
3364
3345
|
);
|
|
3365
3346
|
}
|
|
3366
|
-
const specifiers =
|
|
3347
|
+
const specifiers = importDeclarationText.slice(importDeclarationText.indexOf("{"), importDeclarationText.indexOf("}") + 1);
|
|
3367
3348
|
return fixer.replaceText(
|
|
3368
3349
|
node.parent,
|
|
3369
|
-
|
|
3370
|
-
|
|
3350
|
+
[
|
|
3351
|
+
`${importStringPrefix} * as ${node.local.name} from ${importSourceQuoted}${semi}`,
|
|
3352
|
+
`${importStringPrefix} ${specifiers} from ${importSourceQuoted}${semi}`
|
|
3353
|
+
].join("\n")
|
|
3371
3354
|
);
|
|
3372
3355
|
}
|
|
3373
3356
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -7,7 +7,7 @@ import * as VAR2 from '@eslint-react/var';
|
|
|
7
7
|
import { match, isMatching, P } from 'ts-pattern';
|
|
8
8
|
import { JsxRuntime, RE_JSX_ANNOTATION, RE_JSX_FRAG_ANNOTATION, createReport } from '@eslint-react/kit';
|
|
9
9
|
import ts, { JsxEmit } from 'typescript';
|
|
10
|
-
import * as
|
|
10
|
+
import * as AST8 from '@eslint-react/ast';
|
|
11
11
|
import * as ER21 from '@eslint-react/core';
|
|
12
12
|
import { compare } from 'compare-versions';
|
|
13
13
|
import { getConstrainedTypeAtLocation, isTypeReadonly } from '@typescript-eslint/type-utils';
|
|
@@ -113,7 +113,7 @@ var settings3 = {
|
|
|
113
113
|
|
|
114
114
|
// package.json
|
|
115
115
|
var name4 = "eslint-plugin-react-x";
|
|
116
|
-
var version = "1.40.4-next.
|
|
116
|
+
var version = "1.40.4-next.2";
|
|
117
117
|
var createRule = ESLintUtils.RuleCreator(getDocsUrl("x"));
|
|
118
118
|
|
|
119
119
|
// src/rules/avoid-shorthand-boolean.ts
|
|
@@ -424,7 +424,7 @@ function create7(context) {
|
|
|
424
424
|
classEntries.pop();
|
|
425
425
|
},
|
|
426
426
|
MemberExpression(node) {
|
|
427
|
-
if (!
|
|
427
|
+
if (!AST8.isThisExpression(node.object)) {
|
|
428
428
|
return;
|
|
429
429
|
}
|
|
430
430
|
const [currClass, isComponent = false] = classEntries.at(-1) ?? [];
|
|
@@ -439,7 +439,7 @@ function create7(context) {
|
|
|
439
439
|
if (setState == null || hasThisState) {
|
|
440
440
|
return;
|
|
441
441
|
}
|
|
442
|
-
if (
|
|
442
|
+
if (AST8.getPropertyName(node.property) !== "state") {
|
|
443
443
|
return;
|
|
444
444
|
}
|
|
445
445
|
context.report({ messageId: "noAccessStateInSetstate", node });
|
|
@@ -469,11 +469,11 @@ function create7(context) {
|
|
|
469
469
|
if (setState == null || hasThisState) {
|
|
470
470
|
return;
|
|
471
471
|
}
|
|
472
|
-
if (node.init == null || !
|
|
472
|
+
if (node.init == null || !AST8.isThisExpression(node.init) || node.id.type !== AST_NODE_TYPES.ObjectPattern) {
|
|
473
473
|
return;
|
|
474
474
|
}
|
|
475
475
|
const hasState = node.id.properties.some(
|
|
476
|
-
(prop) => prop.type === AST_NODE_TYPES.Property && isKeyLiteral(prop, prop.key) &&
|
|
476
|
+
(prop) => prop.type === AST_NODE_TYPES.Property && isKeyLiteral(prop, prop.key) && AST8.getPropertyName(prop.key) === "state"
|
|
477
477
|
);
|
|
478
478
|
if (!hasState) {
|
|
479
479
|
return;
|
|
@@ -515,18 +515,18 @@ function getMapIndexParamName(context, node) {
|
|
|
515
515
|
return _;
|
|
516
516
|
}
|
|
517
517
|
const { name: name5 } = callee.property;
|
|
518
|
-
if (!
|
|
518
|
+
if (!AST8.ITERATOR_FUNCTION_INDEX_PARAM_POSITION.has(name5)) {
|
|
519
519
|
return _;
|
|
520
520
|
}
|
|
521
521
|
const callbackArg = node.arguments[isUsingReactChildren(context, node) ? 1 : 0];
|
|
522
522
|
if (callbackArg == null) {
|
|
523
523
|
return _;
|
|
524
524
|
}
|
|
525
|
-
if (!
|
|
525
|
+
if (!AST8.isOneOf([AST_NODE_TYPES.ArrowFunctionExpression, AST_NODE_TYPES.FunctionExpression])(callbackArg)) {
|
|
526
526
|
return _;
|
|
527
527
|
}
|
|
528
528
|
const { params } = callbackArg;
|
|
529
|
-
const indexParamPosition =
|
|
529
|
+
const indexParamPosition = AST8.ITERATOR_FUNCTION_INDEX_PARAM_POSITION.get(name5);
|
|
530
530
|
if (indexParamPosition == null) {
|
|
531
531
|
return _;
|
|
532
532
|
}
|
|
@@ -938,14 +938,14 @@ var no_comment_textnodes_default = createRule({
|
|
|
938
938
|
});
|
|
939
939
|
function create17(context) {
|
|
940
940
|
function hasCommentLike(node) {
|
|
941
|
-
if (
|
|
941
|
+
if (AST8.isOneOf([AST_NODE_TYPES.JSXAttribute, AST_NODE_TYPES.JSXExpressionContainer])(node.parent)) {
|
|
942
942
|
return false;
|
|
943
943
|
}
|
|
944
944
|
const rawValue = context.sourceCode.getText(node);
|
|
945
945
|
return /^\s*\/(?:\/|\*)/mu.test(rawValue);
|
|
946
946
|
}
|
|
947
947
|
const visitorFunction = (node) => {
|
|
948
|
-
if (!
|
|
948
|
+
if (!AST8.isOneOf([AST_NODE_TYPES.JSXElement, AST_NODE_TYPES.JSXFragment])(node.parent)) {
|
|
949
949
|
return;
|
|
950
950
|
}
|
|
951
951
|
if (!hasCommentLike(node)) {
|
|
@@ -987,10 +987,10 @@ var no_complex_conditional_rendering_default = createRule({
|
|
|
987
987
|
function create18(context) {
|
|
988
988
|
const visitorFunction = (node) => {
|
|
989
989
|
const jsxExpContainer = node.parent?.parent;
|
|
990
|
-
if (!
|
|
990
|
+
if (!AST8.is(AST_NODE_TYPES.JSXExpressionContainer)(jsxExpContainer)) {
|
|
991
991
|
return;
|
|
992
992
|
}
|
|
993
|
-
if (!
|
|
993
|
+
if (!AST8.isOneOf([AST_NODE_TYPES.JSXElement, AST_NODE_TYPES.JSXFragment])(jsxExpContainer.parent)) {
|
|
994
994
|
return;
|
|
995
995
|
}
|
|
996
996
|
if (!jsxExpContainer.parent.children.includes(jsxExpContainer)) {
|
|
@@ -1013,9 +1013,6 @@ var RULE_NAME19 = "no-component-will-mount";
|
|
|
1013
1013
|
var RULE_FEATURES19 = [
|
|
1014
1014
|
"MOD"
|
|
1015
1015
|
];
|
|
1016
|
-
function isComponentWillMount(node) {
|
|
1017
|
-
return AST11.isMethodOrProperty(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentWillMount";
|
|
1018
|
-
}
|
|
1019
1016
|
var no_component_will_mount_default = createRule({
|
|
1020
1017
|
meta: {
|
|
1021
1018
|
type: "problem",
|
|
@@ -1043,7 +1040,7 @@ function create19(context) {
|
|
|
1043
1040
|
for (const { node: component } of components.values()) {
|
|
1044
1041
|
const { body } = component.body;
|
|
1045
1042
|
for (const member of body) {
|
|
1046
|
-
if (isComponentWillMount(member)) {
|
|
1043
|
+
if (ER21.isComponentWillMount(member)) {
|
|
1047
1044
|
context.report({
|
|
1048
1045
|
messageId: "noComponentWillMount",
|
|
1049
1046
|
node: member,
|
|
@@ -1064,9 +1061,6 @@ var RULE_NAME20 = "no-component-will-receive-props";
|
|
|
1064
1061
|
var RULE_FEATURES20 = [
|
|
1065
1062
|
"MOD"
|
|
1066
1063
|
];
|
|
1067
|
-
function isComponentWillUpdate(node) {
|
|
1068
|
-
return AST11.isMethodOrProperty(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentWillReceiveProps";
|
|
1069
|
-
}
|
|
1070
1064
|
var no_component_will_receive_props_default = createRule({
|
|
1071
1065
|
meta: {
|
|
1072
1066
|
type: "problem",
|
|
@@ -1094,7 +1088,7 @@ function create20(context) {
|
|
|
1094
1088
|
for (const { node: component } of components.values()) {
|
|
1095
1089
|
const { body } = component.body;
|
|
1096
1090
|
for (const member of body) {
|
|
1097
|
-
if (
|
|
1091
|
+
if (ER21.isComponentWillReceiveProps(member)) {
|
|
1098
1092
|
context.report({
|
|
1099
1093
|
messageId: "noComponentWillReceiveProps",
|
|
1100
1094
|
node: member,
|
|
@@ -1115,9 +1109,6 @@ var RULE_NAME21 = "no-component-will-update";
|
|
|
1115
1109
|
var RULE_FEATURES21 = [
|
|
1116
1110
|
"MOD"
|
|
1117
1111
|
];
|
|
1118
|
-
function isComponentWillUpdate2(node) {
|
|
1119
|
-
return AST11.isMethodOrProperty(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentWillUpdate";
|
|
1120
|
-
}
|
|
1121
1112
|
var no_component_will_update_default = createRule({
|
|
1122
1113
|
meta: {
|
|
1123
1114
|
type: "problem",
|
|
@@ -1145,7 +1136,7 @@ function create21(context) {
|
|
|
1145
1136
|
for (const { node: component } of components.values()) {
|
|
1146
1137
|
const { body } = component.body;
|
|
1147
1138
|
for (const member of body) {
|
|
1148
|
-
if (
|
|
1139
|
+
if (ER21.isComponentWillUpdate(member)) {
|
|
1149
1140
|
context.report({
|
|
1150
1141
|
messageId: "noComponentWillUpdate",
|
|
1151
1142
|
node: member,
|
|
@@ -1236,7 +1227,7 @@ var no_create_ref_default = createRule({
|
|
|
1236
1227
|
function create23(context) {
|
|
1237
1228
|
return {
|
|
1238
1229
|
CallExpression(node) {
|
|
1239
|
-
if (ER21.isCreateRefCall(context, node) &&
|
|
1230
|
+
if (ER21.isCreateRefCall(context, node) && AST8.findParentNode(node, ER21.isClassComponent) == null) {
|
|
1240
1231
|
context.report({ messageId: "noCreateRef", node });
|
|
1241
1232
|
}
|
|
1242
1233
|
}
|
|
@@ -1280,7 +1271,7 @@ function create24(context) {
|
|
|
1280
1271
|
const variable = VAR2.findVariable(object.name, context.sourceCode.getScope(node));
|
|
1281
1272
|
const variableNode = VAR2.getVariableInitNode(variable, 0);
|
|
1282
1273
|
if (variableNode == null) return;
|
|
1283
|
-
if (!
|
|
1274
|
+
if (!AST8.isFunction(variableNode) && !ER21.isClassComponent(variableNode)) return;
|
|
1284
1275
|
context.report({ messageId: "noDefaultProps", node: property });
|
|
1285
1276
|
},
|
|
1286
1277
|
PropertyDefinition(node) {
|
|
@@ -1297,7 +1288,7 @@ function create24(context) {
|
|
|
1297
1288
|
var RULE_NAME25 = "no-direct-mutation-state";
|
|
1298
1289
|
var RULE_FEATURES25 = [];
|
|
1299
1290
|
function isConstructorFunction(node) {
|
|
1300
|
-
return
|
|
1291
|
+
return AST8.isOneOf([AST_NODE_TYPES.FunctionDeclaration, AST_NODE_TYPES.FunctionExpression])(node) && AST8.isMethodOrProperty(node.parent) && node.parent.key.type === AST_NODE_TYPES.Identifier && node.parent.key.name === "constructor";
|
|
1301
1292
|
}
|
|
1302
1293
|
var no_direct_mutation_state_default = createRule({
|
|
1303
1294
|
meta: {
|
|
@@ -1319,15 +1310,15 @@ function create25(context) {
|
|
|
1319
1310
|
return {
|
|
1320
1311
|
AssignmentExpression(node) {
|
|
1321
1312
|
if (!ER21.isAssignmentToThisState(node)) return;
|
|
1322
|
-
const parentClass =
|
|
1313
|
+
const parentClass = AST8.findParentNode(
|
|
1323
1314
|
node,
|
|
1324
|
-
|
|
1315
|
+
AST8.isOneOf([
|
|
1325
1316
|
AST_NODE_TYPES.ClassDeclaration,
|
|
1326
1317
|
AST_NODE_TYPES.ClassExpression
|
|
1327
1318
|
])
|
|
1328
1319
|
);
|
|
1329
1320
|
if (parentClass == null) return;
|
|
1330
|
-
if (ER21.isClassComponent(parentClass) && context.sourceCode.getScope(node).block !==
|
|
1321
|
+
if (ER21.isClassComponent(parentClass) && context.sourceCode.getScope(node).block !== AST8.findParentNode(node, isConstructorFunction)) {
|
|
1331
1322
|
context.report({
|
|
1332
1323
|
messageId: "noDirectMutationState",
|
|
1333
1324
|
node
|
|
@@ -1365,7 +1356,7 @@ function create26(context) {
|
|
|
1365
1356
|
if (aValue == null || bValue == null) {
|
|
1366
1357
|
return false;
|
|
1367
1358
|
}
|
|
1368
|
-
return
|
|
1359
|
+
return AST8.isNodeEqual(aValue, bValue);
|
|
1369
1360
|
}
|
|
1370
1361
|
return {
|
|
1371
1362
|
"JSXAttribute[name.name='key']"(node) {
|
|
@@ -1384,12 +1375,12 @@ function create26(context) {
|
|
|
1384
1375
|
break;
|
|
1385
1376
|
}
|
|
1386
1377
|
default: {
|
|
1387
|
-
const call =
|
|
1388
|
-
const iter =
|
|
1389
|
-
if (!
|
|
1378
|
+
const call = AST8.findParentNode(jsxElement, AST8.isArrayMapCallLoose);
|
|
1379
|
+
const iter = AST8.findParentNode(jsxElement, (n) => n === call || AST8.isFunction(n));
|
|
1380
|
+
if (!AST8.isFunction(iter)) return;
|
|
1390
1381
|
const arg0 = call?.arguments[0];
|
|
1391
1382
|
if (call == null || arg0 == null) return;
|
|
1392
|
-
if (
|
|
1383
|
+
if (AST8.getEcmaExpression(arg0) !== iter) {
|
|
1393
1384
|
return;
|
|
1394
1385
|
}
|
|
1395
1386
|
keyedEntries.set(call, {
|
|
@@ -1463,7 +1454,7 @@ function create27(context) {
|
|
|
1463
1454
|
function getFix(context, node) {
|
|
1464
1455
|
return (fixer) => {
|
|
1465
1456
|
const [componentNode] = node.arguments;
|
|
1466
|
-
if (componentNode == null || !
|
|
1457
|
+
if (componentNode == null || !AST8.isFunction(componentNode)) {
|
|
1467
1458
|
return [];
|
|
1468
1459
|
}
|
|
1469
1460
|
return [
|
|
@@ -1677,7 +1668,7 @@ function create29(context) {
|
|
|
1677
1668
|
const services = ESLintUtils.getParserServices(context, false);
|
|
1678
1669
|
function getReportDescriptor(node) {
|
|
1679
1670
|
if (node == null) return _;
|
|
1680
|
-
return match(node).when(
|
|
1671
|
+
return match(node).when(AST8.isJSX, () => _).with({ type: AST_NODE_TYPES.LogicalExpression, operator: "&&" }, ({ left, right }) => {
|
|
1681
1672
|
const isLeftUnaryNot = left.type === AST_NODE_TYPES.UnaryExpression && left.operator === "!";
|
|
1682
1673
|
if (isLeftUnaryNot) {
|
|
1683
1674
|
return getReportDescriptor(right);
|
|
@@ -1753,7 +1744,7 @@ function create30(context) {
|
|
|
1753
1744
|
const components = ctx.getAllComponents(node);
|
|
1754
1745
|
for (const { node: node2, displayName, flag } of components.values()) {
|
|
1755
1746
|
const isMemoOrForwardRef = (flag & (ER21.ComponentFlag.ForwardRef | ER21.ComponentFlag.Memo)) > 0n;
|
|
1756
|
-
if (
|
|
1747
|
+
if (AST8.getFunctionIdentifier(node2) != null) {
|
|
1757
1748
|
continue;
|
|
1758
1749
|
}
|
|
1759
1750
|
if (!isMemoOrForwardRef) {
|
|
@@ -1890,7 +1881,7 @@ function create32(context) {
|
|
|
1890
1881
|
}
|
|
1891
1882
|
function checkBlockStatement(node) {
|
|
1892
1883
|
const descriptors = [];
|
|
1893
|
-
for (const statement of
|
|
1884
|
+
for (const statement of AST8.getNestedReturnStatements(node)) {
|
|
1894
1885
|
if (statement.argument == null) continue;
|
|
1895
1886
|
const descriptor = checkIteratorElement(statement.argument);
|
|
1896
1887
|
if (descriptor != null) descriptors.push(descriptor);
|
|
@@ -1902,7 +1893,7 @@ function create32(context) {
|
|
|
1902
1893
|
if (state.isWithinChildrenToArray) {
|
|
1903
1894
|
return;
|
|
1904
1895
|
}
|
|
1905
|
-
const elements = node.elements.filter(
|
|
1896
|
+
const elements = node.elements.filter(AST8.is(AST_NODE_TYPES.JSXElement));
|
|
1906
1897
|
if (elements.length === 0) {
|
|
1907
1898
|
return;
|
|
1908
1899
|
}
|
|
@@ -1921,12 +1912,12 @@ function create32(context) {
|
|
|
1921
1912
|
if (state.isWithinChildrenToArray) {
|
|
1922
1913
|
return;
|
|
1923
1914
|
}
|
|
1924
|
-
const isMapCall =
|
|
1915
|
+
const isMapCall = AST8.isArrayMapCallLoose(node);
|
|
1925
1916
|
if (!isMapCall && !isArrayFromCall(node)) {
|
|
1926
1917
|
return;
|
|
1927
1918
|
}
|
|
1928
1919
|
const fn = node.arguments[isMapCall ? 0 : 1];
|
|
1929
|
-
if (!
|
|
1920
|
+
if (!AST8.isFunction(fn)) {
|
|
1930
1921
|
return;
|
|
1931
1922
|
}
|
|
1932
1923
|
if (fn.body.type === AST_NODE_TYPES.BlockStatement) {
|
|
@@ -1990,10 +1981,10 @@ function create33(context) {
|
|
|
1990
1981
|
...collectorLegacy.ctx.getAllComponents(node).values()
|
|
1991
1982
|
];
|
|
1992
1983
|
const isFunctionComponent = (node2) => {
|
|
1993
|
-
return
|
|
1984
|
+
return AST8.isFunction(node2) && functionComponents.some((component) => component.node === node2);
|
|
1994
1985
|
};
|
|
1995
1986
|
const isClassComponent11 = (node2) => {
|
|
1996
|
-
return
|
|
1987
|
+
return AST8.isClass(node2) && classComponents.some((component) => component.node === node2);
|
|
1997
1988
|
};
|
|
1998
1989
|
for (const { name: name5, node: component } of functionComponents) {
|
|
1999
1990
|
if (name5 == null) continue;
|
|
@@ -2022,7 +2013,7 @@ function create33(context) {
|
|
|
2022
2013
|
});
|
|
2023
2014
|
continue;
|
|
2024
2015
|
}
|
|
2025
|
-
const parentComponent =
|
|
2016
|
+
const parentComponent = AST8.findParentNode(component, isFunctionComponent);
|
|
2026
2017
|
if (parentComponent != null && !ER21.isDirectValueOfRenderPropertyLoose(parentComponent)) {
|
|
2027
2018
|
context.report({
|
|
2028
2019
|
messageId: "noNestedComponentDefinitions",
|
|
@@ -2046,7 +2037,7 @@ function create33(context) {
|
|
|
2046
2037
|
}
|
|
2047
2038
|
}
|
|
2048
2039
|
for (const { name: name5 = "unknown", node: component } of classComponents) {
|
|
2049
|
-
if (
|
|
2040
|
+
if (AST8.findParentNode(component, (n) => isClassComponent11(n) || isFunctionComponent(n)) == null) {
|
|
2050
2041
|
continue;
|
|
2051
2042
|
}
|
|
2052
2043
|
context.report({
|
|
@@ -2065,9 +2056,9 @@ function isInsideJSXAttributeValue(node) {
|
|
|
2065
2056
|
return node.parent.type === AST_NODE_TYPES.JSXAttribute || JSX8.findParentAttribute(node, (n) => n.value?.type === AST_NODE_TYPES.JSXExpressionContainer) != null;
|
|
2066
2057
|
}
|
|
2067
2058
|
function isInsideCreateElementProps(context, node) {
|
|
2068
|
-
const call =
|
|
2059
|
+
const call = AST8.findParentNode(node, ER21.isCreateElementCall(context));
|
|
2069
2060
|
if (call == null) return false;
|
|
2070
|
-
const prop =
|
|
2061
|
+
const prop = AST8.findParentNode(node, AST8.is(AST_NODE_TYPES.ObjectExpression));
|
|
2071
2062
|
if (prop == null) return false;
|
|
2072
2063
|
return prop === call.arguments[1];
|
|
2073
2064
|
}
|
|
@@ -2110,7 +2101,7 @@ function create34(context) {
|
|
|
2110
2101
|
}
|
|
2111
2102
|
const variable = VAR2.findVariable(object.name, context.sourceCode.getScope(node));
|
|
2112
2103
|
const variableNode = VAR2.getVariableInitNode(variable, 0);
|
|
2113
|
-
if (variableNode != null && (
|
|
2104
|
+
if (variableNode != null && (AST8.isFunction(variableNode) || ER21.isClassComponent(variableNode))) {
|
|
2114
2105
|
context.report({ messageId: "noPropTypes", node: property });
|
|
2115
2106
|
}
|
|
2116
2107
|
},
|
|
@@ -2128,7 +2119,7 @@ function create34(context) {
|
|
|
2128
2119
|
var RULE_NAME35 = "no-redundant-should-component-update";
|
|
2129
2120
|
var RULE_FEATURES35 = [];
|
|
2130
2121
|
function isShouldComponentUpdate(node) {
|
|
2131
|
-
return
|
|
2122
|
+
return AST8.isMethodOrProperty(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "shouldComponentUpdate";
|
|
2132
2123
|
}
|
|
2133
2124
|
var no_redundant_should_component_update_default = createRule({
|
|
2134
2125
|
meta: {
|
|
@@ -2175,9 +2166,6 @@ function create35(context) {
|
|
|
2175
2166
|
}
|
|
2176
2167
|
var RULE_NAME36 = "no-set-state-in-component-did-mount";
|
|
2177
2168
|
var RULE_FEATURES36 = [];
|
|
2178
|
-
function isComponentDidMount(node) {
|
|
2179
|
-
return AST11.isMethodOrProperty(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentDidMount";
|
|
2180
|
-
}
|
|
2181
2169
|
var no_set_state_in_component_did_mount_default = createRule({
|
|
2182
2170
|
meta: {
|
|
2183
2171
|
type: "problem",
|
|
@@ -2201,8 +2189,8 @@ function create36(context) {
|
|
|
2201
2189
|
if (!ER21.isThisSetState(node)) {
|
|
2202
2190
|
return;
|
|
2203
2191
|
}
|
|
2204
|
-
const clazz =
|
|
2205
|
-
const method =
|
|
2192
|
+
const clazz = AST8.findParentNode(node, ER21.isClassComponent);
|
|
2193
|
+
const method = AST8.findParentNode(node, (n) => n === clazz || ER21.isComponentDidMount(n));
|
|
2206
2194
|
if (clazz == null || method == null || method === clazz) return;
|
|
2207
2195
|
const methodScope = context.sourceCode.getScope(method);
|
|
2208
2196
|
const upperScope = context.sourceCode.getScope(node).upper;
|
|
@@ -2217,9 +2205,6 @@ function create36(context) {
|
|
|
2217
2205
|
}
|
|
2218
2206
|
var RULE_NAME37 = "no-set-state-in-component-did-update";
|
|
2219
2207
|
var RULE_FEATURES37 = [];
|
|
2220
|
-
function isComponentDidUpdate(node) {
|
|
2221
|
-
return AST11.isMethodOrProperty(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentDidUpdate";
|
|
2222
|
-
}
|
|
2223
2208
|
var no_set_state_in_component_did_update_default = createRule({
|
|
2224
2209
|
meta: {
|
|
2225
2210
|
type: "problem",
|
|
@@ -2243,8 +2228,8 @@ function create37(context) {
|
|
|
2243
2228
|
if (!ER21.isThisSetState(node)) {
|
|
2244
2229
|
return;
|
|
2245
2230
|
}
|
|
2246
|
-
const clazz =
|
|
2247
|
-
const method =
|
|
2231
|
+
const clazz = AST8.findParentNode(node, ER21.isClassComponent);
|
|
2232
|
+
const method = AST8.findParentNode(node, (n) => n === clazz || ER21.isComponentDidUpdate(n));
|
|
2248
2233
|
if (clazz == null || method == null || method === clazz) return;
|
|
2249
2234
|
const methodScope = context.sourceCode.getScope(method);
|
|
2250
2235
|
const upperScope = context.sourceCode.getScope(node).upper;
|
|
@@ -2259,9 +2244,6 @@ function create37(context) {
|
|
|
2259
2244
|
}
|
|
2260
2245
|
var RULE_NAME38 = "no-set-state-in-component-will-update";
|
|
2261
2246
|
var RULE_FEATURES38 = [];
|
|
2262
|
-
function isComponentWillUpdate3(node) {
|
|
2263
|
-
return AST11.isMethodOrProperty(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentWillUpdate";
|
|
2264
|
-
}
|
|
2265
2247
|
var no_set_state_in_component_will_update_default = createRule({
|
|
2266
2248
|
meta: {
|
|
2267
2249
|
type: "problem",
|
|
@@ -2285,8 +2267,8 @@ function create38(context) {
|
|
|
2285
2267
|
if (!ER21.isThisSetState(node)) {
|
|
2286
2268
|
return;
|
|
2287
2269
|
}
|
|
2288
|
-
const clazz =
|
|
2289
|
-
const method =
|
|
2270
|
+
const clazz = AST8.findParentNode(node, ER21.isClassComponent);
|
|
2271
|
+
const method = AST8.findParentNode(node, (n) => n === clazz || ER21.isComponentWillUpdate(n));
|
|
2290
2272
|
if (clazz == null || method == null || method === clazz) return;
|
|
2291
2273
|
const methodScope = context.sourceCode.getScope(method);
|
|
2292
2274
|
const upperScope = context.sourceCode.getScope(node).upper;
|
|
@@ -2347,7 +2329,7 @@ function create39(context) {
|
|
|
2347
2329
|
var RULE_NAME40 = "no-unsafe-component-will-mount";
|
|
2348
2330
|
var RULE_FEATURES40 = [];
|
|
2349
2331
|
function isUnsafeComponentWillMount(node) {
|
|
2350
|
-
return
|
|
2332
|
+
return AST8.isMethodOrProperty(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "UNSAFE_componentWillMount";
|
|
2351
2333
|
}
|
|
2352
2334
|
var no_unsafe_component_will_mount_default = createRule({
|
|
2353
2335
|
meta: {
|
|
@@ -2389,7 +2371,7 @@ function create40(context) {
|
|
|
2389
2371
|
var RULE_NAME41 = "no-unsafe-component-will-receive-props";
|
|
2390
2372
|
var RULE_FEATURES41 = [];
|
|
2391
2373
|
function isUnsafeComponentWillReceiveProps(node) {
|
|
2392
|
-
return
|
|
2374
|
+
return AST8.isMethodOrProperty(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "UNSAFE_componentWillReceiveProps";
|
|
2393
2375
|
}
|
|
2394
2376
|
var no_unsafe_component_will_receive_props_default = createRule({
|
|
2395
2377
|
meta: {
|
|
@@ -2433,7 +2415,7 @@ function create41(context) {
|
|
|
2433
2415
|
var RULE_NAME42 = "no-unsafe-component-will-update";
|
|
2434
2416
|
var RULE_FEATURES42 = [];
|
|
2435
2417
|
function isUnsafeComponentWillUpdate(node) {
|
|
2436
|
-
return
|
|
2418
|
+
return AST8.isMethodOrProperty(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "UNSAFE_componentWillUpdate";
|
|
2437
2419
|
}
|
|
2438
2420
|
var no_unsafe_component_will_update_default = createRule({
|
|
2439
2421
|
meta: {
|
|
@@ -2512,7 +2494,7 @@ function create43(context) {
|
|
|
2512
2494
|
if (value?.type !== AST_NODE_TYPES.JSXExpressionContainer) return;
|
|
2513
2495
|
const valueExpression = value.expression;
|
|
2514
2496
|
const initialScope = context.sourceCode.getScope(valueExpression);
|
|
2515
|
-
const construction = VAR2.
|
|
2497
|
+
const construction = VAR2.getConstructionDetectionResult(valueExpression, initialScope);
|
|
2516
2498
|
if (construction == null) return;
|
|
2517
2499
|
if (ER21.isReactHookCall(construction.node)) {
|
|
2518
2500
|
return;
|
|
@@ -2529,7 +2511,7 @@ function create43(context) {
|
|
|
2529
2511
|
messageId: "unstableContextValue",
|
|
2530
2512
|
node: constructionNode,
|
|
2531
2513
|
data: {
|
|
2532
|
-
type:
|
|
2514
|
+
type: AST8.toReadableNodeType(constructionNode),
|
|
2533
2515
|
suggestion
|
|
2534
2516
|
}
|
|
2535
2517
|
});
|
|
@@ -2586,10 +2568,10 @@ function create44(context) {
|
|
|
2586
2568
|
const { value } = prop;
|
|
2587
2569
|
const { right } = value;
|
|
2588
2570
|
const initialScope = context.sourceCode.getScope(value);
|
|
2589
|
-
const construction = VAR2.
|
|
2571
|
+
const construction = VAR2.getConstructionDetectionResult(
|
|
2590
2572
|
value,
|
|
2591
2573
|
initialScope,
|
|
2592
|
-
VAR2.
|
|
2574
|
+
VAR2.ConstructionDetectionHint.StrictCallExpression
|
|
2593
2575
|
);
|
|
2594
2576
|
if (construction == null) {
|
|
2595
2577
|
continue;
|
|
@@ -2597,7 +2579,7 @@ function create44(context) {
|
|
|
2597
2579
|
if (ER21.isReactHookCall(construction.node)) {
|
|
2598
2580
|
continue;
|
|
2599
2581
|
}
|
|
2600
|
-
const forbiddenType =
|
|
2582
|
+
const forbiddenType = AST8.toReadableNodeType(right);
|
|
2601
2583
|
context.report({
|
|
2602
2584
|
messageId: "noUnstableDefaultProps",
|
|
2603
2585
|
node: right,
|
|
@@ -2675,14 +2657,14 @@ function create45(context) {
|
|
|
2675
2657
|
if (currentClass == null || !ER21.isClassComponent(currentClass)) {
|
|
2676
2658
|
return;
|
|
2677
2659
|
}
|
|
2678
|
-
const className =
|
|
2660
|
+
const className = AST8.getClassIdentifier(currentClass)?.name;
|
|
2679
2661
|
const defs = propertyDefs.get(currentClass);
|
|
2680
2662
|
const usages = propertyUsages.get(currentClass);
|
|
2681
2663
|
if (defs == null) {
|
|
2682
2664
|
return;
|
|
2683
2665
|
}
|
|
2684
2666
|
for (const def of defs) {
|
|
2685
|
-
const methodName =
|
|
2667
|
+
const methodName = AST8.getPropertyName(def);
|
|
2686
2668
|
if (methodName == null) {
|
|
2687
2669
|
continue;
|
|
2688
2670
|
}
|
|
@@ -2729,14 +2711,14 @@ function create45(context) {
|
|
|
2729
2711
|
if (!ER21.isClassComponent(currentClass) || currentMethod.static) {
|
|
2730
2712
|
return;
|
|
2731
2713
|
}
|
|
2732
|
-
if (!
|
|
2714
|
+
if (!AST8.isThisExpression(node.object) || !isKeyLiteral2(node, node.property)) {
|
|
2733
2715
|
return;
|
|
2734
2716
|
}
|
|
2735
2717
|
if (node.parent.type === AST_NODE_TYPES.AssignmentExpression && node.parent.left === node) {
|
|
2736
2718
|
propertyDefs.get(currentClass)?.add(node.property);
|
|
2737
2719
|
return;
|
|
2738
2720
|
}
|
|
2739
|
-
const propertyName =
|
|
2721
|
+
const propertyName = AST8.getPropertyName(node.property);
|
|
2740
2722
|
if (propertyName != null) {
|
|
2741
2723
|
propertyUsages.get(currentClass)?.add(propertyName);
|
|
2742
2724
|
}
|
|
@@ -2754,10 +2736,10 @@ function create45(context) {
|
|
|
2754
2736
|
if (!ER21.isClassComponent(currentClass) || currentMethod.static) {
|
|
2755
2737
|
return;
|
|
2756
2738
|
}
|
|
2757
|
-
if (node.init != null &&
|
|
2739
|
+
if (node.init != null && AST8.isThisExpression(node.init) && node.id.type === AST_NODE_TYPES.ObjectPattern) {
|
|
2758
2740
|
for (const prop of node.id.properties) {
|
|
2759
2741
|
if (prop.type === AST_NODE_TYPES.Property && isKeyLiteral2(prop, prop.key)) {
|
|
2760
|
-
const keyName =
|
|
2742
|
+
const keyName = AST8.getPropertyName(prop.key);
|
|
2761
2743
|
if (keyName != null) {
|
|
2762
2744
|
propertyUsages.get(currentClass)?.add(keyName);
|
|
2763
2745
|
}
|
|
@@ -2801,7 +2783,7 @@ function create46(context) {
|
|
|
2801
2783
|
if (currentClass == null || !ER21.isClassComponent(currentClass)) {
|
|
2802
2784
|
return;
|
|
2803
2785
|
}
|
|
2804
|
-
const className =
|
|
2786
|
+
const className = AST8.getClassIdentifier(currentClass)?.name;
|
|
2805
2787
|
const { node: defNode, isUsed = false } = stateDefs.get(currentClass) ?? {};
|
|
2806
2788
|
if (defNode == null || isUsed) {
|
|
2807
2789
|
return;
|
|
@@ -2827,7 +2809,7 @@ function create46(context) {
|
|
|
2827
2809
|
}
|
|
2828
2810
|
return;
|
|
2829
2811
|
}
|
|
2830
|
-
if (
|
|
2812
|
+
if (AST8.getPropertyName(node.key) === "state") {
|
|
2831
2813
|
stateDefs.set(currentClass, { node: node.key, isUsed: false });
|
|
2832
2814
|
}
|
|
2833
2815
|
}
|
|
@@ -2861,10 +2843,10 @@ function create46(context) {
|
|
|
2861
2843
|
ClassExpression: classEnter,
|
|
2862
2844
|
"ClassExpression:exit": classExit,
|
|
2863
2845
|
MemberExpression(node) {
|
|
2864
|
-
if (!
|
|
2846
|
+
if (!AST8.isThisExpression(node.object)) {
|
|
2865
2847
|
return;
|
|
2866
2848
|
}
|
|
2867
|
-
if (
|
|
2849
|
+
if (AST8.getPropertyName(node.property) !== "state") {
|
|
2868
2850
|
return;
|
|
2869
2851
|
}
|
|
2870
2852
|
const currentClass = classEntries.at(-1);
|
|
@@ -2905,12 +2887,12 @@ function create46(context) {
|
|
|
2905
2887
|
if (!currentClass.body.body.includes(currentMethod)) {
|
|
2906
2888
|
return;
|
|
2907
2889
|
}
|
|
2908
|
-
if (node.init == null || !
|
|
2890
|
+
if (node.init == null || !AST8.isThisExpression(node.init) || node.id.type !== AST_NODE_TYPES.ObjectPattern) {
|
|
2909
2891
|
return;
|
|
2910
2892
|
}
|
|
2911
2893
|
const hasState = node.id.properties.some((prop) => {
|
|
2912
2894
|
if (prop.type === AST_NODE_TYPES.Property && isKeyLiteral3(prop, prop.key)) {
|
|
2913
|
-
return
|
|
2895
|
+
return AST8.getPropertyName(prop.key) === "state";
|
|
2914
2896
|
}
|
|
2915
2897
|
return false;
|
|
2916
2898
|
});
|
|
@@ -3046,7 +3028,7 @@ function create48(context) {
|
|
|
3046
3028
|
return;
|
|
3047
3029
|
}
|
|
3048
3030
|
const [component] = node.arguments;
|
|
3049
|
-
if (component == null || !
|
|
3031
|
+
if (component == null || !AST8.isFunction(component)) {
|
|
3050
3032
|
return;
|
|
3051
3033
|
}
|
|
3052
3034
|
const ref = component.params[1];
|
|
@@ -3141,7 +3123,7 @@ function checkNode(context, node, allowExpressions) {
|
|
|
3141
3123
|
});
|
|
3142
3124
|
return;
|
|
3143
3125
|
}
|
|
3144
|
-
const isChildElement =
|
|
3126
|
+
const isChildElement = AST8.isOneOf([AST_NODE_TYPES.JSXElement, AST_NODE_TYPES.JSXFragment])(node.parent);
|
|
3145
3127
|
switch (true) {
|
|
3146
3128
|
// <Foo content={<>ee eeee eeee ...</>} />
|
|
3147
3129
|
case (allowExpressions && !isChildElement && node.children.length === 1 && JSX8.isJsxText(node.children.at(0))): {
|
|
@@ -3205,7 +3187,7 @@ function canFix(node) {
|
|
|
3205
3187
|
if (node.children.length === 0) {
|
|
3206
3188
|
return false;
|
|
3207
3189
|
}
|
|
3208
|
-
if (node.children.some((child) => JSX8.isJsxText(child) && !isWhiteSpace(child) ||
|
|
3190
|
+
if (node.children.some((child) => JSX8.isJsxText(child) && !isWhiteSpace(child) || AST8.is(AST_NODE_TYPES.JSXExpressionContainer)(child))) {
|
|
3209
3191
|
return false;
|
|
3210
3192
|
}
|
|
3211
3193
|
return true;
|
|
@@ -3247,10 +3229,10 @@ function create50(context) {
|
|
|
3247
3229
|
...ctx.getAllComponents(node).values()
|
|
3248
3230
|
];
|
|
3249
3231
|
function isFunctionComponent(block) {
|
|
3250
|
-
if (!
|
|
3232
|
+
if (!AST8.isFunction(block)) {
|
|
3251
3233
|
return false;
|
|
3252
3234
|
}
|
|
3253
|
-
const id =
|
|
3235
|
+
const id = AST8.getFunctionIdentifier(block);
|
|
3254
3236
|
return id != null && ER21.isComponentNameLoose(id.name) && components.some((component) => component.node === block);
|
|
3255
3237
|
}
|
|
3256
3238
|
for (const [initialScope, memberExpression] of memberExpressionWithNames) {
|
|
@@ -3321,25 +3303,26 @@ function create51(context) {
|
|
|
3321
3303
|
messageId: "preferReactNamespaceImport",
|
|
3322
3304
|
node: hasOtherSpecifiers ? node : node.parent,
|
|
3323
3305
|
data: { importSource },
|
|
3324
|
-
// TODO: Use `settings.languagePreference` to determine what code style to use in the fixer (e.g. single or double quotes)
|
|
3325
3306
|
fix(fixer) {
|
|
3307
|
+
const importDeclarationText = context.sourceCode.getText(node.parent);
|
|
3308
|
+
const semi = importDeclarationText.endsWith(";") ? ";" : "";
|
|
3326
3309
|
const quote = node.parent.source.raw.at(0) ?? "'";
|
|
3327
3310
|
const isTypeImport = node.parent.importKind === "type";
|
|
3328
3311
|
const importStringPrefix = `import${isTypeImport ? " type" : ""}`;
|
|
3329
3312
|
const importSourceQuoted = `${quote}${importSource}${quote}`;
|
|
3330
|
-
const sourceCode = context.sourceCode.getText(node.parent);
|
|
3331
|
-
const semiColon = sourceCode.endsWith(";") ? ";" : "";
|
|
3332
3313
|
if (!hasOtherSpecifiers) {
|
|
3333
3314
|
return fixer.replaceText(
|
|
3334
3315
|
node.parent,
|
|
3335
|
-
`${importStringPrefix} * as ${node.local.name} from ${importSourceQuoted}${
|
|
3316
|
+
`${importStringPrefix} * as ${node.local.name} from ${importSourceQuoted}${semi}`
|
|
3336
3317
|
);
|
|
3337
3318
|
}
|
|
3338
|
-
const specifiers =
|
|
3319
|
+
const specifiers = importDeclarationText.slice(importDeclarationText.indexOf("{"), importDeclarationText.indexOf("}") + 1);
|
|
3339
3320
|
return fixer.replaceText(
|
|
3340
3321
|
node.parent,
|
|
3341
|
-
|
|
3342
|
-
|
|
3322
|
+
[
|
|
3323
|
+
`${importStringPrefix} * as ${node.local.name} from ${importSourceQuoted}${semi}`,
|
|
3324
|
+
`${importStringPrefix} ${specifiers} from ${importSourceQuoted}${semi}`
|
|
3325
|
+
].join("\n")
|
|
3343
3326
|
);
|
|
3344
3327
|
}
|
|
3345
3328
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-react-x",
|
|
3
|
-
"version": "1.40.4-next.
|
|
3
|
+
"version": "1.40.4-next.2",
|
|
4
4
|
"description": "A set of composable linting rules for libraries and frameworks that use React as a UI runtime.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -50,13 +50,13 @@
|
|
|
50
50
|
"is-immutable-type": "^5.0.1",
|
|
51
51
|
"string-ts": "^2.2.1",
|
|
52
52
|
"ts-pattern": "^5.7.0",
|
|
53
|
-
"@eslint-react/
|
|
54
|
-
"@eslint-react/
|
|
55
|
-
"@eslint-react/
|
|
56
|
-
"@eslint-react/
|
|
57
|
-
"@eslint-react/
|
|
58
|
-
"@eslint-react/
|
|
59
|
-
"@eslint-react/
|
|
53
|
+
"@eslint-react/ast": "1.40.4-next.2",
|
|
54
|
+
"@eslint-react/eff": "1.40.4-next.2",
|
|
55
|
+
"@eslint-react/kit": "1.40.4-next.2",
|
|
56
|
+
"@eslint-react/core": "1.40.4-next.2",
|
|
57
|
+
"@eslint-react/jsx": "1.40.4-next.2",
|
|
58
|
+
"@eslint-react/shared": "1.40.4-next.2",
|
|
59
|
+
"@eslint-react/var": "1.40.4-next.2"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
62
|
"@types/react": "^19.1.0",
|