eslint-plugin-react-x 1.18.1-beta.1 → 1.18.1-beta.3
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/README.md +2 -0
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +182 -75
- package/dist/index.mjs +181 -74
- package/package.json +8 -8
package/dist/index.mjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as JSX8 from '@eslint-react/jsx';
|
|
2
2
|
import { F, O, isString, MutRef, isNullable } from '@eslint-react/tools';
|
|
3
3
|
import { createRuleForPlugin, normalizeSettings, decodeSettings, unsafeReadSettings } from '@eslint-react/shared';
|
|
4
4
|
import * as AST11 from '@eslint-react/ast';
|
|
5
5
|
import { isForwardRefCall, isThisSetState, isClassComponent, isChildrenCount, isChildrenForEach, isChildrenMap, isChildrenOnly, isChildrenToArray, useComponentCollectorLegacy, isCloneElementCall, isCreateRefCall, isComponentName, isChildrenToArrayCall, useComponentCollector, ERFunctionComponentFlag, ERComponentHint, isDirectValueOfRenderPropertyLoose, isDeclaredInRenderPropLoose, isInsideCreateElementProps, isInsideRenderMethod, ERClassComponentFlag, isFragmentElement, isCreateElementCall, isInitializedFromReact } from '@eslint-react/core';
|
|
6
6
|
import { AST_NODE_TYPES } from '@typescript-eslint/types';
|
|
7
7
|
import { isMatching, P, match } from 'ts-pattern';
|
|
8
|
-
import * as VAR from '@eslint-react/var';
|
|
9
8
|
import { compare } from 'compare-versions';
|
|
9
|
+
import * as VAR from '@eslint-react/var';
|
|
10
10
|
import { getConstrainedTypeAtLocation, isTypeReadonly } from '@typescript-eslint/type-utils';
|
|
11
11
|
import { ESLintUtils } from '@typescript-eslint/utils';
|
|
12
12
|
import ts from 'typescript';
|
|
@@ -14,7 +14,7 @@ import { getTypeImmutability, isUnknown, isImmutable, isReadonlyShallow, isReado
|
|
|
14
14
|
|
|
15
15
|
// package.json
|
|
16
16
|
var name = "eslint-plugin-react-x";
|
|
17
|
-
var version = "1.18.1-beta.
|
|
17
|
+
var version = "1.18.1-beta.3";
|
|
18
18
|
var createRule = createRuleForPlugin("x");
|
|
19
19
|
|
|
20
20
|
// src/rules/avoid-shorthand-boolean.ts
|
|
@@ -38,7 +38,7 @@ var avoid_shorthand_boolean_default = createRule({
|
|
|
38
38
|
messageId: "avoidShorthandBoolean",
|
|
39
39
|
node,
|
|
40
40
|
data: {
|
|
41
|
-
propName:
|
|
41
|
+
propName: JSX8.getPropName(node)
|
|
42
42
|
},
|
|
43
43
|
fix: (fixer) => fixer.insertTextAfter(node.name, `={true}`)
|
|
44
44
|
});
|
|
@@ -541,7 +541,7 @@ var no_children_prop_default = createRule({
|
|
|
541
541
|
return {
|
|
542
542
|
JSXElement(node) {
|
|
543
543
|
const initialScope = context.sourceCode.getScope(node);
|
|
544
|
-
const prop =
|
|
544
|
+
const prop = JSX8.getProp(node.openingElement.attributes, "children", initialScope);
|
|
545
545
|
const reportDescriptor = O.map(prop, (prop2) => ({ messageId: "noChildrenProp", node: prop2 }));
|
|
546
546
|
O.map(reportDescriptor, context.report);
|
|
547
547
|
}
|
|
@@ -841,7 +841,48 @@ var no_component_will_update_default = createRule({
|
|
|
841
841
|
},
|
|
842
842
|
defaultOptions: []
|
|
843
843
|
});
|
|
844
|
-
var RULE_NAME21 = "no-
|
|
844
|
+
var RULE_NAME21 = "no-context-provider";
|
|
845
|
+
var no_context_provider_default = createRule({
|
|
846
|
+
meta: {
|
|
847
|
+
type: "problem",
|
|
848
|
+
docs: {
|
|
849
|
+
description: "disallow the use of '<Context.Provider>'"
|
|
850
|
+
},
|
|
851
|
+
fixable: "code",
|
|
852
|
+
messages: {
|
|
853
|
+
noContextProvider: "In React 19, you can render '<Context>' as a provider instead of '<Context.Provider>'."
|
|
854
|
+
},
|
|
855
|
+
schema: []
|
|
856
|
+
},
|
|
857
|
+
name: RULE_NAME21,
|
|
858
|
+
create(context) {
|
|
859
|
+
if (!context.sourceCode.text.includes(".Provider")) return {};
|
|
860
|
+
const { version: version2 } = normalizeSettings(decodeSettings(context.settings));
|
|
861
|
+
if (compare(version2, "19.0.0", "<")) return {};
|
|
862
|
+
return {
|
|
863
|
+
JSXElement(node) {
|
|
864
|
+
const elementName = JSX8.getElementName(node.openingElement);
|
|
865
|
+
if (!elementName.endsWith(".Provider")) return;
|
|
866
|
+
context.report({
|
|
867
|
+
messageId: "noContextProvider",
|
|
868
|
+
node,
|
|
869
|
+
fix(fixer) {
|
|
870
|
+
const providerName = elementName.replace(/\.Provider$/, "");
|
|
871
|
+
const openingElement = node.openingElement;
|
|
872
|
+
const closingElement = node.closingElement;
|
|
873
|
+
if (!closingElement) return fixer.replaceText(openingElement.name, providerName);
|
|
874
|
+
return [
|
|
875
|
+
fixer.replaceText(openingElement.name, providerName),
|
|
876
|
+
fixer.replaceText(closingElement.name, providerName)
|
|
877
|
+
];
|
|
878
|
+
}
|
|
879
|
+
});
|
|
880
|
+
}
|
|
881
|
+
};
|
|
882
|
+
},
|
|
883
|
+
defaultOptions: []
|
|
884
|
+
});
|
|
885
|
+
var RULE_NAME22 = "no-create-ref";
|
|
845
886
|
var no_create_ref_default = createRule({
|
|
846
887
|
meta: {
|
|
847
888
|
type: "problem",
|
|
@@ -853,7 +894,7 @@ var no_create_ref_default = createRule({
|
|
|
853
894
|
},
|
|
854
895
|
schema: []
|
|
855
896
|
},
|
|
856
|
-
name:
|
|
897
|
+
name: RULE_NAME22,
|
|
857
898
|
create(context) {
|
|
858
899
|
return {
|
|
859
900
|
CallExpression(node) {
|
|
@@ -865,7 +906,7 @@ var no_create_ref_default = createRule({
|
|
|
865
906
|
},
|
|
866
907
|
defaultOptions: []
|
|
867
908
|
});
|
|
868
|
-
var
|
|
909
|
+
var RULE_NAME23 = "no-default-props";
|
|
869
910
|
var no_default_props_default = createRule({
|
|
870
911
|
meta: {
|
|
871
912
|
type: "problem",
|
|
@@ -877,7 +918,7 @@ var no_default_props_default = createRule({
|
|
|
877
918
|
},
|
|
878
919
|
schema: []
|
|
879
920
|
},
|
|
880
|
-
name:
|
|
921
|
+
name: RULE_NAME23,
|
|
881
922
|
create(context) {
|
|
882
923
|
if (!context.sourceCode.text.includes("defaultProps")) return {};
|
|
883
924
|
return {
|
|
@@ -904,7 +945,7 @@ var no_default_props_default = createRule({
|
|
|
904
945
|
},
|
|
905
946
|
defaultOptions: []
|
|
906
947
|
});
|
|
907
|
-
var
|
|
948
|
+
var RULE_NAME24 = "no-direct-mutation-state";
|
|
908
949
|
function getName2(node) {
|
|
909
950
|
if (node.type === AST_NODE_TYPES.TSAsExpression) {
|
|
910
951
|
return getName2(node.expression);
|
|
@@ -938,7 +979,7 @@ var no_direct_mutation_state_default = createRule({
|
|
|
938
979
|
},
|
|
939
980
|
schema: []
|
|
940
981
|
},
|
|
941
|
-
name:
|
|
982
|
+
name: RULE_NAME24,
|
|
942
983
|
create(context) {
|
|
943
984
|
function getReportDescriptor(node) {
|
|
944
985
|
if (!isAssignmentToThisState(node)) return O.none();
|
|
@@ -962,7 +1003,7 @@ var no_direct_mutation_state_default = createRule({
|
|
|
962
1003
|
},
|
|
963
1004
|
defaultOptions: []
|
|
964
1005
|
});
|
|
965
|
-
var
|
|
1006
|
+
var RULE_NAME25 = "no-duplicate-key";
|
|
966
1007
|
var no_duplicate_key_default = createRule({
|
|
967
1008
|
meta: {
|
|
968
1009
|
type: "problem",
|
|
@@ -974,7 +1015,7 @@ var no_duplicate_key_default = createRule({
|
|
|
974
1015
|
},
|
|
975
1016
|
schema: []
|
|
976
1017
|
},
|
|
977
|
-
name:
|
|
1018
|
+
name: RULE_NAME25,
|
|
978
1019
|
create(context) {
|
|
979
1020
|
const isWithinChildrenToArrayRef = MutRef.make(false);
|
|
980
1021
|
function isKeyEqual(a, b) {
|
|
@@ -984,7 +1025,7 @@ var no_duplicate_key_default = createRule({
|
|
|
984
1025
|
if (node.type !== AST_NODE_TYPES.JSXElement) return O.none();
|
|
985
1026
|
const initialScope = context.sourceCode.getScope(node);
|
|
986
1027
|
return F.pipe(
|
|
987
|
-
|
|
1028
|
+
JSX8.findPropInAttributes(node.openingElement.attributes, initialScope)("key"),
|
|
988
1029
|
O.flatMap((k) => "value" in k ? O.fromNullable(k.value) : O.none()),
|
|
989
1030
|
O.flatMap((v) => {
|
|
990
1031
|
return isKeyEqual(v, v) ? O.some({
|
|
@@ -1091,19 +1132,20 @@ var no_duplicate_key_default = createRule({
|
|
|
1091
1132
|
},
|
|
1092
1133
|
defaultOptions: []
|
|
1093
1134
|
});
|
|
1094
|
-
var
|
|
1135
|
+
var RULE_NAME26 = "no-forward-ref";
|
|
1095
1136
|
var no_forward_ref_default = createRule({
|
|
1096
1137
|
meta: {
|
|
1097
1138
|
type: "problem",
|
|
1098
1139
|
docs: {
|
|
1099
1140
|
description: "disallow the use of 'forwardRef'"
|
|
1100
1141
|
},
|
|
1142
|
+
fixable: "code",
|
|
1101
1143
|
messages: {
|
|
1102
1144
|
noForwardRef: "In React 19, 'forwardRef' is no longer necessary. Pass 'ref' as a prop instead."
|
|
1103
1145
|
},
|
|
1104
1146
|
schema: []
|
|
1105
1147
|
},
|
|
1106
|
-
name:
|
|
1148
|
+
name: RULE_NAME26,
|
|
1107
1149
|
create(context) {
|
|
1108
1150
|
if (!context.sourceCode.text.includes("forwardRef")) return {};
|
|
1109
1151
|
const { version: version2 } = normalizeSettings(decodeSettings(context.settings));
|
|
@@ -1113,14 +1155,78 @@ var no_forward_ref_default = createRule({
|
|
|
1113
1155
|
if (!isForwardRefCall(node, context)) return;
|
|
1114
1156
|
context.report({
|
|
1115
1157
|
messageId: "noForwardRef",
|
|
1116
|
-
node
|
|
1158
|
+
node,
|
|
1159
|
+
fix: getFix(node, context)
|
|
1117
1160
|
});
|
|
1118
1161
|
}
|
|
1119
1162
|
};
|
|
1120
1163
|
},
|
|
1121
1164
|
defaultOptions: []
|
|
1122
1165
|
});
|
|
1123
|
-
|
|
1166
|
+
function getFix(node, context) {
|
|
1167
|
+
return (fixer) => {
|
|
1168
|
+
const [componentNode] = node.arguments;
|
|
1169
|
+
if (!componentNode || !AST11.isFunction(componentNode)) return [];
|
|
1170
|
+
return [
|
|
1171
|
+
fixer.removeRange([node.range[0], componentNode.range[0]]),
|
|
1172
|
+
fixer.removeRange([componentNode.range[1], node.range[1]]),
|
|
1173
|
+
...getParamsFixes(componentNode, context, node.typeArguments?.params ?? [], fixer)
|
|
1174
|
+
];
|
|
1175
|
+
};
|
|
1176
|
+
}
|
|
1177
|
+
function getParamsFixes(node, context, typeArguments, fixer) {
|
|
1178
|
+
const [arg0, arg1] = node.params;
|
|
1179
|
+
const [typeArg0, typeArg1] = typeArguments;
|
|
1180
|
+
if (arg0?.type !== AST_NODE_TYPES.Identifier) return [];
|
|
1181
|
+
if (!arg1) {
|
|
1182
|
+
return [fixer.replaceText(
|
|
1183
|
+
arg0,
|
|
1184
|
+
[
|
|
1185
|
+
"{",
|
|
1186
|
+
"ref,",
|
|
1187
|
+
`...${arg0.name}`,
|
|
1188
|
+
"}"
|
|
1189
|
+
].join(" ")
|
|
1190
|
+
)];
|
|
1191
|
+
}
|
|
1192
|
+
if (arg1.type !== AST_NODE_TYPES.Identifier) return [];
|
|
1193
|
+
if (!typeArg0 || !typeArg1) {
|
|
1194
|
+
return [
|
|
1195
|
+
fixer.replaceText(
|
|
1196
|
+
arg0,
|
|
1197
|
+
[
|
|
1198
|
+
"{",
|
|
1199
|
+
arg1.name === "ref" ? `ref,` : `ref: ${arg1.name},`,
|
|
1200
|
+
`...${arg0.name}`,
|
|
1201
|
+
"}"
|
|
1202
|
+
].join(" ")
|
|
1203
|
+
),
|
|
1204
|
+
fixer.remove(arg1),
|
|
1205
|
+
fixer.removeRange([arg0.range[1], arg1.range[0]])
|
|
1206
|
+
];
|
|
1207
|
+
}
|
|
1208
|
+
const getText = (node2) => context.sourceCode.getText(node2);
|
|
1209
|
+
return [
|
|
1210
|
+
fixer.replaceText(
|
|
1211
|
+
arg0,
|
|
1212
|
+
[
|
|
1213
|
+
"{",
|
|
1214
|
+
arg1.name === "ref" ? `ref,` : `ref: ${arg1.name},`,
|
|
1215
|
+
`...${arg0.name}`,
|
|
1216
|
+
"}:",
|
|
1217
|
+
getText(typeArg1),
|
|
1218
|
+
"&",
|
|
1219
|
+
"{",
|
|
1220
|
+
`ref:`,
|
|
1221
|
+
`React.RefObject<${getText(typeArg0)}>`,
|
|
1222
|
+
"}"
|
|
1223
|
+
].join(" ")
|
|
1224
|
+
),
|
|
1225
|
+
fixer.remove(arg1),
|
|
1226
|
+
fixer.removeRange([arg0.range[1], arg1.range[0]])
|
|
1227
|
+
];
|
|
1228
|
+
}
|
|
1229
|
+
var RULE_NAME27 = "no-implicit-key";
|
|
1124
1230
|
var no_implicit_key_default = createRule({
|
|
1125
1231
|
meta: {
|
|
1126
1232
|
type: "problem",
|
|
@@ -1132,11 +1238,11 @@ var no_implicit_key_default = createRule({
|
|
|
1132
1238
|
},
|
|
1133
1239
|
schema: []
|
|
1134
1240
|
},
|
|
1135
|
-
name:
|
|
1241
|
+
name: RULE_NAME27,
|
|
1136
1242
|
create(context) {
|
|
1137
1243
|
function getReportDescriptor(node) {
|
|
1138
1244
|
const initialScope = context.sourceCode.getScope(node);
|
|
1139
|
-
const keyPropFound =
|
|
1245
|
+
const keyPropFound = JSX8.findPropInAttributes(node.attributes, initialScope)("key");
|
|
1140
1246
|
const keyPropOnElement = node.attributes.some(
|
|
1141
1247
|
(n) => AST11.is(AST_NODE_TYPES.JSXAttribute)(n) && n.name.name === "key"
|
|
1142
1248
|
);
|
|
@@ -1175,7 +1281,7 @@ function isTrueLiteralType(type) {
|
|
|
1175
1281
|
function unionTypeParts(type) {
|
|
1176
1282
|
return isUnionType(type) ? type.types : [type];
|
|
1177
1283
|
}
|
|
1178
|
-
var
|
|
1284
|
+
var RULE_NAME28 = "no-leaked-conditional-rendering";
|
|
1179
1285
|
var tsHelpers = {
|
|
1180
1286
|
isAnyType: (type) => isTypeFlagSet(type, ts.TypeFlags.TypeParameter | ts.TypeFlags.Any),
|
|
1181
1287
|
isBigIntType: (type) => isTypeFlagSet(type, ts.TypeFlags.BigIntLike),
|
|
@@ -1279,7 +1385,7 @@ var no_leaked_conditional_rendering_default = createRule({
|
|
|
1279
1385
|
},
|
|
1280
1386
|
schema: []
|
|
1281
1387
|
},
|
|
1282
|
-
name:
|
|
1388
|
+
name: RULE_NAME28,
|
|
1283
1389
|
create(context) {
|
|
1284
1390
|
if (!context.sourceCode.text.includes("&&") && !context.sourceCode.text.includes("?")) return {};
|
|
1285
1391
|
const { version: version2 } = normalizeSettings(decodeSettings(context.settings));
|
|
@@ -1336,7 +1442,7 @@ var no_leaked_conditional_rendering_default = createRule({
|
|
|
1336
1442
|
},
|
|
1337
1443
|
defaultOptions: []
|
|
1338
1444
|
});
|
|
1339
|
-
var
|
|
1445
|
+
var RULE_NAME29 = "no-missing-component-display-name";
|
|
1340
1446
|
var no_missing_component_display_name_default = createRule({
|
|
1341
1447
|
meta: {
|
|
1342
1448
|
type: "problem",
|
|
@@ -1348,7 +1454,7 @@ var no_missing_component_display_name_default = createRule({
|
|
|
1348
1454
|
},
|
|
1349
1455
|
schema: []
|
|
1350
1456
|
},
|
|
1351
|
-
name:
|
|
1457
|
+
name: RULE_NAME29,
|
|
1352
1458
|
create(context) {
|
|
1353
1459
|
if (!context.sourceCode.text.includes("memo") && !context.sourceCode.text.includes("forwardRef")) return {};
|
|
1354
1460
|
const { ctx, listeners } = useComponentCollector(context);
|
|
@@ -1372,7 +1478,7 @@ var no_missing_component_display_name_default = createRule({
|
|
|
1372
1478
|
},
|
|
1373
1479
|
defaultOptions: []
|
|
1374
1480
|
});
|
|
1375
|
-
var
|
|
1481
|
+
var RULE_NAME30 = "no-missing-key";
|
|
1376
1482
|
var no_missing_key_default = createRule({
|
|
1377
1483
|
meta: {
|
|
1378
1484
|
type: "problem",
|
|
@@ -1385,14 +1491,14 @@ var no_missing_key_default = createRule({
|
|
|
1385
1491
|
},
|
|
1386
1492
|
schema: []
|
|
1387
1493
|
},
|
|
1388
|
-
name:
|
|
1494
|
+
name: RULE_NAME30,
|
|
1389
1495
|
create(context) {
|
|
1390
1496
|
const isWithinChildrenToArrayRef = MutRef.make(false);
|
|
1391
1497
|
function checkIteratorElement(node) {
|
|
1392
1498
|
switch (node.type) {
|
|
1393
1499
|
case AST_NODE_TYPES.JSXElement: {
|
|
1394
1500
|
const initialScope = context.sourceCode.getScope(node);
|
|
1395
|
-
if (!
|
|
1501
|
+
if (!JSX8.hasProp(node.openingElement.attributes, "key", initialScope)) {
|
|
1396
1502
|
return O.some({
|
|
1397
1503
|
messageId: "noMissingKey",
|
|
1398
1504
|
node
|
|
@@ -1441,7 +1547,7 @@ var no_missing_key_default = createRule({
|
|
|
1441
1547
|
if (elements.length === 0) return;
|
|
1442
1548
|
const initialScope = context.sourceCode.getScope(node);
|
|
1443
1549
|
for (const element of elements) {
|
|
1444
|
-
if (!
|
|
1550
|
+
if (!JSX8.hasProp(element.openingElement.attributes, "key", initialScope)) {
|
|
1445
1551
|
context.report({
|
|
1446
1552
|
messageId: "noMissingKey",
|
|
1447
1553
|
node: element
|
|
@@ -1489,7 +1595,7 @@ var no_missing_key_default = createRule({
|
|
|
1489
1595
|
},
|
|
1490
1596
|
defaultOptions: []
|
|
1491
1597
|
});
|
|
1492
|
-
var
|
|
1598
|
+
var RULE_NAME31 = "no-nested-components";
|
|
1493
1599
|
var no_nested_components_default = createRule({
|
|
1494
1600
|
meta: {
|
|
1495
1601
|
type: "problem",
|
|
@@ -1502,7 +1608,7 @@ var no_nested_components_default = createRule({
|
|
|
1502
1608
|
},
|
|
1503
1609
|
schema: []
|
|
1504
1610
|
},
|
|
1505
|
-
name:
|
|
1611
|
+
name: RULE_NAME31,
|
|
1506
1612
|
create(context) {
|
|
1507
1613
|
const hint = ERComponentHint.SkipMapCallback | ERComponentHint.SkipNullLiteral | ERComponentHint.SkipUndefinedLiteral | ERComponentHint.SkipBooleanLiteral | ERComponentHint.SkipStringLiteral | ERComponentHint.SkipNumberLiteral | ERComponentHint.StrictLogical | ERComponentHint.StrictConditional;
|
|
1508
1614
|
const collector = useComponentCollector(context, hint);
|
|
@@ -1524,7 +1630,7 @@ var no_nested_components_default = createRule({
|
|
|
1524
1630
|
if (O.isNone(componentName)) continue;
|
|
1525
1631
|
const name2 = componentName.value;
|
|
1526
1632
|
const isInsideProperty = component.parent.type === AST_NODE_TYPES.Property;
|
|
1527
|
-
const isInsideJSXPropValue = component.parent.type === AST_NODE_TYPES.JSXAttribute || O.isSome(
|
|
1633
|
+
const isInsideJSXPropValue = component.parent.type === AST_NODE_TYPES.JSXAttribute || O.isSome(JSX8.traverseUpProp(node, (n) => n.value?.type === AST_NODE_TYPES.JSXExpressionContainer));
|
|
1528
1634
|
if (isInsideJSXPropValue) {
|
|
1529
1635
|
if (!isDeclaredInRenderPropLoose(component)) {
|
|
1530
1636
|
context.report({
|
|
@@ -1586,7 +1692,7 @@ var no_nested_components_default = createRule({
|
|
|
1586
1692
|
},
|
|
1587
1693
|
defaultOptions: []
|
|
1588
1694
|
});
|
|
1589
|
-
var
|
|
1695
|
+
var RULE_NAME32 = "no-prop-types";
|
|
1590
1696
|
var no_prop_types_default = createRule({
|
|
1591
1697
|
meta: {
|
|
1592
1698
|
type: "problem",
|
|
@@ -1598,7 +1704,7 @@ var no_prop_types_default = createRule({
|
|
|
1598
1704
|
},
|
|
1599
1705
|
schema: []
|
|
1600
1706
|
},
|
|
1601
|
-
name:
|
|
1707
|
+
name: RULE_NAME32,
|
|
1602
1708
|
create(context) {
|
|
1603
1709
|
if (!context.sourceCode.text.includes("propTypes")) return {};
|
|
1604
1710
|
return {
|
|
@@ -1625,7 +1731,7 @@ var no_prop_types_default = createRule({
|
|
|
1625
1731
|
},
|
|
1626
1732
|
defaultOptions: []
|
|
1627
1733
|
});
|
|
1628
|
-
var
|
|
1734
|
+
var RULE_NAME33 = "no-redundant-should-component-update";
|
|
1629
1735
|
function isShouldComponentUpdate(node) {
|
|
1630
1736
|
return AST11.isOneOf([AST_NODE_TYPES.MethodDefinition, AST_NODE_TYPES.PropertyDefinition])(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "shouldComponentUpdate";
|
|
1631
1737
|
}
|
|
@@ -1640,7 +1746,7 @@ var no_redundant_should_component_update_default = createRule({
|
|
|
1640
1746
|
},
|
|
1641
1747
|
schema: []
|
|
1642
1748
|
},
|
|
1643
|
-
name:
|
|
1749
|
+
name: RULE_NAME33,
|
|
1644
1750
|
create(context) {
|
|
1645
1751
|
if (!context.sourceCode.text.includes("shouldComponentUpdate")) return {};
|
|
1646
1752
|
const { ctx, listeners } = useComponentCollectorLegacy();
|
|
@@ -1668,7 +1774,7 @@ var no_redundant_should_component_update_default = createRule({
|
|
|
1668
1774
|
},
|
|
1669
1775
|
defaultOptions: []
|
|
1670
1776
|
});
|
|
1671
|
-
var
|
|
1777
|
+
var RULE_NAME34 = "no-set-state-in-component-did-mount";
|
|
1672
1778
|
function isComponentDidMount(node) {
|
|
1673
1779
|
return AST11.isOneOf([AST_NODE_TYPES.MethodDefinition, AST_NODE_TYPES.PropertyDefinition])(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentDidMount";
|
|
1674
1780
|
}
|
|
@@ -1683,7 +1789,7 @@ var no_set_state_in_component_did_mount_default = createRule({
|
|
|
1683
1789
|
},
|
|
1684
1790
|
schema: []
|
|
1685
1791
|
},
|
|
1686
|
-
name:
|
|
1792
|
+
name: RULE_NAME34,
|
|
1687
1793
|
create(context) {
|
|
1688
1794
|
if (!context.sourceCode.text.includes("componentDidMount")) return {};
|
|
1689
1795
|
function getReportDescriptor(node) {
|
|
@@ -1711,7 +1817,7 @@ var no_set_state_in_component_did_mount_default = createRule({
|
|
|
1711
1817
|
},
|
|
1712
1818
|
defaultOptions: []
|
|
1713
1819
|
});
|
|
1714
|
-
var
|
|
1820
|
+
var RULE_NAME35 = "no-set-state-in-component-did-update";
|
|
1715
1821
|
function isComponentDidUpdate(node) {
|
|
1716
1822
|
return AST11.isOneOf([AST_NODE_TYPES.MethodDefinition, AST_NODE_TYPES.PropertyDefinition])(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentDidUpdate";
|
|
1717
1823
|
}
|
|
@@ -1726,7 +1832,7 @@ var no_set_state_in_component_did_update_default = createRule({
|
|
|
1726
1832
|
},
|
|
1727
1833
|
schema: []
|
|
1728
1834
|
},
|
|
1729
|
-
name:
|
|
1835
|
+
name: RULE_NAME35,
|
|
1730
1836
|
create(context) {
|
|
1731
1837
|
if (!context.sourceCode.text.includes("componentDidUpdate")) return {};
|
|
1732
1838
|
function getReportDescriptor(node) {
|
|
@@ -1754,7 +1860,7 @@ var no_set_state_in_component_did_update_default = createRule({
|
|
|
1754
1860
|
},
|
|
1755
1861
|
defaultOptions: []
|
|
1756
1862
|
});
|
|
1757
|
-
var
|
|
1863
|
+
var RULE_NAME36 = "no-set-state-in-component-will-update";
|
|
1758
1864
|
function isComponentWillUpdate3(node) {
|
|
1759
1865
|
return AST11.isOneOf([AST_NODE_TYPES.MethodDefinition, AST_NODE_TYPES.PropertyDefinition])(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentWillUpdate";
|
|
1760
1866
|
}
|
|
@@ -1769,7 +1875,7 @@ var no_set_state_in_component_will_update_default = createRule({
|
|
|
1769
1875
|
},
|
|
1770
1876
|
schema: []
|
|
1771
1877
|
},
|
|
1772
|
-
name:
|
|
1878
|
+
name: RULE_NAME36,
|
|
1773
1879
|
create(context) {
|
|
1774
1880
|
if (!context.sourceCode.text.includes("componentWillUpdate")) return {};
|
|
1775
1881
|
function getReportDescriptor(node) {
|
|
@@ -1797,7 +1903,7 @@ var no_set_state_in_component_will_update_default = createRule({
|
|
|
1797
1903
|
},
|
|
1798
1904
|
defaultOptions: []
|
|
1799
1905
|
});
|
|
1800
|
-
var
|
|
1906
|
+
var RULE_NAME37 = "no-string-refs";
|
|
1801
1907
|
function containsStringLiteral({ value }) {
|
|
1802
1908
|
return value?.type === AST_NODE_TYPES.Literal && isString(value.value);
|
|
1803
1909
|
}
|
|
@@ -1817,7 +1923,7 @@ var no_string_refs_default = createRule({
|
|
|
1817
1923
|
},
|
|
1818
1924
|
schema: []
|
|
1819
1925
|
},
|
|
1820
|
-
name:
|
|
1926
|
+
name: RULE_NAME37,
|
|
1821
1927
|
create(context) {
|
|
1822
1928
|
return {
|
|
1823
1929
|
JSXAttribute(node) {
|
|
@@ -1833,7 +1939,7 @@ var no_string_refs_default = createRule({
|
|
|
1833
1939
|
},
|
|
1834
1940
|
defaultOptions: []
|
|
1835
1941
|
});
|
|
1836
|
-
var
|
|
1942
|
+
var RULE_NAME38 = "no-unsafe-component-will-mount";
|
|
1837
1943
|
function isUnsafeComponentWillMount(node) {
|
|
1838
1944
|
return AST11.isOneOf([AST_NODE_TYPES.MethodDefinition, AST_NODE_TYPES.PropertyDefinition])(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "UNSAFE_componentWillMount";
|
|
1839
1945
|
}
|
|
@@ -1848,7 +1954,7 @@ var no_unsafe_component_will_mount_default = createRule({
|
|
|
1848
1954
|
},
|
|
1849
1955
|
schema: []
|
|
1850
1956
|
},
|
|
1851
|
-
name:
|
|
1957
|
+
name: RULE_NAME38,
|
|
1852
1958
|
create(context) {
|
|
1853
1959
|
if (!context.sourceCode.text.includes("UNSAFE_componentWillMount")) return {};
|
|
1854
1960
|
const { ctx, listeners } = useComponentCollectorLegacy();
|
|
@@ -1872,7 +1978,7 @@ var no_unsafe_component_will_mount_default = createRule({
|
|
|
1872
1978
|
},
|
|
1873
1979
|
defaultOptions: []
|
|
1874
1980
|
});
|
|
1875
|
-
var
|
|
1981
|
+
var RULE_NAME39 = "no-unsafe-component-will-receive-props";
|
|
1876
1982
|
function isUnsafeComponentWillReceiveProps(node) {
|
|
1877
1983
|
return AST11.isOneOf([AST_NODE_TYPES.MethodDefinition, AST_NODE_TYPES.PropertyDefinition])(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "UNSAFE_componentWillReceiveProps";
|
|
1878
1984
|
}
|
|
@@ -1887,7 +1993,7 @@ var no_unsafe_component_will_receive_props_default = createRule({
|
|
|
1887
1993
|
},
|
|
1888
1994
|
schema: []
|
|
1889
1995
|
},
|
|
1890
|
-
name:
|
|
1996
|
+
name: RULE_NAME39,
|
|
1891
1997
|
create(context) {
|
|
1892
1998
|
if (!context.sourceCode.text.includes("UNSAFE_componentWillReceiveProps")) return {};
|
|
1893
1999
|
const { ctx, listeners } = useComponentCollectorLegacy();
|
|
@@ -1911,7 +2017,7 @@ var no_unsafe_component_will_receive_props_default = createRule({
|
|
|
1911
2017
|
},
|
|
1912
2018
|
defaultOptions: []
|
|
1913
2019
|
});
|
|
1914
|
-
var
|
|
2020
|
+
var RULE_NAME40 = "no-unsafe-component-will-update";
|
|
1915
2021
|
function isUnsafeComponentWillUpdate(node) {
|
|
1916
2022
|
return AST11.isOneOf([AST_NODE_TYPES.MethodDefinition, AST_NODE_TYPES.PropertyDefinition])(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "UNSAFE_componentWillUpdate";
|
|
1917
2023
|
}
|
|
@@ -1926,7 +2032,7 @@ var no_unsafe_component_will_update_default = createRule({
|
|
|
1926
2032
|
},
|
|
1927
2033
|
schema: []
|
|
1928
2034
|
},
|
|
1929
|
-
name:
|
|
2035
|
+
name: RULE_NAME40,
|
|
1930
2036
|
create(context) {
|
|
1931
2037
|
if (!context.sourceCode.text.includes("UNSAFE_componentWillUpdate")) return {};
|
|
1932
2038
|
const { ctx, listeners } = useComponentCollectorLegacy();
|
|
@@ -1950,7 +2056,7 @@ var no_unsafe_component_will_update_default = createRule({
|
|
|
1950
2056
|
},
|
|
1951
2057
|
defaultOptions: []
|
|
1952
2058
|
});
|
|
1953
|
-
var
|
|
2059
|
+
var RULE_NAME41 = "no-unstable-context-value";
|
|
1954
2060
|
var no_unstable_context_value_default = createRule({
|
|
1955
2061
|
meta: {
|
|
1956
2062
|
type: "problem",
|
|
@@ -1964,7 +2070,7 @@ var no_unstable_context_value_default = createRule({
|
|
|
1964
2070
|
},
|
|
1965
2071
|
schema: []
|
|
1966
2072
|
},
|
|
1967
|
-
name:
|
|
2073
|
+
name: RULE_NAME41,
|
|
1968
2074
|
create(context) {
|
|
1969
2075
|
const { ctx, listeners } = useComponentCollector(context);
|
|
1970
2076
|
const possibleValueConstructions = /* @__PURE__ */ new Map();
|
|
@@ -2017,7 +2123,7 @@ var no_unstable_context_value_default = createRule({
|
|
|
2017
2123
|
},
|
|
2018
2124
|
defaultOptions: []
|
|
2019
2125
|
});
|
|
2020
|
-
var
|
|
2126
|
+
var RULE_NAME42 = "no-unstable-default-props";
|
|
2021
2127
|
var no_unstable_default_props_default = createRule({
|
|
2022
2128
|
meta: {
|
|
2023
2129
|
type: "problem",
|
|
@@ -2029,7 +2135,7 @@ var no_unstable_default_props_default = createRule({
|
|
|
2029
2135
|
},
|
|
2030
2136
|
schema: []
|
|
2031
2137
|
},
|
|
2032
|
-
name:
|
|
2138
|
+
name: RULE_NAME42,
|
|
2033
2139
|
create(context) {
|
|
2034
2140
|
const { ctx, listeners } = useComponentCollector(context);
|
|
2035
2141
|
const possibleDestructuringDeclarators = /* @__PURE__ */ new WeakMap();
|
|
@@ -2082,7 +2188,7 @@ var no_unstable_default_props_default = createRule({
|
|
|
2082
2188
|
},
|
|
2083
2189
|
defaultOptions: []
|
|
2084
2190
|
});
|
|
2085
|
-
var
|
|
2191
|
+
var RULE_NAME43 = "no-unused-class-component-members";
|
|
2086
2192
|
var LIFECYCLE_METHODS = /* @__PURE__ */ new Set([
|
|
2087
2193
|
"componentDidCatch",
|
|
2088
2194
|
"componentDidMount",
|
|
@@ -2126,7 +2232,7 @@ var no_unused_class_component_members_default = createRule({
|
|
|
2126
2232
|
},
|
|
2127
2233
|
schema: []
|
|
2128
2234
|
},
|
|
2129
|
-
name:
|
|
2235
|
+
name: RULE_NAME43,
|
|
2130
2236
|
create(context) {
|
|
2131
2237
|
const classStack = [];
|
|
2132
2238
|
const methodStack = [];
|
|
@@ -2209,7 +2315,7 @@ var no_unused_class_component_members_default = createRule({
|
|
|
2209
2315
|
},
|
|
2210
2316
|
defaultOptions: []
|
|
2211
2317
|
});
|
|
2212
|
-
var
|
|
2318
|
+
var RULE_NAME44 = "no-unused-state";
|
|
2213
2319
|
function getName4(node) {
|
|
2214
2320
|
if (node.type === AST_NODE_TYPES.TSAsExpression) {
|
|
2215
2321
|
return getName4(node.expression);
|
|
@@ -2249,7 +2355,7 @@ var no_unused_state_default = createRule({
|
|
|
2249
2355
|
},
|
|
2250
2356
|
schema: []
|
|
2251
2357
|
},
|
|
2252
|
-
name:
|
|
2358
|
+
name: RULE_NAME44,
|
|
2253
2359
|
create(context) {
|
|
2254
2360
|
const classStack = [];
|
|
2255
2361
|
const methodStack = [];
|
|
@@ -2350,21 +2456,21 @@ var no_unused_state_default = createRule({
|
|
|
2350
2456
|
},
|
|
2351
2457
|
defaultOptions: []
|
|
2352
2458
|
});
|
|
2353
|
-
var
|
|
2459
|
+
var RULE_NAME45 = "no-useless-fragment";
|
|
2354
2460
|
function check(node, context, allowExpressions) {
|
|
2355
2461
|
const initialScope = context.sourceCode.getScope(node);
|
|
2356
|
-
if (
|
|
2357
|
-
if (
|
|
2462
|
+
if (JSX8.isKeyedElement(node, initialScope)) return;
|
|
2463
|
+
if (JSX8.isBuiltInElement(node.parent)) context.report({ messageId: "noUselessFragmentInBuiltIn", node });
|
|
2358
2464
|
if (node.children.length === 0) return context.report({ messageId: "noUselessFragment", node });
|
|
2359
2465
|
const isChildren = AST11.isOneOf([AST_NODE_TYPES.JSXElement, AST_NODE_TYPES.JSXFragment])(node.parent);
|
|
2360
2466
|
const [firstChildren] = node.children;
|
|
2361
|
-
if (allowExpressions && node.children.length === 1 &&
|
|
2467
|
+
if (allowExpressions && node.children.length === 1 && JSX8.isLiteral(firstChildren) && !isChildren) return;
|
|
2362
2468
|
if (!allowExpressions && isChildren) {
|
|
2363
2469
|
return context.report({ messageId: "noUselessFragment", node });
|
|
2364
2470
|
} else if (!allowExpressions && !isChildren && node.children.length === 1) {
|
|
2365
2471
|
return context.report({ messageId: "noUselessFragment", node });
|
|
2366
2472
|
}
|
|
2367
|
-
const nonPaddingChildren = node.children.filter((child) => !
|
|
2473
|
+
const nonPaddingChildren = node.children.filter((child) => !JSX8.isPaddingSpaces(child));
|
|
2368
2474
|
if (nonPaddingChildren.length > 1) return;
|
|
2369
2475
|
if (nonPaddingChildren.length === 0) return context.report({ messageId: "noUselessFragment", node });
|
|
2370
2476
|
const [first] = nonPaddingChildren;
|
|
@@ -2392,7 +2498,7 @@ var no_useless_fragment_default = createRule({
|
|
|
2392
2498
|
}
|
|
2393
2499
|
}]
|
|
2394
2500
|
},
|
|
2395
|
-
name:
|
|
2501
|
+
name: RULE_NAME45,
|
|
2396
2502
|
create(context, [option]) {
|
|
2397
2503
|
const { allowExpressions = true } = option;
|
|
2398
2504
|
return {
|
|
@@ -2409,7 +2515,7 @@ var no_useless_fragment_default = createRule({
|
|
|
2409
2515
|
allowExpressions: true
|
|
2410
2516
|
}]
|
|
2411
2517
|
});
|
|
2412
|
-
var
|
|
2518
|
+
var RULE_NAME46 = "prefer-destructuring-assignment";
|
|
2413
2519
|
function isMemberExpressionWithObjectName(node) {
|
|
2414
2520
|
return node.object.type === AST_NODE_TYPES.Identifier && "name" in node.object;
|
|
2415
2521
|
}
|
|
@@ -2424,7 +2530,7 @@ var prefer_destructuring_assignment_default = createRule({
|
|
|
2424
2530
|
},
|
|
2425
2531
|
schema: []
|
|
2426
2532
|
},
|
|
2427
|
-
name:
|
|
2533
|
+
name: RULE_NAME46,
|
|
2428
2534
|
create(context) {
|
|
2429
2535
|
const { ctx, listeners } = useComponentCollector(context);
|
|
2430
2536
|
const memberExpressionWithNames = [];
|
|
@@ -2479,7 +2585,7 @@ var prefer_destructuring_assignment_default = createRule({
|
|
|
2479
2585
|
},
|
|
2480
2586
|
defaultOptions: []
|
|
2481
2587
|
});
|
|
2482
|
-
var
|
|
2588
|
+
var RULE_NAME47 = "prefer-react-namespace-import";
|
|
2483
2589
|
var prefer_react_namespace_import_default = createRule({
|
|
2484
2590
|
meta: {
|
|
2485
2591
|
type: "problem",
|
|
@@ -2492,7 +2598,7 @@ var prefer_react_namespace_import_default = createRule({
|
|
|
2492
2598
|
},
|
|
2493
2599
|
schema: []
|
|
2494
2600
|
},
|
|
2495
|
-
name:
|
|
2601
|
+
name: RULE_NAME47,
|
|
2496
2602
|
create(context) {
|
|
2497
2603
|
const importSource = decodeSettings(context.settings).importSource ?? "react";
|
|
2498
2604
|
return {
|
|
@@ -2528,7 +2634,7 @@ ${importStringPrefix} ${specifiers} from ${importSourceQuoted}${semiColon}`
|
|
|
2528
2634
|
},
|
|
2529
2635
|
defaultOptions: []
|
|
2530
2636
|
});
|
|
2531
|
-
var
|
|
2637
|
+
var RULE_NAME48 = "prefer-read-only-props";
|
|
2532
2638
|
function isReadonlyType(type, services) {
|
|
2533
2639
|
try {
|
|
2534
2640
|
const im = getTypeImmutability(services.program, type);
|
|
@@ -2548,7 +2654,7 @@ var prefer_read_only_props_default = createRule({
|
|
|
2548
2654
|
},
|
|
2549
2655
|
schema: []
|
|
2550
2656
|
},
|
|
2551
|
-
name:
|
|
2657
|
+
name: RULE_NAME48,
|
|
2552
2658
|
create(context) {
|
|
2553
2659
|
const services = ESLintUtils.getParserServices(context, false);
|
|
2554
2660
|
const { ctx, listeners } = useComponentCollector(context);
|
|
@@ -2568,7 +2674,7 @@ var prefer_read_only_props_default = createRule({
|
|
|
2568
2674
|
},
|
|
2569
2675
|
defaultOptions: []
|
|
2570
2676
|
});
|
|
2571
|
-
var
|
|
2677
|
+
var RULE_NAME49 = "prefer-shorthand-boolean";
|
|
2572
2678
|
var prefer_shorthand_boolean_default = createRule({
|
|
2573
2679
|
meta: {
|
|
2574
2680
|
type: "problem",
|
|
@@ -2581,11 +2687,11 @@ var prefer_shorthand_boolean_default = createRule({
|
|
|
2581
2687
|
},
|
|
2582
2688
|
schema: []
|
|
2583
2689
|
},
|
|
2584
|
-
name:
|
|
2690
|
+
name: RULE_NAME49,
|
|
2585
2691
|
create(context) {
|
|
2586
2692
|
function getReportDescriptor(node) {
|
|
2587
2693
|
const { value } = node;
|
|
2588
|
-
const propName =
|
|
2694
|
+
const propName = JSX8.getPropName(node);
|
|
2589
2695
|
const hasValueTrue = value?.type === AST_NODE_TYPES.JSXExpressionContainer && value.expression.type === AST_NODE_TYPES.Literal && value.expression.value === true;
|
|
2590
2696
|
if (!hasValueTrue) return O.none();
|
|
2591
2697
|
return O.some({
|
|
@@ -2603,7 +2709,7 @@ var prefer_shorthand_boolean_default = createRule({
|
|
|
2603
2709
|
},
|
|
2604
2710
|
defaultOptions: []
|
|
2605
2711
|
});
|
|
2606
|
-
var
|
|
2712
|
+
var RULE_NAME50 = "prefer-shorthand-fragment";
|
|
2607
2713
|
var prefer_shorthand_fragment_default = createRule({
|
|
2608
2714
|
meta: {
|
|
2609
2715
|
type: "problem",
|
|
@@ -2615,7 +2721,7 @@ var prefer_shorthand_fragment_default = createRule({
|
|
|
2615
2721
|
},
|
|
2616
2722
|
schema: []
|
|
2617
2723
|
},
|
|
2618
|
-
name:
|
|
2724
|
+
name: RULE_NAME50,
|
|
2619
2725
|
create(context) {
|
|
2620
2726
|
function getReportDescriptor(node) {
|
|
2621
2727
|
if (!isFragmentElement(node, context)) return O.none();
|
|
@@ -2668,6 +2774,7 @@ var src_default = {
|
|
|
2668
2774
|
"no-component-will-mount": no_component_will_mount_default,
|
|
2669
2775
|
"no-component-will-receive-props": no_component_will_receive_props_default,
|
|
2670
2776
|
"no-component-will-update": no_component_will_update_default,
|
|
2777
|
+
"no-context-provider": no_context_provider_default,
|
|
2671
2778
|
"no-create-ref": no_create_ref_default,
|
|
2672
2779
|
"no-default-props": no_default_props_default,
|
|
2673
2780
|
"no-direct-mutation-state": no_direct_mutation_state_default,
|