eslint-plugin-react-x 1.46.1-next.0 → 1.47.0-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +113 -115
- package/dist/index.mjs +112 -113
- package/package.json +7 -8
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var shared = require('@eslint-react/shared');
|
|
4
|
-
var
|
|
4
|
+
var ER25 = require('@eslint-react/core');
|
|
5
5
|
var utils = require('@typescript-eslint/utils');
|
|
6
6
|
var kit = require('@eslint-react/kit');
|
|
7
7
|
var types = require('@typescript-eslint/types');
|
|
@@ -9,7 +9,6 @@ var VAR2 = require('@eslint-react/var');
|
|
|
9
9
|
var tsPattern = require('ts-pattern');
|
|
10
10
|
var ts = require('typescript');
|
|
11
11
|
var AST8 = require('@eslint-react/ast');
|
|
12
|
-
var ER22 = require('@eslint-react/core');
|
|
13
12
|
var eff = require('@eslint-react/eff');
|
|
14
13
|
var compareVersions = require('compare-versions');
|
|
15
14
|
var typeUtils = require('@typescript-eslint/type-utils');
|
|
@@ -36,11 +35,10 @@ function _interopNamespace(e) {
|
|
|
36
35
|
return Object.freeze(n);
|
|
37
36
|
}
|
|
38
37
|
|
|
39
|
-
var
|
|
38
|
+
var ER25__namespace = /*#__PURE__*/_interopNamespace(ER25);
|
|
40
39
|
var VAR2__namespace = /*#__PURE__*/_interopNamespace(VAR2);
|
|
41
40
|
var ts__default = /*#__PURE__*/_interopDefault(ts);
|
|
42
41
|
var AST8__namespace = /*#__PURE__*/_interopNamespace(AST8);
|
|
43
|
-
var ER22__namespace = /*#__PURE__*/_interopNamespace(ER22);
|
|
44
42
|
|
|
45
43
|
var __defProp = Object.defineProperty;
|
|
46
44
|
var __export = (target, all) => {
|
|
@@ -143,7 +141,7 @@ var settings3 = {
|
|
|
143
141
|
|
|
144
142
|
// package.json
|
|
145
143
|
var name4 = "eslint-plugin-react-x";
|
|
146
|
-
var version = "1.
|
|
144
|
+
var version = "1.47.0-next.0";
|
|
147
145
|
var createRule = utils.ESLintUtils.RuleCreator(shared.getDocsUrl("x"));
|
|
148
146
|
|
|
149
147
|
// src/rules/avoid-shorthand-boolean.ts
|
|
@@ -174,7 +172,7 @@ function create(context) {
|
|
|
174
172
|
messageId: "avoidShorthandBoolean",
|
|
175
173
|
node,
|
|
176
174
|
data: {
|
|
177
|
-
propName:
|
|
175
|
+
propName: ER25__namespace.getAttributeName(context, node)
|
|
178
176
|
},
|
|
179
177
|
fix: (fixer) => fixer.insertTextAfter(node.name, `={true}`)
|
|
180
178
|
});
|
|
@@ -415,25 +413,25 @@ function create7(context) {
|
|
|
415
413
|
const setStateEntries = [];
|
|
416
414
|
return {
|
|
417
415
|
CallExpression(node) {
|
|
418
|
-
if (!
|
|
416
|
+
if (!ER25__namespace.isThisSetState(node)) {
|
|
419
417
|
return;
|
|
420
418
|
}
|
|
421
419
|
setStateEntries.push([node, false]);
|
|
422
420
|
},
|
|
423
421
|
"CallExpression:exit"(node) {
|
|
424
|
-
if (!
|
|
422
|
+
if (!ER25__namespace.isThisSetState(node)) {
|
|
425
423
|
return;
|
|
426
424
|
}
|
|
427
425
|
setStateEntries.pop();
|
|
428
426
|
},
|
|
429
427
|
ClassDeclaration(node) {
|
|
430
|
-
classEntries.push([node,
|
|
428
|
+
classEntries.push([node, ER25__namespace.isClassComponent(node)]);
|
|
431
429
|
},
|
|
432
430
|
"ClassDeclaration:exit"() {
|
|
433
431
|
classEntries.pop();
|
|
434
432
|
},
|
|
435
433
|
ClassExpression(node) {
|
|
436
|
-
classEntries.push([node,
|
|
434
|
+
classEntries.push([node, ER25__namespace.isClassComponent(node)]);
|
|
437
435
|
},
|
|
438
436
|
"ClassExpression:exit"() {
|
|
439
437
|
classEntries.pop();
|
|
@@ -517,7 +515,7 @@ function isUsingReactChildren(context, node) {
|
|
|
517
515
|
return true;
|
|
518
516
|
}
|
|
519
517
|
if (callee.object.type === types.AST_NODE_TYPES.MemberExpression && "name" in callee.object.object) {
|
|
520
|
-
return
|
|
518
|
+
return ER25__namespace.isInitializedFromReact(callee.object.object.name, importSource, initialScope);
|
|
521
519
|
}
|
|
522
520
|
return false;
|
|
523
521
|
}
|
|
@@ -583,7 +581,7 @@ function create8(context) {
|
|
|
583
581
|
return node.type === types.AST_NODE_TYPES.Identifier && indexParamNames.some((name5) => name5 != null && name5 === node.name);
|
|
584
582
|
}
|
|
585
583
|
function isCreateOrCloneElementCall(node) {
|
|
586
|
-
return
|
|
584
|
+
return ER25__namespace.isCreateElementCall(context, node) || ER25__namespace.isCloneElementCall(context, node);
|
|
587
585
|
}
|
|
588
586
|
function getReportDescriptors(node) {
|
|
589
587
|
switch (node.type) {
|
|
@@ -699,7 +697,7 @@ var no_children_count_default = createRule({
|
|
|
699
697
|
function create9(context) {
|
|
700
698
|
return {
|
|
701
699
|
MemberExpression(node) {
|
|
702
|
-
if (
|
|
700
|
+
if (ER25__namespace.isChildrenCount(context, node)) {
|
|
703
701
|
context.report({
|
|
704
702
|
messageId: "noChildrenCount",
|
|
705
703
|
node: node.property
|
|
@@ -729,7 +727,7 @@ var no_children_for_each_default = createRule({
|
|
|
729
727
|
function create10(context) {
|
|
730
728
|
return {
|
|
731
729
|
MemberExpression(node) {
|
|
732
|
-
if (
|
|
730
|
+
if (ER25__namespace.isChildrenForEach(context, node)) {
|
|
733
731
|
context.report({
|
|
734
732
|
messageId: "noChildrenForEach",
|
|
735
733
|
node: node.property
|
|
@@ -759,7 +757,7 @@ var no_children_map_default = createRule({
|
|
|
759
757
|
function create11(context) {
|
|
760
758
|
return {
|
|
761
759
|
MemberExpression(node) {
|
|
762
|
-
if (
|
|
760
|
+
if (ER25__namespace.isChildrenMap(context, node)) {
|
|
763
761
|
context.report({
|
|
764
762
|
messageId: "noChildrenMap",
|
|
765
763
|
node: node.property
|
|
@@ -789,7 +787,7 @@ var no_children_only_default = createRule({
|
|
|
789
787
|
function create12(context) {
|
|
790
788
|
return {
|
|
791
789
|
MemberExpression(node) {
|
|
792
|
-
if (
|
|
790
|
+
if (ER25__namespace.isChildrenOnly(context, node)) {
|
|
793
791
|
context.report({
|
|
794
792
|
messageId: "noChildrenOnly",
|
|
795
793
|
node: node.property
|
|
@@ -820,7 +818,7 @@ function create13(context) {
|
|
|
820
818
|
return {
|
|
821
819
|
JSXElement(node) {
|
|
822
820
|
const attributes = node.openingElement.attributes;
|
|
823
|
-
const childrenProp =
|
|
821
|
+
const childrenProp = ER25__namespace.getAttribute(context, "children", attributes, context.sourceCode.getScope(node));
|
|
824
822
|
if (childrenProp != null) {
|
|
825
823
|
context.report({
|
|
826
824
|
messageId: "noChildrenProp",
|
|
@@ -851,7 +849,7 @@ var no_children_to_array_default = createRule({
|
|
|
851
849
|
function create14(context) {
|
|
852
850
|
return {
|
|
853
851
|
MemberExpression(node) {
|
|
854
|
-
if (
|
|
852
|
+
if (ER25__namespace.isChildrenToArray(context, node)) {
|
|
855
853
|
context.report({
|
|
856
854
|
messageId: "noChildrenToArray",
|
|
857
855
|
node: node.property
|
|
@@ -880,13 +878,13 @@ var no_class_component_default = createRule({
|
|
|
880
878
|
});
|
|
881
879
|
function create15(context) {
|
|
882
880
|
if (!context.sourceCode.text.includes("Component")) return {};
|
|
883
|
-
const { ctx, listeners } =
|
|
881
|
+
const { ctx, listeners } = ER25__namespace.useComponentCollectorLegacy();
|
|
884
882
|
return {
|
|
885
883
|
...listeners,
|
|
886
884
|
"Program:exit"(program) {
|
|
887
885
|
const components = ctx.getAllComponents(program);
|
|
888
886
|
for (const { name: name5 = "anonymous", node: component } of components.values()) {
|
|
889
|
-
if (component.body.body.some((m) =>
|
|
887
|
+
if (component.body.body.some((m) => ER25__namespace.isComponentDidCatch(m) || ER25__namespace.isGetDerivedStateFromError(m))) {
|
|
890
888
|
continue;
|
|
891
889
|
}
|
|
892
890
|
context.report({
|
|
@@ -921,7 +919,7 @@ var no_clone_element_default = createRule({
|
|
|
921
919
|
function create16(context) {
|
|
922
920
|
return {
|
|
923
921
|
CallExpression(node) {
|
|
924
|
-
if (
|
|
922
|
+
if (ER25__namespace.isCloneElementCall(context, node)) {
|
|
925
923
|
context.report({
|
|
926
924
|
messageId: "noCloneElement",
|
|
927
925
|
node
|
|
@@ -1044,7 +1042,7 @@ var no_component_will_mount_default = createRule({
|
|
|
1044
1042
|
});
|
|
1045
1043
|
function create19(context) {
|
|
1046
1044
|
if (!context.sourceCode.text.includes("componentWillMount")) return {};
|
|
1047
|
-
const { ctx, listeners } =
|
|
1045
|
+
const { ctx, listeners } = ER25__namespace.useComponentCollectorLegacy();
|
|
1048
1046
|
return {
|
|
1049
1047
|
...listeners,
|
|
1050
1048
|
"Program:exit"(program) {
|
|
@@ -1052,7 +1050,7 @@ function create19(context) {
|
|
|
1052
1050
|
for (const { node: component } of components.values()) {
|
|
1053
1051
|
const { body } = component.body;
|
|
1054
1052
|
for (const member of body) {
|
|
1055
|
-
if (
|
|
1053
|
+
if (ER25__namespace.isComponentWillMount(member)) {
|
|
1056
1054
|
context.report({
|
|
1057
1055
|
messageId: "noComponentWillMount",
|
|
1058
1056
|
node: member,
|
|
@@ -1092,7 +1090,7 @@ var no_component_will_receive_props_default = createRule({
|
|
|
1092
1090
|
});
|
|
1093
1091
|
function create20(context) {
|
|
1094
1092
|
if (!context.sourceCode.text.includes("componentWillReceiveProps")) return {};
|
|
1095
|
-
const { ctx, listeners } =
|
|
1093
|
+
const { ctx, listeners } = ER25__namespace.useComponentCollectorLegacy();
|
|
1096
1094
|
return {
|
|
1097
1095
|
...listeners,
|
|
1098
1096
|
"Program:exit"(program) {
|
|
@@ -1100,7 +1098,7 @@ function create20(context) {
|
|
|
1100
1098
|
for (const { node: component } of components.values()) {
|
|
1101
1099
|
const { body } = component.body;
|
|
1102
1100
|
for (const member of body) {
|
|
1103
|
-
if (
|
|
1101
|
+
if (ER25__namespace.isComponentWillReceiveProps(member)) {
|
|
1104
1102
|
context.report({
|
|
1105
1103
|
messageId: "noComponentWillReceiveProps",
|
|
1106
1104
|
node: member,
|
|
@@ -1140,7 +1138,7 @@ var no_component_will_update_default = createRule({
|
|
|
1140
1138
|
});
|
|
1141
1139
|
function create21(context) {
|
|
1142
1140
|
if (!context.sourceCode.text.includes("componentWillUpdate")) return {};
|
|
1143
|
-
const { ctx, listeners } =
|
|
1141
|
+
const { ctx, listeners } = ER25__namespace.useComponentCollectorLegacy();
|
|
1144
1142
|
return {
|
|
1145
1143
|
...listeners,
|
|
1146
1144
|
"Program:exit"(program) {
|
|
@@ -1148,7 +1146,7 @@ function create21(context) {
|
|
|
1148
1146
|
for (const { node: component } of components.values()) {
|
|
1149
1147
|
const { body } = component.body;
|
|
1150
1148
|
for (const member of body) {
|
|
1151
|
-
if (
|
|
1149
|
+
if (ER25__namespace.isComponentWillUpdate(member)) {
|
|
1152
1150
|
context.report({
|
|
1153
1151
|
messageId: "noComponentWillUpdate",
|
|
1154
1152
|
node: member,
|
|
@@ -1192,7 +1190,7 @@ function create22(context) {
|
|
|
1192
1190
|
if (compareVersions.compare(version2, "19.0.0", "<")) return {};
|
|
1193
1191
|
return {
|
|
1194
1192
|
JSXElement(node) {
|
|
1195
|
-
const fullName =
|
|
1193
|
+
const fullName = ER25__namespace.getElementType(context, node);
|
|
1196
1194
|
const parts = fullName.split(".");
|
|
1197
1195
|
const selfName = parts.pop();
|
|
1198
1196
|
const contextFullName = parts.join(".");
|
|
@@ -1203,7 +1201,7 @@ function create22(context) {
|
|
|
1203
1201
|
messageId: "noContextProvider",
|
|
1204
1202
|
node,
|
|
1205
1203
|
fix(fixer) {
|
|
1206
|
-
if (!
|
|
1204
|
+
if (!ER25__namespace.isComponentNameLoose(contextSelfName)) return null;
|
|
1207
1205
|
const openingElement = node.openingElement;
|
|
1208
1206
|
const closingElement = node.closingElement;
|
|
1209
1207
|
if (closingElement == null) {
|
|
@@ -1239,7 +1237,7 @@ var no_create_ref_default = createRule({
|
|
|
1239
1237
|
function create23(context) {
|
|
1240
1238
|
return {
|
|
1241
1239
|
CallExpression(node) {
|
|
1242
|
-
if (
|
|
1240
|
+
if (ER25__namespace.isCreateRefCall(context, node) && AST8__namespace.findParentNode(node, ER25__namespace.isClassComponent) == null) {
|
|
1243
1241
|
context.report({ messageId: "noCreateRef", node });
|
|
1244
1242
|
}
|
|
1245
1243
|
}
|
|
@@ -1277,17 +1275,17 @@ function create24(context) {
|
|
|
1277
1275
|
if (property.type !== types.AST_NODE_TYPES.Identifier || property.name !== "defaultProps") {
|
|
1278
1276
|
return;
|
|
1279
1277
|
}
|
|
1280
|
-
if (!
|
|
1278
|
+
if (!ER25__namespace.isComponentNameLoose(object.name)) {
|
|
1281
1279
|
return;
|
|
1282
1280
|
}
|
|
1283
1281
|
const variable = VAR2__namespace.findVariable(object.name, context.sourceCode.getScope(node));
|
|
1284
1282
|
const variableNode = VAR2__namespace.getVariableInitNode(variable, 0);
|
|
1285
1283
|
if (variableNode == null) return;
|
|
1286
|
-
if (!AST8__namespace.isFunction(variableNode) && !
|
|
1284
|
+
if (!AST8__namespace.isFunction(variableNode) && !ER25__namespace.isClassComponent(variableNode)) return;
|
|
1287
1285
|
context.report({ messageId: "noDefaultProps", node: property });
|
|
1288
1286
|
},
|
|
1289
1287
|
PropertyDefinition(node) {
|
|
1290
|
-
if (!
|
|
1288
|
+
if (!ER25__namespace.isClassComponent(node.parent.parent)) {
|
|
1291
1289
|
return;
|
|
1292
1290
|
}
|
|
1293
1291
|
if (!node.static || node.key.type !== types.AST_NODE_TYPES.Identifier || node.key.name !== "defaultProps") {
|
|
@@ -1321,7 +1319,7 @@ var no_direct_mutation_state_default = createRule({
|
|
|
1321
1319
|
function create25(context) {
|
|
1322
1320
|
return {
|
|
1323
1321
|
AssignmentExpression(node) {
|
|
1324
|
-
if (!
|
|
1322
|
+
if (!ER25__namespace.isAssignmentToThisState(node)) return;
|
|
1325
1323
|
const parentClass = AST8__namespace.findParentNode(
|
|
1326
1324
|
node,
|
|
1327
1325
|
AST8__namespace.isOneOf([
|
|
@@ -1330,7 +1328,7 @@ function create25(context) {
|
|
|
1330
1328
|
])
|
|
1331
1329
|
);
|
|
1332
1330
|
if (parentClass == null) return;
|
|
1333
|
-
if (
|
|
1331
|
+
if (ER25__namespace.isClassComponent(parentClass) && context.sourceCode.getScope(node).block !== AST8__namespace.findParentNode(node, isConstructorFunction)) {
|
|
1334
1332
|
context.report({
|
|
1335
1333
|
messageId: "noDirectMutationState",
|
|
1336
1334
|
node
|
|
@@ -1452,7 +1450,7 @@ function create27(context) {
|
|
|
1452
1450
|
}
|
|
1453
1451
|
return {
|
|
1454
1452
|
CallExpression(node) {
|
|
1455
|
-
if (!
|
|
1453
|
+
if (!ER25__namespace.isForwardRefCall(context, node)) {
|
|
1456
1454
|
return;
|
|
1457
1455
|
}
|
|
1458
1456
|
context.report({
|
|
@@ -1554,7 +1552,7 @@ function create28(context) {
|
|
|
1554
1552
|
return {
|
|
1555
1553
|
JSXOpeningElement(node) {
|
|
1556
1554
|
const initialScope = context.sourceCode.getScope(node);
|
|
1557
|
-
const keyPropFound =
|
|
1555
|
+
const keyPropFound = ER25__namespace.getAttribute(context, "key", node.attributes, initialScope);
|
|
1558
1556
|
const keyPropOnElement = node.attributes.some(
|
|
1559
1557
|
(n) => n.type === types.AST_NODE_TYPES.JSXAttribute && n.name.type === types.AST_NODE_TYPES.JSXIdentifier && n.name.name === "key"
|
|
1560
1558
|
);
|
|
@@ -1742,12 +1740,12 @@ function create30(context) {
|
|
|
1742
1740
|
const {
|
|
1743
1741
|
ctx,
|
|
1744
1742
|
listeners
|
|
1745
|
-
} =
|
|
1743
|
+
} = ER25__namespace.useComponentCollector(
|
|
1746
1744
|
context,
|
|
1747
1745
|
{
|
|
1748
1746
|
collectDisplayName: true,
|
|
1749
1747
|
collectHookCalls: false,
|
|
1750
|
-
hint:
|
|
1748
|
+
hint: ER25__namespace.DEFAULT_COMPONENT_DETECTION_HINT
|
|
1751
1749
|
}
|
|
1752
1750
|
);
|
|
1753
1751
|
return {
|
|
@@ -1755,7 +1753,7 @@ function create30(context) {
|
|
|
1755
1753
|
"Program:exit"(program) {
|
|
1756
1754
|
const components = ctx.getAllComponents(program);
|
|
1757
1755
|
for (const { node, displayName, flag } of components.values()) {
|
|
1758
|
-
const isMemoOrForwardRef = (flag & (
|
|
1756
|
+
const isMemoOrForwardRef = (flag & (ER25__namespace.ComponentFlag.ForwardRef | ER25__namespace.ComponentFlag.Memo)) > 0n;
|
|
1759
1757
|
if (AST8__namespace.getFunctionIdentifier(node) != null) {
|
|
1760
1758
|
continue;
|
|
1761
1759
|
}
|
|
@@ -1796,12 +1794,12 @@ function create31(context) {
|
|
|
1796
1794
|
const displayNameAssignments = [];
|
|
1797
1795
|
return {
|
|
1798
1796
|
CallExpression(node) {
|
|
1799
|
-
if (!
|
|
1797
|
+
if (!ER25__namespace.isCreateContextCall(context, node)) return;
|
|
1800
1798
|
createCalls.push(node);
|
|
1801
1799
|
},
|
|
1802
1800
|
"Program:exit"() {
|
|
1803
1801
|
for (const call of createCalls) {
|
|
1804
|
-
const id =
|
|
1802
|
+
const id = ER25__namespace.getInstanceId(call);
|
|
1805
1803
|
if (id == null) {
|
|
1806
1804
|
context.report({
|
|
1807
1805
|
messageId: "noMissingContextDisplayName",
|
|
@@ -1813,7 +1811,7 @@ function create31(context) {
|
|
|
1813
1811
|
const left = node.left;
|
|
1814
1812
|
if (left.type !== types.AST_NODE_TYPES.MemberExpression) return false;
|
|
1815
1813
|
const object = left.object;
|
|
1816
|
-
return
|
|
1814
|
+
return ER25__namespace.isInstanceIdEqual(context, id, object);
|
|
1817
1815
|
});
|
|
1818
1816
|
if (!hasDisplayNameAssignment) {
|
|
1819
1817
|
context.report({
|
|
@@ -1854,7 +1852,7 @@ function create32(context) {
|
|
|
1854
1852
|
switch (node.type) {
|
|
1855
1853
|
case types.AST_NODE_TYPES.JSXElement: {
|
|
1856
1854
|
const initialScope = context.sourceCode.getScope(node);
|
|
1857
|
-
if (!
|
|
1855
|
+
if (!ER25__namespace.hasAttribute(context, "key", node.openingElement.attributes, initialScope)) {
|
|
1858
1856
|
return {
|
|
1859
1857
|
messageId: "missingKey",
|
|
1860
1858
|
node
|
|
@@ -1911,7 +1909,7 @@ function create32(context) {
|
|
|
1911
1909
|
}
|
|
1912
1910
|
const initialScope = context.sourceCode.getScope(node);
|
|
1913
1911
|
for (const element of elements) {
|
|
1914
|
-
if (!
|
|
1912
|
+
if (!ER25__namespace.hasAttribute(context, "key", element.openingElement.attributes, initialScope)) {
|
|
1915
1913
|
report.send({
|
|
1916
1914
|
messageId: "missingKey",
|
|
1917
1915
|
node: element
|
|
@@ -1920,7 +1918,7 @@ function create32(context) {
|
|
|
1920
1918
|
}
|
|
1921
1919
|
},
|
|
1922
1920
|
CallExpression(node) {
|
|
1923
|
-
state.isWithinChildrenToArray ||=
|
|
1921
|
+
state.isWithinChildrenToArray ||= ER25__namespace.isChildrenToArrayCall(context, node);
|
|
1924
1922
|
if (state.isWithinChildrenToArray) return;
|
|
1925
1923
|
const callback = tsPattern.match(node).when(AST8__namespace.isArrayMapCall, (n) => n.arguments[0]).when(AST8__namespace.isArrayFromCall, (n) => n.arguments[1]).otherwise(() => null);
|
|
1926
1924
|
if (!AST8__namespace.isFunction(callback)) return;
|
|
@@ -1932,7 +1930,7 @@ function create32(context) {
|
|
|
1932
1930
|
report.send(checkExpression(body));
|
|
1933
1931
|
},
|
|
1934
1932
|
"CallExpression:exit"(node) {
|
|
1935
|
-
if (!
|
|
1933
|
+
if (!ER25__namespace.isChildrenToArrayCall(context, node)) {
|
|
1936
1934
|
return;
|
|
1937
1935
|
}
|
|
1938
1936
|
state.isWithinChildrenToArray = false;
|
|
@@ -1978,7 +1976,7 @@ function create33(context) {
|
|
|
1978
1976
|
const { importSource } = shared.getSettingsFromContext(context);
|
|
1979
1977
|
return {
|
|
1980
1978
|
CallExpression(node) {
|
|
1981
|
-
if (!
|
|
1979
|
+
if (!ER25__namespace.isCaptureOwnerStackCall(context, node)) return;
|
|
1982
1980
|
if (AST8__namespace.findParentNode(node, isDevelopmentOnlyCheck) == null) {
|
|
1983
1981
|
context.report({
|
|
1984
1982
|
messageId: "missingDevelopmentOnlyCheck",
|
|
@@ -2025,9 +2023,9 @@ var no_nested_component_definitions_default = createRule({
|
|
|
2025
2023
|
defaultOptions: []
|
|
2026
2024
|
});
|
|
2027
2025
|
function create34(context) {
|
|
2028
|
-
const hint =
|
|
2029
|
-
const collector =
|
|
2030
|
-
const collectorLegacy =
|
|
2026
|
+
const hint = ER25__namespace.ComponentDetectionHint.SkipArrayMapArgument | ER25__namespace.ComponentDetectionHint.SkipNullLiteral | ER25__namespace.ComponentDetectionHint.SkipUndefined | ER25__namespace.ComponentDetectionHint.SkipBooleanLiteral | ER25__namespace.ComponentDetectionHint.SkipStringLiteral | ER25__namespace.ComponentDetectionHint.SkipNumberLiteral | ER25__namespace.ComponentDetectionHint.StrictLogical | ER25__namespace.ComponentDetectionHint.StrictConditional;
|
|
2027
|
+
const collector = ER25__namespace.useComponentCollector(context, { hint });
|
|
2028
|
+
const collectorLegacy = ER25__namespace.useComponentCollectorLegacy();
|
|
2031
2029
|
return {
|
|
2032
2030
|
...collector.listeners,
|
|
2033
2031
|
...collectorLegacy.listeners,
|
|
@@ -2046,9 +2044,9 @@ function create34(context) {
|
|
|
2046
2044
|
};
|
|
2047
2045
|
for (const { name: name5, node: component } of functionComponents) {
|
|
2048
2046
|
if (name5 == null) continue;
|
|
2049
|
-
if (
|
|
2047
|
+
if (ER25__namespace.isDirectValueOfRenderPropertyLoose(component)) continue;
|
|
2050
2048
|
if (isInsideJSXAttributeValue(component)) {
|
|
2051
|
-
if (!
|
|
2049
|
+
if (!ER25__namespace.isDeclaredInRenderPropLoose(component)) {
|
|
2052
2050
|
context.report({
|
|
2053
2051
|
messageId: "noNestedComponentDefinitions",
|
|
2054
2052
|
node: component,
|
|
@@ -2072,7 +2070,7 @@ function create34(context) {
|
|
|
2072
2070
|
continue;
|
|
2073
2071
|
}
|
|
2074
2072
|
const parentComponent = AST8__namespace.findParentNode(component, isFunctionComponent);
|
|
2075
|
-
if (parentComponent != null && !
|
|
2073
|
+
if (parentComponent != null && !ER25__namespace.isDirectValueOfRenderPropertyLoose(parentComponent)) {
|
|
2076
2074
|
context.report({
|
|
2077
2075
|
messageId: "noNestedComponentDefinitions",
|
|
2078
2076
|
node: component,
|
|
@@ -2083,7 +2081,7 @@ function create34(context) {
|
|
|
2083
2081
|
});
|
|
2084
2082
|
continue;
|
|
2085
2083
|
}
|
|
2086
|
-
if (
|
|
2084
|
+
if (ER25__namespace.isInsideRenderMethod(component)) {
|
|
2087
2085
|
context.report({
|
|
2088
2086
|
messageId: "noNestedComponentDefinitions",
|
|
2089
2087
|
node: component,
|
|
@@ -2111,10 +2109,10 @@ function create34(context) {
|
|
|
2111
2109
|
};
|
|
2112
2110
|
}
|
|
2113
2111
|
function isInsideJSXAttributeValue(node) {
|
|
2114
|
-
return node.parent.type === types.AST_NODE_TYPES.JSXAttribute ||
|
|
2112
|
+
return node.parent.type === types.AST_NODE_TYPES.JSXAttribute || ER25__namespace.findParentAttribute(node, (n) => n.value?.type === types.AST_NODE_TYPES.JSXExpressionContainer) != null;
|
|
2115
2113
|
}
|
|
2116
2114
|
function isInsideCreateElementProps(context, node) {
|
|
2117
|
-
const call = AST8__namespace.findParentNode(node,
|
|
2115
|
+
const call = AST8__namespace.findParentNode(node, ER25__namespace.isCreateElementCall(context));
|
|
2118
2116
|
if (call == null) return false;
|
|
2119
2117
|
const prop = AST8__namespace.findParentNode(node, AST8__namespace.is(types.AST_NODE_TYPES.ObjectExpression));
|
|
2120
2118
|
if (prop == null) return false;
|
|
@@ -2139,15 +2137,15 @@ var no_nested_lazy_component_declarations_default = createRule({
|
|
|
2139
2137
|
defaultOptions: []
|
|
2140
2138
|
});
|
|
2141
2139
|
function create35(context) {
|
|
2142
|
-
const hint =
|
|
2143
|
-
const collector =
|
|
2144
|
-
const collectorLegacy =
|
|
2140
|
+
const hint = ER25__namespace.ComponentDetectionHint.None;
|
|
2141
|
+
const collector = ER25__namespace.useComponentCollector(context, { hint });
|
|
2142
|
+
const collectorLegacy = ER25__namespace.useComponentCollectorLegacy();
|
|
2145
2143
|
const lazyComponentDeclarations = /* @__PURE__ */ new Set();
|
|
2146
2144
|
return {
|
|
2147
2145
|
...collector.listeners,
|
|
2148
2146
|
...collectorLegacy.listeners,
|
|
2149
2147
|
ImportExpression(node) {
|
|
2150
|
-
const lazyCall = AST8__namespace.findParentNode(node, (n) =>
|
|
2148
|
+
const lazyCall = AST8__namespace.findParentNode(node, (n) => ER25__namespace.isLazyCall(context, n));
|
|
2151
2149
|
if (lazyCall != null) {
|
|
2152
2150
|
lazyComponentDeclarations.add(lazyCall);
|
|
2153
2151
|
}
|
|
@@ -2161,9 +2159,9 @@ function create35(context) {
|
|
|
2161
2159
|
];
|
|
2162
2160
|
for (const lazy of lazyComponentDeclarations) {
|
|
2163
2161
|
const significantParent = AST8__namespace.findParentNode(lazy, (n) => {
|
|
2164
|
-
if (
|
|
2162
|
+
if (ER25__namespace.isJSX(n)) return true;
|
|
2165
2163
|
if (n.type === types.AST_NODE_TYPES.CallExpression) {
|
|
2166
|
-
return
|
|
2164
|
+
return ER25__namespace.isReactHookCall(n) || ER25__namespace.isCreateElementCall(context, n) || ER25__namespace.isCreateContextCall(context, n);
|
|
2167
2165
|
}
|
|
2168
2166
|
if (AST8__namespace.isFunction(n)) {
|
|
2169
2167
|
return functionComponents.some((c) => c.node === n);
|
|
@@ -2217,17 +2215,17 @@ function create36(context) {
|
|
|
2217
2215
|
if (property.type !== types.AST_NODE_TYPES.Identifier || property.name !== "propTypes") {
|
|
2218
2216
|
return;
|
|
2219
2217
|
}
|
|
2220
|
-
if (!
|
|
2218
|
+
if (!ER25__namespace.isComponentNameLoose(object.name)) {
|
|
2221
2219
|
return;
|
|
2222
2220
|
}
|
|
2223
2221
|
const variable = VAR2__namespace.findVariable(object.name, context.sourceCode.getScope(node));
|
|
2224
2222
|
const variableNode = VAR2__namespace.getVariableInitNode(variable, 0);
|
|
2225
|
-
if (variableNode != null && (AST8__namespace.isFunction(variableNode) ||
|
|
2223
|
+
if (variableNode != null && (AST8__namespace.isFunction(variableNode) || ER25__namespace.isClassComponent(variableNode))) {
|
|
2226
2224
|
context.report({ messageId: "noPropTypes", node: property });
|
|
2227
2225
|
}
|
|
2228
2226
|
},
|
|
2229
2227
|
PropertyDefinition(node) {
|
|
2230
|
-
if (!
|
|
2228
|
+
if (!ER25__namespace.isClassComponent(node.parent.parent)) {
|
|
2231
2229
|
return;
|
|
2232
2230
|
}
|
|
2233
2231
|
if (!node.static || node.key.type !== types.AST_NODE_TYPES.Identifier || node.key.name !== "propTypes") {
|
|
@@ -2260,13 +2258,13 @@ var no_redundant_should_component_update_default = createRule({
|
|
|
2260
2258
|
});
|
|
2261
2259
|
function create37(context) {
|
|
2262
2260
|
if (!context.sourceCode.text.includes("shouldComponentUpdate")) return {};
|
|
2263
|
-
const { ctx, listeners } =
|
|
2261
|
+
const { ctx, listeners } = ER25__namespace.useComponentCollectorLegacy();
|
|
2264
2262
|
return {
|
|
2265
2263
|
...listeners,
|
|
2266
2264
|
"Program:exit"(program) {
|
|
2267
2265
|
const components = ctx.getAllComponents(program);
|
|
2268
2266
|
for (const { name: name5 = "PureComponent", node: component, flag } of components.values()) {
|
|
2269
|
-
if ((flag &
|
|
2267
|
+
if ((flag & ER25__namespace.ComponentFlag.PureComponent) === 0n) {
|
|
2270
2268
|
continue;
|
|
2271
2269
|
}
|
|
2272
2270
|
const { body } = component.body;
|
|
@@ -2307,11 +2305,11 @@ function create38(context) {
|
|
|
2307
2305
|
if (!context.sourceCode.text.includes("componentDidMount")) return {};
|
|
2308
2306
|
return {
|
|
2309
2307
|
CallExpression(node) {
|
|
2310
|
-
if (!
|
|
2308
|
+
if (!ER25__namespace.isThisSetState(node)) {
|
|
2311
2309
|
return;
|
|
2312
2310
|
}
|
|
2313
|
-
const clazz = AST8__namespace.findParentNode(node,
|
|
2314
|
-
const method = AST8__namespace.findParentNode(node, (n) => n === clazz ||
|
|
2311
|
+
const clazz = AST8__namespace.findParentNode(node, ER25__namespace.isClassComponent);
|
|
2312
|
+
const method = AST8__namespace.findParentNode(node, (n) => n === clazz || ER25__namespace.isComponentDidMount(n));
|
|
2315
2313
|
if (clazz == null || method == null || method === clazz) return;
|
|
2316
2314
|
const methodScope = context.sourceCode.getScope(method);
|
|
2317
2315
|
const upperScope = context.sourceCode.getScope(node).upper;
|
|
@@ -2346,11 +2344,11 @@ function create39(context) {
|
|
|
2346
2344
|
if (!context.sourceCode.text.includes("componentDidUpdate")) return {};
|
|
2347
2345
|
return {
|
|
2348
2346
|
CallExpression(node) {
|
|
2349
|
-
if (!
|
|
2347
|
+
if (!ER25__namespace.isThisSetState(node)) {
|
|
2350
2348
|
return;
|
|
2351
2349
|
}
|
|
2352
|
-
const clazz = AST8__namespace.findParentNode(node,
|
|
2353
|
-
const method = AST8__namespace.findParentNode(node, (n) => n === clazz ||
|
|
2350
|
+
const clazz = AST8__namespace.findParentNode(node, ER25__namespace.isClassComponent);
|
|
2351
|
+
const method = AST8__namespace.findParentNode(node, (n) => n === clazz || ER25__namespace.isComponentDidUpdate(n));
|
|
2354
2352
|
if (clazz == null || method == null || method === clazz) return;
|
|
2355
2353
|
const methodScope = context.sourceCode.getScope(method);
|
|
2356
2354
|
const upperScope = context.sourceCode.getScope(node).upper;
|
|
@@ -2385,11 +2383,11 @@ function create40(context) {
|
|
|
2385
2383
|
if (!context.sourceCode.text.includes("componentWillUpdate")) return {};
|
|
2386
2384
|
return {
|
|
2387
2385
|
CallExpression(node) {
|
|
2388
|
-
if (!
|
|
2386
|
+
if (!ER25__namespace.isThisSetState(node)) {
|
|
2389
2387
|
return;
|
|
2390
2388
|
}
|
|
2391
|
-
const clazz = AST8__namespace.findParentNode(node,
|
|
2392
|
-
const method = AST8__namespace.findParentNode(node, (n) => n === clazz ||
|
|
2389
|
+
const clazz = AST8__namespace.findParentNode(node, ER25__namespace.isClassComponent);
|
|
2390
|
+
const method = AST8__namespace.findParentNode(node, (n) => n === clazz || ER25__namespace.isComponentWillUpdate(n));
|
|
2393
2391
|
if (clazz == null || method == null || method === clazz) return;
|
|
2394
2392
|
const methodScope = context.sourceCode.getScope(method);
|
|
2395
2393
|
const upperScope = context.sourceCode.getScope(node).upper;
|
|
@@ -2428,7 +2426,7 @@ function create41(context) {
|
|
|
2428
2426
|
isWithinClassComponent: false
|
|
2429
2427
|
};
|
|
2430
2428
|
function onClassBodyEnter(node) {
|
|
2431
|
-
if (
|
|
2429
|
+
if (ER25__namespace.isClassComponent(node.parent)) {
|
|
2432
2430
|
state.isWithinClassComponent = true;
|
|
2433
2431
|
}
|
|
2434
2432
|
}
|
|
@@ -2490,7 +2488,7 @@ var no_unsafe_component_will_mount_default = createRule({
|
|
|
2490
2488
|
});
|
|
2491
2489
|
function create42(context) {
|
|
2492
2490
|
if (!context.sourceCode.text.includes("UNSAFE_componentWillMount")) return {};
|
|
2493
|
-
const { ctx, listeners } =
|
|
2491
|
+
const { ctx, listeners } = ER25__namespace.useComponentCollectorLegacy();
|
|
2494
2492
|
return {
|
|
2495
2493
|
...listeners,
|
|
2496
2494
|
"Program:exit"(program) {
|
|
@@ -2534,7 +2532,7 @@ function create43(context) {
|
|
|
2534
2532
|
if (!context.sourceCode.text.includes("UNSAFE_componentWillReceiveProps")) {
|
|
2535
2533
|
return {};
|
|
2536
2534
|
}
|
|
2537
|
-
const { ctx, listeners } =
|
|
2535
|
+
const { ctx, listeners } = ER25__namespace.useComponentCollectorLegacy();
|
|
2538
2536
|
return {
|
|
2539
2537
|
...listeners,
|
|
2540
2538
|
"Program:exit"(program) {
|
|
@@ -2576,7 +2574,7 @@ var no_unsafe_component_will_update_default = createRule({
|
|
|
2576
2574
|
});
|
|
2577
2575
|
function create44(context) {
|
|
2578
2576
|
if (!context.sourceCode.text.includes("UNSAFE_componentWillUpdate")) return {};
|
|
2579
|
-
const { ctx, listeners } =
|
|
2577
|
+
const { ctx, listeners } = ER25__namespace.useComponentCollectorLegacy();
|
|
2580
2578
|
return {
|
|
2581
2579
|
...listeners,
|
|
2582
2580
|
"Program:exit"(program) {
|
|
@@ -2616,12 +2614,12 @@ var no_unstable_context_value_default = createRule({
|
|
|
2616
2614
|
function create45(context) {
|
|
2617
2615
|
const { version: version2 } = shared.getSettingsFromContext(context);
|
|
2618
2616
|
const isReact18OrBelow = compareVersions.compare(version2, "19.0.0", "<");
|
|
2619
|
-
const { ctx, listeners } =
|
|
2617
|
+
const { ctx, listeners } = ER25__namespace.useComponentCollector(context);
|
|
2620
2618
|
const constructions = /* @__PURE__ */ new WeakMap();
|
|
2621
2619
|
return {
|
|
2622
2620
|
...listeners,
|
|
2623
2621
|
JSXOpeningElement(node) {
|
|
2624
|
-
const fullName =
|
|
2622
|
+
const fullName = ER25__namespace.getElementType(context, node.parent);
|
|
2625
2623
|
const selfName = fullName.split(".").at(-1);
|
|
2626
2624
|
if (selfName == null) return;
|
|
2627
2625
|
if (!isContextName(selfName, isReact18OrBelow)) return;
|
|
@@ -2637,7 +2635,7 @@ function create45(context) {
|
|
|
2637
2635
|
const initialScope = context.sourceCode.getScope(valueExpression);
|
|
2638
2636
|
const construction = VAR2__namespace.getConstructionDetectionResult(valueExpression, initialScope);
|
|
2639
2637
|
if (construction == null) return;
|
|
2640
|
-
if (
|
|
2638
|
+
if (ER25__namespace.isReactHookCall(construction.node)) {
|
|
2641
2639
|
return;
|
|
2642
2640
|
}
|
|
2643
2641
|
eff.getOrElseUpdate(constructions, functionEntry.node, () => []).push(construction);
|
|
@@ -2687,7 +2685,7 @@ var no_unstable_default_props_default = createRule({
|
|
|
2687
2685
|
defaultOptions: []
|
|
2688
2686
|
});
|
|
2689
2687
|
function create46(context) {
|
|
2690
|
-
const { ctx, listeners } =
|
|
2688
|
+
const { ctx, listeners } = ER25__namespace.useComponentCollector(context);
|
|
2691
2689
|
const declarators = /* @__PURE__ */ new WeakMap();
|
|
2692
2690
|
return {
|
|
2693
2691
|
...listeners,
|
|
@@ -2717,7 +2715,7 @@ function create46(context) {
|
|
|
2717
2715
|
if (construction == null) {
|
|
2718
2716
|
continue;
|
|
2719
2717
|
}
|
|
2720
|
-
if (
|
|
2718
|
+
if (ER25__namespace.isReactHookCall(construction.node)) {
|
|
2721
2719
|
continue;
|
|
2722
2720
|
}
|
|
2723
2721
|
const forbiddenType = AST8__namespace.toReadableNodeType(right);
|
|
@@ -2787,7 +2785,7 @@ function create47(context) {
|
|
|
2787
2785
|
const propertyUsages = /* @__PURE__ */ new WeakMap();
|
|
2788
2786
|
function classEnter(node) {
|
|
2789
2787
|
classEntries.push(node);
|
|
2790
|
-
if (!
|
|
2788
|
+
if (!ER25__namespace.isClassComponent(node)) {
|
|
2791
2789
|
return;
|
|
2792
2790
|
}
|
|
2793
2791
|
propertyDefs.set(node, /* @__PURE__ */ new Set());
|
|
@@ -2795,7 +2793,7 @@ function create47(context) {
|
|
|
2795
2793
|
}
|
|
2796
2794
|
function classExit() {
|
|
2797
2795
|
const currentClass = classEntries.pop();
|
|
2798
|
-
if (currentClass == null || !
|
|
2796
|
+
if (currentClass == null || !ER25__namespace.isClassComponent(currentClass)) {
|
|
2799
2797
|
return;
|
|
2800
2798
|
}
|
|
2801
2799
|
const className = AST8__namespace.getClassIdentifier(currentClass)?.name;
|
|
@@ -2825,7 +2823,7 @@ function create47(context) {
|
|
|
2825
2823
|
function methodEnter(node) {
|
|
2826
2824
|
methodEntries.push(node);
|
|
2827
2825
|
const currentClass = classEntries.at(-1);
|
|
2828
|
-
if (currentClass == null || !
|
|
2826
|
+
if (currentClass == null || !ER25__namespace.isClassComponent(currentClass)) {
|
|
2829
2827
|
return;
|
|
2830
2828
|
}
|
|
2831
2829
|
if (node.static) {
|
|
@@ -2849,7 +2847,7 @@ function create47(context) {
|
|
|
2849
2847
|
if (currentClass == null || currentMethod == null) {
|
|
2850
2848
|
return;
|
|
2851
2849
|
}
|
|
2852
|
-
if (!
|
|
2850
|
+
if (!ER25__namespace.isClassComponent(currentClass) || currentMethod.static) {
|
|
2853
2851
|
return;
|
|
2854
2852
|
}
|
|
2855
2853
|
if (!AST8__namespace.isThisExpression(node.object) || !isKeyLiteral2(node, node.property)) {
|
|
@@ -2874,7 +2872,7 @@ function create47(context) {
|
|
|
2874
2872
|
if (currentClass == null || currentMethod == null) {
|
|
2875
2873
|
return;
|
|
2876
2874
|
}
|
|
2877
|
-
if (!
|
|
2875
|
+
if (!ER25__namespace.isClassComponent(currentClass) || currentMethod.static) {
|
|
2878
2876
|
return;
|
|
2879
2877
|
}
|
|
2880
2878
|
if (node.init != null && AST8__namespace.isThisExpression(node.init) && node.id.type === types.AST_NODE_TYPES.ObjectPattern) {
|
|
@@ -2921,7 +2919,7 @@ function create48(context) {
|
|
|
2921
2919
|
}
|
|
2922
2920
|
function classExit() {
|
|
2923
2921
|
const currentClass = classEntries.pop();
|
|
2924
|
-
if (currentClass == null || !
|
|
2922
|
+
if (currentClass == null || !ER25__namespace.isClassComponent(currentClass)) {
|
|
2925
2923
|
return;
|
|
2926
2924
|
}
|
|
2927
2925
|
const className = AST8__namespace.getClassIdentifier(currentClass)?.name;
|
|
@@ -2940,11 +2938,11 @@ function create48(context) {
|
|
|
2940
2938
|
function methodEnter(node) {
|
|
2941
2939
|
methodEntries.push(node);
|
|
2942
2940
|
const currentClass = classEntries.at(-1);
|
|
2943
|
-
if (currentClass == null || !
|
|
2941
|
+
if (currentClass == null || !ER25__namespace.isClassComponent(currentClass)) {
|
|
2944
2942
|
return;
|
|
2945
2943
|
}
|
|
2946
2944
|
if (node.static) {
|
|
2947
|
-
if (
|
|
2945
|
+
if (ER25__namespace.isGetDerivedStateFromProps(node) && tsPattern.isMatching({ params: [tsPattern.P.nonNullable, ...tsPattern.P.array()] })(node.value)) {
|
|
2948
2946
|
const defNode = stateDefs.get(currentClass)?.node;
|
|
2949
2947
|
stateDefs.set(currentClass, { node: defNode, isUsed: true });
|
|
2950
2948
|
}
|
|
@@ -2965,11 +2963,11 @@ function create48(context) {
|
|
|
2965
2963
|
}
|
|
2966
2964
|
return {
|
|
2967
2965
|
AssignmentExpression(node) {
|
|
2968
|
-
if (!
|
|
2966
|
+
if (!ER25__namespace.isAssignmentToThisState(node)) {
|
|
2969
2967
|
return;
|
|
2970
2968
|
}
|
|
2971
2969
|
const currentClass = classEntries.at(-1);
|
|
2972
|
-
if (currentClass == null || !
|
|
2970
|
+
if (currentClass == null || !ER25__namespace.isClassComponent(currentClass)) {
|
|
2973
2971
|
return;
|
|
2974
2972
|
}
|
|
2975
2973
|
const currentConstructor = constructorEntries.at(-1);
|
|
@@ -2991,7 +2989,7 @@ function create48(context) {
|
|
|
2991
2989
|
return;
|
|
2992
2990
|
}
|
|
2993
2991
|
const currentClass = classEntries.at(-1);
|
|
2994
|
-
if (currentClass == null || !
|
|
2992
|
+
if (currentClass == null || !ER25__namespace.isClassComponent(currentClass)) {
|
|
2995
2993
|
return;
|
|
2996
2994
|
}
|
|
2997
2995
|
const currentMethod = methodEntries.at(-1);
|
|
@@ -3015,7 +3013,7 @@ function create48(context) {
|
|
|
3015
3013
|
"PropertyDefinition:exit": methodExit,
|
|
3016
3014
|
VariableDeclarator(node) {
|
|
3017
3015
|
const currentClass = classEntries.at(-1);
|
|
3018
|
-
if (currentClass == null || !
|
|
3016
|
+
if (currentClass == null || !ER25__namespace.isClassComponent(currentClass)) {
|
|
3019
3017
|
return;
|
|
3020
3018
|
}
|
|
3021
3019
|
const currentMethod = methodEntries.at(-1);
|
|
@@ -3075,10 +3073,10 @@ function create49(context) {
|
|
|
3075
3073
|
}
|
|
3076
3074
|
return {
|
|
3077
3075
|
CallExpression(node) {
|
|
3078
|
-
if (!
|
|
3076
|
+
if (!ER25__namespace.isReactHookCall(node)) {
|
|
3079
3077
|
return;
|
|
3080
3078
|
}
|
|
3081
|
-
if (!
|
|
3079
|
+
if (!ER25__namespace.isReactHookCallWithNameAlias(context, "useContext", [...useContextAlias])(node)) {
|
|
3082
3080
|
return;
|
|
3083
3081
|
}
|
|
3084
3082
|
context.report({
|
|
@@ -3165,7 +3163,7 @@ var no_useless_forward_ref_default = createRule({
|
|
|
3165
3163
|
function create50(context) {
|
|
3166
3164
|
return {
|
|
3167
3165
|
CallExpression(node) {
|
|
3168
|
-
if (!
|
|
3166
|
+
if (!ER25__namespace.isForwardRefCall(context, node)) {
|
|
3169
3167
|
return;
|
|
3170
3168
|
}
|
|
3171
3169
|
const [component] = node.arguments;
|
|
@@ -3217,7 +3215,7 @@ function create51(context, [option]) {
|
|
|
3217
3215
|
const { allowExpressions = true } = option;
|
|
3218
3216
|
return {
|
|
3219
3217
|
JSXElement(node) {
|
|
3220
|
-
if (!
|
|
3218
|
+
if (!ER25__namespace.isFragmentElement(context, node)) return;
|
|
3221
3219
|
checkNode(context, node, allowExpressions);
|
|
3222
3220
|
},
|
|
3223
3221
|
JSXFragment(node) {
|
|
@@ -3229,7 +3227,7 @@ function isWhiteSpace(node) {
|
|
|
3229
3227
|
return typeof node.value === "string" && node.raw.trim() === "";
|
|
3230
3228
|
}
|
|
3231
3229
|
function isPaddingSpaces(node) {
|
|
3232
|
-
return
|
|
3230
|
+
return ER25__namespace.isJsxText(node) && isWhiteSpace(node) && node.raw.includes("\n");
|
|
3233
3231
|
}
|
|
3234
3232
|
function trimLikeReact(text) {
|
|
3235
3233
|
const leadingSpaces = /^\s*/.exec(text)?.[0] ?? "";
|
|
@@ -3240,10 +3238,10 @@ function trimLikeReact(text) {
|
|
|
3240
3238
|
}
|
|
3241
3239
|
function checkNode(context, node, allowExpressions) {
|
|
3242
3240
|
const initialScope = context.sourceCode.getScope(node);
|
|
3243
|
-
if (
|
|
3241
|
+
if (ER25__namespace.isKeyedElement(context, node, initialScope)) {
|
|
3244
3242
|
return;
|
|
3245
3243
|
}
|
|
3246
|
-
if (
|
|
3244
|
+
if (ER25__namespace.isHostElement(context, node.parent)) {
|
|
3247
3245
|
context.report({
|
|
3248
3246
|
messageId: "uselessFragment",
|
|
3249
3247
|
node,
|
|
@@ -3267,7 +3265,7 @@ function checkNode(context, node, allowExpressions) {
|
|
|
3267
3265
|
const isChildElement = AST8__namespace.isOneOf([types.AST_NODE_TYPES.JSXElement, types.AST_NODE_TYPES.JSXFragment])(node.parent);
|
|
3268
3266
|
switch (true) {
|
|
3269
3267
|
// <Foo content={<>ee eeee eeee ...</>} />
|
|
3270
|
-
case (allowExpressions && !isChildElement && node.children.length === 1 &&
|
|
3268
|
+
case (allowExpressions && !isChildElement && node.children.length === 1 && ER25__namespace.isJsxText(node.children.at(0))): {
|
|
3271
3269
|
return;
|
|
3272
3270
|
}
|
|
3273
3271
|
// <Foo><>hello, world</></Foo>
|
|
@@ -3313,7 +3311,7 @@ function checkNode(context, node, allowExpressions) {
|
|
|
3313
3311
|
return;
|
|
3314
3312
|
}
|
|
3315
3313
|
function getFix2(context, node) {
|
|
3316
|
-
if (!canFix(node)) return null;
|
|
3314
|
+
if (!canFix(context, node)) return null;
|
|
3317
3315
|
return (fixer) => {
|
|
3318
3316
|
const opener = node.type === types.AST_NODE_TYPES.JSXFragment ? node.openingFragment : node.openingElement;
|
|
3319
3317
|
const closer = node.type === types.AST_NODE_TYPES.JSXFragment ? node.closingFragment : node.closingElement;
|
|
@@ -3321,14 +3319,14 @@ function getFix2(context, node) {
|
|
|
3321
3319
|
return fixer.replaceText(node, trimLikeReact(childrenText));
|
|
3322
3320
|
};
|
|
3323
3321
|
}
|
|
3324
|
-
function canFix(node) {
|
|
3322
|
+
function canFix(context, node) {
|
|
3325
3323
|
if (node.parent.type === types.AST_NODE_TYPES.JSXElement || node.parent.type === types.AST_NODE_TYPES.JSXFragment) {
|
|
3326
|
-
return
|
|
3324
|
+
return ER25__namespace.isHostElement(context, node.parent);
|
|
3327
3325
|
}
|
|
3328
3326
|
if (node.children.length === 0) {
|
|
3329
3327
|
return false;
|
|
3330
3328
|
}
|
|
3331
|
-
if (node.children.some((child) =>
|
|
3329
|
+
if (node.children.some((child) => ER25__namespace.isJsxText(child) && !isWhiteSpace(child) || AST8__namespace.is(types.AST_NODE_TYPES.JSXExpressionContainer)(child))) {
|
|
3332
3330
|
return false;
|
|
3333
3331
|
}
|
|
3334
3332
|
return true;
|
|
@@ -3355,7 +3353,7 @@ var prefer_destructuring_assignment_default = createRule({
|
|
|
3355
3353
|
defaultOptions: []
|
|
3356
3354
|
});
|
|
3357
3355
|
function create52(context) {
|
|
3358
|
-
const { ctx, listeners } =
|
|
3356
|
+
const { ctx, listeners } = ER25__namespace.useComponentCollector(context);
|
|
3359
3357
|
const memberExpressionWithNames = [];
|
|
3360
3358
|
return {
|
|
3361
3359
|
...listeners,
|
|
@@ -3374,7 +3372,7 @@ function create52(context) {
|
|
|
3374
3372
|
return false;
|
|
3375
3373
|
}
|
|
3376
3374
|
const id = AST8__namespace.getFunctionIdentifier(block);
|
|
3377
|
-
return id != null &&
|
|
3375
|
+
return id != null && ER25__namespace.isComponentNameLoose(id.name) && components.some((component) => component.node === block);
|
|
3378
3376
|
}
|
|
3379
3377
|
for (const [initialScope, memberExpression] of memberExpressionWithNames) {
|
|
3380
3378
|
let scope = initialScope;
|
|
@@ -3493,7 +3491,7 @@ var prefer_read_only_props_default = createRule({
|
|
|
3493
3491
|
});
|
|
3494
3492
|
function create54(context) {
|
|
3495
3493
|
const services = utils.ESLintUtils.getParserServices(context, false);
|
|
3496
|
-
const { ctx, listeners } =
|
|
3494
|
+
const { ctx, listeners } = ER25__namespace.useComponentCollector(context);
|
|
3497
3495
|
return {
|
|
3498
3496
|
...listeners,
|
|
3499
3497
|
"Program:exit"(program) {
|
|
@@ -3546,7 +3544,7 @@ function create55(context) {
|
|
|
3546
3544
|
return {
|
|
3547
3545
|
JSXAttribute(node) {
|
|
3548
3546
|
const { value } = node;
|
|
3549
|
-
const propName =
|
|
3547
|
+
const propName = ER25__namespace.getAttributeName(context, node);
|
|
3550
3548
|
const hasValueTrue = value?.type === types.AST_NODE_TYPES.JSXExpressionContainer && value.expression.type === types.AST_NODE_TYPES.Literal && value.expression.value === true;
|
|
3551
3549
|
if (!hasValueTrue) {
|
|
3552
3550
|
return;
|
|
@@ -3586,7 +3584,7 @@ var prefer_shorthand_fragment_default = createRule({
|
|
|
3586
3584
|
function create56(context) {
|
|
3587
3585
|
return {
|
|
3588
3586
|
JSXElement(node) {
|
|
3589
|
-
if (!
|
|
3587
|
+
if (!ER25__namespace.isFragmentElement(context, node)) return;
|
|
3590
3588
|
const hasAttributes = node.openingElement.attributes.length > 0;
|
|
3591
3589
|
if (hasAttributes) {
|
|
3592
3590
|
return;
|