eslint-plugin-react-x 1.46.0 → 1.47.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +113 -115
- package/dist/index.mjs +112 -113
- package/package.json +7 -8
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getDocsUrl, getSettingsFromContext, unsafeDecodeSettings, DEFAULT_ESLINT_REACT_SETTINGS } from '@eslint-react/shared';
|
|
2
|
-
import * as
|
|
2
|
+
import * as ER25 from '@eslint-react/core';
|
|
3
3
|
import { ESLintUtils } from '@typescript-eslint/utils';
|
|
4
4
|
import { JsxConfig, Report, SEL } from '@eslint-react/kit';
|
|
5
5
|
import { AST_NODE_TYPES } from '@typescript-eslint/types';
|
|
@@ -7,7 +7,6 @@ import * as VAR2 from '@eslint-react/var';
|
|
|
7
7
|
import { match, isMatching, P } from 'ts-pattern';
|
|
8
8
|
import ts, { JsxEmit } from 'typescript';
|
|
9
9
|
import * as AST8 from '@eslint-react/ast';
|
|
10
|
-
import * as ER22 from '@eslint-react/core';
|
|
11
10
|
import { flow, getOrElseUpdate, constTrue, constFalse, _ } from '@eslint-react/eff';
|
|
12
11
|
import { compare } from 'compare-versions';
|
|
13
12
|
import { getConstrainedTypeAtLocation, isTypeReadonly } from '@typescript-eslint/type-utils';
|
|
@@ -115,7 +114,7 @@ var settings3 = {
|
|
|
115
114
|
|
|
116
115
|
// package.json
|
|
117
116
|
var name4 = "eslint-plugin-react-x";
|
|
118
|
-
var version = "1.
|
|
117
|
+
var version = "1.47.0-beta.0";
|
|
119
118
|
var createRule = ESLintUtils.RuleCreator(getDocsUrl("x"));
|
|
120
119
|
|
|
121
120
|
// src/rules/avoid-shorthand-boolean.ts
|
|
@@ -146,7 +145,7 @@ function create(context) {
|
|
|
146
145
|
messageId: "avoidShorthandBoolean",
|
|
147
146
|
node,
|
|
148
147
|
data: {
|
|
149
|
-
propName:
|
|
148
|
+
propName: ER25.getAttributeName(context, node)
|
|
150
149
|
},
|
|
151
150
|
fix: (fixer) => fixer.insertTextAfter(node.name, `={true}`)
|
|
152
151
|
});
|
|
@@ -387,25 +386,25 @@ function create7(context) {
|
|
|
387
386
|
const setStateEntries = [];
|
|
388
387
|
return {
|
|
389
388
|
CallExpression(node) {
|
|
390
|
-
if (!
|
|
389
|
+
if (!ER25.isThisSetState(node)) {
|
|
391
390
|
return;
|
|
392
391
|
}
|
|
393
392
|
setStateEntries.push([node, false]);
|
|
394
393
|
},
|
|
395
394
|
"CallExpression:exit"(node) {
|
|
396
|
-
if (!
|
|
395
|
+
if (!ER25.isThisSetState(node)) {
|
|
397
396
|
return;
|
|
398
397
|
}
|
|
399
398
|
setStateEntries.pop();
|
|
400
399
|
},
|
|
401
400
|
ClassDeclaration(node) {
|
|
402
|
-
classEntries.push([node,
|
|
401
|
+
classEntries.push([node, ER25.isClassComponent(node)]);
|
|
403
402
|
},
|
|
404
403
|
"ClassDeclaration:exit"() {
|
|
405
404
|
classEntries.pop();
|
|
406
405
|
},
|
|
407
406
|
ClassExpression(node) {
|
|
408
|
-
classEntries.push([node,
|
|
407
|
+
classEntries.push([node, ER25.isClassComponent(node)]);
|
|
409
408
|
},
|
|
410
409
|
"ClassExpression:exit"() {
|
|
411
410
|
classEntries.pop();
|
|
@@ -489,7 +488,7 @@ function isUsingReactChildren(context, node) {
|
|
|
489
488
|
return true;
|
|
490
489
|
}
|
|
491
490
|
if (callee.object.type === AST_NODE_TYPES.MemberExpression && "name" in callee.object.object) {
|
|
492
|
-
return
|
|
491
|
+
return ER25.isInitializedFromReact(callee.object.object.name, importSource, initialScope);
|
|
493
492
|
}
|
|
494
493
|
return false;
|
|
495
494
|
}
|
|
@@ -555,7 +554,7 @@ function create8(context) {
|
|
|
555
554
|
return node.type === AST_NODE_TYPES.Identifier && indexParamNames.some((name5) => name5 != null && name5 === node.name);
|
|
556
555
|
}
|
|
557
556
|
function isCreateOrCloneElementCall(node) {
|
|
558
|
-
return
|
|
557
|
+
return ER25.isCreateElementCall(context, node) || ER25.isCloneElementCall(context, node);
|
|
559
558
|
}
|
|
560
559
|
function getReportDescriptors(node) {
|
|
561
560
|
switch (node.type) {
|
|
@@ -671,7 +670,7 @@ var no_children_count_default = createRule({
|
|
|
671
670
|
function create9(context) {
|
|
672
671
|
return {
|
|
673
672
|
MemberExpression(node) {
|
|
674
|
-
if (
|
|
673
|
+
if (ER25.isChildrenCount(context, node)) {
|
|
675
674
|
context.report({
|
|
676
675
|
messageId: "noChildrenCount",
|
|
677
676
|
node: node.property
|
|
@@ -701,7 +700,7 @@ var no_children_for_each_default = createRule({
|
|
|
701
700
|
function create10(context) {
|
|
702
701
|
return {
|
|
703
702
|
MemberExpression(node) {
|
|
704
|
-
if (
|
|
703
|
+
if (ER25.isChildrenForEach(context, node)) {
|
|
705
704
|
context.report({
|
|
706
705
|
messageId: "noChildrenForEach",
|
|
707
706
|
node: node.property
|
|
@@ -731,7 +730,7 @@ var no_children_map_default = createRule({
|
|
|
731
730
|
function create11(context) {
|
|
732
731
|
return {
|
|
733
732
|
MemberExpression(node) {
|
|
734
|
-
if (
|
|
733
|
+
if (ER25.isChildrenMap(context, node)) {
|
|
735
734
|
context.report({
|
|
736
735
|
messageId: "noChildrenMap",
|
|
737
736
|
node: node.property
|
|
@@ -761,7 +760,7 @@ var no_children_only_default = createRule({
|
|
|
761
760
|
function create12(context) {
|
|
762
761
|
return {
|
|
763
762
|
MemberExpression(node) {
|
|
764
|
-
if (
|
|
763
|
+
if (ER25.isChildrenOnly(context, node)) {
|
|
765
764
|
context.report({
|
|
766
765
|
messageId: "noChildrenOnly",
|
|
767
766
|
node: node.property
|
|
@@ -792,7 +791,7 @@ function create13(context) {
|
|
|
792
791
|
return {
|
|
793
792
|
JSXElement(node) {
|
|
794
793
|
const attributes = node.openingElement.attributes;
|
|
795
|
-
const childrenProp =
|
|
794
|
+
const childrenProp = ER25.getAttribute(context, "children", attributes, context.sourceCode.getScope(node));
|
|
796
795
|
if (childrenProp != null) {
|
|
797
796
|
context.report({
|
|
798
797
|
messageId: "noChildrenProp",
|
|
@@ -823,7 +822,7 @@ var no_children_to_array_default = createRule({
|
|
|
823
822
|
function create14(context) {
|
|
824
823
|
return {
|
|
825
824
|
MemberExpression(node) {
|
|
826
|
-
if (
|
|
825
|
+
if (ER25.isChildrenToArray(context, node)) {
|
|
827
826
|
context.report({
|
|
828
827
|
messageId: "noChildrenToArray",
|
|
829
828
|
node: node.property
|
|
@@ -852,13 +851,13 @@ var no_class_component_default = createRule({
|
|
|
852
851
|
});
|
|
853
852
|
function create15(context) {
|
|
854
853
|
if (!context.sourceCode.text.includes("Component")) return {};
|
|
855
|
-
const { ctx, listeners } =
|
|
854
|
+
const { ctx, listeners } = ER25.useComponentCollectorLegacy();
|
|
856
855
|
return {
|
|
857
856
|
...listeners,
|
|
858
857
|
"Program:exit"(program) {
|
|
859
858
|
const components = ctx.getAllComponents(program);
|
|
860
859
|
for (const { name: name5 = "anonymous", node: component } of components.values()) {
|
|
861
|
-
if (component.body.body.some((m) =>
|
|
860
|
+
if (component.body.body.some((m) => ER25.isComponentDidCatch(m) || ER25.isGetDerivedStateFromError(m))) {
|
|
862
861
|
continue;
|
|
863
862
|
}
|
|
864
863
|
context.report({
|
|
@@ -893,7 +892,7 @@ var no_clone_element_default = createRule({
|
|
|
893
892
|
function create16(context) {
|
|
894
893
|
return {
|
|
895
894
|
CallExpression(node) {
|
|
896
|
-
if (
|
|
895
|
+
if (ER25.isCloneElementCall(context, node)) {
|
|
897
896
|
context.report({
|
|
898
897
|
messageId: "noCloneElement",
|
|
899
898
|
node
|
|
@@ -1016,7 +1015,7 @@ var no_component_will_mount_default = createRule({
|
|
|
1016
1015
|
});
|
|
1017
1016
|
function create19(context) {
|
|
1018
1017
|
if (!context.sourceCode.text.includes("componentWillMount")) return {};
|
|
1019
|
-
const { ctx, listeners } =
|
|
1018
|
+
const { ctx, listeners } = ER25.useComponentCollectorLegacy();
|
|
1020
1019
|
return {
|
|
1021
1020
|
...listeners,
|
|
1022
1021
|
"Program:exit"(program) {
|
|
@@ -1024,7 +1023,7 @@ function create19(context) {
|
|
|
1024
1023
|
for (const { node: component } of components.values()) {
|
|
1025
1024
|
const { body } = component.body;
|
|
1026
1025
|
for (const member of body) {
|
|
1027
|
-
if (
|
|
1026
|
+
if (ER25.isComponentWillMount(member)) {
|
|
1028
1027
|
context.report({
|
|
1029
1028
|
messageId: "noComponentWillMount",
|
|
1030
1029
|
node: member,
|
|
@@ -1064,7 +1063,7 @@ var no_component_will_receive_props_default = createRule({
|
|
|
1064
1063
|
});
|
|
1065
1064
|
function create20(context) {
|
|
1066
1065
|
if (!context.sourceCode.text.includes("componentWillReceiveProps")) return {};
|
|
1067
|
-
const { ctx, listeners } =
|
|
1066
|
+
const { ctx, listeners } = ER25.useComponentCollectorLegacy();
|
|
1068
1067
|
return {
|
|
1069
1068
|
...listeners,
|
|
1070
1069
|
"Program:exit"(program) {
|
|
@@ -1072,7 +1071,7 @@ function create20(context) {
|
|
|
1072
1071
|
for (const { node: component } of components.values()) {
|
|
1073
1072
|
const { body } = component.body;
|
|
1074
1073
|
for (const member of body) {
|
|
1075
|
-
if (
|
|
1074
|
+
if (ER25.isComponentWillReceiveProps(member)) {
|
|
1076
1075
|
context.report({
|
|
1077
1076
|
messageId: "noComponentWillReceiveProps",
|
|
1078
1077
|
node: member,
|
|
@@ -1112,7 +1111,7 @@ var no_component_will_update_default = createRule({
|
|
|
1112
1111
|
});
|
|
1113
1112
|
function create21(context) {
|
|
1114
1113
|
if (!context.sourceCode.text.includes("componentWillUpdate")) return {};
|
|
1115
|
-
const { ctx, listeners } =
|
|
1114
|
+
const { ctx, listeners } = ER25.useComponentCollectorLegacy();
|
|
1116
1115
|
return {
|
|
1117
1116
|
...listeners,
|
|
1118
1117
|
"Program:exit"(program) {
|
|
@@ -1120,7 +1119,7 @@ function create21(context) {
|
|
|
1120
1119
|
for (const { node: component } of components.values()) {
|
|
1121
1120
|
const { body } = component.body;
|
|
1122
1121
|
for (const member of body) {
|
|
1123
|
-
if (
|
|
1122
|
+
if (ER25.isComponentWillUpdate(member)) {
|
|
1124
1123
|
context.report({
|
|
1125
1124
|
messageId: "noComponentWillUpdate",
|
|
1126
1125
|
node: member,
|
|
@@ -1164,7 +1163,7 @@ function create22(context) {
|
|
|
1164
1163
|
if (compare(version2, "19.0.0", "<")) return {};
|
|
1165
1164
|
return {
|
|
1166
1165
|
JSXElement(node) {
|
|
1167
|
-
const fullName =
|
|
1166
|
+
const fullName = ER25.getElementType(context, node);
|
|
1168
1167
|
const parts = fullName.split(".");
|
|
1169
1168
|
const selfName = parts.pop();
|
|
1170
1169
|
const contextFullName = parts.join(".");
|
|
@@ -1175,7 +1174,7 @@ function create22(context) {
|
|
|
1175
1174
|
messageId: "noContextProvider",
|
|
1176
1175
|
node,
|
|
1177
1176
|
fix(fixer) {
|
|
1178
|
-
if (!
|
|
1177
|
+
if (!ER25.isComponentNameLoose(contextSelfName)) return null;
|
|
1179
1178
|
const openingElement = node.openingElement;
|
|
1180
1179
|
const closingElement = node.closingElement;
|
|
1181
1180
|
if (closingElement == null) {
|
|
@@ -1211,7 +1210,7 @@ var no_create_ref_default = createRule({
|
|
|
1211
1210
|
function create23(context) {
|
|
1212
1211
|
return {
|
|
1213
1212
|
CallExpression(node) {
|
|
1214
|
-
if (
|
|
1213
|
+
if (ER25.isCreateRefCall(context, node) && AST8.findParentNode(node, ER25.isClassComponent) == null) {
|
|
1215
1214
|
context.report({ messageId: "noCreateRef", node });
|
|
1216
1215
|
}
|
|
1217
1216
|
}
|
|
@@ -1249,17 +1248,17 @@ function create24(context) {
|
|
|
1249
1248
|
if (property.type !== AST_NODE_TYPES.Identifier || property.name !== "defaultProps") {
|
|
1250
1249
|
return;
|
|
1251
1250
|
}
|
|
1252
|
-
if (!
|
|
1251
|
+
if (!ER25.isComponentNameLoose(object.name)) {
|
|
1253
1252
|
return;
|
|
1254
1253
|
}
|
|
1255
1254
|
const variable = VAR2.findVariable(object.name, context.sourceCode.getScope(node));
|
|
1256
1255
|
const variableNode = VAR2.getVariableInitNode(variable, 0);
|
|
1257
1256
|
if (variableNode == null) return;
|
|
1258
|
-
if (!AST8.isFunction(variableNode) && !
|
|
1257
|
+
if (!AST8.isFunction(variableNode) && !ER25.isClassComponent(variableNode)) return;
|
|
1259
1258
|
context.report({ messageId: "noDefaultProps", node: property });
|
|
1260
1259
|
},
|
|
1261
1260
|
PropertyDefinition(node) {
|
|
1262
|
-
if (!
|
|
1261
|
+
if (!ER25.isClassComponent(node.parent.parent)) {
|
|
1263
1262
|
return;
|
|
1264
1263
|
}
|
|
1265
1264
|
if (!node.static || node.key.type !== AST_NODE_TYPES.Identifier || node.key.name !== "defaultProps") {
|
|
@@ -1293,7 +1292,7 @@ var no_direct_mutation_state_default = createRule({
|
|
|
1293
1292
|
function create25(context) {
|
|
1294
1293
|
return {
|
|
1295
1294
|
AssignmentExpression(node) {
|
|
1296
|
-
if (!
|
|
1295
|
+
if (!ER25.isAssignmentToThisState(node)) return;
|
|
1297
1296
|
const parentClass = AST8.findParentNode(
|
|
1298
1297
|
node,
|
|
1299
1298
|
AST8.isOneOf([
|
|
@@ -1302,7 +1301,7 @@ function create25(context) {
|
|
|
1302
1301
|
])
|
|
1303
1302
|
);
|
|
1304
1303
|
if (parentClass == null) return;
|
|
1305
|
-
if (
|
|
1304
|
+
if (ER25.isClassComponent(parentClass) && context.sourceCode.getScope(node).block !== AST8.findParentNode(node, isConstructorFunction)) {
|
|
1306
1305
|
context.report({
|
|
1307
1306
|
messageId: "noDirectMutationState",
|
|
1308
1307
|
node
|
|
@@ -1424,7 +1423,7 @@ function create27(context) {
|
|
|
1424
1423
|
}
|
|
1425
1424
|
return {
|
|
1426
1425
|
CallExpression(node) {
|
|
1427
|
-
if (!
|
|
1426
|
+
if (!ER25.isForwardRefCall(context, node)) {
|
|
1428
1427
|
return;
|
|
1429
1428
|
}
|
|
1430
1429
|
context.report({
|
|
@@ -1526,7 +1525,7 @@ function create28(context) {
|
|
|
1526
1525
|
return {
|
|
1527
1526
|
JSXOpeningElement(node) {
|
|
1528
1527
|
const initialScope = context.sourceCode.getScope(node);
|
|
1529
|
-
const keyPropFound =
|
|
1528
|
+
const keyPropFound = ER25.getAttribute(context, "key", node.attributes, initialScope);
|
|
1530
1529
|
const keyPropOnElement = node.attributes.some(
|
|
1531
1530
|
(n) => n.type === AST_NODE_TYPES.JSXAttribute && n.name.type === AST_NODE_TYPES.JSXIdentifier && n.name.name === "key"
|
|
1532
1531
|
);
|
|
@@ -1714,12 +1713,12 @@ function create30(context) {
|
|
|
1714
1713
|
const {
|
|
1715
1714
|
ctx,
|
|
1716
1715
|
listeners
|
|
1717
|
-
} =
|
|
1716
|
+
} = ER25.useComponentCollector(
|
|
1718
1717
|
context,
|
|
1719
1718
|
{
|
|
1720
1719
|
collectDisplayName: true,
|
|
1721
1720
|
collectHookCalls: false,
|
|
1722
|
-
hint:
|
|
1721
|
+
hint: ER25.DEFAULT_COMPONENT_DETECTION_HINT
|
|
1723
1722
|
}
|
|
1724
1723
|
);
|
|
1725
1724
|
return {
|
|
@@ -1727,7 +1726,7 @@ function create30(context) {
|
|
|
1727
1726
|
"Program:exit"(program) {
|
|
1728
1727
|
const components = ctx.getAllComponents(program);
|
|
1729
1728
|
for (const { node, displayName, flag } of components.values()) {
|
|
1730
|
-
const isMemoOrForwardRef = (flag & (
|
|
1729
|
+
const isMemoOrForwardRef = (flag & (ER25.ComponentFlag.ForwardRef | ER25.ComponentFlag.Memo)) > 0n;
|
|
1731
1730
|
if (AST8.getFunctionIdentifier(node) != null) {
|
|
1732
1731
|
continue;
|
|
1733
1732
|
}
|
|
@@ -1768,12 +1767,12 @@ function create31(context) {
|
|
|
1768
1767
|
const displayNameAssignments = [];
|
|
1769
1768
|
return {
|
|
1770
1769
|
CallExpression(node) {
|
|
1771
|
-
if (!
|
|
1770
|
+
if (!ER25.isCreateContextCall(context, node)) return;
|
|
1772
1771
|
createCalls.push(node);
|
|
1773
1772
|
},
|
|
1774
1773
|
"Program:exit"() {
|
|
1775
1774
|
for (const call of createCalls) {
|
|
1776
|
-
const id =
|
|
1775
|
+
const id = ER25.getInstanceId(call);
|
|
1777
1776
|
if (id == null) {
|
|
1778
1777
|
context.report({
|
|
1779
1778
|
messageId: "noMissingContextDisplayName",
|
|
@@ -1785,7 +1784,7 @@ function create31(context) {
|
|
|
1785
1784
|
const left = node.left;
|
|
1786
1785
|
if (left.type !== AST_NODE_TYPES.MemberExpression) return false;
|
|
1787
1786
|
const object = left.object;
|
|
1788
|
-
return
|
|
1787
|
+
return ER25.isInstanceIdEqual(context, id, object);
|
|
1789
1788
|
});
|
|
1790
1789
|
if (!hasDisplayNameAssignment) {
|
|
1791
1790
|
context.report({
|
|
@@ -1826,7 +1825,7 @@ function create32(context) {
|
|
|
1826
1825
|
switch (node.type) {
|
|
1827
1826
|
case AST_NODE_TYPES.JSXElement: {
|
|
1828
1827
|
const initialScope = context.sourceCode.getScope(node);
|
|
1829
|
-
if (!
|
|
1828
|
+
if (!ER25.hasAttribute(context, "key", node.openingElement.attributes, initialScope)) {
|
|
1830
1829
|
return {
|
|
1831
1830
|
messageId: "missingKey",
|
|
1832
1831
|
node
|
|
@@ -1883,7 +1882,7 @@ function create32(context) {
|
|
|
1883
1882
|
}
|
|
1884
1883
|
const initialScope = context.sourceCode.getScope(node);
|
|
1885
1884
|
for (const element of elements) {
|
|
1886
|
-
if (!
|
|
1885
|
+
if (!ER25.hasAttribute(context, "key", element.openingElement.attributes, initialScope)) {
|
|
1887
1886
|
report.send({
|
|
1888
1887
|
messageId: "missingKey",
|
|
1889
1888
|
node: element
|
|
@@ -1892,7 +1891,7 @@ function create32(context) {
|
|
|
1892
1891
|
}
|
|
1893
1892
|
},
|
|
1894
1893
|
CallExpression(node) {
|
|
1895
|
-
state.isWithinChildrenToArray ||=
|
|
1894
|
+
state.isWithinChildrenToArray ||= ER25.isChildrenToArrayCall(context, node);
|
|
1896
1895
|
if (state.isWithinChildrenToArray) return;
|
|
1897
1896
|
const callback = match(node).when(AST8.isArrayMapCall, (n) => n.arguments[0]).when(AST8.isArrayFromCall, (n) => n.arguments[1]).otherwise(() => null);
|
|
1898
1897
|
if (!AST8.isFunction(callback)) return;
|
|
@@ -1904,7 +1903,7 @@ function create32(context) {
|
|
|
1904
1903
|
report.send(checkExpression(body));
|
|
1905
1904
|
},
|
|
1906
1905
|
"CallExpression:exit"(node) {
|
|
1907
|
-
if (!
|
|
1906
|
+
if (!ER25.isChildrenToArrayCall(context, node)) {
|
|
1908
1907
|
return;
|
|
1909
1908
|
}
|
|
1910
1909
|
state.isWithinChildrenToArray = false;
|
|
@@ -1950,7 +1949,7 @@ function create33(context) {
|
|
|
1950
1949
|
const { importSource } = getSettingsFromContext(context);
|
|
1951
1950
|
return {
|
|
1952
1951
|
CallExpression(node) {
|
|
1953
|
-
if (!
|
|
1952
|
+
if (!ER25.isCaptureOwnerStackCall(context, node)) return;
|
|
1954
1953
|
if (AST8.findParentNode(node, isDevelopmentOnlyCheck) == null) {
|
|
1955
1954
|
context.report({
|
|
1956
1955
|
messageId: "missingDevelopmentOnlyCheck",
|
|
@@ -1997,9 +1996,9 @@ var no_nested_component_definitions_default = createRule({
|
|
|
1997
1996
|
defaultOptions: []
|
|
1998
1997
|
});
|
|
1999
1998
|
function create34(context) {
|
|
2000
|
-
const hint =
|
|
2001
|
-
const collector =
|
|
2002
|
-
const collectorLegacy =
|
|
1999
|
+
const hint = ER25.ComponentDetectionHint.SkipArrayMapArgument | ER25.ComponentDetectionHint.SkipNullLiteral | ER25.ComponentDetectionHint.SkipUndefined | ER25.ComponentDetectionHint.SkipBooleanLiteral | ER25.ComponentDetectionHint.SkipStringLiteral | ER25.ComponentDetectionHint.SkipNumberLiteral | ER25.ComponentDetectionHint.StrictLogical | ER25.ComponentDetectionHint.StrictConditional;
|
|
2000
|
+
const collector = ER25.useComponentCollector(context, { hint });
|
|
2001
|
+
const collectorLegacy = ER25.useComponentCollectorLegacy();
|
|
2003
2002
|
return {
|
|
2004
2003
|
...collector.listeners,
|
|
2005
2004
|
...collectorLegacy.listeners,
|
|
@@ -2018,9 +2017,9 @@ function create34(context) {
|
|
|
2018
2017
|
};
|
|
2019
2018
|
for (const { name: name5, node: component } of functionComponents) {
|
|
2020
2019
|
if (name5 == null) continue;
|
|
2021
|
-
if (
|
|
2020
|
+
if (ER25.isDirectValueOfRenderPropertyLoose(component)) continue;
|
|
2022
2021
|
if (isInsideJSXAttributeValue(component)) {
|
|
2023
|
-
if (!
|
|
2022
|
+
if (!ER25.isDeclaredInRenderPropLoose(component)) {
|
|
2024
2023
|
context.report({
|
|
2025
2024
|
messageId: "noNestedComponentDefinitions",
|
|
2026
2025
|
node: component,
|
|
@@ -2044,7 +2043,7 @@ function create34(context) {
|
|
|
2044
2043
|
continue;
|
|
2045
2044
|
}
|
|
2046
2045
|
const parentComponent = AST8.findParentNode(component, isFunctionComponent);
|
|
2047
|
-
if (parentComponent != null && !
|
|
2046
|
+
if (parentComponent != null && !ER25.isDirectValueOfRenderPropertyLoose(parentComponent)) {
|
|
2048
2047
|
context.report({
|
|
2049
2048
|
messageId: "noNestedComponentDefinitions",
|
|
2050
2049
|
node: component,
|
|
@@ -2055,7 +2054,7 @@ function create34(context) {
|
|
|
2055
2054
|
});
|
|
2056
2055
|
continue;
|
|
2057
2056
|
}
|
|
2058
|
-
if (
|
|
2057
|
+
if (ER25.isInsideRenderMethod(component)) {
|
|
2059
2058
|
context.report({
|
|
2060
2059
|
messageId: "noNestedComponentDefinitions",
|
|
2061
2060
|
node: component,
|
|
@@ -2083,10 +2082,10 @@ function create34(context) {
|
|
|
2083
2082
|
};
|
|
2084
2083
|
}
|
|
2085
2084
|
function isInsideJSXAttributeValue(node) {
|
|
2086
|
-
return node.parent.type === AST_NODE_TYPES.JSXAttribute ||
|
|
2085
|
+
return node.parent.type === AST_NODE_TYPES.JSXAttribute || ER25.findParentAttribute(node, (n) => n.value?.type === AST_NODE_TYPES.JSXExpressionContainer) != null;
|
|
2087
2086
|
}
|
|
2088
2087
|
function isInsideCreateElementProps(context, node) {
|
|
2089
|
-
const call = AST8.findParentNode(node,
|
|
2088
|
+
const call = AST8.findParentNode(node, ER25.isCreateElementCall(context));
|
|
2090
2089
|
if (call == null) return false;
|
|
2091
2090
|
const prop = AST8.findParentNode(node, AST8.is(AST_NODE_TYPES.ObjectExpression));
|
|
2092
2091
|
if (prop == null) return false;
|
|
@@ -2111,15 +2110,15 @@ var no_nested_lazy_component_declarations_default = createRule({
|
|
|
2111
2110
|
defaultOptions: []
|
|
2112
2111
|
});
|
|
2113
2112
|
function create35(context) {
|
|
2114
|
-
const hint =
|
|
2115
|
-
const collector =
|
|
2116
|
-
const collectorLegacy =
|
|
2113
|
+
const hint = ER25.ComponentDetectionHint.None;
|
|
2114
|
+
const collector = ER25.useComponentCollector(context, { hint });
|
|
2115
|
+
const collectorLegacy = ER25.useComponentCollectorLegacy();
|
|
2117
2116
|
const lazyComponentDeclarations = /* @__PURE__ */ new Set();
|
|
2118
2117
|
return {
|
|
2119
2118
|
...collector.listeners,
|
|
2120
2119
|
...collectorLegacy.listeners,
|
|
2121
2120
|
ImportExpression(node) {
|
|
2122
|
-
const lazyCall = AST8.findParentNode(node, (n) =>
|
|
2121
|
+
const lazyCall = AST8.findParentNode(node, (n) => ER25.isLazyCall(context, n));
|
|
2123
2122
|
if (lazyCall != null) {
|
|
2124
2123
|
lazyComponentDeclarations.add(lazyCall);
|
|
2125
2124
|
}
|
|
@@ -2133,9 +2132,9 @@ function create35(context) {
|
|
|
2133
2132
|
];
|
|
2134
2133
|
for (const lazy of lazyComponentDeclarations) {
|
|
2135
2134
|
const significantParent = AST8.findParentNode(lazy, (n) => {
|
|
2136
|
-
if (
|
|
2135
|
+
if (ER25.isJSX(n)) return true;
|
|
2137
2136
|
if (n.type === AST_NODE_TYPES.CallExpression) {
|
|
2138
|
-
return
|
|
2137
|
+
return ER25.isReactHookCall(n) || ER25.isCreateElementCall(context, n) || ER25.isCreateContextCall(context, n);
|
|
2139
2138
|
}
|
|
2140
2139
|
if (AST8.isFunction(n)) {
|
|
2141
2140
|
return functionComponents.some((c) => c.node === n);
|
|
@@ -2189,17 +2188,17 @@ function create36(context) {
|
|
|
2189
2188
|
if (property.type !== AST_NODE_TYPES.Identifier || property.name !== "propTypes") {
|
|
2190
2189
|
return;
|
|
2191
2190
|
}
|
|
2192
|
-
if (!
|
|
2191
|
+
if (!ER25.isComponentNameLoose(object.name)) {
|
|
2193
2192
|
return;
|
|
2194
2193
|
}
|
|
2195
2194
|
const variable = VAR2.findVariable(object.name, context.sourceCode.getScope(node));
|
|
2196
2195
|
const variableNode = VAR2.getVariableInitNode(variable, 0);
|
|
2197
|
-
if (variableNode != null && (AST8.isFunction(variableNode) ||
|
|
2196
|
+
if (variableNode != null && (AST8.isFunction(variableNode) || ER25.isClassComponent(variableNode))) {
|
|
2198
2197
|
context.report({ messageId: "noPropTypes", node: property });
|
|
2199
2198
|
}
|
|
2200
2199
|
},
|
|
2201
2200
|
PropertyDefinition(node) {
|
|
2202
|
-
if (!
|
|
2201
|
+
if (!ER25.isClassComponent(node.parent.parent)) {
|
|
2203
2202
|
return;
|
|
2204
2203
|
}
|
|
2205
2204
|
if (!node.static || node.key.type !== AST_NODE_TYPES.Identifier || node.key.name !== "propTypes") {
|
|
@@ -2232,13 +2231,13 @@ var no_redundant_should_component_update_default = createRule({
|
|
|
2232
2231
|
});
|
|
2233
2232
|
function create37(context) {
|
|
2234
2233
|
if (!context.sourceCode.text.includes("shouldComponentUpdate")) return {};
|
|
2235
|
-
const { ctx, listeners } =
|
|
2234
|
+
const { ctx, listeners } = ER25.useComponentCollectorLegacy();
|
|
2236
2235
|
return {
|
|
2237
2236
|
...listeners,
|
|
2238
2237
|
"Program:exit"(program) {
|
|
2239
2238
|
const components = ctx.getAllComponents(program);
|
|
2240
2239
|
for (const { name: name5 = "PureComponent", node: component, flag } of components.values()) {
|
|
2241
|
-
if ((flag &
|
|
2240
|
+
if ((flag & ER25.ComponentFlag.PureComponent) === 0n) {
|
|
2242
2241
|
continue;
|
|
2243
2242
|
}
|
|
2244
2243
|
const { body } = component.body;
|
|
@@ -2279,11 +2278,11 @@ function create38(context) {
|
|
|
2279
2278
|
if (!context.sourceCode.text.includes("componentDidMount")) return {};
|
|
2280
2279
|
return {
|
|
2281
2280
|
CallExpression(node) {
|
|
2282
|
-
if (!
|
|
2281
|
+
if (!ER25.isThisSetState(node)) {
|
|
2283
2282
|
return;
|
|
2284
2283
|
}
|
|
2285
|
-
const clazz = AST8.findParentNode(node,
|
|
2286
|
-
const method = AST8.findParentNode(node, (n) => n === clazz ||
|
|
2284
|
+
const clazz = AST8.findParentNode(node, ER25.isClassComponent);
|
|
2285
|
+
const method = AST8.findParentNode(node, (n) => n === clazz || ER25.isComponentDidMount(n));
|
|
2287
2286
|
if (clazz == null || method == null || method === clazz) return;
|
|
2288
2287
|
const methodScope = context.sourceCode.getScope(method);
|
|
2289
2288
|
const upperScope = context.sourceCode.getScope(node).upper;
|
|
@@ -2318,11 +2317,11 @@ function create39(context) {
|
|
|
2318
2317
|
if (!context.sourceCode.text.includes("componentDidUpdate")) return {};
|
|
2319
2318
|
return {
|
|
2320
2319
|
CallExpression(node) {
|
|
2321
|
-
if (!
|
|
2320
|
+
if (!ER25.isThisSetState(node)) {
|
|
2322
2321
|
return;
|
|
2323
2322
|
}
|
|
2324
|
-
const clazz = AST8.findParentNode(node,
|
|
2325
|
-
const method = AST8.findParentNode(node, (n) => n === clazz ||
|
|
2323
|
+
const clazz = AST8.findParentNode(node, ER25.isClassComponent);
|
|
2324
|
+
const method = AST8.findParentNode(node, (n) => n === clazz || ER25.isComponentDidUpdate(n));
|
|
2326
2325
|
if (clazz == null || method == null || method === clazz) return;
|
|
2327
2326
|
const methodScope = context.sourceCode.getScope(method);
|
|
2328
2327
|
const upperScope = context.sourceCode.getScope(node).upper;
|
|
@@ -2357,11 +2356,11 @@ function create40(context) {
|
|
|
2357
2356
|
if (!context.sourceCode.text.includes("componentWillUpdate")) return {};
|
|
2358
2357
|
return {
|
|
2359
2358
|
CallExpression(node) {
|
|
2360
|
-
if (!
|
|
2359
|
+
if (!ER25.isThisSetState(node)) {
|
|
2361
2360
|
return;
|
|
2362
2361
|
}
|
|
2363
|
-
const clazz = AST8.findParentNode(node,
|
|
2364
|
-
const method = AST8.findParentNode(node, (n) => n === clazz ||
|
|
2362
|
+
const clazz = AST8.findParentNode(node, ER25.isClassComponent);
|
|
2363
|
+
const method = AST8.findParentNode(node, (n) => n === clazz || ER25.isComponentWillUpdate(n));
|
|
2365
2364
|
if (clazz == null || method == null || method === clazz) return;
|
|
2366
2365
|
const methodScope = context.sourceCode.getScope(method);
|
|
2367
2366
|
const upperScope = context.sourceCode.getScope(node).upper;
|
|
@@ -2400,7 +2399,7 @@ function create41(context) {
|
|
|
2400
2399
|
isWithinClassComponent: false
|
|
2401
2400
|
};
|
|
2402
2401
|
function onClassBodyEnter(node) {
|
|
2403
|
-
if (
|
|
2402
|
+
if (ER25.isClassComponent(node.parent)) {
|
|
2404
2403
|
state.isWithinClassComponent = true;
|
|
2405
2404
|
}
|
|
2406
2405
|
}
|
|
@@ -2462,7 +2461,7 @@ var no_unsafe_component_will_mount_default = createRule({
|
|
|
2462
2461
|
});
|
|
2463
2462
|
function create42(context) {
|
|
2464
2463
|
if (!context.sourceCode.text.includes("UNSAFE_componentWillMount")) return {};
|
|
2465
|
-
const { ctx, listeners } =
|
|
2464
|
+
const { ctx, listeners } = ER25.useComponentCollectorLegacy();
|
|
2466
2465
|
return {
|
|
2467
2466
|
...listeners,
|
|
2468
2467
|
"Program:exit"(program) {
|
|
@@ -2506,7 +2505,7 @@ function create43(context) {
|
|
|
2506
2505
|
if (!context.sourceCode.text.includes("UNSAFE_componentWillReceiveProps")) {
|
|
2507
2506
|
return {};
|
|
2508
2507
|
}
|
|
2509
|
-
const { ctx, listeners } =
|
|
2508
|
+
const { ctx, listeners } = ER25.useComponentCollectorLegacy();
|
|
2510
2509
|
return {
|
|
2511
2510
|
...listeners,
|
|
2512
2511
|
"Program:exit"(program) {
|
|
@@ -2548,7 +2547,7 @@ var no_unsafe_component_will_update_default = createRule({
|
|
|
2548
2547
|
});
|
|
2549
2548
|
function create44(context) {
|
|
2550
2549
|
if (!context.sourceCode.text.includes("UNSAFE_componentWillUpdate")) return {};
|
|
2551
|
-
const { ctx, listeners } =
|
|
2550
|
+
const { ctx, listeners } = ER25.useComponentCollectorLegacy();
|
|
2552
2551
|
return {
|
|
2553
2552
|
...listeners,
|
|
2554
2553
|
"Program:exit"(program) {
|
|
@@ -2588,12 +2587,12 @@ var no_unstable_context_value_default = createRule({
|
|
|
2588
2587
|
function create45(context) {
|
|
2589
2588
|
const { version: version2 } = getSettingsFromContext(context);
|
|
2590
2589
|
const isReact18OrBelow = compare(version2, "19.0.0", "<");
|
|
2591
|
-
const { ctx, listeners } =
|
|
2590
|
+
const { ctx, listeners } = ER25.useComponentCollector(context);
|
|
2592
2591
|
const constructions = /* @__PURE__ */ new WeakMap();
|
|
2593
2592
|
return {
|
|
2594
2593
|
...listeners,
|
|
2595
2594
|
JSXOpeningElement(node) {
|
|
2596
|
-
const fullName =
|
|
2595
|
+
const fullName = ER25.getElementType(context, node.parent);
|
|
2597
2596
|
const selfName = fullName.split(".").at(-1);
|
|
2598
2597
|
if (selfName == null) return;
|
|
2599
2598
|
if (!isContextName(selfName, isReact18OrBelow)) return;
|
|
@@ -2609,7 +2608,7 @@ function create45(context) {
|
|
|
2609
2608
|
const initialScope = context.sourceCode.getScope(valueExpression);
|
|
2610
2609
|
const construction = VAR2.getConstructionDetectionResult(valueExpression, initialScope);
|
|
2611
2610
|
if (construction == null) return;
|
|
2612
|
-
if (
|
|
2611
|
+
if (ER25.isReactHookCall(construction.node)) {
|
|
2613
2612
|
return;
|
|
2614
2613
|
}
|
|
2615
2614
|
getOrElseUpdate(constructions, functionEntry.node, () => []).push(construction);
|
|
@@ -2659,7 +2658,7 @@ var no_unstable_default_props_default = createRule({
|
|
|
2659
2658
|
defaultOptions: []
|
|
2660
2659
|
});
|
|
2661
2660
|
function create46(context) {
|
|
2662
|
-
const { ctx, listeners } =
|
|
2661
|
+
const { ctx, listeners } = ER25.useComponentCollector(context);
|
|
2663
2662
|
const declarators = /* @__PURE__ */ new WeakMap();
|
|
2664
2663
|
return {
|
|
2665
2664
|
...listeners,
|
|
@@ -2689,7 +2688,7 @@ function create46(context) {
|
|
|
2689
2688
|
if (construction == null) {
|
|
2690
2689
|
continue;
|
|
2691
2690
|
}
|
|
2692
|
-
if (
|
|
2691
|
+
if (ER25.isReactHookCall(construction.node)) {
|
|
2693
2692
|
continue;
|
|
2694
2693
|
}
|
|
2695
2694
|
const forbiddenType = AST8.toReadableNodeType(right);
|
|
@@ -2759,7 +2758,7 @@ function create47(context) {
|
|
|
2759
2758
|
const propertyUsages = /* @__PURE__ */ new WeakMap();
|
|
2760
2759
|
function classEnter(node) {
|
|
2761
2760
|
classEntries.push(node);
|
|
2762
|
-
if (!
|
|
2761
|
+
if (!ER25.isClassComponent(node)) {
|
|
2763
2762
|
return;
|
|
2764
2763
|
}
|
|
2765
2764
|
propertyDefs.set(node, /* @__PURE__ */ new Set());
|
|
@@ -2767,7 +2766,7 @@ function create47(context) {
|
|
|
2767
2766
|
}
|
|
2768
2767
|
function classExit() {
|
|
2769
2768
|
const currentClass = classEntries.pop();
|
|
2770
|
-
if (currentClass == null || !
|
|
2769
|
+
if (currentClass == null || !ER25.isClassComponent(currentClass)) {
|
|
2771
2770
|
return;
|
|
2772
2771
|
}
|
|
2773
2772
|
const className = AST8.getClassIdentifier(currentClass)?.name;
|
|
@@ -2797,7 +2796,7 @@ function create47(context) {
|
|
|
2797
2796
|
function methodEnter(node) {
|
|
2798
2797
|
methodEntries.push(node);
|
|
2799
2798
|
const currentClass = classEntries.at(-1);
|
|
2800
|
-
if (currentClass == null || !
|
|
2799
|
+
if (currentClass == null || !ER25.isClassComponent(currentClass)) {
|
|
2801
2800
|
return;
|
|
2802
2801
|
}
|
|
2803
2802
|
if (node.static) {
|
|
@@ -2821,7 +2820,7 @@ function create47(context) {
|
|
|
2821
2820
|
if (currentClass == null || currentMethod == null) {
|
|
2822
2821
|
return;
|
|
2823
2822
|
}
|
|
2824
|
-
if (!
|
|
2823
|
+
if (!ER25.isClassComponent(currentClass) || currentMethod.static) {
|
|
2825
2824
|
return;
|
|
2826
2825
|
}
|
|
2827
2826
|
if (!AST8.isThisExpression(node.object) || !isKeyLiteral2(node, node.property)) {
|
|
@@ -2846,7 +2845,7 @@ function create47(context) {
|
|
|
2846
2845
|
if (currentClass == null || currentMethod == null) {
|
|
2847
2846
|
return;
|
|
2848
2847
|
}
|
|
2849
|
-
if (!
|
|
2848
|
+
if (!ER25.isClassComponent(currentClass) || currentMethod.static) {
|
|
2850
2849
|
return;
|
|
2851
2850
|
}
|
|
2852
2851
|
if (node.init != null && AST8.isThisExpression(node.init) && node.id.type === AST_NODE_TYPES.ObjectPattern) {
|
|
@@ -2893,7 +2892,7 @@ function create48(context) {
|
|
|
2893
2892
|
}
|
|
2894
2893
|
function classExit() {
|
|
2895
2894
|
const currentClass = classEntries.pop();
|
|
2896
|
-
if (currentClass == null || !
|
|
2895
|
+
if (currentClass == null || !ER25.isClassComponent(currentClass)) {
|
|
2897
2896
|
return;
|
|
2898
2897
|
}
|
|
2899
2898
|
const className = AST8.getClassIdentifier(currentClass)?.name;
|
|
@@ -2912,11 +2911,11 @@ function create48(context) {
|
|
|
2912
2911
|
function methodEnter(node) {
|
|
2913
2912
|
methodEntries.push(node);
|
|
2914
2913
|
const currentClass = classEntries.at(-1);
|
|
2915
|
-
if (currentClass == null || !
|
|
2914
|
+
if (currentClass == null || !ER25.isClassComponent(currentClass)) {
|
|
2916
2915
|
return;
|
|
2917
2916
|
}
|
|
2918
2917
|
if (node.static) {
|
|
2919
|
-
if (
|
|
2918
|
+
if (ER25.isGetDerivedStateFromProps(node) && isMatching({ params: [P.nonNullable, ...P.array()] })(node.value)) {
|
|
2920
2919
|
const defNode = stateDefs.get(currentClass)?.node;
|
|
2921
2920
|
stateDefs.set(currentClass, { node: defNode, isUsed: true });
|
|
2922
2921
|
}
|
|
@@ -2937,11 +2936,11 @@ function create48(context) {
|
|
|
2937
2936
|
}
|
|
2938
2937
|
return {
|
|
2939
2938
|
AssignmentExpression(node) {
|
|
2940
|
-
if (!
|
|
2939
|
+
if (!ER25.isAssignmentToThisState(node)) {
|
|
2941
2940
|
return;
|
|
2942
2941
|
}
|
|
2943
2942
|
const currentClass = classEntries.at(-1);
|
|
2944
|
-
if (currentClass == null || !
|
|
2943
|
+
if (currentClass == null || !ER25.isClassComponent(currentClass)) {
|
|
2945
2944
|
return;
|
|
2946
2945
|
}
|
|
2947
2946
|
const currentConstructor = constructorEntries.at(-1);
|
|
@@ -2963,7 +2962,7 @@ function create48(context) {
|
|
|
2963
2962
|
return;
|
|
2964
2963
|
}
|
|
2965
2964
|
const currentClass = classEntries.at(-1);
|
|
2966
|
-
if (currentClass == null || !
|
|
2965
|
+
if (currentClass == null || !ER25.isClassComponent(currentClass)) {
|
|
2967
2966
|
return;
|
|
2968
2967
|
}
|
|
2969
2968
|
const currentMethod = methodEntries.at(-1);
|
|
@@ -2987,7 +2986,7 @@ function create48(context) {
|
|
|
2987
2986
|
"PropertyDefinition:exit": methodExit,
|
|
2988
2987
|
VariableDeclarator(node) {
|
|
2989
2988
|
const currentClass = classEntries.at(-1);
|
|
2990
|
-
if (currentClass == null || !
|
|
2989
|
+
if (currentClass == null || !ER25.isClassComponent(currentClass)) {
|
|
2991
2990
|
return;
|
|
2992
2991
|
}
|
|
2993
2992
|
const currentMethod = methodEntries.at(-1);
|
|
@@ -3047,10 +3046,10 @@ function create49(context) {
|
|
|
3047
3046
|
}
|
|
3048
3047
|
return {
|
|
3049
3048
|
CallExpression(node) {
|
|
3050
|
-
if (!
|
|
3049
|
+
if (!ER25.isReactHookCall(node)) {
|
|
3051
3050
|
return;
|
|
3052
3051
|
}
|
|
3053
|
-
if (!
|
|
3052
|
+
if (!ER25.isReactHookCallWithNameAlias(context, "useContext", [...useContextAlias])(node)) {
|
|
3054
3053
|
return;
|
|
3055
3054
|
}
|
|
3056
3055
|
context.report({
|
|
@@ -3137,7 +3136,7 @@ var no_useless_forward_ref_default = createRule({
|
|
|
3137
3136
|
function create50(context) {
|
|
3138
3137
|
return {
|
|
3139
3138
|
CallExpression(node) {
|
|
3140
|
-
if (!
|
|
3139
|
+
if (!ER25.isForwardRefCall(context, node)) {
|
|
3141
3140
|
return;
|
|
3142
3141
|
}
|
|
3143
3142
|
const [component] = node.arguments;
|
|
@@ -3189,7 +3188,7 @@ function create51(context, [option]) {
|
|
|
3189
3188
|
const { allowExpressions = true } = option;
|
|
3190
3189
|
return {
|
|
3191
3190
|
JSXElement(node) {
|
|
3192
|
-
if (!
|
|
3191
|
+
if (!ER25.isFragmentElement(context, node)) return;
|
|
3193
3192
|
checkNode(context, node, allowExpressions);
|
|
3194
3193
|
},
|
|
3195
3194
|
JSXFragment(node) {
|
|
@@ -3201,7 +3200,7 @@ function isWhiteSpace(node) {
|
|
|
3201
3200
|
return typeof node.value === "string" && node.raw.trim() === "";
|
|
3202
3201
|
}
|
|
3203
3202
|
function isPaddingSpaces(node) {
|
|
3204
|
-
return
|
|
3203
|
+
return ER25.isJsxText(node) && isWhiteSpace(node) && node.raw.includes("\n");
|
|
3205
3204
|
}
|
|
3206
3205
|
function trimLikeReact(text) {
|
|
3207
3206
|
const leadingSpaces = /^\s*/.exec(text)?.[0] ?? "";
|
|
@@ -3212,10 +3211,10 @@ function trimLikeReact(text) {
|
|
|
3212
3211
|
}
|
|
3213
3212
|
function checkNode(context, node, allowExpressions) {
|
|
3214
3213
|
const initialScope = context.sourceCode.getScope(node);
|
|
3215
|
-
if (
|
|
3214
|
+
if (ER25.isKeyedElement(context, node, initialScope)) {
|
|
3216
3215
|
return;
|
|
3217
3216
|
}
|
|
3218
|
-
if (
|
|
3217
|
+
if (ER25.isHostElement(context, node.parent)) {
|
|
3219
3218
|
context.report({
|
|
3220
3219
|
messageId: "uselessFragment",
|
|
3221
3220
|
node,
|
|
@@ -3239,7 +3238,7 @@ function checkNode(context, node, allowExpressions) {
|
|
|
3239
3238
|
const isChildElement = AST8.isOneOf([AST_NODE_TYPES.JSXElement, AST_NODE_TYPES.JSXFragment])(node.parent);
|
|
3240
3239
|
switch (true) {
|
|
3241
3240
|
// <Foo content={<>ee eeee eeee ...</>} />
|
|
3242
|
-
case (allowExpressions && !isChildElement && node.children.length === 1 &&
|
|
3241
|
+
case (allowExpressions && !isChildElement && node.children.length === 1 && ER25.isJsxText(node.children.at(0))): {
|
|
3243
3242
|
return;
|
|
3244
3243
|
}
|
|
3245
3244
|
// <Foo><>hello, world</></Foo>
|
|
@@ -3285,7 +3284,7 @@ function checkNode(context, node, allowExpressions) {
|
|
|
3285
3284
|
return;
|
|
3286
3285
|
}
|
|
3287
3286
|
function getFix2(context, node) {
|
|
3288
|
-
if (!canFix(node)) return null;
|
|
3287
|
+
if (!canFix(context, node)) return null;
|
|
3289
3288
|
return (fixer) => {
|
|
3290
3289
|
const opener = node.type === AST_NODE_TYPES.JSXFragment ? node.openingFragment : node.openingElement;
|
|
3291
3290
|
const closer = node.type === AST_NODE_TYPES.JSXFragment ? node.closingFragment : node.closingElement;
|
|
@@ -3293,14 +3292,14 @@ function getFix2(context, node) {
|
|
|
3293
3292
|
return fixer.replaceText(node, trimLikeReact(childrenText));
|
|
3294
3293
|
};
|
|
3295
3294
|
}
|
|
3296
|
-
function canFix(node) {
|
|
3295
|
+
function canFix(context, node) {
|
|
3297
3296
|
if (node.parent.type === AST_NODE_TYPES.JSXElement || node.parent.type === AST_NODE_TYPES.JSXFragment) {
|
|
3298
|
-
return
|
|
3297
|
+
return ER25.isHostElement(context, node.parent);
|
|
3299
3298
|
}
|
|
3300
3299
|
if (node.children.length === 0) {
|
|
3301
3300
|
return false;
|
|
3302
3301
|
}
|
|
3303
|
-
if (node.children.some((child) =>
|
|
3302
|
+
if (node.children.some((child) => ER25.isJsxText(child) && !isWhiteSpace(child) || AST8.is(AST_NODE_TYPES.JSXExpressionContainer)(child))) {
|
|
3304
3303
|
return false;
|
|
3305
3304
|
}
|
|
3306
3305
|
return true;
|
|
@@ -3327,7 +3326,7 @@ var prefer_destructuring_assignment_default = createRule({
|
|
|
3327
3326
|
defaultOptions: []
|
|
3328
3327
|
});
|
|
3329
3328
|
function create52(context) {
|
|
3330
|
-
const { ctx, listeners } =
|
|
3329
|
+
const { ctx, listeners } = ER25.useComponentCollector(context);
|
|
3331
3330
|
const memberExpressionWithNames = [];
|
|
3332
3331
|
return {
|
|
3333
3332
|
...listeners,
|
|
@@ -3346,7 +3345,7 @@ function create52(context) {
|
|
|
3346
3345
|
return false;
|
|
3347
3346
|
}
|
|
3348
3347
|
const id = AST8.getFunctionIdentifier(block);
|
|
3349
|
-
return id != null &&
|
|
3348
|
+
return id != null && ER25.isComponentNameLoose(id.name) && components.some((component) => component.node === block);
|
|
3350
3349
|
}
|
|
3351
3350
|
for (const [initialScope, memberExpression] of memberExpressionWithNames) {
|
|
3352
3351
|
let scope = initialScope;
|
|
@@ -3465,7 +3464,7 @@ var prefer_read_only_props_default = createRule({
|
|
|
3465
3464
|
});
|
|
3466
3465
|
function create54(context) {
|
|
3467
3466
|
const services = ESLintUtils.getParserServices(context, false);
|
|
3468
|
-
const { ctx, listeners } =
|
|
3467
|
+
const { ctx, listeners } = ER25.useComponentCollector(context);
|
|
3469
3468
|
return {
|
|
3470
3469
|
...listeners,
|
|
3471
3470
|
"Program:exit"(program) {
|
|
@@ -3518,7 +3517,7 @@ function create55(context) {
|
|
|
3518
3517
|
return {
|
|
3519
3518
|
JSXAttribute(node) {
|
|
3520
3519
|
const { value } = node;
|
|
3521
|
-
const propName =
|
|
3520
|
+
const propName = ER25.getAttributeName(context, node);
|
|
3522
3521
|
const hasValueTrue = value?.type === AST_NODE_TYPES.JSXExpressionContainer && value.expression.type === AST_NODE_TYPES.Literal && value.expression.value === true;
|
|
3523
3522
|
if (!hasValueTrue) {
|
|
3524
3523
|
return;
|
|
@@ -3558,7 +3557,7 @@ var prefer_shorthand_fragment_default = createRule({
|
|
|
3558
3557
|
function create56(context) {
|
|
3559
3558
|
return {
|
|
3560
3559
|
JSXElement(node) {
|
|
3561
|
-
if (!
|
|
3560
|
+
if (!ER25.isFragmentElement(context, node)) return;
|
|
3562
3561
|
const hasAttributes = node.openingElement.attributes.length > 0;
|
|
3563
3562
|
if (hasAttributes) {
|
|
3564
3563
|
return;
|