eslint-plugin-react-x 1.30.2 → 1.30.3-beta.1
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 +74 -142
- package/dist/index.mjs +73 -141
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var shared = require('@eslint-react/shared');
|
|
4
4
|
var JSX8 = require('@eslint-react/jsx');
|
|
5
|
-
var
|
|
5
|
+
var AST12 = require('@eslint-react/ast');
|
|
6
6
|
var core = require('@eslint-react/core');
|
|
7
7
|
var eff = require('@eslint-react/eff');
|
|
8
8
|
var types = require('@typescript-eslint/types');
|
|
@@ -35,7 +35,7 @@ function _interopNamespace(e) {
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
var JSX8__namespace = /*#__PURE__*/_interopNamespace(JSX8);
|
|
38
|
-
var
|
|
38
|
+
var AST12__namespace = /*#__PURE__*/_interopNamespace(AST12);
|
|
39
39
|
var VAR__namespace = /*#__PURE__*/_interopNamespace(VAR);
|
|
40
40
|
var ts__default = /*#__PURE__*/_interopDefault(ts);
|
|
41
41
|
|
|
@@ -136,7 +136,7 @@ var settings3 = {
|
|
|
136
136
|
|
|
137
137
|
// package.json
|
|
138
138
|
var name4 = "eslint-plugin-react-x";
|
|
139
|
-
var version = "1.30.
|
|
139
|
+
var version = "1.30.3-beta.1";
|
|
140
140
|
var createRule = shared.createRuleForPlugin("x");
|
|
141
141
|
|
|
142
142
|
// src/rules/avoid-shorthand-boolean.ts
|
|
@@ -231,7 +231,7 @@ var ensure_forward_ref_using_ref_default = createRule({
|
|
|
231
231
|
return;
|
|
232
232
|
}
|
|
233
233
|
const [component] = node.arguments;
|
|
234
|
-
if (component == null || !
|
|
234
|
+
if (component == null || !AST12__namespace.isFunction(component)) {
|
|
235
235
|
return;
|
|
236
236
|
}
|
|
237
237
|
const ref = component.params[1];
|
|
@@ -254,21 +254,6 @@ var RULE_FEATURES4 = [
|
|
|
254
254
|
function isKeyLiteral(node, key) {
|
|
255
255
|
return tsPattern.match(key).with({ type: types.AST_NODE_TYPES.Literal }, eff.constTrue).with({ type: types.AST_NODE_TYPES.TemplateLiteral, expressions: [] }, eff.constTrue).with({ type: types.AST_NODE_TYPES.Identifier }, () => !node.computed).otherwise(eff.constFalse);
|
|
256
256
|
}
|
|
257
|
-
function getName(node) {
|
|
258
|
-
if (AST11__namespace.isTsOnlyExpression(node)) {
|
|
259
|
-
return getName(node.expression);
|
|
260
|
-
}
|
|
261
|
-
if (node.type === types.AST_NODE_TYPES.Identifier || node.type === types.AST_NODE_TYPES.PrivateIdentifier) {
|
|
262
|
-
return node.name;
|
|
263
|
-
}
|
|
264
|
-
if (node.type === types.AST_NODE_TYPES.Literal) {
|
|
265
|
-
return String(node.value);
|
|
266
|
-
}
|
|
267
|
-
if (node.type === types.AST_NODE_TYPES.TemplateLiteral && node.expressions.length === 0) {
|
|
268
|
-
return node.quasis[0]?.value.raw;
|
|
269
|
-
}
|
|
270
|
-
return eff._;
|
|
271
|
-
}
|
|
272
257
|
var no_access_state_in_setstate_default = createRule({
|
|
273
258
|
meta: {
|
|
274
259
|
type: "problem",
|
|
@@ -315,7 +300,7 @@ var no_access_state_in_setstate_default = createRule({
|
|
|
315
300
|
classEntries.pop();
|
|
316
301
|
},
|
|
317
302
|
MemberExpression(node) {
|
|
318
|
-
if (!
|
|
303
|
+
if (!AST12__namespace.isThisExpression(node.object)) {
|
|
319
304
|
return;
|
|
320
305
|
}
|
|
321
306
|
const [currClass, isComponent = false] = classEntries.at(-1) ?? [];
|
|
@@ -330,7 +315,7 @@ var no_access_state_in_setstate_default = createRule({
|
|
|
330
315
|
if (setState == null || hasThisState) {
|
|
331
316
|
return;
|
|
332
317
|
}
|
|
333
|
-
if (
|
|
318
|
+
if (AST12__namespace.getPropertyName(node.property) !== "state") {
|
|
334
319
|
return;
|
|
335
320
|
}
|
|
336
321
|
context.report({ messageId: "noAccessStateInSetstate", node });
|
|
@@ -360,11 +345,11 @@ var no_access_state_in_setstate_default = createRule({
|
|
|
360
345
|
if (setState == null || hasThisState) {
|
|
361
346
|
return;
|
|
362
347
|
}
|
|
363
|
-
if (node.init == null || !
|
|
348
|
+
if (node.init == null || !AST12__namespace.isThisExpression(node.init) || node.id.type !== types.AST_NODE_TYPES.ObjectPattern) {
|
|
364
349
|
return;
|
|
365
350
|
}
|
|
366
351
|
const hasState = node.id.properties.some(
|
|
367
|
-
(prop) => prop.type === types.AST_NODE_TYPES.Property && isKeyLiteral(prop, prop.key) &&
|
|
352
|
+
(prop) => prop.type === types.AST_NODE_TYPES.Property && isKeyLiteral(prop, prop.key) && AST12__namespace.getPropertyName(prop.key) === "state"
|
|
368
353
|
);
|
|
369
354
|
if (!hasState) {
|
|
370
355
|
return;
|
|
@@ -431,7 +416,7 @@ function getMapIndexParamName(context, node) {
|
|
|
431
416
|
if (callbackArg == null) {
|
|
432
417
|
return eff._;
|
|
433
418
|
}
|
|
434
|
-
if (!
|
|
419
|
+
if (!AST12__namespace.isOneOf([types.AST_NODE_TYPES.ArrowFunctionExpression, types.AST_NODE_TYPES.FunctionExpression])(callbackArg)) {
|
|
435
420
|
return eff._;
|
|
436
421
|
}
|
|
437
422
|
const { params } = callbackArg;
|
|
@@ -860,14 +845,14 @@ var no_comment_textnodes_default = createRule({
|
|
|
860
845
|
name: RULE_NAME14,
|
|
861
846
|
create(context) {
|
|
862
847
|
function hasCommentLike(node) {
|
|
863
|
-
if (
|
|
848
|
+
if (AST12__namespace.isOneOf([types.AST_NODE_TYPES.JSXAttribute, types.AST_NODE_TYPES.JSXExpressionContainer])(node.parent)) {
|
|
864
849
|
return false;
|
|
865
850
|
}
|
|
866
851
|
const rawValue = context.sourceCode.getText(node);
|
|
867
852
|
return /^\s*\/(?:\/|\*)/mu.test(rawValue);
|
|
868
853
|
}
|
|
869
854
|
const visitorFunction = (node) => {
|
|
870
|
-
if (!
|
|
855
|
+
if (!AST12__namespace.isOneOf([types.AST_NODE_TYPES.JSXElement, types.AST_NODE_TYPES.JSXFragment])(node.parent)) {
|
|
871
856
|
return;
|
|
872
857
|
}
|
|
873
858
|
if (!hasCommentLike(node)) {
|
|
@@ -908,10 +893,10 @@ var no_complex_conditional_rendering_default = createRule({
|
|
|
908
893
|
create(context) {
|
|
909
894
|
const visitorFunction = (node) => {
|
|
910
895
|
const jsxExpContainer = node.parent?.parent;
|
|
911
|
-
if (!
|
|
896
|
+
if (!AST12__namespace.is(types.AST_NODE_TYPES.JSXExpressionContainer)(jsxExpContainer)) {
|
|
912
897
|
return;
|
|
913
898
|
}
|
|
914
|
-
if (!
|
|
899
|
+
if (!AST12__namespace.isOneOf([types.AST_NODE_TYPES.JSXElement, types.AST_NODE_TYPES.JSXFragment])(jsxExpContainer.parent)) {
|
|
915
900
|
return;
|
|
916
901
|
}
|
|
917
902
|
if (!jsxExpContainer.parent.children.includes(jsxExpContainer)) {
|
|
@@ -938,7 +923,7 @@ var RULE_FEATURES16 = [
|
|
|
938
923
|
"MOD"
|
|
939
924
|
];
|
|
940
925
|
function isComponentWillMount(node) {
|
|
941
|
-
return
|
|
926
|
+
return AST12__namespace.isMethodOrProperty(node) && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentWillMount";
|
|
942
927
|
}
|
|
943
928
|
var no_component_will_mount_default = createRule({
|
|
944
929
|
meta: {
|
|
@@ -991,7 +976,7 @@ var RULE_FEATURES17 = [
|
|
|
991
976
|
"MOD"
|
|
992
977
|
];
|
|
993
978
|
function isComponentWillUpdate(node) {
|
|
994
|
-
return
|
|
979
|
+
return AST12__namespace.isMethodOrProperty(node) && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentWillReceiveProps";
|
|
995
980
|
}
|
|
996
981
|
var no_component_will_receive_props_default = createRule({
|
|
997
982
|
meta: {
|
|
@@ -1044,7 +1029,7 @@ var RULE_FEATURES18 = [
|
|
|
1044
1029
|
"MOD"
|
|
1045
1030
|
];
|
|
1046
1031
|
function isComponentWillUpdate2(node) {
|
|
1047
|
-
return
|
|
1032
|
+
return AST12__namespace.isMethodOrProperty(node) && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentWillUpdate";
|
|
1048
1033
|
}
|
|
1049
1034
|
var no_component_will_update_default = createRule({
|
|
1050
1035
|
meta: {
|
|
@@ -1164,7 +1149,7 @@ var no_create_ref_default = createRule({
|
|
|
1164
1149
|
create(context) {
|
|
1165
1150
|
return {
|
|
1166
1151
|
CallExpression(node) {
|
|
1167
|
-
if (core.isCreateRefCall(context, node) &&
|
|
1152
|
+
if (core.isCreateRefCall(context, node) && AST12__namespace.findParentNode(node, core.isClassComponent) == null) {
|
|
1168
1153
|
context.report({ messageId: "noCreateRef", node });
|
|
1169
1154
|
}
|
|
1170
1155
|
}
|
|
@@ -1211,7 +1196,7 @@ var no_default_props_default = createRule({
|
|
|
1211
1196
|
const variable = VAR__namespace.findVariable(object.name, context.sourceCode.getScope(node));
|
|
1212
1197
|
const variableNode = VAR__namespace.getVariableInitNode(variable, 0);
|
|
1213
1198
|
if (variableNode == null) return;
|
|
1214
|
-
if (!
|
|
1199
|
+
if (!AST12__namespace.isFunction(variableNode) && !core.isClassComponent(variableNode)) return;
|
|
1215
1200
|
context.report({ messageId: "noDefaultProps", node: property });
|
|
1216
1201
|
},
|
|
1217
1202
|
PropertyDefinition(node) {
|
|
@@ -1231,27 +1216,8 @@ var RULE_NAME22 = "no-direct-mutation-state";
|
|
|
1231
1216
|
var RULE_FEATURES22 = [
|
|
1232
1217
|
"CHK"
|
|
1233
1218
|
];
|
|
1234
|
-
function getName2(node) {
|
|
1235
|
-
if (AST11__namespace.isTsOnlyExpression(node)) {
|
|
1236
|
-
return getName2(node.expression);
|
|
1237
|
-
}
|
|
1238
|
-
if (node.type === types.AST_NODE_TYPES.Identifier || node.type === types.AST_NODE_TYPES.PrivateIdentifier) {
|
|
1239
|
-
return node.name;
|
|
1240
|
-
}
|
|
1241
|
-
if (node.type === types.AST_NODE_TYPES.Literal) {
|
|
1242
|
-
return node.value?.toString();
|
|
1243
|
-
}
|
|
1244
|
-
if (node.type === types.AST_NODE_TYPES.TemplateLiteral && node.expressions.length === 0) {
|
|
1245
|
-
return node.quasis[0]?.value.raw;
|
|
1246
|
-
}
|
|
1247
|
-
return eff._;
|
|
1248
|
-
}
|
|
1249
|
-
function isAssignmentToThisState(node) {
|
|
1250
|
-
const { left } = node;
|
|
1251
|
-
return left.type === types.AST_NODE_TYPES.MemberExpression && AST11__namespace.isThisExpression(left.object) && getName2(left.property) === "state";
|
|
1252
|
-
}
|
|
1253
1219
|
function isConstructorFunction(node) {
|
|
1254
|
-
return
|
|
1220
|
+
return AST12__namespace.isOneOf([types.AST_NODE_TYPES.FunctionDeclaration, types.AST_NODE_TYPES.FunctionExpression])(node) && AST12__namespace.isMethodOrProperty(node.parent) && node.parent.key.type === types.AST_NODE_TYPES.Identifier && node.parent.key.name === "constructor";
|
|
1255
1221
|
}
|
|
1256
1222
|
var no_direct_mutation_state_default = createRule({
|
|
1257
1223
|
meta: {
|
|
@@ -1269,18 +1235,18 @@ var no_direct_mutation_state_default = createRule({
|
|
|
1269
1235
|
create(context) {
|
|
1270
1236
|
return {
|
|
1271
1237
|
AssignmentExpression(node) {
|
|
1272
|
-
if (!isAssignmentToThisState(node)) {
|
|
1238
|
+
if (!core.isAssignmentToThisState(node)) {
|
|
1273
1239
|
return;
|
|
1274
1240
|
}
|
|
1275
|
-
const parentClass =
|
|
1241
|
+
const parentClass = AST12__namespace.findParentNode(
|
|
1276
1242
|
node,
|
|
1277
|
-
|
|
1243
|
+
AST12__namespace.isOneOf([
|
|
1278
1244
|
types.AST_NODE_TYPES.ClassDeclaration,
|
|
1279
1245
|
types.AST_NODE_TYPES.ClassExpression
|
|
1280
1246
|
])
|
|
1281
1247
|
);
|
|
1282
1248
|
if (parentClass == null) return;
|
|
1283
|
-
if (core.isClassComponent(parentClass) && context.sourceCode.getScope(node).block !==
|
|
1249
|
+
if (core.isClassComponent(parentClass) && context.sourceCode.getScope(node).block !== AST12__namespace.findParentNode(node, isConstructorFunction)) {
|
|
1284
1250
|
context.report({
|
|
1285
1251
|
messageId: "noDirectMutationState",
|
|
1286
1252
|
node
|
|
@@ -1362,7 +1328,7 @@ var no_duplicate_key_default = createRule({
|
|
|
1362
1328
|
if (aValue == null || bValue == null) {
|
|
1363
1329
|
return false;
|
|
1364
1330
|
}
|
|
1365
|
-
return
|
|
1331
|
+
return AST12__namespace.isNodeEqual(aValue, bValue);
|
|
1366
1332
|
}
|
|
1367
1333
|
return {
|
|
1368
1334
|
"JSXAttribute[name.name='key']"(node) {
|
|
@@ -1381,12 +1347,12 @@ var no_duplicate_key_default = createRule({
|
|
|
1381
1347
|
break;
|
|
1382
1348
|
}
|
|
1383
1349
|
default: {
|
|
1384
|
-
const call =
|
|
1385
|
-
const iter =
|
|
1386
|
-
if (!
|
|
1350
|
+
const call = AST12__namespace.findParentNode(jsxElement, AST12__namespace.isMapCallLoose);
|
|
1351
|
+
const iter = AST12__namespace.findParentNode(jsxElement, (n) => n === call || AST12__namespace.isFunction(n));
|
|
1352
|
+
if (!AST12__namespace.isFunction(iter)) return;
|
|
1387
1353
|
const arg0 = call?.arguments[0];
|
|
1388
1354
|
if (call == null || arg0 == null) return;
|
|
1389
|
-
if (
|
|
1355
|
+
if (AST12__namespace.getEcmaExpression(arg0) !== iter) {
|
|
1390
1356
|
return;
|
|
1391
1357
|
}
|
|
1392
1358
|
keyedEntries.set(call, {
|
|
@@ -1462,7 +1428,7 @@ var no_forward_ref_default = createRule({
|
|
|
1462
1428
|
function getFix(context, node) {
|
|
1463
1429
|
return (fixer) => {
|
|
1464
1430
|
const [componentNode] = node.arguments;
|
|
1465
|
-
if (componentNode == null || !
|
|
1431
|
+
if (componentNode == null || !AST12__namespace.isFunction(componentNode)) {
|
|
1466
1432
|
return [];
|
|
1467
1433
|
}
|
|
1468
1434
|
return [
|
|
@@ -1675,7 +1641,7 @@ var no_leaked_conditional_rendering_default = createRule({
|
|
|
1675
1641
|
const services = utils.ESLintUtils.getParserServices(context, false);
|
|
1676
1642
|
function getReportDescriptor(node) {
|
|
1677
1643
|
if (node == null) return eff._;
|
|
1678
|
-
return tsPattern.match(node).when(
|
|
1644
|
+
return tsPattern.match(node).when(AST12__namespace.isJSX, () => eff._).with({ type: types.AST_NODE_TYPES.LogicalExpression, operator: "&&" }, ({ left, right }) => {
|
|
1679
1645
|
const isLeftUnaryNot = left.type === types.AST_NODE_TYPES.UnaryExpression && left.operator === "!";
|
|
1680
1646
|
if (isLeftUnaryNot) {
|
|
1681
1647
|
return getReportDescriptor(right);
|
|
@@ -1758,7 +1724,7 @@ var no_missing_component_display_name_default = createRule({
|
|
|
1758
1724
|
const components = ctx.getAllComponents(node);
|
|
1759
1725
|
for (const { node: node2, displayName, flag } of components.values()) {
|
|
1760
1726
|
const isMemoOrForwardRef = (flag & (core.ERComponentFlag.ForwardRef | core.ERComponentFlag.Memo)) > 0n;
|
|
1761
|
-
if (
|
|
1727
|
+
if (AST12__namespace.getFunctionIdentifier(node2) != null) {
|
|
1762
1728
|
continue;
|
|
1763
1729
|
}
|
|
1764
1730
|
if (!isMemoOrForwardRef) {
|
|
@@ -1896,7 +1862,7 @@ var no_missing_key_default = createRule({
|
|
|
1896
1862
|
}
|
|
1897
1863
|
function checkBlockStatement(node) {
|
|
1898
1864
|
const descriptors = [];
|
|
1899
|
-
for (const statement of
|
|
1865
|
+
for (const statement of AST12__namespace.getNestedReturnStatements(node)) {
|
|
1900
1866
|
if (statement.argument == null) {
|
|
1901
1867
|
continue;
|
|
1902
1868
|
}
|
|
@@ -1912,7 +1878,7 @@ var no_missing_key_default = createRule({
|
|
|
1912
1878
|
if (state.isWithinChildrenToArray) {
|
|
1913
1879
|
return;
|
|
1914
1880
|
}
|
|
1915
|
-
const elements = node.elements.filter(
|
|
1881
|
+
const elements = node.elements.filter(AST12__namespace.is(types.AST_NODE_TYPES.JSXElement));
|
|
1916
1882
|
if (elements.length === 0) {
|
|
1917
1883
|
return;
|
|
1918
1884
|
}
|
|
@@ -1931,7 +1897,7 @@ var no_missing_key_default = createRule({
|
|
|
1931
1897
|
if (state.isWithinChildrenToArray) {
|
|
1932
1898
|
return;
|
|
1933
1899
|
}
|
|
1934
|
-
const isMapCallLike =
|
|
1900
|
+
const isMapCallLike = AST12__namespace.isMapCallLoose(node);
|
|
1935
1901
|
if (!isMapCallLike && !isArrayFromCall(node)) {
|
|
1936
1902
|
return;
|
|
1937
1903
|
}
|
|
@@ -2007,16 +1973,16 @@ var no_nested_components_default = createRule({
|
|
|
2007
1973
|
...collectorLegacy.ctx.getAllComponents(node).values()
|
|
2008
1974
|
];
|
|
2009
1975
|
const isFunctionComponent = (node2) => {
|
|
2010
|
-
return
|
|
1976
|
+
return AST12__namespace.isFunction(node2) && functionComponents.some((component) => component.node === node2);
|
|
2011
1977
|
};
|
|
2012
1978
|
const isClassComponent11 = (node2) => {
|
|
2013
|
-
return
|
|
1979
|
+
return AST12__namespace.isClass(node2) && classComponents.some((component) => component.node === node2);
|
|
2014
1980
|
};
|
|
2015
1981
|
for (const { name: name5, node: component } of functionComponents) {
|
|
2016
1982
|
if (core.isDirectValueOfRenderPropertyLoose(component)) {
|
|
2017
1983
|
continue;
|
|
2018
1984
|
}
|
|
2019
|
-
if (name5
|
|
1985
|
+
if (name5 == null) {
|
|
2020
1986
|
continue;
|
|
2021
1987
|
}
|
|
2022
1988
|
const isInsideProperty = component.parent.type === types.AST_NODE_TYPES.Property;
|
|
@@ -2043,7 +2009,7 @@ var no_nested_components_default = createRule({
|
|
|
2043
2009
|
});
|
|
2044
2010
|
continue;
|
|
2045
2011
|
}
|
|
2046
|
-
const parentComponent =
|
|
2012
|
+
const parentComponent = AST12__namespace.findParentNode(component, isFunctionComponent);
|
|
2047
2013
|
const isParentComponentNotDirectValueOfRenderProperty = parentComponent != null && !core.isDirectValueOfRenderPropertyLoose(parentComponent);
|
|
2048
2014
|
if (isParentComponentNotDirectValueOfRenderProperty) {
|
|
2049
2015
|
context.report({
|
|
@@ -2066,7 +2032,7 @@ var no_nested_components_default = createRule({
|
|
|
2066
2032
|
}
|
|
2067
2033
|
}
|
|
2068
2034
|
for (const { name: name5 = "unknown", node: component } of classComponents) {
|
|
2069
|
-
if (
|
|
2035
|
+
if (AST12__namespace.findParentNode(component, (n) => isClassComponent11(n) || isFunctionComponent(n)) == null) {
|
|
2070
2036
|
continue;
|
|
2071
2037
|
}
|
|
2072
2038
|
context.report({
|
|
@@ -2083,9 +2049,9 @@ var no_nested_components_default = createRule({
|
|
|
2083
2049
|
defaultOptions: []
|
|
2084
2050
|
});
|
|
2085
2051
|
function isInsideCreateElementProps(context, node) {
|
|
2086
|
-
const call =
|
|
2052
|
+
const call = AST12__namespace.findParentNode(node, core.isCreateElementCall(context));
|
|
2087
2053
|
if (call == null) return false;
|
|
2088
|
-
const prop =
|
|
2054
|
+
const prop = AST12__namespace.findParentNode(node, AST12__namespace.is(types.AST_NODE_TYPES.ObjectExpression));
|
|
2089
2055
|
if (prop == null) return false;
|
|
2090
2056
|
return prop === call.arguments[1];
|
|
2091
2057
|
}
|
|
@@ -2127,7 +2093,7 @@ var no_prop_types_default = createRule({
|
|
|
2127
2093
|
}
|
|
2128
2094
|
const variable = VAR__namespace.findVariable(object.name, context.sourceCode.getScope(node));
|
|
2129
2095
|
const variableNode = VAR__namespace.getVariableInitNode(variable, 0);
|
|
2130
|
-
if (variableNode != null && (
|
|
2096
|
+
if (variableNode != null && (AST12__namespace.isFunction(variableNode) || core.isClassComponent(variableNode))) {
|
|
2131
2097
|
context.report({ messageId: "noPropTypes", node: property });
|
|
2132
2098
|
}
|
|
2133
2099
|
},
|
|
@@ -2149,7 +2115,7 @@ var RULE_FEATURES33 = [
|
|
|
2149
2115
|
"CHK"
|
|
2150
2116
|
];
|
|
2151
2117
|
function isShouldComponentUpdate(node) {
|
|
2152
|
-
return
|
|
2118
|
+
return AST12__namespace.isMethodOrProperty(node) && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "shouldComponentUpdate";
|
|
2153
2119
|
}
|
|
2154
2120
|
var no_redundant_should_component_update_default = createRule({
|
|
2155
2121
|
meta: {
|
|
@@ -2200,7 +2166,7 @@ var RULE_FEATURES34 = [
|
|
|
2200
2166
|
"CHK"
|
|
2201
2167
|
];
|
|
2202
2168
|
function isComponentDidMount(node) {
|
|
2203
|
-
return
|
|
2169
|
+
return AST12__namespace.isMethodOrProperty(node) && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentDidMount";
|
|
2204
2170
|
}
|
|
2205
2171
|
var no_set_state_in_component_did_mount_default = createRule({
|
|
2206
2172
|
meta: {
|
|
@@ -2224,8 +2190,8 @@ var no_set_state_in_component_did_mount_default = createRule({
|
|
|
2224
2190
|
if (!core.isThisSetState(node)) {
|
|
2225
2191
|
return;
|
|
2226
2192
|
}
|
|
2227
|
-
const clazz =
|
|
2228
|
-
const method =
|
|
2193
|
+
const clazz = AST12__namespace.findParentNode(node, core.isClassComponent);
|
|
2194
|
+
const method = AST12__namespace.findParentNode(node, (n) => n === clazz || isComponentDidMount(n));
|
|
2229
2195
|
if (clazz == null || method == null || method === clazz) return;
|
|
2230
2196
|
const methodScope = context.sourceCode.getScope(method);
|
|
2231
2197
|
const upperScope = context.sourceCode.getScope(node).upper;
|
|
@@ -2245,7 +2211,7 @@ var RULE_FEATURES35 = [
|
|
|
2245
2211
|
"CHK"
|
|
2246
2212
|
];
|
|
2247
2213
|
function isComponentDidUpdate(node) {
|
|
2248
|
-
return
|
|
2214
|
+
return AST12__namespace.isMethodOrProperty(node) && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentDidUpdate";
|
|
2249
2215
|
}
|
|
2250
2216
|
var no_set_state_in_component_did_update_default = createRule({
|
|
2251
2217
|
meta: {
|
|
@@ -2269,8 +2235,8 @@ var no_set_state_in_component_did_update_default = createRule({
|
|
|
2269
2235
|
if (!core.isThisSetState(node)) {
|
|
2270
2236
|
return;
|
|
2271
2237
|
}
|
|
2272
|
-
const clazz =
|
|
2273
|
-
const method =
|
|
2238
|
+
const clazz = AST12__namespace.findParentNode(node, core.isClassComponent);
|
|
2239
|
+
const method = AST12__namespace.findParentNode(node, (n) => n === clazz || isComponentDidUpdate(n));
|
|
2274
2240
|
if (clazz == null || method == null || method === clazz) return;
|
|
2275
2241
|
const methodScope = context.sourceCode.getScope(method);
|
|
2276
2242
|
const upperScope = context.sourceCode.getScope(node).upper;
|
|
@@ -2290,7 +2256,7 @@ var RULE_FEATURES36 = [
|
|
|
2290
2256
|
"CHK"
|
|
2291
2257
|
];
|
|
2292
2258
|
function isComponentWillUpdate3(node) {
|
|
2293
|
-
return
|
|
2259
|
+
return AST12__namespace.isMethodOrProperty(node) && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentWillUpdate";
|
|
2294
2260
|
}
|
|
2295
2261
|
var no_set_state_in_component_will_update_default = createRule({
|
|
2296
2262
|
meta: {
|
|
@@ -2314,8 +2280,8 @@ var no_set_state_in_component_will_update_default = createRule({
|
|
|
2314
2280
|
if (!core.isThisSetState(node)) {
|
|
2315
2281
|
return;
|
|
2316
2282
|
}
|
|
2317
|
-
const clazz =
|
|
2318
|
-
const method =
|
|
2283
|
+
const clazz = AST12__namespace.findParentNode(node, core.isClassComponent);
|
|
2284
|
+
const method = AST12__namespace.findParentNode(node, (n) => n === clazz || isComponentWillUpdate3(n));
|
|
2319
2285
|
if (clazz == null || method == null || method === clazz) return;
|
|
2320
2286
|
const methodScope = context.sourceCode.getScope(method);
|
|
2321
2287
|
const upperScope = context.sourceCode.getScope(node).upper;
|
|
@@ -2381,7 +2347,7 @@ var RULE_FEATURES38 = [
|
|
|
2381
2347
|
"CHK"
|
|
2382
2348
|
];
|
|
2383
2349
|
function isUnsafeComponentWillMount(node) {
|
|
2384
|
-
return
|
|
2350
|
+
return AST12__namespace.isMethodOrProperty(node) && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "UNSAFE_componentWillMount";
|
|
2385
2351
|
}
|
|
2386
2352
|
var no_unsafe_component_will_mount_default = createRule({
|
|
2387
2353
|
meta: {
|
|
@@ -2426,7 +2392,7 @@ var RULE_FEATURES39 = [
|
|
|
2426
2392
|
"CHK"
|
|
2427
2393
|
];
|
|
2428
2394
|
function isUnsafeComponentWillReceiveProps(node) {
|
|
2429
|
-
return
|
|
2395
|
+
return AST12__namespace.isMethodOrProperty(node) && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "UNSAFE_componentWillReceiveProps";
|
|
2430
2396
|
}
|
|
2431
2397
|
var no_unsafe_component_will_receive_props_default = createRule({
|
|
2432
2398
|
meta: {
|
|
@@ -2471,7 +2437,7 @@ var RULE_FEATURES40 = [
|
|
|
2471
2437
|
"CHK"
|
|
2472
2438
|
];
|
|
2473
2439
|
function isUnsafeComponentWillUpdate(node) {
|
|
2474
|
-
return
|
|
2440
|
+
return AST12__namespace.isMethodOrProperty(node) && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "UNSAFE_componentWillUpdate";
|
|
2475
2441
|
}
|
|
2476
2442
|
var no_unsafe_component_will_update_default = createRule({
|
|
2477
2443
|
meta: {
|
|
@@ -2567,7 +2533,7 @@ var no_unstable_context_value_default = createRule({
|
|
|
2567
2533
|
messageId: "unstableContextValue",
|
|
2568
2534
|
node: constructionNode,
|
|
2569
2535
|
data: {
|
|
2570
|
-
type:
|
|
2536
|
+
type: AST12__namespace.toReadableNodeType(constructionNode),
|
|
2571
2537
|
suggestion
|
|
2572
2538
|
}
|
|
2573
2539
|
});
|
|
@@ -2636,7 +2602,7 @@ var no_unstable_default_props_default = createRule({
|
|
|
2636
2602
|
if (core.isReactHookCall(construction.node)) {
|
|
2637
2603
|
continue;
|
|
2638
2604
|
}
|
|
2639
|
-
const forbiddenType =
|
|
2605
|
+
const forbiddenType = AST12__namespace.toReadableNodeType(right);
|
|
2640
2606
|
context.report({
|
|
2641
2607
|
messageId: "noUnstableDefaultProps",
|
|
2642
2608
|
node: right,
|
|
@@ -2684,21 +2650,6 @@ var LIFECYCLE_METHODS = /* @__PURE__ */ new Set([
|
|
|
2684
2650
|
function isKeyLiteral2(node, key) {
|
|
2685
2651
|
return tsPattern.match(key).with({ type: types.AST_NODE_TYPES.Literal }, eff.constTrue).with({ type: types.AST_NODE_TYPES.TemplateLiteral, expressions: [] }, eff.constTrue).with({ type: types.AST_NODE_TYPES.Identifier }, () => !node.computed).otherwise(eff.constFalse);
|
|
2686
2652
|
}
|
|
2687
|
-
function getName3(node) {
|
|
2688
|
-
if (AST11__namespace.isTsOnlyExpression(node)) {
|
|
2689
|
-
return getName3(node.expression);
|
|
2690
|
-
}
|
|
2691
|
-
if (node.type === types.AST_NODE_TYPES.Identifier || node.type === types.AST_NODE_TYPES.PrivateIdentifier) {
|
|
2692
|
-
return node.name;
|
|
2693
|
-
}
|
|
2694
|
-
if (node.type === types.AST_NODE_TYPES.Literal) {
|
|
2695
|
-
return node.value?.toString();
|
|
2696
|
-
}
|
|
2697
|
-
if (node.type === types.AST_NODE_TYPES.TemplateLiteral && node.expressions.length === 0) {
|
|
2698
|
-
return node.quasis[0]?.value.raw;
|
|
2699
|
-
}
|
|
2700
|
-
return eff._;
|
|
2701
|
-
}
|
|
2702
2653
|
var no_unused_class_component_members_default = createRule({
|
|
2703
2654
|
meta: {
|
|
2704
2655
|
type: "problem",
|
|
@@ -2730,14 +2681,14 @@ var no_unused_class_component_members_default = createRule({
|
|
|
2730
2681
|
if (currentClass == null || !core.isClassComponent(currentClass)) {
|
|
2731
2682
|
return;
|
|
2732
2683
|
}
|
|
2733
|
-
const className =
|
|
2684
|
+
const className = AST12__namespace.getClassIdentifier(currentClass)?.name;
|
|
2734
2685
|
const defs = propertyDefs.get(currentClass);
|
|
2735
2686
|
const usages = propertyUsages.get(currentClass);
|
|
2736
2687
|
if (defs == null) {
|
|
2737
2688
|
return;
|
|
2738
2689
|
}
|
|
2739
2690
|
for (const def of defs) {
|
|
2740
|
-
const methodName =
|
|
2691
|
+
const methodName = AST12__namespace.getPropertyName(def);
|
|
2741
2692
|
if (methodName == null) {
|
|
2742
2693
|
continue;
|
|
2743
2694
|
}
|
|
@@ -2784,14 +2735,14 @@ var no_unused_class_component_members_default = createRule({
|
|
|
2784
2735
|
if (!core.isClassComponent(currentClass) || currentMethod.static) {
|
|
2785
2736
|
return;
|
|
2786
2737
|
}
|
|
2787
|
-
if (!
|
|
2738
|
+
if (!AST12__namespace.isThisExpression(node.object) || !isKeyLiteral2(node, node.property)) {
|
|
2788
2739
|
return;
|
|
2789
2740
|
}
|
|
2790
2741
|
if (node.parent.type === types.AST_NODE_TYPES.AssignmentExpression && node.parent.left === node) {
|
|
2791
2742
|
propertyDefs.get(currentClass)?.add(node.property);
|
|
2792
2743
|
return;
|
|
2793
2744
|
}
|
|
2794
|
-
const propertyName =
|
|
2745
|
+
const propertyName = AST12__namespace.getPropertyName(node.property);
|
|
2795
2746
|
if (propertyName != null) {
|
|
2796
2747
|
propertyUsages.get(currentClass)?.add(propertyName);
|
|
2797
2748
|
}
|
|
@@ -2809,10 +2760,10 @@ var no_unused_class_component_members_default = createRule({
|
|
|
2809
2760
|
if (!core.isClassComponent(currentClass) || currentMethod.static) {
|
|
2810
2761
|
return;
|
|
2811
2762
|
}
|
|
2812
|
-
if (node.init != null &&
|
|
2763
|
+
if (node.init != null && AST12__namespace.isThisExpression(node.init) && node.id.type === types.AST_NODE_TYPES.ObjectPattern) {
|
|
2813
2764
|
for (const prop of node.id.properties) {
|
|
2814
2765
|
if (prop.type === types.AST_NODE_TYPES.Property && isKeyLiteral2(prop, prop.key)) {
|
|
2815
|
-
const keyName =
|
|
2766
|
+
const keyName = AST12__namespace.getPropertyName(prop.key);
|
|
2816
2767
|
if (keyName != null) {
|
|
2817
2768
|
propertyUsages.get(currentClass)?.add(keyName);
|
|
2818
2769
|
}
|
|
@@ -2831,25 +2782,6 @@ var RULE_FEATURES44 = [
|
|
|
2831
2782
|
function isKeyLiteral3(node, key) {
|
|
2832
2783
|
return tsPattern.match(key).with({ type: types.AST_NODE_TYPES.Literal }, eff.constTrue).with({ type: types.AST_NODE_TYPES.TemplateLiteral, expressions: [] }, eff.constTrue).with({ type: types.AST_NODE_TYPES.Identifier }, () => !node.computed).otherwise(eff.constFalse);
|
|
2833
2784
|
}
|
|
2834
|
-
function getName4(node) {
|
|
2835
|
-
if (AST11__namespace.isTsOnlyExpression(node)) {
|
|
2836
|
-
return getName4(node.expression);
|
|
2837
|
-
}
|
|
2838
|
-
if (node.type === types.AST_NODE_TYPES.Identifier || node.type === types.AST_NODE_TYPES.PrivateIdentifier) {
|
|
2839
|
-
return node.name;
|
|
2840
|
-
}
|
|
2841
|
-
if (node.type === types.AST_NODE_TYPES.Literal) {
|
|
2842
|
-
return String(node.value);
|
|
2843
|
-
}
|
|
2844
|
-
if (node.type === types.AST_NODE_TYPES.TemplateLiteral && node.expressions.length === 0) {
|
|
2845
|
-
return node.quasis[0]?.value.raw;
|
|
2846
|
-
}
|
|
2847
|
-
return eff._;
|
|
2848
|
-
}
|
|
2849
|
-
function isAssignmentToThisState2(node) {
|
|
2850
|
-
const { left } = node;
|
|
2851
|
-
return left.type === types.AST_NODE_TYPES.MemberExpression && AST11__namespace.isThisExpression(left.object) && getName4(left.property) === "state";
|
|
2852
|
-
}
|
|
2853
2785
|
var no_unused_state_default = createRule({
|
|
2854
2786
|
meta: {
|
|
2855
2787
|
type: "problem",
|
|
@@ -2876,7 +2808,7 @@ var no_unused_state_default = createRule({
|
|
|
2876
2808
|
if (currentClass == null || !core.isClassComponent(currentClass)) {
|
|
2877
2809
|
return;
|
|
2878
2810
|
}
|
|
2879
|
-
const className =
|
|
2811
|
+
const className = AST12__namespace.getClassIdentifier(currentClass)?.name;
|
|
2880
2812
|
const { node: defNode, isUsed = false } = stateDefs.get(currentClass) ?? {};
|
|
2881
2813
|
if (defNode == null || isUsed) {
|
|
2882
2814
|
return;
|
|
@@ -2902,7 +2834,7 @@ var no_unused_state_default = createRule({
|
|
|
2902
2834
|
}
|
|
2903
2835
|
return;
|
|
2904
2836
|
}
|
|
2905
|
-
if (
|
|
2837
|
+
if (AST12__namespace.getPropertyName(node.key) === "state") {
|
|
2906
2838
|
stateDefs.set(currentClass, { node: node.key, isUsed: false });
|
|
2907
2839
|
}
|
|
2908
2840
|
}
|
|
@@ -2917,7 +2849,7 @@ var no_unused_state_default = createRule({
|
|
|
2917
2849
|
}
|
|
2918
2850
|
return {
|
|
2919
2851
|
AssignmentExpression(node) {
|
|
2920
|
-
if (!
|
|
2852
|
+
if (!core.isAssignmentToThisState(node)) {
|
|
2921
2853
|
return;
|
|
2922
2854
|
}
|
|
2923
2855
|
const currentClass = classEntries.at(-1);
|
|
@@ -2936,10 +2868,10 @@ var no_unused_state_default = createRule({
|
|
|
2936
2868
|
ClassExpression: classEnter,
|
|
2937
2869
|
"ClassExpression:exit": classExit,
|
|
2938
2870
|
MemberExpression(node) {
|
|
2939
|
-
if (!
|
|
2871
|
+
if (!AST12__namespace.isThisExpression(node.object)) {
|
|
2940
2872
|
return;
|
|
2941
2873
|
}
|
|
2942
|
-
if (
|
|
2874
|
+
if (AST12__namespace.getPropertyName(node.property) !== "state") {
|
|
2943
2875
|
return;
|
|
2944
2876
|
}
|
|
2945
2877
|
const currentClass = classEntries.at(-1);
|
|
@@ -2980,12 +2912,12 @@ var no_unused_state_default = createRule({
|
|
|
2980
2912
|
if (!currentClass.body.body.includes(currentMethod)) {
|
|
2981
2913
|
return;
|
|
2982
2914
|
}
|
|
2983
|
-
if (node.init == null || !
|
|
2915
|
+
if (node.init == null || !AST12__namespace.isThisExpression(node.init) || node.id.type !== types.AST_NODE_TYPES.ObjectPattern) {
|
|
2984
2916
|
return;
|
|
2985
2917
|
}
|
|
2986
2918
|
const hasState = node.id.properties.some((prop) => {
|
|
2987
2919
|
if (prop.type === types.AST_NODE_TYPES.Property && isKeyLiteral3(prop, prop.key)) {
|
|
2988
|
-
return
|
|
2920
|
+
return AST12__namespace.getPropertyName(prop.key) === "state";
|
|
2989
2921
|
}
|
|
2990
2922
|
return false;
|
|
2991
2923
|
});
|
|
@@ -3116,7 +3048,7 @@ function checkAndReport(context, node, allowExpressions) {
|
|
|
3116
3048
|
return null;
|
|
3117
3049
|
}
|
|
3118
3050
|
if (node.children.some(
|
|
3119
|
-
(child) => JSX8__namespace.isLiteral(child) && !JSX8__namespace.isWhiteSpace(child) ||
|
|
3051
|
+
(child) => JSX8__namespace.isLiteral(child) && !JSX8__namespace.isWhiteSpace(child) || AST12__namespace.is(types.AST_NODE_TYPES.JSXExpressionContainer)(child)
|
|
3120
3052
|
)) {
|
|
3121
3053
|
return null;
|
|
3122
3054
|
}
|
|
@@ -3154,7 +3086,7 @@ function checkAndReport(context, node, allowExpressions) {
|
|
|
3154
3086
|
});
|
|
3155
3087
|
return;
|
|
3156
3088
|
}
|
|
3157
|
-
const isChildElement =
|
|
3089
|
+
const isChildElement = AST12__namespace.isOneOf([types.AST_NODE_TYPES.JSXElement, types.AST_NODE_TYPES.JSXFragment])(node.parent);
|
|
3158
3090
|
switch (true) {
|
|
3159
3091
|
// <Foo content={<>ee eeee eeee ...</>} />
|
|
3160
3092
|
case (allowExpressions && !isChildElement && node.children.length === 1 && JSX8__namespace.isLiteral(node.children.at(0))): {
|
|
@@ -3275,10 +3207,10 @@ var prefer_destructuring_assignment_default = createRule({
|
|
|
3275
3207
|
...ctx.getAllComponents(node).values()
|
|
3276
3208
|
];
|
|
3277
3209
|
function isFunctionComponent(block) {
|
|
3278
|
-
if (!
|
|
3210
|
+
if (!AST12__namespace.isFunction(block)) {
|
|
3279
3211
|
return false;
|
|
3280
3212
|
}
|
|
3281
|
-
const id =
|
|
3213
|
+
const id = AST12__namespace.getFunctionIdentifier(block);
|
|
3282
3214
|
return id != null && core.isComponentName(id.name) && components.some((component) => component.node === block);
|
|
3283
3215
|
}
|
|
3284
3216
|
for (const [initialScope, memberExpression] of memberExpressionWithNames) {
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createRuleForPlugin, getSettingsFromContext, unsafeDecodeSettings, DEFAULT_ESLINT_REACT_SETTINGS } from '@eslint-react/shared';
|
|
2
2
|
import * as JSX8 from '@eslint-react/jsx';
|
|
3
|
-
import * as
|
|
4
|
-
import { isForwardRefCall, isClassComponent, isThisSetState, isChildrenCount, isChildrenForEach, isChildrenMap, isChildrenOnly, isChildrenToArray, useComponentCollectorLegacy, isComponentDidCatch, isGetDerivedStateFromError, isCloneElementCall, isCreateRefCall, isComponentName, useComponentCollector, DEFAULT_COMPONENT_HINT, ERComponentFlag, getInstanceId, isInstanceIdEqual, DISPLAY_NAME_ASSIGNMENT_SELECTOR, isCreateContextCall, isChildrenToArrayCall, ERComponentHint, isDirectValueOfRenderPropertyLoose, isDeclaredInRenderPropLoose, isInsideRenderMethod, isCreateElementCall, isReactHookCall, isReactHookCallWithNameAlias, isGetDerivedStateFromProps, isInitializedFromReact } from '@eslint-react/core';
|
|
3
|
+
import * as AST12 from '@eslint-react/ast';
|
|
4
|
+
import { isForwardRefCall, isClassComponent, isThisSetState, isChildrenCount, isChildrenForEach, isChildrenMap, isChildrenOnly, isChildrenToArray, useComponentCollectorLegacy, isComponentDidCatch, isGetDerivedStateFromError, isCloneElementCall, isCreateRefCall, isComponentName, isAssignmentToThisState, useComponentCollector, DEFAULT_COMPONENT_HINT, ERComponentFlag, getInstanceId, isInstanceIdEqual, DISPLAY_NAME_ASSIGNMENT_SELECTOR, isCreateContextCall, isChildrenToArrayCall, ERComponentHint, isDirectValueOfRenderPropertyLoose, isDeclaredInRenderPropLoose, isInsideRenderMethod, isCreateElementCall, isReactHookCall, isReactHookCallWithNameAlias, isGetDerivedStateFromProps, isInitializedFromReact } from '@eslint-react/core';
|
|
5
5
|
import { _, getOrUpdate, constTrue, constFalse, identity } from '@eslint-react/eff';
|
|
6
6
|
import { AST_NODE_TYPES } from '@typescript-eslint/types';
|
|
7
7
|
import { isMatching, match, P } from 'ts-pattern';
|
|
@@ -109,7 +109,7 @@ var settings3 = {
|
|
|
109
109
|
|
|
110
110
|
// package.json
|
|
111
111
|
var name4 = "eslint-plugin-react-x";
|
|
112
|
-
var version = "1.30.
|
|
112
|
+
var version = "1.30.3-beta.1";
|
|
113
113
|
var createRule = createRuleForPlugin("x");
|
|
114
114
|
|
|
115
115
|
// src/rules/avoid-shorthand-boolean.ts
|
|
@@ -204,7 +204,7 @@ var ensure_forward_ref_using_ref_default = createRule({
|
|
|
204
204
|
return;
|
|
205
205
|
}
|
|
206
206
|
const [component] = node.arguments;
|
|
207
|
-
if (component == null || !
|
|
207
|
+
if (component == null || !AST12.isFunction(component)) {
|
|
208
208
|
return;
|
|
209
209
|
}
|
|
210
210
|
const ref = component.params[1];
|
|
@@ -227,21 +227,6 @@ var RULE_FEATURES4 = [
|
|
|
227
227
|
function isKeyLiteral(node, key) {
|
|
228
228
|
return match(key).with({ type: AST_NODE_TYPES.Literal }, constTrue).with({ type: AST_NODE_TYPES.TemplateLiteral, expressions: [] }, constTrue).with({ type: AST_NODE_TYPES.Identifier }, () => !node.computed).otherwise(constFalse);
|
|
229
229
|
}
|
|
230
|
-
function getName(node) {
|
|
231
|
-
if (AST11.isTsOnlyExpression(node)) {
|
|
232
|
-
return getName(node.expression);
|
|
233
|
-
}
|
|
234
|
-
if (node.type === AST_NODE_TYPES.Identifier || node.type === AST_NODE_TYPES.PrivateIdentifier) {
|
|
235
|
-
return node.name;
|
|
236
|
-
}
|
|
237
|
-
if (node.type === AST_NODE_TYPES.Literal) {
|
|
238
|
-
return String(node.value);
|
|
239
|
-
}
|
|
240
|
-
if (node.type === AST_NODE_TYPES.TemplateLiteral && node.expressions.length === 0) {
|
|
241
|
-
return node.quasis[0]?.value.raw;
|
|
242
|
-
}
|
|
243
|
-
return _;
|
|
244
|
-
}
|
|
245
230
|
var no_access_state_in_setstate_default = createRule({
|
|
246
231
|
meta: {
|
|
247
232
|
type: "problem",
|
|
@@ -288,7 +273,7 @@ var no_access_state_in_setstate_default = createRule({
|
|
|
288
273
|
classEntries.pop();
|
|
289
274
|
},
|
|
290
275
|
MemberExpression(node) {
|
|
291
|
-
if (!
|
|
276
|
+
if (!AST12.isThisExpression(node.object)) {
|
|
292
277
|
return;
|
|
293
278
|
}
|
|
294
279
|
const [currClass, isComponent = false] = classEntries.at(-1) ?? [];
|
|
@@ -303,7 +288,7 @@ var no_access_state_in_setstate_default = createRule({
|
|
|
303
288
|
if (setState == null || hasThisState) {
|
|
304
289
|
return;
|
|
305
290
|
}
|
|
306
|
-
if (
|
|
291
|
+
if (AST12.getPropertyName(node.property) !== "state") {
|
|
307
292
|
return;
|
|
308
293
|
}
|
|
309
294
|
context.report({ messageId: "noAccessStateInSetstate", node });
|
|
@@ -333,11 +318,11 @@ var no_access_state_in_setstate_default = createRule({
|
|
|
333
318
|
if (setState == null || hasThisState) {
|
|
334
319
|
return;
|
|
335
320
|
}
|
|
336
|
-
if (node.init == null || !
|
|
321
|
+
if (node.init == null || !AST12.isThisExpression(node.init) || node.id.type !== AST_NODE_TYPES.ObjectPattern) {
|
|
337
322
|
return;
|
|
338
323
|
}
|
|
339
324
|
const hasState = node.id.properties.some(
|
|
340
|
-
(prop) => prop.type === AST_NODE_TYPES.Property && isKeyLiteral(prop, prop.key) &&
|
|
325
|
+
(prop) => prop.type === AST_NODE_TYPES.Property && isKeyLiteral(prop, prop.key) && AST12.getPropertyName(prop.key) === "state"
|
|
341
326
|
);
|
|
342
327
|
if (!hasState) {
|
|
343
328
|
return;
|
|
@@ -404,7 +389,7 @@ function getMapIndexParamName(context, node) {
|
|
|
404
389
|
if (callbackArg == null) {
|
|
405
390
|
return _;
|
|
406
391
|
}
|
|
407
|
-
if (!
|
|
392
|
+
if (!AST12.isOneOf([AST_NODE_TYPES.ArrowFunctionExpression, AST_NODE_TYPES.FunctionExpression])(callbackArg)) {
|
|
408
393
|
return _;
|
|
409
394
|
}
|
|
410
395
|
const { params } = callbackArg;
|
|
@@ -833,14 +818,14 @@ var no_comment_textnodes_default = createRule({
|
|
|
833
818
|
name: RULE_NAME14,
|
|
834
819
|
create(context) {
|
|
835
820
|
function hasCommentLike(node) {
|
|
836
|
-
if (
|
|
821
|
+
if (AST12.isOneOf([AST_NODE_TYPES.JSXAttribute, AST_NODE_TYPES.JSXExpressionContainer])(node.parent)) {
|
|
837
822
|
return false;
|
|
838
823
|
}
|
|
839
824
|
const rawValue = context.sourceCode.getText(node);
|
|
840
825
|
return /^\s*\/(?:\/|\*)/mu.test(rawValue);
|
|
841
826
|
}
|
|
842
827
|
const visitorFunction = (node) => {
|
|
843
|
-
if (!
|
|
828
|
+
if (!AST12.isOneOf([AST_NODE_TYPES.JSXElement, AST_NODE_TYPES.JSXFragment])(node.parent)) {
|
|
844
829
|
return;
|
|
845
830
|
}
|
|
846
831
|
if (!hasCommentLike(node)) {
|
|
@@ -881,10 +866,10 @@ var no_complex_conditional_rendering_default = createRule({
|
|
|
881
866
|
create(context) {
|
|
882
867
|
const visitorFunction = (node) => {
|
|
883
868
|
const jsxExpContainer = node.parent?.parent;
|
|
884
|
-
if (!
|
|
869
|
+
if (!AST12.is(AST_NODE_TYPES.JSXExpressionContainer)(jsxExpContainer)) {
|
|
885
870
|
return;
|
|
886
871
|
}
|
|
887
|
-
if (!
|
|
872
|
+
if (!AST12.isOneOf([AST_NODE_TYPES.JSXElement, AST_NODE_TYPES.JSXFragment])(jsxExpContainer.parent)) {
|
|
888
873
|
return;
|
|
889
874
|
}
|
|
890
875
|
if (!jsxExpContainer.parent.children.includes(jsxExpContainer)) {
|
|
@@ -911,7 +896,7 @@ var RULE_FEATURES16 = [
|
|
|
911
896
|
"MOD"
|
|
912
897
|
];
|
|
913
898
|
function isComponentWillMount(node) {
|
|
914
|
-
return
|
|
899
|
+
return AST12.isMethodOrProperty(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentWillMount";
|
|
915
900
|
}
|
|
916
901
|
var no_component_will_mount_default = createRule({
|
|
917
902
|
meta: {
|
|
@@ -964,7 +949,7 @@ var RULE_FEATURES17 = [
|
|
|
964
949
|
"MOD"
|
|
965
950
|
];
|
|
966
951
|
function isComponentWillUpdate(node) {
|
|
967
|
-
return
|
|
952
|
+
return AST12.isMethodOrProperty(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentWillReceiveProps";
|
|
968
953
|
}
|
|
969
954
|
var no_component_will_receive_props_default = createRule({
|
|
970
955
|
meta: {
|
|
@@ -1017,7 +1002,7 @@ var RULE_FEATURES18 = [
|
|
|
1017
1002
|
"MOD"
|
|
1018
1003
|
];
|
|
1019
1004
|
function isComponentWillUpdate2(node) {
|
|
1020
|
-
return
|
|
1005
|
+
return AST12.isMethodOrProperty(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentWillUpdate";
|
|
1021
1006
|
}
|
|
1022
1007
|
var no_component_will_update_default = createRule({
|
|
1023
1008
|
meta: {
|
|
@@ -1137,7 +1122,7 @@ var no_create_ref_default = createRule({
|
|
|
1137
1122
|
create(context) {
|
|
1138
1123
|
return {
|
|
1139
1124
|
CallExpression(node) {
|
|
1140
|
-
if (isCreateRefCall(context, node) &&
|
|
1125
|
+
if (isCreateRefCall(context, node) && AST12.findParentNode(node, isClassComponent) == null) {
|
|
1141
1126
|
context.report({ messageId: "noCreateRef", node });
|
|
1142
1127
|
}
|
|
1143
1128
|
}
|
|
@@ -1184,7 +1169,7 @@ var no_default_props_default = createRule({
|
|
|
1184
1169
|
const variable = VAR.findVariable(object.name, context.sourceCode.getScope(node));
|
|
1185
1170
|
const variableNode = VAR.getVariableInitNode(variable, 0);
|
|
1186
1171
|
if (variableNode == null) return;
|
|
1187
|
-
if (!
|
|
1172
|
+
if (!AST12.isFunction(variableNode) && !isClassComponent(variableNode)) return;
|
|
1188
1173
|
context.report({ messageId: "noDefaultProps", node: property });
|
|
1189
1174
|
},
|
|
1190
1175
|
PropertyDefinition(node) {
|
|
@@ -1204,27 +1189,8 @@ var RULE_NAME22 = "no-direct-mutation-state";
|
|
|
1204
1189
|
var RULE_FEATURES22 = [
|
|
1205
1190
|
"CHK"
|
|
1206
1191
|
];
|
|
1207
|
-
function getName2(node) {
|
|
1208
|
-
if (AST11.isTsOnlyExpression(node)) {
|
|
1209
|
-
return getName2(node.expression);
|
|
1210
|
-
}
|
|
1211
|
-
if (node.type === AST_NODE_TYPES.Identifier || node.type === AST_NODE_TYPES.PrivateIdentifier) {
|
|
1212
|
-
return node.name;
|
|
1213
|
-
}
|
|
1214
|
-
if (node.type === AST_NODE_TYPES.Literal) {
|
|
1215
|
-
return node.value?.toString();
|
|
1216
|
-
}
|
|
1217
|
-
if (node.type === AST_NODE_TYPES.TemplateLiteral && node.expressions.length === 0) {
|
|
1218
|
-
return node.quasis[0]?.value.raw;
|
|
1219
|
-
}
|
|
1220
|
-
return _;
|
|
1221
|
-
}
|
|
1222
|
-
function isAssignmentToThisState(node) {
|
|
1223
|
-
const { left } = node;
|
|
1224
|
-
return left.type === AST_NODE_TYPES.MemberExpression && AST11.isThisExpression(left.object) && getName2(left.property) === "state";
|
|
1225
|
-
}
|
|
1226
1192
|
function isConstructorFunction(node) {
|
|
1227
|
-
return
|
|
1193
|
+
return AST12.isOneOf([AST_NODE_TYPES.FunctionDeclaration, AST_NODE_TYPES.FunctionExpression])(node) && AST12.isMethodOrProperty(node.parent) && node.parent.key.type === AST_NODE_TYPES.Identifier && node.parent.key.name === "constructor";
|
|
1228
1194
|
}
|
|
1229
1195
|
var no_direct_mutation_state_default = createRule({
|
|
1230
1196
|
meta: {
|
|
@@ -1245,15 +1211,15 @@ var no_direct_mutation_state_default = createRule({
|
|
|
1245
1211
|
if (!isAssignmentToThisState(node)) {
|
|
1246
1212
|
return;
|
|
1247
1213
|
}
|
|
1248
|
-
const parentClass =
|
|
1214
|
+
const parentClass = AST12.findParentNode(
|
|
1249
1215
|
node,
|
|
1250
|
-
|
|
1216
|
+
AST12.isOneOf([
|
|
1251
1217
|
AST_NODE_TYPES.ClassDeclaration,
|
|
1252
1218
|
AST_NODE_TYPES.ClassExpression
|
|
1253
1219
|
])
|
|
1254
1220
|
);
|
|
1255
1221
|
if (parentClass == null) return;
|
|
1256
|
-
if (isClassComponent(parentClass) && context.sourceCode.getScope(node).block !==
|
|
1222
|
+
if (isClassComponent(parentClass) && context.sourceCode.getScope(node).block !== AST12.findParentNode(node, isConstructorFunction)) {
|
|
1257
1223
|
context.report({
|
|
1258
1224
|
messageId: "noDirectMutationState",
|
|
1259
1225
|
node
|
|
@@ -1335,7 +1301,7 @@ var no_duplicate_key_default = createRule({
|
|
|
1335
1301
|
if (aValue == null || bValue == null) {
|
|
1336
1302
|
return false;
|
|
1337
1303
|
}
|
|
1338
|
-
return
|
|
1304
|
+
return AST12.isNodeEqual(aValue, bValue);
|
|
1339
1305
|
}
|
|
1340
1306
|
return {
|
|
1341
1307
|
"JSXAttribute[name.name='key']"(node) {
|
|
@@ -1354,12 +1320,12 @@ var no_duplicate_key_default = createRule({
|
|
|
1354
1320
|
break;
|
|
1355
1321
|
}
|
|
1356
1322
|
default: {
|
|
1357
|
-
const call =
|
|
1358
|
-
const iter =
|
|
1359
|
-
if (!
|
|
1323
|
+
const call = AST12.findParentNode(jsxElement, AST12.isMapCallLoose);
|
|
1324
|
+
const iter = AST12.findParentNode(jsxElement, (n) => n === call || AST12.isFunction(n));
|
|
1325
|
+
if (!AST12.isFunction(iter)) return;
|
|
1360
1326
|
const arg0 = call?.arguments[0];
|
|
1361
1327
|
if (call == null || arg0 == null) return;
|
|
1362
|
-
if (
|
|
1328
|
+
if (AST12.getEcmaExpression(arg0) !== iter) {
|
|
1363
1329
|
return;
|
|
1364
1330
|
}
|
|
1365
1331
|
keyedEntries.set(call, {
|
|
@@ -1435,7 +1401,7 @@ var no_forward_ref_default = createRule({
|
|
|
1435
1401
|
function getFix(context, node) {
|
|
1436
1402
|
return (fixer) => {
|
|
1437
1403
|
const [componentNode] = node.arguments;
|
|
1438
|
-
if (componentNode == null || !
|
|
1404
|
+
if (componentNode == null || !AST12.isFunction(componentNode)) {
|
|
1439
1405
|
return [];
|
|
1440
1406
|
}
|
|
1441
1407
|
return [
|
|
@@ -1648,7 +1614,7 @@ var no_leaked_conditional_rendering_default = createRule({
|
|
|
1648
1614
|
const services = ESLintUtils.getParserServices(context, false);
|
|
1649
1615
|
function getReportDescriptor(node) {
|
|
1650
1616
|
if (node == null) return _;
|
|
1651
|
-
return match(node).when(
|
|
1617
|
+
return match(node).when(AST12.isJSX, () => _).with({ type: AST_NODE_TYPES.LogicalExpression, operator: "&&" }, ({ left, right }) => {
|
|
1652
1618
|
const isLeftUnaryNot = left.type === AST_NODE_TYPES.UnaryExpression && left.operator === "!";
|
|
1653
1619
|
if (isLeftUnaryNot) {
|
|
1654
1620
|
return getReportDescriptor(right);
|
|
@@ -1731,7 +1697,7 @@ var no_missing_component_display_name_default = createRule({
|
|
|
1731
1697
|
const components = ctx.getAllComponents(node);
|
|
1732
1698
|
for (const { node: node2, displayName, flag } of components.values()) {
|
|
1733
1699
|
const isMemoOrForwardRef = (flag & (ERComponentFlag.ForwardRef | ERComponentFlag.Memo)) > 0n;
|
|
1734
|
-
if (
|
|
1700
|
+
if (AST12.getFunctionIdentifier(node2) != null) {
|
|
1735
1701
|
continue;
|
|
1736
1702
|
}
|
|
1737
1703
|
if (!isMemoOrForwardRef) {
|
|
@@ -1869,7 +1835,7 @@ var no_missing_key_default = createRule({
|
|
|
1869
1835
|
}
|
|
1870
1836
|
function checkBlockStatement(node) {
|
|
1871
1837
|
const descriptors = [];
|
|
1872
|
-
for (const statement of
|
|
1838
|
+
for (const statement of AST12.getNestedReturnStatements(node)) {
|
|
1873
1839
|
if (statement.argument == null) {
|
|
1874
1840
|
continue;
|
|
1875
1841
|
}
|
|
@@ -1885,7 +1851,7 @@ var no_missing_key_default = createRule({
|
|
|
1885
1851
|
if (state.isWithinChildrenToArray) {
|
|
1886
1852
|
return;
|
|
1887
1853
|
}
|
|
1888
|
-
const elements = node.elements.filter(
|
|
1854
|
+
const elements = node.elements.filter(AST12.is(AST_NODE_TYPES.JSXElement));
|
|
1889
1855
|
if (elements.length === 0) {
|
|
1890
1856
|
return;
|
|
1891
1857
|
}
|
|
@@ -1904,7 +1870,7 @@ var no_missing_key_default = createRule({
|
|
|
1904
1870
|
if (state.isWithinChildrenToArray) {
|
|
1905
1871
|
return;
|
|
1906
1872
|
}
|
|
1907
|
-
const isMapCallLike =
|
|
1873
|
+
const isMapCallLike = AST12.isMapCallLoose(node);
|
|
1908
1874
|
if (!isMapCallLike && !isArrayFromCall(node)) {
|
|
1909
1875
|
return;
|
|
1910
1876
|
}
|
|
@@ -1980,16 +1946,16 @@ var no_nested_components_default = createRule({
|
|
|
1980
1946
|
...collectorLegacy.ctx.getAllComponents(node).values()
|
|
1981
1947
|
];
|
|
1982
1948
|
const isFunctionComponent = (node2) => {
|
|
1983
|
-
return
|
|
1949
|
+
return AST12.isFunction(node2) && functionComponents.some((component) => component.node === node2);
|
|
1984
1950
|
};
|
|
1985
1951
|
const isClassComponent11 = (node2) => {
|
|
1986
|
-
return
|
|
1952
|
+
return AST12.isClass(node2) && classComponents.some((component) => component.node === node2);
|
|
1987
1953
|
};
|
|
1988
1954
|
for (const { name: name5, node: component } of functionComponents) {
|
|
1989
1955
|
if (isDirectValueOfRenderPropertyLoose(component)) {
|
|
1990
1956
|
continue;
|
|
1991
1957
|
}
|
|
1992
|
-
if (name5
|
|
1958
|
+
if (name5 == null) {
|
|
1993
1959
|
continue;
|
|
1994
1960
|
}
|
|
1995
1961
|
const isInsideProperty = component.parent.type === AST_NODE_TYPES.Property;
|
|
@@ -2016,7 +1982,7 @@ var no_nested_components_default = createRule({
|
|
|
2016
1982
|
});
|
|
2017
1983
|
continue;
|
|
2018
1984
|
}
|
|
2019
|
-
const parentComponent =
|
|
1985
|
+
const parentComponent = AST12.findParentNode(component, isFunctionComponent);
|
|
2020
1986
|
const isParentComponentNotDirectValueOfRenderProperty = parentComponent != null && !isDirectValueOfRenderPropertyLoose(parentComponent);
|
|
2021
1987
|
if (isParentComponentNotDirectValueOfRenderProperty) {
|
|
2022
1988
|
context.report({
|
|
@@ -2039,7 +2005,7 @@ var no_nested_components_default = createRule({
|
|
|
2039
2005
|
}
|
|
2040
2006
|
}
|
|
2041
2007
|
for (const { name: name5 = "unknown", node: component } of classComponents) {
|
|
2042
|
-
if (
|
|
2008
|
+
if (AST12.findParentNode(component, (n) => isClassComponent11(n) || isFunctionComponent(n)) == null) {
|
|
2043
2009
|
continue;
|
|
2044
2010
|
}
|
|
2045
2011
|
context.report({
|
|
@@ -2056,9 +2022,9 @@ var no_nested_components_default = createRule({
|
|
|
2056
2022
|
defaultOptions: []
|
|
2057
2023
|
});
|
|
2058
2024
|
function isInsideCreateElementProps(context, node) {
|
|
2059
|
-
const call =
|
|
2025
|
+
const call = AST12.findParentNode(node, isCreateElementCall(context));
|
|
2060
2026
|
if (call == null) return false;
|
|
2061
|
-
const prop =
|
|
2027
|
+
const prop = AST12.findParentNode(node, AST12.is(AST_NODE_TYPES.ObjectExpression));
|
|
2062
2028
|
if (prop == null) return false;
|
|
2063
2029
|
return prop === call.arguments[1];
|
|
2064
2030
|
}
|
|
@@ -2100,7 +2066,7 @@ var no_prop_types_default = createRule({
|
|
|
2100
2066
|
}
|
|
2101
2067
|
const variable = VAR.findVariable(object.name, context.sourceCode.getScope(node));
|
|
2102
2068
|
const variableNode = VAR.getVariableInitNode(variable, 0);
|
|
2103
|
-
if (variableNode != null && (
|
|
2069
|
+
if (variableNode != null && (AST12.isFunction(variableNode) || isClassComponent(variableNode))) {
|
|
2104
2070
|
context.report({ messageId: "noPropTypes", node: property });
|
|
2105
2071
|
}
|
|
2106
2072
|
},
|
|
@@ -2122,7 +2088,7 @@ var RULE_FEATURES33 = [
|
|
|
2122
2088
|
"CHK"
|
|
2123
2089
|
];
|
|
2124
2090
|
function isShouldComponentUpdate(node) {
|
|
2125
|
-
return
|
|
2091
|
+
return AST12.isMethodOrProperty(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "shouldComponentUpdate";
|
|
2126
2092
|
}
|
|
2127
2093
|
var no_redundant_should_component_update_default = createRule({
|
|
2128
2094
|
meta: {
|
|
@@ -2173,7 +2139,7 @@ var RULE_FEATURES34 = [
|
|
|
2173
2139
|
"CHK"
|
|
2174
2140
|
];
|
|
2175
2141
|
function isComponentDidMount(node) {
|
|
2176
|
-
return
|
|
2142
|
+
return AST12.isMethodOrProperty(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentDidMount";
|
|
2177
2143
|
}
|
|
2178
2144
|
var no_set_state_in_component_did_mount_default = createRule({
|
|
2179
2145
|
meta: {
|
|
@@ -2197,8 +2163,8 @@ var no_set_state_in_component_did_mount_default = createRule({
|
|
|
2197
2163
|
if (!isThisSetState(node)) {
|
|
2198
2164
|
return;
|
|
2199
2165
|
}
|
|
2200
|
-
const clazz =
|
|
2201
|
-
const method =
|
|
2166
|
+
const clazz = AST12.findParentNode(node, isClassComponent);
|
|
2167
|
+
const method = AST12.findParentNode(node, (n) => n === clazz || isComponentDidMount(n));
|
|
2202
2168
|
if (clazz == null || method == null || method === clazz) return;
|
|
2203
2169
|
const methodScope = context.sourceCode.getScope(method);
|
|
2204
2170
|
const upperScope = context.sourceCode.getScope(node).upper;
|
|
@@ -2218,7 +2184,7 @@ var RULE_FEATURES35 = [
|
|
|
2218
2184
|
"CHK"
|
|
2219
2185
|
];
|
|
2220
2186
|
function isComponentDidUpdate(node) {
|
|
2221
|
-
return
|
|
2187
|
+
return AST12.isMethodOrProperty(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentDidUpdate";
|
|
2222
2188
|
}
|
|
2223
2189
|
var no_set_state_in_component_did_update_default = createRule({
|
|
2224
2190
|
meta: {
|
|
@@ -2242,8 +2208,8 @@ var no_set_state_in_component_did_update_default = createRule({
|
|
|
2242
2208
|
if (!isThisSetState(node)) {
|
|
2243
2209
|
return;
|
|
2244
2210
|
}
|
|
2245
|
-
const clazz =
|
|
2246
|
-
const method =
|
|
2211
|
+
const clazz = AST12.findParentNode(node, isClassComponent);
|
|
2212
|
+
const method = AST12.findParentNode(node, (n) => n === clazz || isComponentDidUpdate(n));
|
|
2247
2213
|
if (clazz == null || method == null || method === clazz) return;
|
|
2248
2214
|
const methodScope = context.sourceCode.getScope(method);
|
|
2249
2215
|
const upperScope = context.sourceCode.getScope(node).upper;
|
|
@@ -2263,7 +2229,7 @@ var RULE_FEATURES36 = [
|
|
|
2263
2229
|
"CHK"
|
|
2264
2230
|
];
|
|
2265
2231
|
function isComponentWillUpdate3(node) {
|
|
2266
|
-
return
|
|
2232
|
+
return AST12.isMethodOrProperty(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentWillUpdate";
|
|
2267
2233
|
}
|
|
2268
2234
|
var no_set_state_in_component_will_update_default = createRule({
|
|
2269
2235
|
meta: {
|
|
@@ -2287,8 +2253,8 @@ var no_set_state_in_component_will_update_default = createRule({
|
|
|
2287
2253
|
if (!isThisSetState(node)) {
|
|
2288
2254
|
return;
|
|
2289
2255
|
}
|
|
2290
|
-
const clazz =
|
|
2291
|
-
const method =
|
|
2256
|
+
const clazz = AST12.findParentNode(node, isClassComponent);
|
|
2257
|
+
const method = AST12.findParentNode(node, (n) => n === clazz || isComponentWillUpdate3(n));
|
|
2292
2258
|
if (clazz == null || method == null || method === clazz) return;
|
|
2293
2259
|
const methodScope = context.sourceCode.getScope(method);
|
|
2294
2260
|
const upperScope = context.sourceCode.getScope(node).upper;
|
|
@@ -2354,7 +2320,7 @@ var RULE_FEATURES38 = [
|
|
|
2354
2320
|
"CHK"
|
|
2355
2321
|
];
|
|
2356
2322
|
function isUnsafeComponentWillMount(node) {
|
|
2357
|
-
return
|
|
2323
|
+
return AST12.isMethodOrProperty(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "UNSAFE_componentWillMount";
|
|
2358
2324
|
}
|
|
2359
2325
|
var no_unsafe_component_will_mount_default = createRule({
|
|
2360
2326
|
meta: {
|
|
@@ -2399,7 +2365,7 @@ var RULE_FEATURES39 = [
|
|
|
2399
2365
|
"CHK"
|
|
2400
2366
|
];
|
|
2401
2367
|
function isUnsafeComponentWillReceiveProps(node) {
|
|
2402
|
-
return
|
|
2368
|
+
return AST12.isMethodOrProperty(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "UNSAFE_componentWillReceiveProps";
|
|
2403
2369
|
}
|
|
2404
2370
|
var no_unsafe_component_will_receive_props_default = createRule({
|
|
2405
2371
|
meta: {
|
|
@@ -2444,7 +2410,7 @@ var RULE_FEATURES40 = [
|
|
|
2444
2410
|
"CHK"
|
|
2445
2411
|
];
|
|
2446
2412
|
function isUnsafeComponentWillUpdate(node) {
|
|
2447
|
-
return
|
|
2413
|
+
return AST12.isMethodOrProperty(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "UNSAFE_componentWillUpdate";
|
|
2448
2414
|
}
|
|
2449
2415
|
var no_unsafe_component_will_update_default = createRule({
|
|
2450
2416
|
meta: {
|
|
@@ -2540,7 +2506,7 @@ var no_unstable_context_value_default = createRule({
|
|
|
2540
2506
|
messageId: "unstableContextValue",
|
|
2541
2507
|
node: constructionNode,
|
|
2542
2508
|
data: {
|
|
2543
|
-
type:
|
|
2509
|
+
type: AST12.toReadableNodeType(constructionNode),
|
|
2544
2510
|
suggestion
|
|
2545
2511
|
}
|
|
2546
2512
|
});
|
|
@@ -2609,7 +2575,7 @@ var no_unstable_default_props_default = createRule({
|
|
|
2609
2575
|
if (isReactHookCall(construction.node)) {
|
|
2610
2576
|
continue;
|
|
2611
2577
|
}
|
|
2612
|
-
const forbiddenType =
|
|
2578
|
+
const forbiddenType = AST12.toReadableNodeType(right);
|
|
2613
2579
|
context.report({
|
|
2614
2580
|
messageId: "noUnstableDefaultProps",
|
|
2615
2581
|
node: right,
|
|
@@ -2657,21 +2623,6 @@ var LIFECYCLE_METHODS = /* @__PURE__ */ new Set([
|
|
|
2657
2623
|
function isKeyLiteral2(node, key) {
|
|
2658
2624
|
return match(key).with({ type: AST_NODE_TYPES.Literal }, constTrue).with({ type: AST_NODE_TYPES.TemplateLiteral, expressions: [] }, constTrue).with({ type: AST_NODE_TYPES.Identifier }, () => !node.computed).otherwise(constFalse);
|
|
2659
2625
|
}
|
|
2660
|
-
function getName3(node) {
|
|
2661
|
-
if (AST11.isTsOnlyExpression(node)) {
|
|
2662
|
-
return getName3(node.expression);
|
|
2663
|
-
}
|
|
2664
|
-
if (node.type === AST_NODE_TYPES.Identifier || node.type === AST_NODE_TYPES.PrivateIdentifier) {
|
|
2665
|
-
return node.name;
|
|
2666
|
-
}
|
|
2667
|
-
if (node.type === AST_NODE_TYPES.Literal) {
|
|
2668
|
-
return node.value?.toString();
|
|
2669
|
-
}
|
|
2670
|
-
if (node.type === AST_NODE_TYPES.TemplateLiteral && node.expressions.length === 0) {
|
|
2671
|
-
return node.quasis[0]?.value.raw;
|
|
2672
|
-
}
|
|
2673
|
-
return _;
|
|
2674
|
-
}
|
|
2675
2626
|
var no_unused_class_component_members_default = createRule({
|
|
2676
2627
|
meta: {
|
|
2677
2628
|
type: "problem",
|
|
@@ -2703,14 +2654,14 @@ var no_unused_class_component_members_default = createRule({
|
|
|
2703
2654
|
if (currentClass == null || !isClassComponent(currentClass)) {
|
|
2704
2655
|
return;
|
|
2705
2656
|
}
|
|
2706
|
-
const className =
|
|
2657
|
+
const className = AST12.getClassIdentifier(currentClass)?.name;
|
|
2707
2658
|
const defs = propertyDefs.get(currentClass);
|
|
2708
2659
|
const usages = propertyUsages.get(currentClass);
|
|
2709
2660
|
if (defs == null) {
|
|
2710
2661
|
return;
|
|
2711
2662
|
}
|
|
2712
2663
|
for (const def of defs) {
|
|
2713
|
-
const methodName =
|
|
2664
|
+
const methodName = AST12.getPropertyName(def);
|
|
2714
2665
|
if (methodName == null) {
|
|
2715
2666
|
continue;
|
|
2716
2667
|
}
|
|
@@ -2757,14 +2708,14 @@ var no_unused_class_component_members_default = createRule({
|
|
|
2757
2708
|
if (!isClassComponent(currentClass) || currentMethod.static) {
|
|
2758
2709
|
return;
|
|
2759
2710
|
}
|
|
2760
|
-
if (!
|
|
2711
|
+
if (!AST12.isThisExpression(node.object) || !isKeyLiteral2(node, node.property)) {
|
|
2761
2712
|
return;
|
|
2762
2713
|
}
|
|
2763
2714
|
if (node.parent.type === AST_NODE_TYPES.AssignmentExpression && node.parent.left === node) {
|
|
2764
2715
|
propertyDefs.get(currentClass)?.add(node.property);
|
|
2765
2716
|
return;
|
|
2766
2717
|
}
|
|
2767
|
-
const propertyName =
|
|
2718
|
+
const propertyName = AST12.getPropertyName(node.property);
|
|
2768
2719
|
if (propertyName != null) {
|
|
2769
2720
|
propertyUsages.get(currentClass)?.add(propertyName);
|
|
2770
2721
|
}
|
|
@@ -2782,10 +2733,10 @@ var no_unused_class_component_members_default = createRule({
|
|
|
2782
2733
|
if (!isClassComponent(currentClass) || currentMethod.static) {
|
|
2783
2734
|
return;
|
|
2784
2735
|
}
|
|
2785
|
-
if (node.init != null &&
|
|
2736
|
+
if (node.init != null && AST12.isThisExpression(node.init) && node.id.type === AST_NODE_TYPES.ObjectPattern) {
|
|
2786
2737
|
for (const prop of node.id.properties) {
|
|
2787
2738
|
if (prop.type === AST_NODE_TYPES.Property && isKeyLiteral2(prop, prop.key)) {
|
|
2788
|
-
const keyName =
|
|
2739
|
+
const keyName = AST12.getPropertyName(prop.key);
|
|
2789
2740
|
if (keyName != null) {
|
|
2790
2741
|
propertyUsages.get(currentClass)?.add(keyName);
|
|
2791
2742
|
}
|
|
@@ -2804,25 +2755,6 @@ var RULE_FEATURES44 = [
|
|
|
2804
2755
|
function isKeyLiteral3(node, key) {
|
|
2805
2756
|
return match(key).with({ type: AST_NODE_TYPES.Literal }, constTrue).with({ type: AST_NODE_TYPES.TemplateLiteral, expressions: [] }, constTrue).with({ type: AST_NODE_TYPES.Identifier }, () => !node.computed).otherwise(constFalse);
|
|
2806
2757
|
}
|
|
2807
|
-
function getName4(node) {
|
|
2808
|
-
if (AST11.isTsOnlyExpression(node)) {
|
|
2809
|
-
return getName4(node.expression);
|
|
2810
|
-
}
|
|
2811
|
-
if (node.type === AST_NODE_TYPES.Identifier || node.type === AST_NODE_TYPES.PrivateIdentifier) {
|
|
2812
|
-
return node.name;
|
|
2813
|
-
}
|
|
2814
|
-
if (node.type === AST_NODE_TYPES.Literal) {
|
|
2815
|
-
return String(node.value);
|
|
2816
|
-
}
|
|
2817
|
-
if (node.type === AST_NODE_TYPES.TemplateLiteral && node.expressions.length === 0) {
|
|
2818
|
-
return node.quasis[0]?.value.raw;
|
|
2819
|
-
}
|
|
2820
|
-
return _;
|
|
2821
|
-
}
|
|
2822
|
-
function isAssignmentToThisState2(node) {
|
|
2823
|
-
const { left } = node;
|
|
2824
|
-
return left.type === AST_NODE_TYPES.MemberExpression && AST11.isThisExpression(left.object) && getName4(left.property) === "state";
|
|
2825
|
-
}
|
|
2826
2758
|
var no_unused_state_default = createRule({
|
|
2827
2759
|
meta: {
|
|
2828
2760
|
type: "problem",
|
|
@@ -2849,7 +2781,7 @@ var no_unused_state_default = createRule({
|
|
|
2849
2781
|
if (currentClass == null || !isClassComponent(currentClass)) {
|
|
2850
2782
|
return;
|
|
2851
2783
|
}
|
|
2852
|
-
const className =
|
|
2784
|
+
const className = AST12.getClassIdentifier(currentClass)?.name;
|
|
2853
2785
|
const { node: defNode, isUsed = false } = stateDefs.get(currentClass) ?? {};
|
|
2854
2786
|
if (defNode == null || isUsed) {
|
|
2855
2787
|
return;
|
|
@@ -2875,7 +2807,7 @@ var no_unused_state_default = createRule({
|
|
|
2875
2807
|
}
|
|
2876
2808
|
return;
|
|
2877
2809
|
}
|
|
2878
|
-
if (
|
|
2810
|
+
if (AST12.getPropertyName(node.key) === "state") {
|
|
2879
2811
|
stateDefs.set(currentClass, { node: node.key, isUsed: false });
|
|
2880
2812
|
}
|
|
2881
2813
|
}
|
|
@@ -2890,7 +2822,7 @@ var no_unused_state_default = createRule({
|
|
|
2890
2822
|
}
|
|
2891
2823
|
return {
|
|
2892
2824
|
AssignmentExpression(node) {
|
|
2893
|
-
if (!
|
|
2825
|
+
if (!isAssignmentToThisState(node)) {
|
|
2894
2826
|
return;
|
|
2895
2827
|
}
|
|
2896
2828
|
const currentClass = classEntries.at(-1);
|
|
@@ -2909,10 +2841,10 @@ var no_unused_state_default = createRule({
|
|
|
2909
2841
|
ClassExpression: classEnter,
|
|
2910
2842
|
"ClassExpression:exit": classExit,
|
|
2911
2843
|
MemberExpression(node) {
|
|
2912
|
-
if (!
|
|
2844
|
+
if (!AST12.isThisExpression(node.object)) {
|
|
2913
2845
|
return;
|
|
2914
2846
|
}
|
|
2915
|
-
if (
|
|
2847
|
+
if (AST12.getPropertyName(node.property) !== "state") {
|
|
2916
2848
|
return;
|
|
2917
2849
|
}
|
|
2918
2850
|
const currentClass = classEntries.at(-1);
|
|
@@ -2953,12 +2885,12 @@ var no_unused_state_default = createRule({
|
|
|
2953
2885
|
if (!currentClass.body.body.includes(currentMethod)) {
|
|
2954
2886
|
return;
|
|
2955
2887
|
}
|
|
2956
|
-
if (node.init == null || !
|
|
2888
|
+
if (node.init == null || !AST12.isThisExpression(node.init) || node.id.type !== AST_NODE_TYPES.ObjectPattern) {
|
|
2957
2889
|
return;
|
|
2958
2890
|
}
|
|
2959
2891
|
const hasState = node.id.properties.some((prop) => {
|
|
2960
2892
|
if (prop.type === AST_NODE_TYPES.Property && isKeyLiteral3(prop, prop.key)) {
|
|
2961
|
-
return
|
|
2893
|
+
return AST12.getPropertyName(prop.key) === "state";
|
|
2962
2894
|
}
|
|
2963
2895
|
return false;
|
|
2964
2896
|
});
|
|
@@ -3089,7 +3021,7 @@ function checkAndReport(context, node, allowExpressions) {
|
|
|
3089
3021
|
return null;
|
|
3090
3022
|
}
|
|
3091
3023
|
if (node.children.some(
|
|
3092
|
-
(child) => JSX8.isLiteral(child) && !JSX8.isWhiteSpace(child) ||
|
|
3024
|
+
(child) => JSX8.isLiteral(child) && !JSX8.isWhiteSpace(child) || AST12.is(AST_NODE_TYPES.JSXExpressionContainer)(child)
|
|
3093
3025
|
)) {
|
|
3094
3026
|
return null;
|
|
3095
3027
|
}
|
|
@@ -3127,7 +3059,7 @@ function checkAndReport(context, node, allowExpressions) {
|
|
|
3127
3059
|
});
|
|
3128
3060
|
return;
|
|
3129
3061
|
}
|
|
3130
|
-
const isChildElement =
|
|
3062
|
+
const isChildElement = AST12.isOneOf([AST_NODE_TYPES.JSXElement, AST_NODE_TYPES.JSXFragment])(node.parent);
|
|
3131
3063
|
switch (true) {
|
|
3132
3064
|
// <Foo content={<>ee eeee eeee ...</>} />
|
|
3133
3065
|
case (allowExpressions && !isChildElement && node.children.length === 1 && JSX8.isLiteral(node.children.at(0))): {
|
|
@@ -3248,10 +3180,10 @@ var prefer_destructuring_assignment_default = createRule({
|
|
|
3248
3180
|
...ctx.getAllComponents(node).values()
|
|
3249
3181
|
];
|
|
3250
3182
|
function isFunctionComponent(block) {
|
|
3251
|
-
if (!
|
|
3183
|
+
if (!AST12.isFunction(block)) {
|
|
3252
3184
|
return false;
|
|
3253
3185
|
}
|
|
3254
|
-
const id =
|
|
3186
|
+
const id = AST12.getFunctionIdentifier(block);
|
|
3255
3187
|
return id != null && isComponentName(id.name) && components.some((component) => component.node === block);
|
|
3256
3188
|
}
|
|
3257
3189
|
for (const [initialScope, memberExpression] of memberExpressionWithNames) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-react-x",
|
|
3
|
-
"version": "1.30.
|
|
3
|
+
"version": "1.30.3-beta.1",
|
|
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",
|
|
@@ -49,12 +49,12 @@
|
|
|
49
49
|
"compare-versions": "^6.1.1",
|
|
50
50
|
"string-ts": "^2.2.1",
|
|
51
51
|
"ts-pattern": "^5.6.2",
|
|
52
|
-
"@eslint-react/
|
|
53
|
-
"@eslint-react/
|
|
54
|
-
"@eslint-react/
|
|
55
|
-
"@eslint-react/
|
|
56
|
-
"@eslint-react/
|
|
57
|
-
"@eslint-react/var": "1.30.
|
|
52
|
+
"@eslint-react/eff": "1.30.3-beta.1",
|
|
53
|
+
"@eslint-react/ast": "1.30.3-beta.1",
|
|
54
|
+
"@eslint-react/jsx": "1.30.3-beta.1",
|
|
55
|
+
"@eslint-react/shared": "1.30.3-beta.1",
|
|
56
|
+
"@eslint-react/core": "1.30.3-beta.1",
|
|
57
|
+
"@eslint-react/var": "1.30.3-beta.1"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
60
|
"@types/react": "^19.0.10",
|