eslint-plugin-react-x 2.0.0-beta.4 → 2.0.0-beta.41
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.d.ts +40 -0
- package/dist/index.js +718 -546
- package/package.json +15 -16
package/dist/index.js
CHANGED
|
@@ -4,13 +4,13 @@ import { ESLintUtils } from '@typescript-eslint/utils';
|
|
|
4
4
|
import * as AST13 from '@eslint-react/ast';
|
|
5
5
|
import * as VAR5 from '@eslint-react/var';
|
|
6
6
|
import { match, isMatching, P } from 'ts-pattern';
|
|
7
|
-
import * as
|
|
8
|
-
import { JsxConfig, Reporter, Selector, LanguagePreference } from '@eslint-react/kit';
|
|
7
|
+
import * as ER27 from '@eslint-react/core';
|
|
8
|
+
import { JsxConfig, Reporter, RegExp, Selector, LanguagePreference, ContextDetection } from '@eslint-react/kit';
|
|
9
9
|
import { flow, identity, getOrElseUpdate, constTrue, constFalse, unit } from '@eslint-react/eff';
|
|
10
10
|
import { compare } from 'compare-versions';
|
|
11
|
+
import { camelCase } from 'string-ts';
|
|
11
12
|
import { getConstrainedTypeAtLocation, isTypeReadonly } from '@typescript-eslint/type-utils';
|
|
12
|
-
import {
|
|
13
|
-
import ts from 'typescript';
|
|
13
|
+
import { unionConstituents } from 'ts-api-utils';
|
|
14
14
|
import { getTypeImmutability, isUnknown, isImmutable, isReadonlyShallow, isReadonlyDeep } from 'is-immutable-type';
|
|
15
15
|
|
|
16
16
|
var __defProp = Object.defineProperty;
|
|
@@ -79,6 +79,7 @@ var rules = {
|
|
|
79
79
|
"react-x/no-unstable-context-value": "warn",
|
|
80
80
|
"react-x/no-unstable-default-props": "warn",
|
|
81
81
|
"react-x/no-unused-class-component-members": "warn",
|
|
82
|
+
// "react-x/no-unused-props": "warn",
|
|
82
83
|
"react-x/no-unused-state": "warn",
|
|
83
84
|
"react-x/no-use-context": "warn",
|
|
84
85
|
"react-x/no-useless-forward-ref": "warn",
|
|
@@ -123,7 +124,8 @@ var settings2 = {
|
|
|
123
124
|
var name3 = "react-x/recommended-type-checked";
|
|
124
125
|
var rules3 = {
|
|
125
126
|
...rules2,
|
|
126
|
-
"react-x/no-leaked-conditional-rendering": "warn"
|
|
127
|
+
"react-x/no-leaked-conditional-rendering": "warn",
|
|
128
|
+
"react-x/no-unused-props": "warn"
|
|
127
129
|
// "react-x/prefer-read-only-props": "warn",
|
|
128
130
|
};
|
|
129
131
|
var settings3 = {
|
|
@@ -132,7 +134,7 @@ var settings3 = {
|
|
|
132
134
|
|
|
133
135
|
// package.json
|
|
134
136
|
var name4 = "eslint-plugin-react-x";
|
|
135
|
-
var version = "2.0.0-beta.
|
|
137
|
+
var version = "2.0.0-beta.41";
|
|
136
138
|
var createRule = ESLintUtils.RuleCreator(getDocsUrl("x"));
|
|
137
139
|
|
|
138
140
|
// src/rules/jsx-key-before-spread.ts
|
|
@@ -377,7 +379,7 @@ function create6(context) {
|
|
|
377
379
|
return {
|
|
378
380
|
JSXAttribute(node) {
|
|
379
381
|
const { value } = node;
|
|
380
|
-
const propName =
|
|
382
|
+
const propName = ER27.getAttributeName(context, node);
|
|
381
383
|
switch (true) {
|
|
382
384
|
case (policy === 1 && value?.type === AST_NODE_TYPES.JSXExpressionContainer && value.expression.type === AST_NODE_TYPES.Literal && value.expression.value === true): {
|
|
383
385
|
context.report({
|
|
@@ -443,7 +445,7 @@ function create7(context) {
|
|
|
443
445
|
const { jsxFragmentFactory } = jsxConfig;
|
|
444
446
|
return match(policy).with(1, () => ({
|
|
445
447
|
JSXElement(node) {
|
|
446
|
-
if (!
|
|
448
|
+
if (!ER27.isFragmentElement(context, node)) return;
|
|
447
449
|
const hasAttributes = node.openingElement.attributes.length > 0;
|
|
448
450
|
if (hasAttributes) return;
|
|
449
451
|
context.report({
|
|
@@ -603,25 +605,25 @@ function create10(context) {
|
|
|
603
605
|
const setStateEntries = [];
|
|
604
606
|
return {
|
|
605
607
|
CallExpression(node) {
|
|
606
|
-
if (!
|
|
608
|
+
if (!ER27.isThisSetState(node)) {
|
|
607
609
|
return;
|
|
608
610
|
}
|
|
609
611
|
setStateEntries.push([node, false]);
|
|
610
612
|
},
|
|
611
613
|
"CallExpression:exit"(node) {
|
|
612
|
-
if (!
|
|
614
|
+
if (!ER27.isThisSetState(node)) {
|
|
613
615
|
return;
|
|
614
616
|
}
|
|
615
617
|
setStateEntries.pop();
|
|
616
618
|
},
|
|
617
619
|
ClassDeclaration(node) {
|
|
618
|
-
classEntries.push([node,
|
|
620
|
+
classEntries.push([node, ER27.isClassComponent(node)]);
|
|
619
621
|
},
|
|
620
622
|
"ClassDeclaration:exit"() {
|
|
621
623
|
classEntries.pop();
|
|
622
624
|
},
|
|
623
625
|
ClassExpression(node) {
|
|
624
|
-
classEntries.push([node,
|
|
626
|
+
classEntries.push([node, ER27.isClassComponent(node)]);
|
|
625
627
|
},
|
|
626
628
|
"ClassExpression:exit"() {
|
|
627
629
|
classEntries.pop();
|
|
@@ -705,7 +707,7 @@ function isUsingReactChildren(context, node) {
|
|
|
705
707
|
return true;
|
|
706
708
|
}
|
|
707
709
|
if (callee.object.type === AST_NODE_TYPES.MemberExpression && "name" in callee.object.object) {
|
|
708
|
-
return
|
|
710
|
+
return ER27.isInitializedFromReact(callee.object.object.name, importSource, initialScope);
|
|
709
711
|
}
|
|
710
712
|
return false;
|
|
711
713
|
}
|
|
@@ -771,7 +773,7 @@ function create11(context) {
|
|
|
771
773
|
return node.type === AST_NODE_TYPES.Identifier && indexParamNames.some((name5) => name5 != null && name5 === node.name);
|
|
772
774
|
}
|
|
773
775
|
function isCreateOrCloneElementCall(node) {
|
|
774
|
-
return
|
|
776
|
+
return ER27.isCreateElementCall(context, node) || ER27.isCloneElementCall(context, node);
|
|
775
777
|
}
|
|
776
778
|
function getReportDescriptors(node) {
|
|
777
779
|
switch (node.type) {
|
|
@@ -887,7 +889,7 @@ var no_children_count_default = createRule({
|
|
|
887
889
|
function create12(context) {
|
|
888
890
|
return {
|
|
889
891
|
MemberExpression(node) {
|
|
890
|
-
if (
|
|
892
|
+
if (ER27.isChildrenCount(context, node)) {
|
|
891
893
|
context.report({
|
|
892
894
|
messageId: "noChildrenCount",
|
|
893
895
|
node: node.property
|
|
@@ -917,7 +919,7 @@ var no_children_for_each_default = createRule({
|
|
|
917
919
|
function create13(context) {
|
|
918
920
|
return {
|
|
919
921
|
MemberExpression(node) {
|
|
920
|
-
if (
|
|
922
|
+
if (ER27.isChildrenForEach(context, node)) {
|
|
921
923
|
context.report({
|
|
922
924
|
messageId: "noChildrenForEach",
|
|
923
925
|
node: node.property
|
|
@@ -947,7 +949,7 @@ var no_children_map_default = createRule({
|
|
|
947
949
|
function create14(context) {
|
|
948
950
|
return {
|
|
949
951
|
MemberExpression(node) {
|
|
950
|
-
if (
|
|
952
|
+
if (ER27.isChildrenMap(context, node)) {
|
|
951
953
|
context.report({
|
|
952
954
|
messageId: "noChildrenMap",
|
|
953
955
|
node: node.property
|
|
@@ -977,7 +979,7 @@ var no_children_only_default = createRule({
|
|
|
977
979
|
function create15(context) {
|
|
978
980
|
return {
|
|
979
981
|
MemberExpression(node) {
|
|
980
|
-
if (
|
|
982
|
+
if (ER27.isChildrenOnly(context, node)) {
|
|
981
983
|
context.report({
|
|
982
984
|
messageId: "noChildrenOnly",
|
|
983
985
|
node: node.property
|
|
@@ -1008,7 +1010,7 @@ function create16(context) {
|
|
|
1008
1010
|
return {
|
|
1009
1011
|
JSXElement(node) {
|
|
1010
1012
|
const attributes = node.openingElement.attributes;
|
|
1011
|
-
const childrenProp =
|
|
1013
|
+
const childrenProp = ER27.getAttribute(context, "children", attributes, context.sourceCode.getScope(node));
|
|
1012
1014
|
if (childrenProp != null) {
|
|
1013
1015
|
context.report({
|
|
1014
1016
|
messageId: "noChildrenProp",
|
|
@@ -1039,7 +1041,7 @@ var no_children_to_array_default = createRule({
|
|
|
1039
1041
|
function create17(context) {
|
|
1040
1042
|
return {
|
|
1041
1043
|
MemberExpression(node) {
|
|
1042
|
-
if (
|
|
1044
|
+
if (ER27.isChildrenToArray(context, node)) {
|
|
1043
1045
|
context.report({
|
|
1044
1046
|
messageId: "noChildrenToArray",
|
|
1045
1047
|
node: node.property
|
|
@@ -1068,13 +1070,13 @@ var no_class_component_default = createRule({
|
|
|
1068
1070
|
});
|
|
1069
1071
|
function create18(context) {
|
|
1070
1072
|
if (!context.sourceCode.text.includes("Component")) return {};
|
|
1071
|
-
const { ctx, listeners } =
|
|
1073
|
+
const { ctx, listeners } = ER27.useComponentCollectorLegacy();
|
|
1072
1074
|
return {
|
|
1073
1075
|
...listeners,
|
|
1074
1076
|
"Program:exit"(program) {
|
|
1075
1077
|
const components = ctx.getAllComponents(program);
|
|
1076
1078
|
for (const { name: name5 = "anonymous", node: component } of components.values()) {
|
|
1077
|
-
if (component.body.body.some((m) =>
|
|
1079
|
+
if (component.body.body.some((m) => ER27.isComponentDidCatch(m) || ER27.isGetDerivedStateFromError(m))) {
|
|
1078
1080
|
continue;
|
|
1079
1081
|
}
|
|
1080
1082
|
context.report({
|
|
@@ -1109,7 +1111,7 @@ var no_clone_element_default = createRule({
|
|
|
1109
1111
|
function create19(context) {
|
|
1110
1112
|
return {
|
|
1111
1113
|
CallExpression(node) {
|
|
1112
|
-
if (
|
|
1114
|
+
if (ER27.isCloneElementCall(context, node)) {
|
|
1113
1115
|
context.report({
|
|
1114
1116
|
messageId: "noCloneElement",
|
|
1115
1117
|
node
|
|
@@ -1141,7 +1143,7 @@ var no_component_will_mount_default = createRule({
|
|
|
1141
1143
|
});
|
|
1142
1144
|
function create20(context) {
|
|
1143
1145
|
if (!context.sourceCode.text.includes("componentWillMount")) return {};
|
|
1144
|
-
const { ctx, listeners } =
|
|
1146
|
+
const { ctx, listeners } = ER27.useComponentCollectorLegacy();
|
|
1145
1147
|
return {
|
|
1146
1148
|
...listeners,
|
|
1147
1149
|
"Program:exit"(program) {
|
|
@@ -1149,7 +1151,7 @@ function create20(context) {
|
|
|
1149
1151
|
for (const { node: component } of components.values()) {
|
|
1150
1152
|
const { body } = component.body;
|
|
1151
1153
|
for (const member of body) {
|
|
1152
|
-
if (
|
|
1154
|
+
if (ER27.isComponentWillMount(member)) {
|
|
1153
1155
|
context.report({
|
|
1154
1156
|
messageId: "noComponentWillMount",
|
|
1155
1157
|
node: member,
|
|
@@ -1189,7 +1191,7 @@ var no_component_will_receive_props_default = createRule({
|
|
|
1189
1191
|
});
|
|
1190
1192
|
function create21(context) {
|
|
1191
1193
|
if (!context.sourceCode.text.includes("componentWillReceiveProps")) return {};
|
|
1192
|
-
const { ctx, listeners } =
|
|
1194
|
+
const { ctx, listeners } = ER27.useComponentCollectorLegacy();
|
|
1193
1195
|
return {
|
|
1194
1196
|
...listeners,
|
|
1195
1197
|
"Program:exit"(program) {
|
|
@@ -1197,7 +1199,7 @@ function create21(context) {
|
|
|
1197
1199
|
for (const { node: component } of components.values()) {
|
|
1198
1200
|
const { body } = component.body;
|
|
1199
1201
|
for (const member of body) {
|
|
1200
|
-
if (
|
|
1202
|
+
if (ER27.isComponentWillReceiveProps(member)) {
|
|
1201
1203
|
context.report({
|
|
1202
1204
|
messageId: "noComponentWillReceiveProps",
|
|
1203
1205
|
node: member,
|
|
@@ -1237,7 +1239,7 @@ var no_component_will_update_default = createRule({
|
|
|
1237
1239
|
});
|
|
1238
1240
|
function create22(context) {
|
|
1239
1241
|
if (!context.sourceCode.text.includes("componentWillUpdate")) return {};
|
|
1240
|
-
const { ctx, listeners } =
|
|
1242
|
+
const { ctx, listeners } = ER27.useComponentCollectorLegacy();
|
|
1241
1243
|
return {
|
|
1242
1244
|
...listeners,
|
|
1243
1245
|
"Program:exit"(program) {
|
|
@@ -1245,7 +1247,7 @@ function create22(context) {
|
|
|
1245
1247
|
for (const { node: component } of components.values()) {
|
|
1246
1248
|
const { body } = component.body;
|
|
1247
1249
|
for (const member of body) {
|
|
1248
|
-
if (
|
|
1250
|
+
if (ER27.isComponentWillUpdate(member)) {
|
|
1249
1251
|
context.report({
|
|
1250
1252
|
messageId: "noComponentWillUpdate",
|
|
1251
1253
|
node: member,
|
|
@@ -1289,7 +1291,7 @@ function create23(context) {
|
|
|
1289
1291
|
if (compare(version2, "19.0.0", "<")) return {};
|
|
1290
1292
|
return {
|
|
1291
1293
|
JSXElement(node) {
|
|
1292
|
-
const fullName =
|
|
1294
|
+
const fullName = ER27.getElementType(context, node);
|
|
1293
1295
|
const parts = fullName.split(".");
|
|
1294
1296
|
const selfName = parts.pop();
|
|
1295
1297
|
const contextFullName = parts.join(".");
|
|
@@ -1300,7 +1302,7 @@ function create23(context) {
|
|
|
1300
1302
|
messageId: "noContextProvider",
|
|
1301
1303
|
node,
|
|
1302
1304
|
fix(fixer) {
|
|
1303
|
-
if (!
|
|
1305
|
+
if (!ER27.isComponentNameLoose(contextSelfName)) return null;
|
|
1304
1306
|
const openingElement = node.openingElement;
|
|
1305
1307
|
const closingElement = node.closingElement;
|
|
1306
1308
|
if (closingElement == null) {
|
|
@@ -1336,7 +1338,7 @@ var no_create_ref_default = createRule({
|
|
|
1336
1338
|
function create24(context) {
|
|
1337
1339
|
return {
|
|
1338
1340
|
CallExpression(node) {
|
|
1339
|
-
if (
|
|
1341
|
+
if (ER27.isCreateRefCall(context, node) && AST13.findParentNode(node, ER27.isClassComponent) == null) {
|
|
1340
1342
|
context.report({ messageId: "noCreateRef", node });
|
|
1341
1343
|
}
|
|
1342
1344
|
}
|
|
@@ -1374,7 +1376,7 @@ function create25(context) {
|
|
|
1374
1376
|
if (property.type !== AST_NODE_TYPES.Identifier || property.name !== "defaultProps") {
|
|
1375
1377
|
return;
|
|
1376
1378
|
}
|
|
1377
|
-
if (!
|
|
1379
|
+
if (!ER27.isComponentNameLoose(object.name)) {
|
|
1378
1380
|
return;
|
|
1379
1381
|
}
|
|
1380
1382
|
const variable = VAR5.findVariable(object.name, context.sourceCode.getScope(node));
|
|
@@ -1409,7 +1411,7 @@ var no_direct_mutation_state_default = createRule({
|
|
|
1409
1411
|
function create26(context) {
|
|
1410
1412
|
return {
|
|
1411
1413
|
AssignmentExpression(node) {
|
|
1412
|
-
if (!
|
|
1414
|
+
if (!ER27.isAssignmentToThisState(node)) return;
|
|
1413
1415
|
const parentClass = AST13.findParentNode(
|
|
1414
1416
|
node,
|
|
1415
1417
|
AST13.isOneOf([
|
|
@@ -1418,7 +1420,7 @@ function create26(context) {
|
|
|
1418
1420
|
])
|
|
1419
1421
|
);
|
|
1420
1422
|
if (parentClass == null) return;
|
|
1421
|
-
if (
|
|
1423
|
+
if (ER27.isClassComponent(parentClass) && context.sourceCode.getScope(node).block !== AST13.findParentNode(node, isConstructorFunction)) {
|
|
1422
1424
|
context.report({
|
|
1423
1425
|
messageId: "noDirectMutationState",
|
|
1424
1426
|
node
|
|
@@ -1509,7 +1511,107 @@ function create27(context) {
|
|
|
1509
1511
|
}
|
|
1510
1512
|
};
|
|
1511
1513
|
}
|
|
1512
|
-
var RULE_NAME28 = "no-
|
|
1514
|
+
var RULE_NAME28 = "no-forbidden-props";
|
|
1515
|
+
var messageId = camelCase(RULE_NAME28);
|
|
1516
|
+
var defaultOptions3 = [{
|
|
1517
|
+
forbid: [{ prop: "/_/" }]
|
|
1518
|
+
}];
|
|
1519
|
+
var no_forbidden_props_default = createRule({
|
|
1520
|
+
meta: {
|
|
1521
|
+
type: "problem",
|
|
1522
|
+
defaultOptions: [...defaultOptions3],
|
|
1523
|
+
docs: {
|
|
1524
|
+
description: "Disallow certain props on components."
|
|
1525
|
+
},
|
|
1526
|
+
messages: {
|
|
1527
|
+
[messageId]: 'Prop "{{name}}" is forbidden.'
|
|
1528
|
+
},
|
|
1529
|
+
schema: [{
|
|
1530
|
+
type: "object",
|
|
1531
|
+
properties: {
|
|
1532
|
+
forbid: {
|
|
1533
|
+
type: "array",
|
|
1534
|
+
items: {
|
|
1535
|
+
anyOf: [
|
|
1536
|
+
{ type: "string" },
|
|
1537
|
+
{
|
|
1538
|
+
type: "object",
|
|
1539
|
+
additionalProperties: false,
|
|
1540
|
+
properties: {
|
|
1541
|
+
excludedNodes: {
|
|
1542
|
+
type: "array",
|
|
1543
|
+
items: { type: "string" },
|
|
1544
|
+
uniqueItems: true
|
|
1545
|
+
},
|
|
1546
|
+
prop: { type: "string" }
|
|
1547
|
+
},
|
|
1548
|
+
required: ["prop"]
|
|
1549
|
+
},
|
|
1550
|
+
{
|
|
1551
|
+
type: "object",
|
|
1552
|
+
additionalProperties: false,
|
|
1553
|
+
properties: {
|
|
1554
|
+
includedNodes: {
|
|
1555
|
+
type: "array",
|
|
1556
|
+
items: { type: "string" },
|
|
1557
|
+
uniqueItems: true
|
|
1558
|
+
},
|
|
1559
|
+
prop: { type: "string" }
|
|
1560
|
+
},
|
|
1561
|
+
required: ["prop"]
|
|
1562
|
+
}
|
|
1563
|
+
]
|
|
1564
|
+
}
|
|
1565
|
+
}
|
|
1566
|
+
}
|
|
1567
|
+
}]
|
|
1568
|
+
},
|
|
1569
|
+
name: RULE_NAME28,
|
|
1570
|
+
create: create28,
|
|
1571
|
+
defaultOptions: defaultOptions3
|
|
1572
|
+
});
|
|
1573
|
+
function create28(context, [option]) {
|
|
1574
|
+
const { forbid = [{ prop: "/_/" }] } = option;
|
|
1575
|
+
return {
|
|
1576
|
+
JSXOpeningElement(node) {
|
|
1577
|
+
let nodeName = null;
|
|
1578
|
+
if (node.name.type === AST_NODE_TYPES.JSXIdentifier) {
|
|
1579
|
+
nodeName = node.name.name;
|
|
1580
|
+
} else if (node.name.type === AST_NODE_TYPES.JSXNamespacedName) {
|
|
1581
|
+
nodeName = node.name.name.name;
|
|
1582
|
+
}
|
|
1583
|
+
for (const attr of node.attributes) {
|
|
1584
|
+
if (attr.type === AST_NODE_TYPES.JSXSpreadAttribute) {
|
|
1585
|
+
continue;
|
|
1586
|
+
}
|
|
1587
|
+
const name5 = attr.name.name;
|
|
1588
|
+
if (typeof name5 !== "string") {
|
|
1589
|
+
continue;
|
|
1590
|
+
}
|
|
1591
|
+
for (const forbiddenPropItem of forbid) {
|
|
1592
|
+
if (typeof forbiddenPropItem !== "string" && nodeName != null) {
|
|
1593
|
+
if ("excludedNodes" in forbiddenPropItem && forbiddenPropItem.excludedNodes.includes(nodeName)) {
|
|
1594
|
+
continue;
|
|
1595
|
+
}
|
|
1596
|
+
if ("includedNodes" in forbiddenPropItem && !forbiddenPropItem.includedNodes.includes(nodeName)) {
|
|
1597
|
+
continue;
|
|
1598
|
+
}
|
|
1599
|
+
}
|
|
1600
|
+
const forbiddenProp = typeof forbiddenPropItem === "string" ? forbiddenPropItem : forbiddenPropItem.prop;
|
|
1601
|
+
const forbiddenPropRegExp = RegExp.toRegExp(forbiddenProp);
|
|
1602
|
+
if (forbiddenPropRegExp.test(name5)) {
|
|
1603
|
+
context.report({
|
|
1604
|
+
messageId,
|
|
1605
|
+
node: attr,
|
|
1606
|
+
data: { name: name5 }
|
|
1607
|
+
});
|
|
1608
|
+
}
|
|
1609
|
+
}
|
|
1610
|
+
}
|
|
1611
|
+
}
|
|
1612
|
+
};
|
|
1613
|
+
}
|
|
1614
|
+
var RULE_NAME29 = "no-forward-ref";
|
|
1513
1615
|
var RULE_FEATURES28 = [
|
|
1514
1616
|
"MOD"
|
|
1515
1617
|
];
|
|
@@ -1526,11 +1628,11 @@ var no_forward_ref_default = createRule({
|
|
|
1526
1628
|
},
|
|
1527
1629
|
schema: []
|
|
1528
1630
|
},
|
|
1529
|
-
name:
|
|
1530
|
-
create:
|
|
1631
|
+
name: RULE_NAME29,
|
|
1632
|
+
create: create29,
|
|
1531
1633
|
defaultOptions: []
|
|
1532
1634
|
});
|
|
1533
|
-
function
|
|
1635
|
+
function create29(context) {
|
|
1534
1636
|
if (!context.sourceCode.text.includes("forwardRef")) {
|
|
1535
1637
|
return {};
|
|
1536
1638
|
}
|
|
@@ -1540,18 +1642,31 @@ function create28(context) {
|
|
|
1540
1642
|
}
|
|
1541
1643
|
return {
|
|
1542
1644
|
CallExpression(node) {
|
|
1543
|
-
if (!
|
|
1645
|
+
if (!ER27.isForwardRefCall(context, node)) {
|
|
1544
1646
|
return;
|
|
1545
1647
|
}
|
|
1546
1648
|
const id = AST13.getFunctionId(node);
|
|
1649
|
+
const fix = canFix(context, node) ? getFix(context, node) : null;
|
|
1547
1650
|
context.report({
|
|
1548
1651
|
messageId: "noForwardRef",
|
|
1549
1652
|
node: id ?? node,
|
|
1550
|
-
fix
|
|
1653
|
+
fix
|
|
1551
1654
|
});
|
|
1552
1655
|
}
|
|
1553
1656
|
};
|
|
1554
1657
|
}
|
|
1658
|
+
function canFix(context, node) {
|
|
1659
|
+
const { importSource } = getSettingsFromContext(context);
|
|
1660
|
+
const initialScope = context.sourceCode.getScope(node);
|
|
1661
|
+
switch (node.callee.type) {
|
|
1662
|
+
case AST_NODE_TYPES.Identifier:
|
|
1663
|
+
return ER27.isInitializedFromReact(node.callee.name, importSource, initialScope);
|
|
1664
|
+
case AST_NODE_TYPES.MemberExpression:
|
|
1665
|
+
return node.callee.object.type === AST_NODE_TYPES.Identifier && ER27.isInitializedFromReact(node.callee.object.name, importSource, initialScope);
|
|
1666
|
+
default:
|
|
1667
|
+
return false;
|
|
1668
|
+
}
|
|
1669
|
+
}
|
|
1555
1670
|
function getFix(context, node) {
|
|
1556
1671
|
return (fixer) => {
|
|
1557
1672
|
const [componentNode] = node.arguments;
|
|
@@ -1619,7 +1734,7 @@ function getComponentPropsFixes(context, fixer, node, typeArguments) {
|
|
|
1619
1734
|
...arg1 == null ? [] : [fixer.remove(arg1), fixer.removeRange([arg0.range[1], arg1.range[0]])]
|
|
1620
1735
|
];
|
|
1621
1736
|
}
|
|
1622
|
-
var
|
|
1737
|
+
var RULE_NAME30 = "no-implicit-key";
|
|
1623
1738
|
var RULE_FEATURES29 = [
|
|
1624
1739
|
"EXP"
|
|
1625
1740
|
];
|
|
@@ -1635,15 +1750,15 @@ var no_implicit_key_default = createRule({
|
|
|
1635
1750
|
},
|
|
1636
1751
|
schema: []
|
|
1637
1752
|
},
|
|
1638
|
-
name:
|
|
1639
|
-
create:
|
|
1753
|
+
name: RULE_NAME30,
|
|
1754
|
+
create: create30,
|
|
1640
1755
|
defaultOptions: []
|
|
1641
1756
|
});
|
|
1642
|
-
function
|
|
1757
|
+
function create30(context) {
|
|
1643
1758
|
return {
|
|
1644
1759
|
JSXOpeningElement(node) {
|
|
1645
1760
|
const initialScope = context.sourceCode.getScope(node);
|
|
1646
|
-
const keyProp =
|
|
1761
|
+
const keyProp = ER27.getAttribute(context, "key", node.attributes, initialScope);
|
|
1647
1762
|
const isKeyPropOnElement = node.attributes.some(
|
|
1648
1763
|
(n) => n.type === AST_NODE_TYPES.JSXAttribute && n.name.type === AST_NODE_TYPES.JSXIdentifier && n.name.name === "key"
|
|
1649
1764
|
);
|
|
@@ -1653,88 +1768,10 @@ function create29(context) {
|
|
|
1653
1768
|
}
|
|
1654
1769
|
};
|
|
1655
1770
|
}
|
|
1656
|
-
var
|
|
1771
|
+
var RULE_NAME31 = "no-leaked-conditional-rendering";
|
|
1657
1772
|
var RULE_FEATURES30 = [
|
|
1658
1773
|
"TSC"
|
|
1659
1774
|
];
|
|
1660
|
-
var tsHelpers = {
|
|
1661
|
-
isAnyType: (type) => isTypeFlagSet(type, ts.TypeFlags.TypeParameter | ts.TypeFlags.Any),
|
|
1662
|
-
isBigIntType: (type) => isTypeFlagSet(type, ts.TypeFlags.BigIntLike),
|
|
1663
|
-
isBooleanType: (type) => isTypeFlagSet(type, ts.TypeFlags.BooleanLike),
|
|
1664
|
-
isEnumType: (type) => isTypeFlagSet(type, ts.TypeFlags.EnumLike),
|
|
1665
|
-
isFalsyBigIntType: (type) => type.isLiteral() && isMatching({ value: { base10Value: "0" } }, type),
|
|
1666
|
-
isFalsyNumberType: (type) => type.isNumberLiteral() && type.value === 0,
|
|
1667
|
-
isFalsyStringType: (type) => type.isStringLiteral() && type.value === "",
|
|
1668
|
-
isNeverType: (type) => isTypeFlagSet(type, ts.TypeFlags.Never),
|
|
1669
|
-
isNullishType: (type) => isTypeFlagSet(
|
|
1670
|
-
type,
|
|
1671
|
-
ts.TypeFlags.Null | ts.TypeFlags.Undefined | ts.TypeFlags.VoidLike
|
|
1672
|
-
),
|
|
1673
|
-
isNumberType: (type) => isTypeFlagSet(type, ts.TypeFlags.NumberLike),
|
|
1674
|
-
isObjectType: (type) => !isTypeFlagSet(
|
|
1675
|
-
type,
|
|
1676
|
-
ts.TypeFlags.Null | ts.TypeFlags.Undefined | ts.TypeFlags.VoidLike | ts.TypeFlags.BooleanLike | ts.TypeFlags.StringLike | ts.TypeFlags.NumberLike | ts.TypeFlags.BigIntLike | ts.TypeFlags.TypeParameter | ts.TypeFlags.Any | ts.TypeFlags.Unknown | ts.TypeFlags.Never
|
|
1677
|
-
),
|
|
1678
|
-
isStringType: (type) => isTypeFlagSet(type, ts.TypeFlags.StringLike),
|
|
1679
|
-
isTruthyBigIntType: (type) => type.isLiteral() && isMatching({ value: { base10Value: P.not("0") } }, type),
|
|
1680
|
-
isTruthyNumberType: (type) => type.isNumberLiteral() && type.value !== 0,
|
|
1681
|
-
isTruthyStringType: (type) => type.isStringLiteral() && type.value !== "",
|
|
1682
|
-
isUnknownType: (type) => isTypeFlagSet(type, ts.TypeFlags.Unknown)
|
|
1683
|
-
};
|
|
1684
|
-
function inspectVariantTypes(types) {
|
|
1685
|
-
const variantTypes = /* @__PURE__ */ new Set();
|
|
1686
|
-
if (types.some(tsHelpers.isUnknownType)) {
|
|
1687
|
-
variantTypes.add("unknown");
|
|
1688
|
-
return variantTypes;
|
|
1689
|
-
}
|
|
1690
|
-
if (types.some(tsHelpers.isNullishType)) {
|
|
1691
|
-
variantTypes.add("nullish");
|
|
1692
|
-
}
|
|
1693
|
-
const booleans = types.filter(tsHelpers.isBooleanType);
|
|
1694
|
-
switch (true) {
|
|
1695
|
-
case (booleans.length === 1 && booleans[0] != null): {
|
|
1696
|
-
const first = booleans[0];
|
|
1697
|
-
if (isTrueLiteralType(first)) {
|
|
1698
|
-
variantTypes.add("truthy boolean");
|
|
1699
|
-
} else if (isFalseLiteralType(first)) {
|
|
1700
|
-
variantTypes.add("falsy boolean");
|
|
1701
|
-
}
|
|
1702
|
-
break;
|
|
1703
|
-
}
|
|
1704
|
-
case booleans.length === 2: {
|
|
1705
|
-
variantTypes.add("boolean");
|
|
1706
|
-
break;
|
|
1707
|
-
}
|
|
1708
|
-
}
|
|
1709
|
-
const strings = types.filter(tsHelpers.isStringType);
|
|
1710
|
-
if (strings.length > 0) {
|
|
1711
|
-
const evaluated = match(strings).when((types2) => types2.every(tsHelpers.isTruthyStringType), () => "truthy string").when((types2) => types2.every(tsHelpers.isFalsyStringType), () => "falsy string").otherwise(() => "string");
|
|
1712
|
-
variantTypes.add(evaluated);
|
|
1713
|
-
}
|
|
1714
|
-
const bigints = types.filter(tsHelpers.isBigIntType);
|
|
1715
|
-
if (bigints.length > 0) {
|
|
1716
|
-
const evaluated = match(bigints).when((types2) => types2.every(tsHelpers.isTruthyBigIntType), () => "truthy bigint").when((types2) => types2.every(tsHelpers.isFalsyBigIntType), () => "falsy bigint").otherwise(() => "bigint");
|
|
1717
|
-
variantTypes.add(evaluated);
|
|
1718
|
-
}
|
|
1719
|
-
const numbers = types.filter(tsHelpers.isNumberType);
|
|
1720
|
-
if (numbers.length > 0) {
|
|
1721
|
-
const evaluated = match(numbers).when((types2) => types2.every(tsHelpers.isTruthyNumberType), () => "truthy number").when((types2) => types2.every(tsHelpers.isFalsyNumberType), () => "falsy number").otherwise(() => "number");
|
|
1722
|
-
variantTypes.add(evaluated);
|
|
1723
|
-
}
|
|
1724
|
-
if (types.some(tsHelpers.isEnumType)) {
|
|
1725
|
-
variantTypes.add("enum");
|
|
1726
|
-
}
|
|
1727
|
-
if (types.some(tsHelpers.isObjectType)) {
|
|
1728
|
-
variantTypes.add("object");
|
|
1729
|
-
}
|
|
1730
|
-
if (types.some(tsHelpers.isAnyType)) {
|
|
1731
|
-
variantTypes.add("any");
|
|
1732
|
-
}
|
|
1733
|
-
if (types.some(tsHelpers.isNeverType)) {
|
|
1734
|
-
variantTypes.add("never");
|
|
1735
|
-
}
|
|
1736
|
-
return variantTypes;
|
|
1737
|
-
}
|
|
1738
1775
|
var no_leaked_conditional_rendering_default = createRule({
|
|
1739
1776
|
meta: {
|
|
1740
1777
|
type: "problem",
|
|
@@ -1747,11 +1784,11 @@ var no_leaked_conditional_rendering_default = createRule({
|
|
|
1747
1784
|
},
|
|
1748
1785
|
schema: []
|
|
1749
1786
|
},
|
|
1750
|
-
name:
|
|
1751
|
-
create:
|
|
1787
|
+
name: RULE_NAME31,
|
|
1788
|
+
create: create31,
|
|
1752
1789
|
defaultOptions: []
|
|
1753
1790
|
});
|
|
1754
|
-
function
|
|
1791
|
+
function create31(context) {
|
|
1755
1792
|
if (!context.sourceCode.text.includes("&&")) return {};
|
|
1756
1793
|
const { version: version2 } = getSettingsFromContext(context);
|
|
1757
1794
|
const allowedVariants = [
|
|
@@ -1787,7 +1824,7 @@ function create30(context) {
|
|
|
1787
1824
|
};
|
|
1788
1825
|
}
|
|
1789
1826
|
const leftType = getConstrainedTypeAtLocation(services, left);
|
|
1790
|
-
const leftTypeVariants =
|
|
1827
|
+
const leftTypeVariants = ER27.getTypeVariants(unionConstituents(leftType));
|
|
1791
1828
|
const isLeftValid = Array.from(leftTypeVariants.values()).every((type) => allowedVariants.some((allowed) => allowed === type));
|
|
1792
1829
|
if (isLeftValid) {
|
|
1793
1830
|
return getReportDescriptor(right);
|
|
@@ -1809,7 +1846,7 @@ function create30(context) {
|
|
|
1809
1846
|
JSXExpressionContainer: flow(getReportDescriptor, Reporter.make(context).send)
|
|
1810
1847
|
};
|
|
1811
1848
|
}
|
|
1812
|
-
var
|
|
1849
|
+
var RULE_NAME32 = "no-missing-component-display-name";
|
|
1813
1850
|
var RULE_FEATURES31 = [];
|
|
1814
1851
|
var no_missing_component_display_name_default = createRule({
|
|
1815
1852
|
meta: {
|
|
@@ -1823,21 +1860,21 @@ var no_missing_component_display_name_default = createRule({
|
|
|
1823
1860
|
},
|
|
1824
1861
|
schema: []
|
|
1825
1862
|
},
|
|
1826
|
-
name:
|
|
1827
|
-
create:
|
|
1863
|
+
name: RULE_NAME32,
|
|
1864
|
+
create: create32,
|
|
1828
1865
|
defaultOptions: []
|
|
1829
1866
|
});
|
|
1830
|
-
function
|
|
1867
|
+
function create32(context) {
|
|
1831
1868
|
if (!context.sourceCode.text.includes("memo") && !context.sourceCode.text.includes("forwardRef")) return {};
|
|
1832
1869
|
const {
|
|
1833
1870
|
ctx,
|
|
1834
1871
|
listeners
|
|
1835
|
-
} =
|
|
1872
|
+
} = ER27.useComponentCollector(
|
|
1836
1873
|
context,
|
|
1837
1874
|
{
|
|
1838
1875
|
collectDisplayName: true,
|
|
1839
1876
|
collectHookCalls: false,
|
|
1840
|
-
hint:
|
|
1877
|
+
hint: ER27.DEFAULT_COMPONENT_DETECTION_HINT
|
|
1841
1878
|
}
|
|
1842
1879
|
);
|
|
1843
1880
|
return {
|
|
@@ -1845,7 +1882,7 @@ function create31(context) {
|
|
|
1845
1882
|
"Program:exit"(program) {
|
|
1846
1883
|
const components = ctx.getAllComponents(program);
|
|
1847
1884
|
for (const { node, displayName, flag } of components.values()) {
|
|
1848
|
-
const isMemoOrForwardRef = (flag & (
|
|
1885
|
+
const isMemoOrForwardRef = (flag & (ER27.ComponentFlag.ForwardRef | ER27.ComponentFlag.Memo)) > 0n;
|
|
1849
1886
|
if (AST13.getFunctionId(node) != null) {
|
|
1850
1887
|
continue;
|
|
1851
1888
|
}
|
|
@@ -1863,7 +1900,7 @@ function create31(context) {
|
|
|
1863
1900
|
}
|
|
1864
1901
|
};
|
|
1865
1902
|
}
|
|
1866
|
-
var
|
|
1903
|
+
var RULE_NAME33 = "no-missing-context-display-name";
|
|
1867
1904
|
var RULE_FEATURES32 = [
|
|
1868
1905
|
"FIX"
|
|
1869
1906
|
];
|
|
@@ -1880,22 +1917,22 @@ var no_missing_context_display_name_default = createRule({
|
|
|
1880
1917
|
},
|
|
1881
1918
|
schema: []
|
|
1882
1919
|
},
|
|
1883
|
-
name:
|
|
1884
|
-
create:
|
|
1920
|
+
name: RULE_NAME33,
|
|
1921
|
+
create: create33,
|
|
1885
1922
|
defaultOptions: []
|
|
1886
1923
|
});
|
|
1887
|
-
function
|
|
1924
|
+
function create33(context) {
|
|
1888
1925
|
if (!context.sourceCode.text.includes("createContext")) return {};
|
|
1889
1926
|
const createCalls = [];
|
|
1890
1927
|
const displayNameAssignments = [];
|
|
1891
1928
|
return {
|
|
1892
1929
|
CallExpression(node) {
|
|
1893
|
-
if (!
|
|
1930
|
+
if (!ER27.isCreateContextCall(context, node)) return;
|
|
1894
1931
|
createCalls.push(node);
|
|
1895
1932
|
},
|
|
1896
1933
|
"Program:exit"() {
|
|
1897
1934
|
for (const call of createCalls) {
|
|
1898
|
-
const id =
|
|
1935
|
+
const id = ER27.getInstanceId(call);
|
|
1899
1936
|
if (id == null) {
|
|
1900
1937
|
context.report({
|
|
1901
1938
|
messageId: "noMissingContextDisplayName",
|
|
@@ -1907,7 +1944,7 @@ function create32(context) {
|
|
|
1907
1944
|
const left = node.left;
|
|
1908
1945
|
if (left.type !== AST_NODE_TYPES.MemberExpression) return false;
|
|
1909
1946
|
const object = left.object;
|
|
1910
|
-
return
|
|
1947
|
+
return ER27.isInstanceIdEqual(context, id, object);
|
|
1911
1948
|
});
|
|
1912
1949
|
if (!hasDisplayNameAssignment) {
|
|
1913
1950
|
const semi = LanguagePreference.defaultLanguagePreference.semicolons === "always" ? ";" : "";
|
|
@@ -1940,7 +1977,7 @@ function create32(context) {
|
|
|
1940
1977
|
}
|
|
1941
1978
|
};
|
|
1942
1979
|
}
|
|
1943
|
-
var
|
|
1980
|
+
var RULE_NAME34 = "no-missing-key";
|
|
1944
1981
|
var RULE_FEATURES33 = [];
|
|
1945
1982
|
var no_missing_key_default = createRule({
|
|
1946
1983
|
meta: {
|
|
@@ -1955,18 +1992,18 @@ var no_missing_key_default = createRule({
|
|
|
1955
1992
|
},
|
|
1956
1993
|
schema: []
|
|
1957
1994
|
},
|
|
1958
|
-
name:
|
|
1959
|
-
create:
|
|
1995
|
+
name: RULE_NAME34,
|
|
1996
|
+
create: create34,
|
|
1960
1997
|
defaultOptions: []
|
|
1961
1998
|
});
|
|
1962
|
-
function
|
|
1999
|
+
function create34(context) {
|
|
1963
2000
|
const report = Reporter.make(context);
|
|
1964
2001
|
const state = { isWithinChildrenToArray: false };
|
|
1965
2002
|
function checkIteratorElement(node) {
|
|
1966
2003
|
switch (node.type) {
|
|
1967
2004
|
case AST_NODE_TYPES.JSXElement: {
|
|
1968
2005
|
const initialScope = context.sourceCode.getScope(node);
|
|
1969
|
-
if (!
|
|
2006
|
+
if (!ER27.hasAttribute(context, "key", node.openingElement.attributes, initialScope)) {
|
|
1970
2007
|
return {
|
|
1971
2008
|
messageId: "missingKey",
|
|
1972
2009
|
node
|
|
@@ -2023,7 +2060,7 @@ function create33(context) {
|
|
|
2023
2060
|
}
|
|
2024
2061
|
const initialScope = context.sourceCode.getScope(node);
|
|
2025
2062
|
for (const element of elements) {
|
|
2026
|
-
if (!
|
|
2063
|
+
if (!ER27.hasAttribute(context, "key", element.openingElement.attributes, initialScope)) {
|
|
2027
2064
|
report.send({
|
|
2028
2065
|
messageId: "missingKey",
|
|
2029
2066
|
node: element
|
|
@@ -2032,7 +2069,7 @@ function create33(context) {
|
|
|
2032
2069
|
}
|
|
2033
2070
|
},
|
|
2034
2071
|
CallExpression(node) {
|
|
2035
|
-
state.isWithinChildrenToArray ||=
|
|
2072
|
+
state.isWithinChildrenToArray ||= ER27.isChildrenToArrayCall(context, node);
|
|
2036
2073
|
if (state.isWithinChildrenToArray) return;
|
|
2037
2074
|
const callback = match(node).when(AST13.isArrayMapCall, (n) => n.arguments[0]).when(AST13.isArrayFromCall, (n) => n.arguments[1]).otherwise(() => null);
|
|
2038
2075
|
if (!AST13.isFunction(callback)) return;
|
|
@@ -2044,7 +2081,7 @@ function create33(context) {
|
|
|
2044
2081
|
report.send(checkExpression(body));
|
|
2045
2082
|
},
|
|
2046
2083
|
"CallExpression:exit"(node) {
|
|
2047
|
-
if (!
|
|
2084
|
+
if (!ER27.isChildrenToArrayCall(context, node)) {
|
|
2048
2085
|
return;
|
|
2049
2086
|
}
|
|
2050
2087
|
state.isWithinChildrenToArray = false;
|
|
@@ -2062,7 +2099,7 @@ function create33(context) {
|
|
|
2062
2099
|
}
|
|
2063
2100
|
};
|
|
2064
2101
|
}
|
|
2065
|
-
var
|
|
2102
|
+
var RULE_NAME35 = "no-misused-capture-owner-stack";
|
|
2066
2103
|
var RULE_FEATURES34 = [
|
|
2067
2104
|
"EXP"
|
|
2068
2105
|
];
|
|
@@ -2081,16 +2118,16 @@ var no_misused_capture_owner_stack_default = createRule({
|
|
|
2081
2118
|
},
|
|
2082
2119
|
schema: []
|
|
2083
2120
|
},
|
|
2084
|
-
name:
|
|
2085
|
-
create:
|
|
2121
|
+
name: RULE_NAME35,
|
|
2122
|
+
create: create35,
|
|
2086
2123
|
defaultOptions: []
|
|
2087
2124
|
});
|
|
2088
|
-
function
|
|
2125
|
+
function create35(context) {
|
|
2089
2126
|
if (!context.sourceCode.text.includes("captureOwnerStack")) return {};
|
|
2090
2127
|
const { importSource } = getSettingsFromContext(context);
|
|
2091
2128
|
return {
|
|
2092
2129
|
CallExpression(node) {
|
|
2093
|
-
if (!
|
|
2130
|
+
if (!ER27.isCaptureOwnerStackCall(context, node)) return;
|
|
2094
2131
|
if (AST13.findParentNode(node, isDevelopmentOnlyCheck) == null) {
|
|
2095
2132
|
context.report({
|
|
2096
2133
|
messageId: "missingDevelopmentOnlyCheck",
|
|
@@ -2115,10 +2152,10 @@ function create34(context) {
|
|
|
2115
2152
|
}
|
|
2116
2153
|
function isDevelopmentOnlyCheck(node) {
|
|
2117
2154
|
if (node.type !== AST_NODE_TYPES.IfStatement) return false;
|
|
2118
|
-
if (
|
|
2155
|
+
if (ContextDetection.isProcessEnvNodeEnvCompare(node.test, "!==", "production")) return true;
|
|
2119
2156
|
return false;
|
|
2120
2157
|
}
|
|
2121
|
-
var
|
|
2158
|
+
var RULE_NAME36 = "no-nested-component-definitions";
|
|
2122
2159
|
var RULE_FEATURES35 = [];
|
|
2123
2160
|
var no_nested_component_definitions_default = createRule({
|
|
2124
2161
|
meta: {
|
|
@@ -2132,14 +2169,14 @@ var no_nested_component_definitions_default = createRule({
|
|
|
2132
2169
|
},
|
|
2133
2170
|
schema: []
|
|
2134
2171
|
},
|
|
2135
|
-
name:
|
|
2136
|
-
create:
|
|
2172
|
+
name: RULE_NAME36,
|
|
2173
|
+
create: create36,
|
|
2137
2174
|
defaultOptions: []
|
|
2138
2175
|
});
|
|
2139
|
-
function
|
|
2140
|
-
const hint =
|
|
2141
|
-
const collector =
|
|
2142
|
-
const collectorLegacy =
|
|
2176
|
+
function create36(context) {
|
|
2177
|
+
const hint = ER27.ComponentDetectionHint.SkipArrayMapArgument | ER27.ComponentDetectionHint.SkipNullLiteral | ER27.ComponentDetectionHint.SkipUndefined | ER27.ComponentDetectionHint.SkipBooleanLiteral | ER27.ComponentDetectionHint.SkipStringLiteral | ER27.ComponentDetectionHint.SkipNumberLiteral | ER27.ComponentDetectionHint.StrictLogical | ER27.ComponentDetectionHint.StrictConditional;
|
|
2178
|
+
const collector = ER27.useComponentCollector(context, { hint });
|
|
2179
|
+
const collectorLegacy = ER27.useComponentCollectorLegacy();
|
|
2143
2180
|
return {
|
|
2144
2181
|
...collector.listeners,
|
|
2145
2182
|
...collectorLegacy.listeners,
|
|
@@ -2158,9 +2195,9 @@ function create35(context) {
|
|
|
2158
2195
|
};
|
|
2159
2196
|
for (const { name: name5, node: component } of functionComponents) {
|
|
2160
2197
|
if (name5 == null) continue;
|
|
2161
|
-
if (
|
|
2198
|
+
if (ER27.isDirectValueOfRenderPropertyLoose(component)) continue;
|
|
2162
2199
|
if (isInsideJSXAttributeValue(component)) {
|
|
2163
|
-
if (!
|
|
2200
|
+
if (!ER27.isDeclaredInRenderPropLoose(component)) {
|
|
2164
2201
|
context.report({
|
|
2165
2202
|
messageId: "noNestedComponentDefinitions",
|
|
2166
2203
|
node: component,
|
|
@@ -2184,7 +2221,7 @@ function create35(context) {
|
|
|
2184
2221
|
continue;
|
|
2185
2222
|
}
|
|
2186
2223
|
const parentComponent = AST13.findParentNode(component, isFunctionComponent);
|
|
2187
|
-
if (parentComponent != null && !
|
|
2224
|
+
if (parentComponent != null && !ER27.isDirectValueOfRenderPropertyLoose(parentComponent)) {
|
|
2188
2225
|
context.report({
|
|
2189
2226
|
messageId: "noNestedComponentDefinitions",
|
|
2190
2227
|
node: component,
|
|
@@ -2223,19 +2260,19 @@ function create35(context) {
|
|
|
2223
2260
|
};
|
|
2224
2261
|
}
|
|
2225
2262
|
function isInsideJSXAttributeValue(node) {
|
|
2226
|
-
return node.parent.type === AST_NODE_TYPES.JSXAttribute ||
|
|
2263
|
+
return node.parent.type === AST_NODE_TYPES.JSXAttribute || ER27.findParentAttribute(node, (n) => n.value?.type === AST_NODE_TYPES.JSXExpressionContainer) != null;
|
|
2227
2264
|
}
|
|
2228
2265
|
function isInsideRenderMethod(node) {
|
|
2229
|
-
return AST13.findParentNode(node, (n) =>
|
|
2266
|
+
return AST13.findParentNode(node, (n) => ER27.isRenderLike(n) && ER27.isClassComponent(n.parent.parent)) != null;
|
|
2230
2267
|
}
|
|
2231
2268
|
function isInsideCreateElementProps(context, node) {
|
|
2232
|
-
const call = AST13.findParentNode(node,
|
|
2269
|
+
const call = AST13.findParentNode(node, ER27.isCreateElementCall(context));
|
|
2233
2270
|
if (call == null) return false;
|
|
2234
2271
|
const prop = AST13.findParentNode(node, AST13.is(AST_NODE_TYPES.ObjectExpression));
|
|
2235
2272
|
if (prop == null) return false;
|
|
2236
2273
|
return prop === call.arguments[1];
|
|
2237
2274
|
}
|
|
2238
|
-
var
|
|
2275
|
+
var RULE_NAME37 = "no-nested-component-definitions";
|
|
2239
2276
|
var RULE_FEATURES36 = [];
|
|
2240
2277
|
var no_nested_lazy_component_declarations_default = createRule({
|
|
2241
2278
|
meta: {
|
|
@@ -2249,20 +2286,20 @@ var no_nested_lazy_component_declarations_default = createRule({
|
|
|
2249
2286
|
},
|
|
2250
2287
|
schema: []
|
|
2251
2288
|
},
|
|
2252
|
-
name:
|
|
2253
|
-
create:
|
|
2289
|
+
name: RULE_NAME37,
|
|
2290
|
+
create: create37,
|
|
2254
2291
|
defaultOptions: []
|
|
2255
2292
|
});
|
|
2256
|
-
function
|
|
2257
|
-
const hint =
|
|
2258
|
-
const collector =
|
|
2259
|
-
const collectorLegacy =
|
|
2293
|
+
function create37(context) {
|
|
2294
|
+
const hint = ER27.ComponentDetectionHint.None;
|
|
2295
|
+
const collector = ER27.useComponentCollector(context, { hint });
|
|
2296
|
+
const collectorLegacy = ER27.useComponentCollectorLegacy();
|
|
2260
2297
|
const lazyComponentDeclarations = /* @__PURE__ */ new Set();
|
|
2261
2298
|
return {
|
|
2262
2299
|
...collector.listeners,
|
|
2263
2300
|
...collectorLegacy.listeners,
|
|
2264
2301
|
ImportExpression(node) {
|
|
2265
|
-
const lazyCall = AST13.findParentNode(node, (n) =>
|
|
2302
|
+
const lazyCall = AST13.findParentNode(node, (n) => ER27.isLazyCall(context, n));
|
|
2266
2303
|
if (lazyCall != null) {
|
|
2267
2304
|
lazyComponentDeclarations.add(lazyCall);
|
|
2268
2305
|
}
|
|
@@ -2278,7 +2315,7 @@ function create36(context) {
|
|
|
2278
2315
|
const significantParent = AST13.findParentNode(lazy, (n) => {
|
|
2279
2316
|
if (AST13.isJSX(n)) return true;
|
|
2280
2317
|
if (n.type === AST_NODE_TYPES.CallExpression) {
|
|
2281
|
-
return
|
|
2318
|
+
return ER27.isReactHookCall(n) || ER27.isCreateElementCall(context, n) || ER27.isCreateContextCall(context, n);
|
|
2282
2319
|
}
|
|
2283
2320
|
if (AST13.isFunction(n)) {
|
|
2284
2321
|
return functionComponents.some((c) => c.node === n);
|
|
@@ -2298,7 +2335,7 @@ function create36(context) {
|
|
|
2298
2335
|
}
|
|
2299
2336
|
};
|
|
2300
2337
|
}
|
|
2301
|
-
var
|
|
2338
|
+
var RULE_NAME38 = "no-prop-types";
|
|
2302
2339
|
var RULE_FEATURES37 = [];
|
|
2303
2340
|
var no_prop_types_default = createRule({
|
|
2304
2341
|
meta: {
|
|
@@ -2312,11 +2349,11 @@ var no_prop_types_default = createRule({
|
|
|
2312
2349
|
},
|
|
2313
2350
|
schema: []
|
|
2314
2351
|
},
|
|
2315
|
-
name:
|
|
2316
|
-
create:
|
|
2352
|
+
name: RULE_NAME38,
|
|
2353
|
+
create: create38,
|
|
2317
2354
|
defaultOptions: []
|
|
2318
2355
|
});
|
|
2319
|
-
function
|
|
2356
|
+
function create38(context) {
|
|
2320
2357
|
if (!context.sourceCode.text.includes("propTypes")) {
|
|
2321
2358
|
return {};
|
|
2322
2359
|
}
|
|
@@ -2332,17 +2369,17 @@ function create37(context) {
|
|
|
2332
2369
|
if (property.type !== AST_NODE_TYPES.Identifier || property.name !== "propTypes") {
|
|
2333
2370
|
return;
|
|
2334
2371
|
}
|
|
2335
|
-
if (!
|
|
2372
|
+
if (!ER27.isComponentNameLoose(object.name)) {
|
|
2336
2373
|
return;
|
|
2337
2374
|
}
|
|
2338
2375
|
const variable = VAR5.findVariable(object.name, context.sourceCode.getScope(node));
|
|
2339
2376
|
const variableNode = VAR5.getVariableInitNode(variable, 0);
|
|
2340
|
-
if (variableNode != null && (AST13.isFunction(variableNode) ||
|
|
2377
|
+
if (variableNode != null && (AST13.isFunction(variableNode) || ER27.isClassComponent(variableNode))) {
|
|
2341
2378
|
context.report({ messageId: "noPropTypes", node: property });
|
|
2342
2379
|
}
|
|
2343
2380
|
},
|
|
2344
2381
|
PropertyDefinition(node) {
|
|
2345
|
-
if (!
|
|
2382
|
+
if (!ER27.isClassComponent(node.parent.parent)) {
|
|
2346
2383
|
return;
|
|
2347
2384
|
}
|
|
2348
2385
|
if (!node.static || node.key.type !== AST_NODE_TYPES.Identifier || node.key.name !== "propTypes") {
|
|
@@ -2352,7 +2389,7 @@ function create37(context) {
|
|
|
2352
2389
|
}
|
|
2353
2390
|
};
|
|
2354
2391
|
}
|
|
2355
|
-
var
|
|
2392
|
+
var RULE_NAME39 = "no-redundant-should-component-update";
|
|
2356
2393
|
var RULE_FEATURES38 = [];
|
|
2357
2394
|
function isShouldComponentUpdate(node) {
|
|
2358
2395
|
return AST13.isMethodOrProperty(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "shouldComponentUpdate";
|
|
@@ -2369,19 +2406,19 @@ var no_redundant_should_component_update_default = createRule({
|
|
|
2369
2406
|
},
|
|
2370
2407
|
schema: []
|
|
2371
2408
|
},
|
|
2372
|
-
name:
|
|
2373
|
-
create:
|
|
2409
|
+
name: RULE_NAME39,
|
|
2410
|
+
create: create39,
|
|
2374
2411
|
defaultOptions: []
|
|
2375
2412
|
});
|
|
2376
|
-
function
|
|
2413
|
+
function create39(context) {
|
|
2377
2414
|
if (!context.sourceCode.text.includes("shouldComponentUpdate")) return {};
|
|
2378
|
-
const { ctx, listeners } =
|
|
2415
|
+
const { ctx, listeners } = ER27.useComponentCollectorLegacy();
|
|
2379
2416
|
return {
|
|
2380
2417
|
...listeners,
|
|
2381
2418
|
"Program:exit"(program) {
|
|
2382
2419
|
const components = ctx.getAllComponents(program);
|
|
2383
2420
|
for (const { name: name5 = "PureComponent", node: component, flag } of components.values()) {
|
|
2384
|
-
if ((flag &
|
|
2421
|
+
if ((flag & ER27.ComponentFlag.PureComponent) === 0n) {
|
|
2385
2422
|
continue;
|
|
2386
2423
|
}
|
|
2387
2424
|
const { body } = component.body;
|
|
@@ -2400,7 +2437,7 @@ function create38(context) {
|
|
|
2400
2437
|
}
|
|
2401
2438
|
};
|
|
2402
2439
|
}
|
|
2403
|
-
var
|
|
2440
|
+
var RULE_NAME40 = "no-set-state-in-component-did-mount";
|
|
2404
2441
|
var RULE_FEATURES39 = [];
|
|
2405
2442
|
var no_set_state_in_component_did_mount_default = createRule({
|
|
2406
2443
|
meta: {
|
|
@@ -2414,19 +2451,19 @@ var no_set_state_in_component_did_mount_default = createRule({
|
|
|
2414
2451
|
},
|
|
2415
2452
|
schema: []
|
|
2416
2453
|
},
|
|
2417
|
-
name:
|
|
2418
|
-
create:
|
|
2454
|
+
name: RULE_NAME40,
|
|
2455
|
+
create: create40,
|
|
2419
2456
|
defaultOptions: []
|
|
2420
2457
|
});
|
|
2421
|
-
function
|
|
2458
|
+
function create40(context) {
|
|
2422
2459
|
if (!context.sourceCode.text.includes("componentDidMount")) return {};
|
|
2423
2460
|
return {
|
|
2424
2461
|
CallExpression(node) {
|
|
2425
|
-
if (!
|
|
2462
|
+
if (!ER27.isThisSetState(node)) {
|
|
2426
2463
|
return;
|
|
2427
2464
|
}
|
|
2428
|
-
const clazz = AST13.findParentNode(node,
|
|
2429
|
-
const method = AST13.findParentNode(node, (n) => n === clazz ||
|
|
2465
|
+
const clazz = AST13.findParentNode(node, ER27.isClassComponent);
|
|
2466
|
+
const method = AST13.findParentNode(node, (n) => n === clazz || ER27.isComponentDidMount(n));
|
|
2430
2467
|
if (clazz == null || method == null || method === clazz) return;
|
|
2431
2468
|
const methodScope = context.sourceCode.getScope(method);
|
|
2432
2469
|
const upperScope = context.sourceCode.getScope(node).upper;
|
|
@@ -2439,7 +2476,7 @@ function create39(context) {
|
|
|
2439
2476
|
}
|
|
2440
2477
|
};
|
|
2441
2478
|
}
|
|
2442
|
-
var
|
|
2479
|
+
var RULE_NAME41 = "no-set-state-in-component-did-update";
|
|
2443
2480
|
var RULE_FEATURES40 = [];
|
|
2444
2481
|
var no_set_state_in_component_did_update_default = createRule({
|
|
2445
2482
|
meta: {
|
|
@@ -2453,19 +2490,19 @@ var no_set_state_in_component_did_update_default = createRule({
|
|
|
2453
2490
|
},
|
|
2454
2491
|
schema: []
|
|
2455
2492
|
},
|
|
2456
|
-
name:
|
|
2457
|
-
create:
|
|
2493
|
+
name: RULE_NAME41,
|
|
2494
|
+
create: create41,
|
|
2458
2495
|
defaultOptions: []
|
|
2459
2496
|
});
|
|
2460
|
-
function
|
|
2497
|
+
function create41(context) {
|
|
2461
2498
|
if (!context.sourceCode.text.includes("componentDidUpdate")) return {};
|
|
2462
2499
|
return {
|
|
2463
2500
|
CallExpression(node) {
|
|
2464
|
-
if (!
|
|
2501
|
+
if (!ER27.isThisSetState(node)) {
|
|
2465
2502
|
return;
|
|
2466
2503
|
}
|
|
2467
|
-
const clazz = AST13.findParentNode(node,
|
|
2468
|
-
const method = AST13.findParentNode(node, (n) => n === clazz ||
|
|
2504
|
+
const clazz = AST13.findParentNode(node, ER27.isClassComponent);
|
|
2505
|
+
const method = AST13.findParentNode(node, (n) => n === clazz || ER27.isComponentDidUpdate(n));
|
|
2469
2506
|
if (clazz == null || method == null || method === clazz) return;
|
|
2470
2507
|
const methodScope = context.sourceCode.getScope(method);
|
|
2471
2508
|
const upperScope = context.sourceCode.getScope(node).upper;
|
|
@@ -2478,7 +2515,7 @@ function create40(context) {
|
|
|
2478
2515
|
}
|
|
2479
2516
|
};
|
|
2480
2517
|
}
|
|
2481
|
-
var
|
|
2518
|
+
var RULE_NAME42 = "no-set-state-in-component-will-update";
|
|
2482
2519
|
var RULE_FEATURES41 = [];
|
|
2483
2520
|
var no_set_state_in_component_will_update_default = createRule({
|
|
2484
2521
|
meta: {
|
|
@@ -2492,19 +2529,19 @@ var no_set_state_in_component_will_update_default = createRule({
|
|
|
2492
2529
|
},
|
|
2493
2530
|
schema: []
|
|
2494
2531
|
},
|
|
2495
|
-
name:
|
|
2496
|
-
create:
|
|
2532
|
+
name: RULE_NAME42,
|
|
2533
|
+
create: create42,
|
|
2497
2534
|
defaultOptions: []
|
|
2498
2535
|
});
|
|
2499
|
-
function
|
|
2536
|
+
function create42(context) {
|
|
2500
2537
|
if (!context.sourceCode.text.includes("componentWillUpdate")) return {};
|
|
2501
2538
|
return {
|
|
2502
2539
|
CallExpression(node) {
|
|
2503
|
-
if (!
|
|
2540
|
+
if (!ER27.isThisSetState(node)) {
|
|
2504
2541
|
return;
|
|
2505
2542
|
}
|
|
2506
|
-
const clazz = AST13.findParentNode(node,
|
|
2507
|
-
const method = AST13.findParentNode(node, (n) => n === clazz ||
|
|
2543
|
+
const clazz = AST13.findParentNode(node, ER27.isClassComponent);
|
|
2544
|
+
const method = AST13.findParentNode(node, (n) => n === clazz || ER27.isComponentWillUpdate(n));
|
|
2508
2545
|
if (clazz == null || method == null || method === clazz) return;
|
|
2509
2546
|
const methodScope = context.sourceCode.getScope(method);
|
|
2510
2547
|
const upperScope = context.sourceCode.getScope(node).upper;
|
|
@@ -2517,7 +2554,7 @@ function create41(context) {
|
|
|
2517
2554
|
}
|
|
2518
2555
|
};
|
|
2519
2556
|
}
|
|
2520
|
-
var
|
|
2557
|
+
var RULE_NAME43 = "no-string-refs";
|
|
2521
2558
|
var RULE_FEATURES42 = [
|
|
2522
2559
|
"MOD"
|
|
2523
2560
|
];
|
|
@@ -2534,16 +2571,16 @@ var no_string_refs_default = createRule({
|
|
|
2534
2571
|
},
|
|
2535
2572
|
schema: []
|
|
2536
2573
|
},
|
|
2537
|
-
name:
|
|
2538
|
-
create:
|
|
2574
|
+
name: RULE_NAME43,
|
|
2575
|
+
create: create43,
|
|
2539
2576
|
defaultOptions: []
|
|
2540
2577
|
});
|
|
2541
|
-
function
|
|
2578
|
+
function create43(context) {
|
|
2542
2579
|
const state = {
|
|
2543
2580
|
isWithinClassComponent: false
|
|
2544
2581
|
};
|
|
2545
2582
|
function onClassBodyEnter(node) {
|
|
2546
|
-
if (
|
|
2583
|
+
if (ER27.isClassComponent(node.parent)) {
|
|
2547
2584
|
state.isWithinClassComponent = true;
|
|
2548
2585
|
}
|
|
2549
2586
|
}
|
|
@@ -2582,7 +2619,7 @@ function getAttributeValueText(context, node) {
|
|
|
2582
2619
|
return null;
|
|
2583
2620
|
}
|
|
2584
2621
|
}
|
|
2585
|
-
var
|
|
2622
|
+
var RULE_NAME44 = "no-unnecessary-use-callback";
|
|
2586
2623
|
var RULE_FEATURES43 = [
|
|
2587
2624
|
"EXP"
|
|
2588
2625
|
];
|
|
@@ -2598,17 +2635,17 @@ var no_unnecessary_use_callback_default = createRule({
|
|
|
2598
2635
|
},
|
|
2599
2636
|
schema: []
|
|
2600
2637
|
},
|
|
2601
|
-
name:
|
|
2602
|
-
create:
|
|
2638
|
+
name: RULE_NAME44,
|
|
2639
|
+
create: create44,
|
|
2603
2640
|
defaultOptions: []
|
|
2604
2641
|
});
|
|
2605
|
-
function
|
|
2642
|
+
function create44(context) {
|
|
2606
2643
|
if (!context.sourceCode.text.includes("use")) return {};
|
|
2607
2644
|
const alias = getSettingsFromContext(context).additionalHooks.useCallback ?? [];
|
|
2608
|
-
const isUseCallbackCall =
|
|
2645
|
+
const isUseCallbackCall = ER27.isReactHookCallWithNameAlias(context, "useCallback", alias);
|
|
2609
2646
|
return {
|
|
2610
2647
|
CallExpression(node) {
|
|
2611
|
-
if (!
|
|
2648
|
+
if (!ER27.isReactHookCall(node)) {
|
|
2612
2649
|
return;
|
|
2613
2650
|
}
|
|
2614
2651
|
const initialScope = context.sourceCode.getScope(node);
|
|
@@ -2661,7 +2698,7 @@ function create43(context) {
|
|
|
2661
2698
|
}
|
|
2662
2699
|
};
|
|
2663
2700
|
}
|
|
2664
|
-
var
|
|
2701
|
+
var RULE_NAME45 = "no-unnecessary-use-memo";
|
|
2665
2702
|
var RULE_FEATURES44 = [
|
|
2666
2703
|
"EXP"
|
|
2667
2704
|
];
|
|
@@ -2677,17 +2714,17 @@ var no_unnecessary_use_memo_default = createRule({
|
|
|
2677
2714
|
},
|
|
2678
2715
|
schema: []
|
|
2679
2716
|
},
|
|
2680
|
-
name:
|
|
2681
|
-
create:
|
|
2717
|
+
name: RULE_NAME45,
|
|
2718
|
+
create: create45,
|
|
2682
2719
|
defaultOptions: []
|
|
2683
2720
|
});
|
|
2684
|
-
function
|
|
2721
|
+
function create45(context) {
|
|
2685
2722
|
if (!context.sourceCode.text.includes("use")) return {};
|
|
2686
2723
|
const alias = getSettingsFromContext(context).additionalHooks.useMemo ?? [];
|
|
2687
|
-
const isUseMemoCall =
|
|
2724
|
+
const isUseMemoCall = ER27.isReactHookCallWithNameAlias(context, "useMemo", alias);
|
|
2688
2725
|
return {
|
|
2689
2726
|
CallExpression(node) {
|
|
2690
|
-
if (!
|
|
2727
|
+
if (!ER27.isReactHookCall(node)) {
|
|
2691
2728
|
return;
|
|
2692
2729
|
}
|
|
2693
2730
|
const initialScope = context.sourceCode.getScope(node);
|
|
@@ -2744,7 +2781,7 @@ function create44(context) {
|
|
|
2744
2781
|
}
|
|
2745
2782
|
};
|
|
2746
2783
|
}
|
|
2747
|
-
var
|
|
2784
|
+
var RULE_NAME46 = "no-unnecessary-use-prefix";
|
|
2748
2785
|
var RULE_FEATURES45 = [];
|
|
2749
2786
|
var WELL_KNOWN_HOOKS = [
|
|
2750
2787
|
"useMDXComponents"
|
|
@@ -2764,42 +2801,35 @@ var no_unnecessary_use_prefix_default = createRule({
|
|
|
2764
2801
|
},
|
|
2765
2802
|
schema: []
|
|
2766
2803
|
},
|
|
2767
|
-
name:
|
|
2768
|
-
create:
|
|
2804
|
+
name: RULE_NAME46,
|
|
2805
|
+
create: create46,
|
|
2769
2806
|
defaultOptions: []
|
|
2770
2807
|
});
|
|
2771
|
-
function
|
|
2772
|
-
const { ctx, listeners } =
|
|
2808
|
+
function create46(context) {
|
|
2809
|
+
const { ctx, listeners } = ER27.useHookCollector();
|
|
2773
2810
|
return {
|
|
2774
2811
|
...listeners,
|
|
2775
2812
|
"Program:exit"(program) {
|
|
2776
2813
|
const allHooks = ctx.getAllHooks(program);
|
|
2777
2814
|
for (const { id, name: name5, node, hookCalls } of allHooks.values()) {
|
|
2778
|
-
if (
|
|
2815
|
+
if (hookCalls.length > 0) {
|
|
2779
2816
|
continue;
|
|
2780
2817
|
}
|
|
2781
2818
|
if (AST13.isEmptyFunction(node)) {
|
|
2782
2819
|
continue;
|
|
2783
2820
|
}
|
|
2784
|
-
if (
|
|
2821
|
+
if (WELL_KNOWN_HOOKS.includes(name5)) {
|
|
2785
2822
|
continue;
|
|
2786
2823
|
}
|
|
2787
2824
|
if (containsUseComments(context, node)) {
|
|
2788
2825
|
continue;
|
|
2789
2826
|
}
|
|
2790
|
-
if (
|
|
2791
|
-
context.report({
|
|
2792
|
-
messageId: "noUnnecessaryUsePrefix",
|
|
2793
|
-
data: {
|
|
2794
|
-
name: name5
|
|
2795
|
-
},
|
|
2796
|
-
loc: getPreferredLoc(context, id)
|
|
2797
|
-
});
|
|
2827
|
+
if (AST13.findParentNode(node, ContextDetection.isViMockCallback) != null) {
|
|
2798
2828
|
continue;
|
|
2799
2829
|
}
|
|
2800
2830
|
context.report({
|
|
2801
2831
|
messageId: "noUnnecessaryUsePrefix",
|
|
2802
|
-
node,
|
|
2832
|
+
node: id ?? node,
|
|
2803
2833
|
data: {
|
|
2804
2834
|
name: name5
|
|
2805
2835
|
}
|
|
@@ -2808,21 +2838,7 @@ function create45(context) {
|
|
|
2808
2838
|
}
|
|
2809
2839
|
};
|
|
2810
2840
|
}
|
|
2811
|
-
|
|
2812
|
-
if (AST13.isMultiLine(id)) return id.loc;
|
|
2813
|
-
if (!context.sourceCode.getText(id).startsWith("use")) return id.loc;
|
|
2814
|
-
return {
|
|
2815
|
-
end: {
|
|
2816
|
-
column: id.loc.start.column + 3,
|
|
2817
|
-
line: id.loc.start.line
|
|
2818
|
-
},
|
|
2819
|
-
start: {
|
|
2820
|
-
column: id.loc.start.column,
|
|
2821
|
-
line: id.loc.start.line
|
|
2822
|
-
}
|
|
2823
|
-
};
|
|
2824
|
-
}
|
|
2825
|
-
var RULE_NAME46 = "no-unsafe-component-will-mount";
|
|
2841
|
+
var RULE_NAME47 = "no-unsafe-component-will-mount";
|
|
2826
2842
|
var RULE_FEATURES46 = [];
|
|
2827
2843
|
var no_unsafe_component_will_mount_default = createRule({
|
|
2828
2844
|
meta: {
|
|
@@ -2836,13 +2852,13 @@ var no_unsafe_component_will_mount_default = createRule({
|
|
|
2836
2852
|
},
|
|
2837
2853
|
schema: []
|
|
2838
2854
|
},
|
|
2839
|
-
name:
|
|
2840
|
-
create:
|
|
2855
|
+
name: RULE_NAME47,
|
|
2856
|
+
create: create47,
|
|
2841
2857
|
defaultOptions: []
|
|
2842
2858
|
});
|
|
2843
|
-
function
|
|
2859
|
+
function create47(context) {
|
|
2844
2860
|
if (!context.sourceCode.text.includes("UNSAFE_componentWillMount")) return {};
|
|
2845
|
-
const { ctx, listeners } =
|
|
2861
|
+
const { ctx, listeners } = ER27.useComponentCollectorLegacy();
|
|
2846
2862
|
return {
|
|
2847
2863
|
...listeners,
|
|
2848
2864
|
"Program:exit"(program) {
|
|
@@ -2850,7 +2866,7 @@ function create46(context) {
|
|
|
2850
2866
|
for (const { node: component } of components.values()) {
|
|
2851
2867
|
const { body } = component.body;
|
|
2852
2868
|
for (const member of body) {
|
|
2853
|
-
if (
|
|
2869
|
+
if (ER27.isUnsafeComponentWillMount(member)) {
|
|
2854
2870
|
context.report({
|
|
2855
2871
|
messageId: "noUnsafeComponentWillMount",
|
|
2856
2872
|
node: member
|
|
@@ -2861,7 +2877,7 @@ function create46(context) {
|
|
|
2861
2877
|
}
|
|
2862
2878
|
};
|
|
2863
2879
|
}
|
|
2864
|
-
var
|
|
2880
|
+
var RULE_NAME48 = "no-unsafe-component-will-receive-props";
|
|
2865
2881
|
var RULE_FEATURES47 = [];
|
|
2866
2882
|
var no_unsafe_component_will_receive_props_default = createRule({
|
|
2867
2883
|
meta: {
|
|
@@ -2875,15 +2891,15 @@ var no_unsafe_component_will_receive_props_default = createRule({
|
|
|
2875
2891
|
},
|
|
2876
2892
|
schema: []
|
|
2877
2893
|
},
|
|
2878
|
-
name:
|
|
2879
|
-
create:
|
|
2894
|
+
name: RULE_NAME48,
|
|
2895
|
+
create: create48,
|
|
2880
2896
|
defaultOptions: []
|
|
2881
2897
|
});
|
|
2882
|
-
function
|
|
2898
|
+
function create48(context) {
|
|
2883
2899
|
if (!context.sourceCode.text.includes("UNSAFE_componentWillReceiveProps")) {
|
|
2884
2900
|
return {};
|
|
2885
2901
|
}
|
|
2886
|
-
const { ctx, listeners } =
|
|
2902
|
+
const { ctx, listeners } = ER27.useComponentCollectorLegacy();
|
|
2887
2903
|
return {
|
|
2888
2904
|
...listeners,
|
|
2889
2905
|
"Program:exit"(program) {
|
|
@@ -2891,7 +2907,7 @@ function create47(context) {
|
|
|
2891
2907
|
for (const { node: component } of components.values()) {
|
|
2892
2908
|
const { body } = component.body;
|
|
2893
2909
|
for (const member of body) {
|
|
2894
|
-
if (
|
|
2910
|
+
if (ER27.isUnsafeComponentWillReceiveProps(member)) {
|
|
2895
2911
|
context.report({
|
|
2896
2912
|
messageId: "noUnsafeComponentWillReceiveProps",
|
|
2897
2913
|
node: member
|
|
@@ -2902,7 +2918,7 @@ function create47(context) {
|
|
|
2902
2918
|
}
|
|
2903
2919
|
};
|
|
2904
2920
|
}
|
|
2905
|
-
var
|
|
2921
|
+
var RULE_NAME49 = "no-unsafe-component-will-update";
|
|
2906
2922
|
var RULE_FEATURES48 = [];
|
|
2907
2923
|
var no_unsafe_component_will_update_default = createRule({
|
|
2908
2924
|
meta: {
|
|
@@ -2916,13 +2932,13 @@ var no_unsafe_component_will_update_default = createRule({
|
|
|
2916
2932
|
},
|
|
2917
2933
|
schema: []
|
|
2918
2934
|
},
|
|
2919
|
-
name:
|
|
2920
|
-
create:
|
|
2935
|
+
name: RULE_NAME49,
|
|
2936
|
+
create: create49,
|
|
2921
2937
|
defaultOptions: []
|
|
2922
2938
|
});
|
|
2923
|
-
function
|
|
2939
|
+
function create49(context) {
|
|
2924
2940
|
if (!context.sourceCode.text.includes("UNSAFE_componentWillUpdate")) return {};
|
|
2925
|
-
const { ctx, listeners } =
|
|
2941
|
+
const { ctx, listeners } = ER27.useComponentCollectorLegacy();
|
|
2926
2942
|
return {
|
|
2927
2943
|
...listeners,
|
|
2928
2944
|
"Program:exit"(program) {
|
|
@@ -2930,7 +2946,7 @@ function create48(context) {
|
|
|
2930
2946
|
for (const { node: component } of components.values()) {
|
|
2931
2947
|
const { body } = component.body;
|
|
2932
2948
|
for (const member of body) {
|
|
2933
|
-
if (
|
|
2949
|
+
if (ER27.isUnsafeComponentWillUpdate(member)) {
|
|
2934
2950
|
context.report({
|
|
2935
2951
|
messageId: "noUnsafeComponentWillUpdate",
|
|
2936
2952
|
node: member
|
|
@@ -2941,7 +2957,7 @@ function create48(context) {
|
|
|
2941
2957
|
}
|
|
2942
2958
|
};
|
|
2943
2959
|
}
|
|
2944
|
-
var
|
|
2960
|
+
var RULE_NAME50 = "no-unstable-context-value";
|
|
2945
2961
|
var RULE_FEATURES49 = [];
|
|
2946
2962
|
var no_unstable_context_value_default = createRule({
|
|
2947
2963
|
meta: {
|
|
@@ -2955,19 +2971,19 @@ var no_unstable_context_value_default = createRule({
|
|
|
2955
2971
|
},
|
|
2956
2972
|
schema: []
|
|
2957
2973
|
},
|
|
2958
|
-
name:
|
|
2959
|
-
create:
|
|
2974
|
+
name: RULE_NAME50,
|
|
2975
|
+
create: create50,
|
|
2960
2976
|
defaultOptions: []
|
|
2961
2977
|
});
|
|
2962
|
-
function
|
|
2978
|
+
function create50(context) {
|
|
2963
2979
|
const { version: version2 } = getSettingsFromContext(context);
|
|
2964
2980
|
const isReact18OrBelow = compare(version2, "19.0.0", "<");
|
|
2965
|
-
const { ctx, listeners } =
|
|
2981
|
+
const { ctx, listeners } = ER27.useComponentCollector(context);
|
|
2966
2982
|
const constructions = /* @__PURE__ */ new WeakMap();
|
|
2967
2983
|
return {
|
|
2968
2984
|
...listeners,
|
|
2969
2985
|
JSXOpeningElement(node) {
|
|
2970
|
-
const fullName =
|
|
2986
|
+
const fullName = ER27.getElementType(context, node.parent);
|
|
2971
2987
|
const selfName = fullName.split(".").at(-1);
|
|
2972
2988
|
if (selfName == null) return;
|
|
2973
2989
|
if (!isContextName(selfName, isReact18OrBelow)) return;
|
|
@@ -2983,7 +2999,7 @@ function create49(context) {
|
|
|
2983
2999
|
const initialScope = context.sourceCode.getScope(valueExpression);
|
|
2984
3000
|
const construction = VAR5.getConstruction(valueExpression, initialScope);
|
|
2985
3001
|
if (construction == null) return;
|
|
2986
|
-
if (
|
|
3002
|
+
if (ER27.isReactHookCall(construction.node)) {
|
|
2987
3003
|
return;
|
|
2988
3004
|
}
|
|
2989
3005
|
getOrElseUpdate(constructions, functionEntry.node, () => []).push(construction);
|
|
@@ -3014,7 +3030,7 @@ function isContextName(name5, isReact18OrBelow) {
|
|
|
3014
3030
|
}
|
|
3015
3031
|
return false;
|
|
3016
3032
|
}
|
|
3017
|
-
var
|
|
3033
|
+
var RULE_NAME51 = "no-unstable-default-props";
|
|
3018
3034
|
var RULE_FEATURES50 = [];
|
|
3019
3035
|
var no_unstable_default_props_default = createRule({
|
|
3020
3036
|
meta: {
|
|
@@ -3028,12 +3044,12 @@ var no_unstable_default_props_default = createRule({
|
|
|
3028
3044
|
},
|
|
3029
3045
|
schema: []
|
|
3030
3046
|
},
|
|
3031
|
-
name:
|
|
3032
|
-
create:
|
|
3047
|
+
name: RULE_NAME51,
|
|
3048
|
+
create: create51,
|
|
3033
3049
|
defaultOptions: []
|
|
3034
3050
|
});
|
|
3035
|
-
function
|
|
3036
|
-
const { ctx, listeners } =
|
|
3051
|
+
function create51(context) {
|
|
3052
|
+
const { ctx, listeners } = ER27.useComponentCollector(context);
|
|
3037
3053
|
const declarators = /* @__PURE__ */ new WeakMap();
|
|
3038
3054
|
return {
|
|
3039
3055
|
...listeners,
|
|
@@ -3063,7 +3079,7 @@ function create50(context) {
|
|
|
3063
3079
|
if (construction == null) {
|
|
3064
3080
|
continue;
|
|
3065
3081
|
}
|
|
3066
|
-
if (
|
|
3082
|
+
if (ER27.isReactHookCall(construction.node)) {
|
|
3067
3083
|
continue;
|
|
3068
3084
|
}
|
|
3069
3085
|
const forbiddenType = AST13.toDelimiterFormat(right);
|
|
@@ -3088,7 +3104,7 @@ function create50(context) {
|
|
|
3088
3104
|
}
|
|
3089
3105
|
};
|
|
3090
3106
|
}
|
|
3091
|
-
var
|
|
3107
|
+
var RULE_NAME52 = "no-unused-class-component-members";
|
|
3092
3108
|
var RULE_FEATURES51 = [];
|
|
3093
3109
|
var LIFECYCLE_METHODS = /* @__PURE__ */ new Set([
|
|
3094
3110
|
"componentDidCatch",
|
|
@@ -3122,18 +3138,18 @@ var no_unused_class_component_members_default = createRule({
|
|
|
3122
3138
|
},
|
|
3123
3139
|
schema: []
|
|
3124
3140
|
},
|
|
3125
|
-
name:
|
|
3126
|
-
create:
|
|
3141
|
+
name: RULE_NAME52,
|
|
3142
|
+
create: create52,
|
|
3127
3143
|
defaultOptions: []
|
|
3128
3144
|
});
|
|
3129
|
-
function
|
|
3145
|
+
function create52(context) {
|
|
3130
3146
|
const classEntries = [];
|
|
3131
3147
|
const methodEntries = [];
|
|
3132
3148
|
const propertyDefs = /* @__PURE__ */ new WeakMap();
|
|
3133
3149
|
const propertyUsages = /* @__PURE__ */ new WeakMap();
|
|
3134
3150
|
function classEnter(node) {
|
|
3135
3151
|
classEntries.push(node);
|
|
3136
|
-
if (!
|
|
3152
|
+
if (!ER27.isClassComponent(node)) {
|
|
3137
3153
|
return;
|
|
3138
3154
|
}
|
|
3139
3155
|
propertyDefs.set(node, /* @__PURE__ */ new Set());
|
|
@@ -3141,7 +3157,7 @@ function create51(context) {
|
|
|
3141
3157
|
}
|
|
3142
3158
|
function classExit() {
|
|
3143
3159
|
const currentClass = classEntries.pop();
|
|
3144
|
-
if (currentClass == null || !
|
|
3160
|
+
if (currentClass == null || !ER27.isClassComponent(currentClass)) {
|
|
3145
3161
|
return;
|
|
3146
3162
|
}
|
|
3147
3163
|
const className = AST13.getClassId(currentClass)?.name;
|
|
@@ -3171,7 +3187,7 @@ function create51(context) {
|
|
|
3171
3187
|
function methodEnter(node) {
|
|
3172
3188
|
methodEntries.push(node);
|
|
3173
3189
|
const currentClass = classEntries.at(-1);
|
|
3174
|
-
if (currentClass == null || !
|
|
3190
|
+
if (currentClass == null || !ER27.isClassComponent(currentClass)) {
|
|
3175
3191
|
return;
|
|
3176
3192
|
}
|
|
3177
3193
|
if (node.static) {
|
|
@@ -3195,7 +3211,7 @@ function create51(context) {
|
|
|
3195
3211
|
if (currentClass == null || currentMethod == null) {
|
|
3196
3212
|
return;
|
|
3197
3213
|
}
|
|
3198
|
-
if (!
|
|
3214
|
+
if (!ER27.isClassComponent(currentClass) || currentMethod.static) {
|
|
3199
3215
|
return;
|
|
3200
3216
|
}
|
|
3201
3217
|
if (!AST13.isThisExpression(node.object) || !isKeyLiteral2(node, node.property)) {
|
|
@@ -3220,7 +3236,7 @@ function create51(context) {
|
|
|
3220
3236
|
if (currentClass == null || currentMethod == null) {
|
|
3221
3237
|
return;
|
|
3222
3238
|
}
|
|
3223
|
-
if (!
|
|
3239
|
+
if (!ER27.isClassComponent(currentClass) || currentMethod.static) {
|
|
3224
3240
|
return;
|
|
3225
3241
|
}
|
|
3226
3242
|
if (node.init != null && AST13.isThisExpression(node.init) && node.id.type === AST_NODE_TYPES.ObjectPattern) {
|
|
@@ -3236,46 +3252,200 @@ function create51(context) {
|
|
|
3236
3252
|
}
|
|
3237
3253
|
};
|
|
3238
3254
|
}
|
|
3239
|
-
var
|
|
3240
|
-
var RULE_FEATURES52 = [];
|
|
3241
|
-
|
|
3242
|
-
return match(key).with({ type: AST_NODE_TYPES.Literal }, constTrue).with({ type: AST_NODE_TYPES.TemplateLiteral, expressions: [] }, constTrue).with({ type: AST_NODE_TYPES.Identifier }, () => !node.computed).otherwise(constFalse);
|
|
3243
|
-
}
|
|
3244
|
-
var no_unused_state_default = createRule({
|
|
3255
|
+
var RULE_NAME53 = "no-unused-props";
|
|
3256
|
+
var RULE_FEATURES52 = ["TSC", "EXP"];
|
|
3257
|
+
var no_unused_props_default = createRule({
|
|
3245
3258
|
meta: {
|
|
3246
3259
|
type: "problem",
|
|
3247
3260
|
docs: {
|
|
3248
|
-
description: "Warns unused
|
|
3261
|
+
description: "Warns about unused component prop declarations.",
|
|
3249
3262
|
[Symbol.for("rule_features")]: RULE_FEATURES52
|
|
3250
3263
|
},
|
|
3251
3264
|
messages: {
|
|
3252
|
-
|
|
3265
|
+
noUnusedProps: "Prop `{{name}}` is declared but never used"
|
|
3253
3266
|
},
|
|
3254
3267
|
schema: []
|
|
3255
3268
|
},
|
|
3256
|
-
name:
|
|
3257
|
-
create:
|
|
3269
|
+
name: RULE_NAME53,
|
|
3270
|
+
create: create53,
|
|
3258
3271
|
defaultOptions: []
|
|
3259
3272
|
});
|
|
3260
|
-
function
|
|
3261
|
-
const
|
|
3262
|
-
const
|
|
3263
|
-
|
|
3264
|
-
|
|
3265
|
-
|
|
3266
|
-
|
|
3267
|
-
|
|
3268
|
-
|
|
3269
|
-
|
|
3270
|
-
|
|
3271
|
-
|
|
3272
|
-
|
|
3273
|
-
|
|
3274
|
-
|
|
3275
|
-
|
|
3276
|
-
|
|
3277
|
-
|
|
3278
|
-
|
|
3273
|
+
function create53(context) {
|
|
3274
|
+
const services = ESLintUtils.getParserServices(context, false);
|
|
3275
|
+
const { ctx, listeners } = ER27.useComponentCollector(context);
|
|
3276
|
+
return {
|
|
3277
|
+
...listeners,
|
|
3278
|
+
"Program:exit"(program) {
|
|
3279
|
+
const checker = services.program.getTypeChecker();
|
|
3280
|
+
const components = ctx.getAllComponents(program);
|
|
3281
|
+
const totalDeclaredProps = /* @__PURE__ */ new Set();
|
|
3282
|
+
const totalUsedProps = /* @__PURE__ */ new Set();
|
|
3283
|
+
for (const [, component] of components) {
|
|
3284
|
+
const [props] = component.node.params;
|
|
3285
|
+
if (props == null) continue;
|
|
3286
|
+
const usedPropKeys = /* @__PURE__ */ new Set();
|
|
3287
|
+
const couldFindAllUsedPropKeys = collectUsedPropKeysOfParameter(context, usedPropKeys, props);
|
|
3288
|
+
if (!couldFindAllUsedPropKeys) {
|
|
3289
|
+
continue;
|
|
3290
|
+
}
|
|
3291
|
+
const tsNode = services.esTreeNodeToTSNodeMap.get(props);
|
|
3292
|
+
const declaredProps = checker.getTypeAtLocation(tsNode).getProperties();
|
|
3293
|
+
for (const declaredProp of declaredProps) {
|
|
3294
|
+
totalDeclaredProps.add(declaredProp);
|
|
3295
|
+
if (usedPropKeys.has(declaredProp.name)) {
|
|
3296
|
+
totalUsedProps.add(declaredProp);
|
|
3297
|
+
}
|
|
3298
|
+
}
|
|
3299
|
+
}
|
|
3300
|
+
const unusedProps = [...totalDeclaredProps].filter((x) => !totalUsedProps.has(x));
|
|
3301
|
+
for (const unusedProp of unusedProps) {
|
|
3302
|
+
reportUnusedProp(context, services, unusedProp);
|
|
3303
|
+
}
|
|
3304
|
+
}
|
|
3305
|
+
};
|
|
3306
|
+
}
|
|
3307
|
+
function collectUsedPropKeysOfParameter(context, usedPropKeys, parameter) {
|
|
3308
|
+
switch (parameter.type) {
|
|
3309
|
+
case AST_NODE_TYPES.Identifier: {
|
|
3310
|
+
return collectUsedPropKeysOfIdentifier(context, usedPropKeys, parameter);
|
|
3311
|
+
}
|
|
3312
|
+
case AST_NODE_TYPES.ObjectPattern: {
|
|
3313
|
+
return collectUsedPropKeysOfObjectPattern(context, usedPropKeys, parameter);
|
|
3314
|
+
}
|
|
3315
|
+
default: {
|
|
3316
|
+
return false;
|
|
3317
|
+
}
|
|
3318
|
+
}
|
|
3319
|
+
}
|
|
3320
|
+
function collectUsedPropKeysOfObjectPattern(context, usedPropKeys, objectPattern) {
|
|
3321
|
+
for (const property of objectPattern.properties) {
|
|
3322
|
+
switch (property.type) {
|
|
3323
|
+
case AST_NODE_TYPES.Property: {
|
|
3324
|
+
const key = getKeyOfExpression(property.key);
|
|
3325
|
+
if (key == null) return false;
|
|
3326
|
+
usedPropKeys.add(key);
|
|
3327
|
+
break;
|
|
3328
|
+
}
|
|
3329
|
+
case AST_NODE_TYPES.RestElement: {
|
|
3330
|
+
if (!collectUsedPropsOfRestElement(context, usedPropKeys, property)) {
|
|
3331
|
+
return false;
|
|
3332
|
+
}
|
|
3333
|
+
break;
|
|
3334
|
+
}
|
|
3335
|
+
}
|
|
3336
|
+
}
|
|
3337
|
+
return true;
|
|
3338
|
+
}
|
|
3339
|
+
function collectUsedPropsOfRestElement(context, usedPropKeys, restElement) {
|
|
3340
|
+
switch (restElement.argument.type) {
|
|
3341
|
+
case AST_NODE_TYPES.Identifier: {
|
|
3342
|
+
return collectUsedPropKeysOfIdentifier(context, usedPropKeys, restElement.argument);
|
|
3343
|
+
}
|
|
3344
|
+
default: {
|
|
3345
|
+
return false;
|
|
3346
|
+
}
|
|
3347
|
+
}
|
|
3348
|
+
}
|
|
3349
|
+
function collectUsedPropKeysOfIdentifier(context, usedPropKeys, identifier) {
|
|
3350
|
+
const scope = context.sourceCode.getScope(identifier);
|
|
3351
|
+
const variable = scope.variables.find((v) => v.name === identifier.name);
|
|
3352
|
+
if (variable == null) return false;
|
|
3353
|
+
for (const ref of variable.references) {
|
|
3354
|
+
if (ref.identifier === identifier) {
|
|
3355
|
+
continue;
|
|
3356
|
+
}
|
|
3357
|
+
if (!collectUsedPropKeysOfReference(context, usedPropKeys, identifier, ref)) {
|
|
3358
|
+
return false;
|
|
3359
|
+
}
|
|
3360
|
+
}
|
|
3361
|
+
return true;
|
|
3362
|
+
}
|
|
3363
|
+
function collectUsedPropKeysOfReference(context, usedPropKeys, identifier, ref) {
|
|
3364
|
+
const { parent } = ref.identifier;
|
|
3365
|
+
switch (parent.type) {
|
|
3366
|
+
case AST_NODE_TYPES.MemberExpression: {
|
|
3367
|
+
if (parent.object.type === AST_NODE_TYPES.Identifier && parent.object.name === identifier.name) {
|
|
3368
|
+
const key = getKeyOfExpression(parent.property);
|
|
3369
|
+
if (key == null) return false;
|
|
3370
|
+
usedPropKeys.add(key);
|
|
3371
|
+
return true;
|
|
3372
|
+
}
|
|
3373
|
+
break;
|
|
3374
|
+
}
|
|
3375
|
+
case AST_NODE_TYPES.VariableDeclarator: {
|
|
3376
|
+
if (parent.id.type === AST_NODE_TYPES.ObjectPattern && parent.init === ref.identifier) {
|
|
3377
|
+
return collectUsedPropKeysOfObjectPattern(context, usedPropKeys, parent.id);
|
|
3378
|
+
}
|
|
3379
|
+
break;
|
|
3380
|
+
}
|
|
3381
|
+
}
|
|
3382
|
+
return false;
|
|
3383
|
+
}
|
|
3384
|
+
function getKeyOfExpression(expr) {
|
|
3385
|
+
switch (expr.type) {
|
|
3386
|
+
case AST_NODE_TYPES.Identifier: {
|
|
3387
|
+
return expr.name;
|
|
3388
|
+
}
|
|
3389
|
+
case AST_NODE_TYPES.Literal: {
|
|
3390
|
+
if (typeof expr.value === "string") {
|
|
3391
|
+
return expr.value;
|
|
3392
|
+
}
|
|
3393
|
+
}
|
|
3394
|
+
}
|
|
3395
|
+
return null;
|
|
3396
|
+
}
|
|
3397
|
+
function reportUnusedProp(context, services, prop) {
|
|
3398
|
+
const declaration = prop.getDeclarations()?.[0];
|
|
3399
|
+
if (declaration == null) return;
|
|
3400
|
+
const declarationNode = services.tsNodeToESTreeNodeMap.get(declaration);
|
|
3401
|
+
if (declarationNode == null) return;
|
|
3402
|
+
const nodeToReport = declarationNode.type === AST_NODE_TYPES.TSPropertySignature ? declarationNode.key : declarationNode;
|
|
3403
|
+
context.report({
|
|
3404
|
+
messageId: "noUnusedProps",
|
|
3405
|
+
node: nodeToReport,
|
|
3406
|
+
data: { name: prop.name }
|
|
3407
|
+
});
|
|
3408
|
+
}
|
|
3409
|
+
var RULE_NAME54 = "no-unused-state";
|
|
3410
|
+
var RULE_FEATURES53 = [];
|
|
3411
|
+
function isKeyLiteral3(node, key) {
|
|
3412
|
+
return match(key).with({ type: AST_NODE_TYPES.Literal }, constTrue).with({ type: AST_NODE_TYPES.TemplateLiteral, expressions: [] }, constTrue).with({ type: AST_NODE_TYPES.Identifier }, () => !node.computed).otherwise(constFalse);
|
|
3413
|
+
}
|
|
3414
|
+
var no_unused_state_default = createRule({
|
|
3415
|
+
meta: {
|
|
3416
|
+
type: "problem",
|
|
3417
|
+
docs: {
|
|
3418
|
+
description: "Warns unused class component state.",
|
|
3419
|
+
[Symbol.for("rule_features")]: RULE_FEATURES53
|
|
3420
|
+
},
|
|
3421
|
+
messages: {
|
|
3422
|
+
noUnusedState: "Unused class component state in '{{className}}'"
|
|
3423
|
+
},
|
|
3424
|
+
schema: []
|
|
3425
|
+
},
|
|
3426
|
+
name: RULE_NAME54,
|
|
3427
|
+
create: create54,
|
|
3428
|
+
defaultOptions: []
|
|
3429
|
+
});
|
|
3430
|
+
function create54(context) {
|
|
3431
|
+
const classEntries = [];
|
|
3432
|
+
const methodEntries = [];
|
|
3433
|
+
const constructorEntries = [];
|
|
3434
|
+
const stateDefs = /* @__PURE__ */ new WeakMap();
|
|
3435
|
+
function classEnter(node) {
|
|
3436
|
+
classEntries.push(node);
|
|
3437
|
+
}
|
|
3438
|
+
function classExit() {
|
|
3439
|
+
const currentClass = classEntries.pop();
|
|
3440
|
+
if (currentClass == null || !ER27.isClassComponent(currentClass)) {
|
|
3441
|
+
return;
|
|
3442
|
+
}
|
|
3443
|
+
const className = AST13.getClassId(currentClass)?.name;
|
|
3444
|
+
const { node: defNode, isUsed = false } = stateDefs.get(currentClass) ?? {};
|
|
3445
|
+
if (defNode == null || isUsed) {
|
|
3446
|
+
return;
|
|
3447
|
+
}
|
|
3448
|
+
context.report({
|
|
3279
3449
|
messageId: "noUnusedState",
|
|
3280
3450
|
node: defNode,
|
|
3281
3451
|
data: {
|
|
@@ -3286,11 +3456,11 @@ function create52(context) {
|
|
|
3286
3456
|
function methodEnter(node) {
|
|
3287
3457
|
methodEntries.push(node);
|
|
3288
3458
|
const currentClass = classEntries.at(-1);
|
|
3289
|
-
if (currentClass == null || !
|
|
3459
|
+
if (currentClass == null || !ER27.isClassComponent(currentClass)) {
|
|
3290
3460
|
return;
|
|
3291
3461
|
}
|
|
3292
3462
|
if (node.static) {
|
|
3293
|
-
if (
|
|
3463
|
+
if (ER27.isGetDerivedStateFromProps(node) && isMatching({ params: [P.nonNullable, ...P.array()] })(node.value)) {
|
|
3294
3464
|
const defNode = stateDefs.get(currentClass)?.node;
|
|
3295
3465
|
stateDefs.set(currentClass, { node: defNode, isUsed: true });
|
|
3296
3466
|
}
|
|
@@ -3311,11 +3481,11 @@ function create52(context) {
|
|
|
3311
3481
|
}
|
|
3312
3482
|
return {
|
|
3313
3483
|
AssignmentExpression(node) {
|
|
3314
|
-
if (!
|
|
3484
|
+
if (!ER27.isAssignmentToThisState(node)) {
|
|
3315
3485
|
return;
|
|
3316
3486
|
}
|
|
3317
3487
|
const currentClass = classEntries.at(-1);
|
|
3318
|
-
if (currentClass == null || !
|
|
3488
|
+
if (currentClass == null || !ER27.isClassComponent(currentClass)) {
|
|
3319
3489
|
return;
|
|
3320
3490
|
}
|
|
3321
3491
|
const currentConstructor = constructorEntries.at(-1);
|
|
@@ -3337,7 +3507,7 @@ function create52(context) {
|
|
|
3337
3507
|
return;
|
|
3338
3508
|
}
|
|
3339
3509
|
const currentClass = classEntries.at(-1);
|
|
3340
|
-
if (currentClass == null || !
|
|
3510
|
+
if (currentClass == null || !ER27.isClassComponent(currentClass)) {
|
|
3341
3511
|
return;
|
|
3342
3512
|
}
|
|
3343
3513
|
const currentMethod = methodEntries.at(-1);
|
|
@@ -3361,7 +3531,7 @@ function create52(context) {
|
|
|
3361
3531
|
"PropertyDefinition:exit": methodExit,
|
|
3362
3532
|
VariableDeclarator(node) {
|
|
3363
3533
|
const currentClass = classEntries.at(-1);
|
|
3364
|
-
if (currentClass == null || !
|
|
3534
|
+
if (currentClass == null || !ER27.isClassComponent(currentClass)) {
|
|
3365
3535
|
return;
|
|
3366
3536
|
}
|
|
3367
3537
|
const currentMethod = methodEntries.at(-1);
|
|
@@ -3391,8 +3561,8 @@ function create52(context) {
|
|
|
3391
3561
|
}
|
|
3392
3562
|
};
|
|
3393
3563
|
}
|
|
3394
|
-
var
|
|
3395
|
-
var
|
|
3564
|
+
var RULE_NAME55 = "no-use-context";
|
|
3565
|
+
var RULE_FEATURES54 = [
|
|
3396
3566
|
"MOD"
|
|
3397
3567
|
];
|
|
3398
3568
|
var no_use_context_default = createRule({
|
|
@@ -3400,7 +3570,7 @@ var no_use_context_default = createRule({
|
|
|
3400
3570
|
type: "problem",
|
|
3401
3571
|
docs: {
|
|
3402
3572
|
description: "Replaces usages of `useContext` with `use`.",
|
|
3403
|
-
[Symbol.for("rule_features")]:
|
|
3573
|
+
[Symbol.for("rule_features")]: RULE_FEATURES54
|
|
3404
3574
|
},
|
|
3405
3575
|
fixable: "code",
|
|
3406
3576
|
messages: {
|
|
@@ -3408,11 +3578,11 @@ var no_use_context_default = createRule({
|
|
|
3408
3578
|
},
|
|
3409
3579
|
schema: []
|
|
3410
3580
|
},
|
|
3411
|
-
name:
|
|
3412
|
-
create:
|
|
3581
|
+
name: RULE_NAME55,
|
|
3582
|
+
create: create55,
|
|
3413
3583
|
defaultOptions: []
|
|
3414
3584
|
});
|
|
3415
|
-
function
|
|
3585
|
+
function create55(context) {
|
|
3416
3586
|
if (!context.sourceCode.text.includes("useContext")) return {};
|
|
3417
3587
|
const settings4 = getSettingsFromContext(context);
|
|
3418
3588
|
if (compare(settings4.version, "19.0.0", "<")) {
|
|
@@ -3422,7 +3592,7 @@ function create53(context) {
|
|
|
3422
3592
|
const hookCalls = /* @__PURE__ */ new Set();
|
|
3423
3593
|
return {
|
|
3424
3594
|
CallExpression(node) {
|
|
3425
|
-
if (!
|
|
3595
|
+
if (!ER27.isReactHookCall(node)) {
|
|
3426
3596
|
return;
|
|
3427
3597
|
}
|
|
3428
3598
|
hookCalls.add(node);
|
|
@@ -3461,7 +3631,7 @@ function create53(context) {
|
|
|
3461
3631
|
}
|
|
3462
3632
|
},
|
|
3463
3633
|
"Program:exit"() {
|
|
3464
|
-
const isUseContextCall =
|
|
3634
|
+
const isUseContextCall = ER27.isReactHookCallWithNameAlias(context, "useContext", [...useContextNames]);
|
|
3465
3635
|
for (const node of hookCalls) {
|
|
3466
3636
|
if (!isUseContextCall(node)) {
|
|
3467
3637
|
continue;
|
|
@@ -3495,28 +3665,28 @@ function getCorrelativeTokens(context, node) {
|
|
|
3495
3665
|
}
|
|
3496
3666
|
return tokens;
|
|
3497
3667
|
}
|
|
3498
|
-
var
|
|
3499
|
-
var
|
|
3668
|
+
var RULE_NAME56 = "no-useless-forward-ref";
|
|
3669
|
+
var RULE_FEATURES55 = [];
|
|
3500
3670
|
var no_useless_forward_ref_default = createRule({
|
|
3501
3671
|
meta: {
|
|
3502
3672
|
type: "problem",
|
|
3503
3673
|
docs: {
|
|
3504
3674
|
description: "Disallow useless `forwardRef` calls on components that don't use `ref`s.",
|
|
3505
|
-
[Symbol.for("rule_features")]:
|
|
3675
|
+
[Symbol.for("rule_features")]: RULE_FEATURES55
|
|
3506
3676
|
},
|
|
3507
3677
|
messages: {
|
|
3508
3678
|
noUselessForwardRef: "A 'forwardRef' is used with this component but no 'ref' parameter is set."
|
|
3509
3679
|
},
|
|
3510
3680
|
schema: []
|
|
3511
3681
|
},
|
|
3512
|
-
name:
|
|
3513
|
-
create:
|
|
3682
|
+
name: RULE_NAME56,
|
|
3683
|
+
create: create56,
|
|
3514
3684
|
defaultOptions: []
|
|
3515
3685
|
});
|
|
3516
|
-
function
|
|
3686
|
+
function create56(context) {
|
|
3517
3687
|
return {
|
|
3518
3688
|
CallExpression(node) {
|
|
3519
|
-
if (!
|
|
3689
|
+
if (!ER27.isForwardRefCall(context, node)) {
|
|
3520
3690
|
return;
|
|
3521
3691
|
}
|
|
3522
3692
|
const [component] = node.arguments;
|
|
@@ -3534,14 +3704,14 @@ function create54(context) {
|
|
|
3534
3704
|
}
|
|
3535
3705
|
};
|
|
3536
3706
|
}
|
|
3537
|
-
var
|
|
3538
|
-
var
|
|
3707
|
+
var RULE_NAME57 = "no-useless-fragment";
|
|
3708
|
+
var defaultOptions4 = [{
|
|
3539
3709
|
allowExpressions: true
|
|
3540
3710
|
}];
|
|
3541
3711
|
var no_useless_fragment_default = createRule({
|
|
3542
3712
|
meta: {
|
|
3543
3713
|
type: "problem",
|
|
3544
|
-
defaultOptions: [...
|
|
3714
|
+
defaultOptions: [...defaultOptions4],
|
|
3545
3715
|
docs: {
|
|
3546
3716
|
description: "Disallow useless fragment elements."
|
|
3547
3717
|
},
|
|
@@ -3560,15 +3730,15 @@ var no_useless_fragment_default = createRule({
|
|
|
3560
3730
|
}
|
|
3561
3731
|
}]
|
|
3562
3732
|
},
|
|
3563
|
-
name:
|
|
3564
|
-
create:
|
|
3565
|
-
defaultOptions:
|
|
3733
|
+
name: RULE_NAME57,
|
|
3734
|
+
create: create57,
|
|
3735
|
+
defaultOptions: defaultOptions4
|
|
3566
3736
|
});
|
|
3567
|
-
function
|
|
3737
|
+
function create57(context, [option]) {
|
|
3568
3738
|
const { allowExpressions = true } = option;
|
|
3569
3739
|
return {
|
|
3570
3740
|
JSXElement(node) {
|
|
3571
|
-
if (!
|
|
3741
|
+
if (!ER27.isFragmentElement(context, node)) return;
|
|
3572
3742
|
checkNode(context, node, allowExpressions);
|
|
3573
3743
|
},
|
|
3574
3744
|
JSXFragment(node) {
|
|
@@ -3580,7 +3750,7 @@ function isWhiteSpace(node) {
|
|
|
3580
3750
|
return typeof node.value === "string" && node.raw.trim() === "";
|
|
3581
3751
|
}
|
|
3582
3752
|
function isPaddingSpaces(node) {
|
|
3583
|
-
return
|
|
3753
|
+
return ER27.isJsxText(node) && isWhiteSpace(node) && node.raw.includes("\n");
|
|
3584
3754
|
}
|
|
3585
3755
|
function trimLikeReact(text) {
|
|
3586
3756
|
const leadingSpaces = /^\s*/.exec(text)?.[0] ?? "";
|
|
@@ -3591,10 +3761,10 @@ function trimLikeReact(text) {
|
|
|
3591
3761
|
}
|
|
3592
3762
|
function checkNode(context, node, allowExpressions) {
|
|
3593
3763
|
const initialScope = context.sourceCode.getScope(node);
|
|
3594
|
-
if (
|
|
3764
|
+
if (node.type === AST_NODE_TYPES.JSXElement && ER27.hasAttribute(context, "key", node.openingElement.attributes, initialScope)) {
|
|
3595
3765
|
return;
|
|
3596
3766
|
}
|
|
3597
|
-
if (
|
|
3767
|
+
if (ER27.isHostElement(context, node.parent)) {
|
|
3598
3768
|
context.report({
|
|
3599
3769
|
messageId: "uselessFragment",
|
|
3600
3770
|
node,
|
|
@@ -3618,7 +3788,7 @@ function checkNode(context, node, allowExpressions) {
|
|
|
3618
3788
|
const isChildElement = AST13.isOneOf([AST_NODE_TYPES.JSXElement, AST_NODE_TYPES.JSXFragment])(node.parent);
|
|
3619
3789
|
switch (true) {
|
|
3620
3790
|
// <Foo content={<>ee eeee eeee ...</>} />
|
|
3621
|
-
case (allowExpressions && !isChildElement && node.children.length === 1 &&
|
|
3791
|
+
case (allowExpressions && !isChildElement && node.children.length === 1 && ER27.isJsxText(node.children.at(0))): {
|
|
3622
3792
|
return;
|
|
3623
3793
|
}
|
|
3624
3794
|
// <Foo><>hello, world</></Foo>
|
|
@@ -3664,7 +3834,7 @@ function checkNode(context, node, allowExpressions) {
|
|
|
3664
3834
|
return;
|
|
3665
3835
|
}
|
|
3666
3836
|
function getFix2(context, node) {
|
|
3667
|
-
if (!
|
|
3837
|
+
if (!canFix2(context, node)) return null;
|
|
3668
3838
|
return (fixer) => {
|
|
3669
3839
|
const opener = node.type === AST_NODE_TYPES.JSXFragment ? node.openingFragment : node.openingElement;
|
|
3670
3840
|
const closer = node.type === AST_NODE_TYPES.JSXFragment ? node.closingFragment : node.closingElement;
|
|
@@ -3672,20 +3842,20 @@ function getFix2(context, node) {
|
|
|
3672
3842
|
return fixer.replaceText(node, trimLikeReact(childrenText));
|
|
3673
3843
|
};
|
|
3674
3844
|
}
|
|
3675
|
-
function
|
|
3845
|
+
function canFix2(context, node) {
|
|
3676
3846
|
if (node.parent.type === AST_NODE_TYPES.JSXElement || node.parent.type === AST_NODE_TYPES.JSXFragment) {
|
|
3677
|
-
return
|
|
3847
|
+
return ER27.isHostElement(context, node.parent);
|
|
3678
3848
|
}
|
|
3679
3849
|
if (node.children.length === 0) {
|
|
3680
3850
|
return false;
|
|
3681
3851
|
}
|
|
3682
|
-
if (node.children.some((child) =>
|
|
3852
|
+
if (node.children.some((child) => ER27.isJsxText(child) && !isWhiteSpace(child) || AST13.is(AST_NODE_TYPES.JSXExpressionContainer)(child))) {
|
|
3683
3853
|
return false;
|
|
3684
3854
|
}
|
|
3685
3855
|
return true;
|
|
3686
3856
|
}
|
|
3687
|
-
var
|
|
3688
|
-
var
|
|
3857
|
+
var RULE_NAME58 = "prefer-destructuring-assignment";
|
|
3858
|
+
var RULE_FEATURES56 = [];
|
|
3689
3859
|
function isMemberExpressionWithObjectName(node) {
|
|
3690
3860
|
return node.object.type === AST_NODE_TYPES.Identifier && "name" in node.object;
|
|
3691
3861
|
}
|
|
@@ -3694,19 +3864,19 @@ var prefer_destructuring_assignment_default = createRule({
|
|
|
3694
3864
|
type: "problem",
|
|
3695
3865
|
docs: {
|
|
3696
3866
|
description: "Enforces destructuring assignment for component props and context.",
|
|
3697
|
-
[Symbol.for("rule_features")]:
|
|
3867
|
+
[Symbol.for("rule_features")]: RULE_FEATURES56
|
|
3698
3868
|
},
|
|
3699
3869
|
messages: {
|
|
3700
3870
|
preferDestructuringAssignment: "Use destructuring assignment for {{name}}."
|
|
3701
3871
|
},
|
|
3702
3872
|
schema: []
|
|
3703
3873
|
},
|
|
3704
|
-
name:
|
|
3705
|
-
create:
|
|
3874
|
+
name: RULE_NAME58,
|
|
3875
|
+
create: create58,
|
|
3706
3876
|
defaultOptions: []
|
|
3707
3877
|
});
|
|
3708
|
-
function
|
|
3709
|
-
const { ctx, listeners } =
|
|
3878
|
+
function create58(context) {
|
|
3879
|
+
const { ctx, listeners } = ER27.useComponentCollector(context);
|
|
3710
3880
|
const memberExpressionWithNames = [];
|
|
3711
3881
|
return {
|
|
3712
3882
|
...listeners,
|
|
@@ -3725,7 +3895,7 @@ function create56(context) {
|
|
|
3725
3895
|
return false;
|
|
3726
3896
|
}
|
|
3727
3897
|
const id = AST13.getFunctionId(block);
|
|
3728
|
-
return id != null &&
|
|
3898
|
+
return id != null && ER27.isComponentNameLoose(id.name) && components.some((component) => component.node === block);
|
|
3729
3899
|
}
|
|
3730
3900
|
for (const [initialScope, memberExpression] of memberExpressionWithNames) {
|
|
3731
3901
|
let scope = initialScope;
|
|
@@ -3765,8 +3935,8 @@ function create56(context) {
|
|
|
3765
3935
|
}
|
|
3766
3936
|
};
|
|
3767
3937
|
}
|
|
3768
|
-
var
|
|
3769
|
-
var
|
|
3938
|
+
var RULE_NAME59 = "prefer-namespace-import";
|
|
3939
|
+
var RULE_FEATURES57 = [
|
|
3770
3940
|
"FIX"
|
|
3771
3941
|
];
|
|
3772
3942
|
var prefer_namespace_import_default = createRule({
|
|
@@ -3774,7 +3944,7 @@ var prefer_namespace_import_default = createRule({
|
|
|
3774
3944
|
type: "problem",
|
|
3775
3945
|
docs: {
|
|
3776
3946
|
description: "Enforces React is imported via a namespace import.",
|
|
3777
|
-
[Symbol.for("rule_features")]:
|
|
3947
|
+
[Symbol.for("rule_features")]: RULE_FEATURES57
|
|
3778
3948
|
},
|
|
3779
3949
|
fixable: "code",
|
|
3780
3950
|
messages: {
|
|
@@ -3782,11 +3952,11 @@ var prefer_namespace_import_default = createRule({
|
|
|
3782
3952
|
},
|
|
3783
3953
|
schema: []
|
|
3784
3954
|
},
|
|
3785
|
-
name:
|
|
3786
|
-
create:
|
|
3955
|
+
name: RULE_NAME59,
|
|
3956
|
+
create: create59,
|
|
3787
3957
|
defaultOptions: []
|
|
3788
3958
|
});
|
|
3789
|
-
function
|
|
3959
|
+
function create59(context) {
|
|
3790
3960
|
const { importSource } = getSettingsFromContext(context);
|
|
3791
3961
|
return {
|
|
3792
3962
|
[`ImportDeclaration[source.value="${importSource}"] ImportDefaultSpecifier`](node) {
|
|
@@ -3821,8 +3991,8 @@ function create57(context) {
|
|
|
3821
3991
|
}
|
|
3822
3992
|
};
|
|
3823
3993
|
}
|
|
3824
|
-
var
|
|
3825
|
-
var
|
|
3994
|
+
var RULE_NAME60 = "prefer-read-only-props";
|
|
3995
|
+
var RULE_FEATURES58 = [
|
|
3826
3996
|
"TSC",
|
|
3827
3997
|
"EXP"
|
|
3828
3998
|
];
|
|
@@ -3831,20 +4001,20 @@ var prefer_read_only_props_default = createRule({
|
|
|
3831
4001
|
type: "problem",
|
|
3832
4002
|
docs: {
|
|
3833
4003
|
description: "Enforces read-only props in components.",
|
|
3834
|
-
[Symbol.for("rule_features")]:
|
|
4004
|
+
[Symbol.for("rule_features")]: RULE_FEATURES58
|
|
3835
4005
|
},
|
|
3836
4006
|
messages: {
|
|
3837
4007
|
preferReadOnlyProps: "A function component's props should be read-only."
|
|
3838
4008
|
},
|
|
3839
4009
|
schema: []
|
|
3840
4010
|
},
|
|
3841
|
-
name:
|
|
3842
|
-
create:
|
|
4011
|
+
name: RULE_NAME60,
|
|
4012
|
+
create: create60,
|
|
3843
4013
|
defaultOptions: []
|
|
3844
4014
|
});
|
|
3845
|
-
function
|
|
4015
|
+
function create60(context) {
|
|
3846
4016
|
const services = ESLintUtils.getParserServices(context, false);
|
|
3847
|
-
const { ctx, listeners } =
|
|
4017
|
+
const { ctx, listeners } = ER27.useComponentCollector(context);
|
|
3848
4018
|
return {
|
|
3849
4019
|
...listeners,
|
|
3850
4020
|
"Program:exit"(program) {
|
|
@@ -3874,8 +4044,8 @@ function isTypeReadonlyLoose(services, type) {
|
|
|
3874
4044
|
return true;
|
|
3875
4045
|
}
|
|
3876
4046
|
}
|
|
3877
|
-
var
|
|
3878
|
-
var
|
|
4047
|
+
var RULE_NAME61 = "prefer-use-state-lazy-initialization";
|
|
4048
|
+
var RULE_FEATURES59 = [
|
|
3879
4049
|
"EXP"
|
|
3880
4050
|
];
|
|
3881
4051
|
var ALLOW_LIST = [
|
|
@@ -3888,23 +4058,23 @@ var prefer_use_state_lazy_initialization_default = createRule({
|
|
|
3888
4058
|
type: "problem",
|
|
3889
4059
|
docs: {
|
|
3890
4060
|
description: "Enforces function calls made inside `useState` to be wrapped in an `initializer function`.",
|
|
3891
|
-
[Symbol.for("rule_features")]:
|
|
4061
|
+
[Symbol.for("rule_features")]: RULE_FEATURES59
|
|
3892
4062
|
},
|
|
3893
4063
|
messages: {
|
|
3894
4064
|
preferUseStateLazyInitialization: "To prevent re-computation, consider using lazy initial state for useState calls that involve function calls. Ex: 'useState(() => getValue())'."
|
|
3895
4065
|
},
|
|
3896
4066
|
schema: []
|
|
3897
4067
|
},
|
|
3898
|
-
name:
|
|
3899
|
-
create:
|
|
4068
|
+
name: RULE_NAME61,
|
|
4069
|
+
create: create61,
|
|
3900
4070
|
defaultOptions: []
|
|
3901
4071
|
});
|
|
3902
|
-
function
|
|
4072
|
+
function create61(context) {
|
|
3903
4073
|
const alias = getSettingsFromContext(context).additionalHooks.useState ?? [];
|
|
3904
|
-
const isUseStateCall =
|
|
4074
|
+
const isUseStateCall = ER27.isReactHookCallWithNameAlias(context, "useState", alias);
|
|
3905
4075
|
return {
|
|
3906
4076
|
CallExpression(node) {
|
|
3907
|
-
if (!
|
|
4077
|
+
if (!ER27.isReactHookCall(node)) {
|
|
3908
4078
|
return;
|
|
3909
4079
|
}
|
|
3910
4080
|
if (!isUseStateCall(node)) {
|
|
@@ -3917,7 +4087,7 @@ function create59(context) {
|
|
|
3917
4087
|
for (const expr of AST13.getNestedNewExpressions(useStateInput)) {
|
|
3918
4088
|
if (!("name" in expr.callee)) continue;
|
|
3919
4089
|
if (ALLOW_LIST.includes(expr.callee.name)) continue;
|
|
3920
|
-
if (AST13.findParentNode(expr, (n) =>
|
|
4090
|
+
if (AST13.findParentNode(expr, (n) => ER27.isUseCall(context, n)) != null) continue;
|
|
3921
4091
|
context.report({
|
|
3922
4092
|
messageId: "preferUseStateLazyInitialization",
|
|
3923
4093
|
node: expr
|
|
@@ -3925,9 +4095,9 @@ function create59(context) {
|
|
|
3925
4095
|
}
|
|
3926
4096
|
for (const expr of AST13.getNestedCallExpressions(useStateInput)) {
|
|
3927
4097
|
if (!("name" in expr.callee)) continue;
|
|
3928
|
-
if (
|
|
4098
|
+
if (ER27.isReactHookName(expr.callee.name)) continue;
|
|
3929
4099
|
if (ALLOW_LIST.includes(expr.callee.name)) continue;
|
|
3930
|
-
if (AST13.findParentNode(expr, (n) =>
|
|
4100
|
+
if (AST13.findParentNode(expr, (n) => ER27.isUseCall(context, n)) != null) continue;
|
|
3931
4101
|
context.report({
|
|
3932
4102
|
messageId: "preferUseStateLazyInitialization",
|
|
3933
4103
|
node: expr
|
|
@@ -3936,15 +4106,15 @@ function create59(context) {
|
|
|
3936
4106
|
}
|
|
3937
4107
|
};
|
|
3938
4108
|
}
|
|
3939
|
-
var
|
|
3940
|
-
var
|
|
4109
|
+
var RULE_NAME62 = "avoid-shorthand-boolean";
|
|
4110
|
+
var RULE_FEATURES60 = [];
|
|
3941
4111
|
var avoid_shorthand_boolean_default = createRule({
|
|
3942
4112
|
meta: {
|
|
3943
4113
|
type: "problem",
|
|
3944
4114
|
deprecated: true,
|
|
3945
4115
|
docs: {
|
|
3946
4116
|
description: "Enforces explicit boolean values for boolean attributes.",
|
|
3947
|
-
[Symbol.for("rule_features")]:
|
|
4117
|
+
[Symbol.for("rule_features")]: RULE_FEATURES60
|
|
3948
4118
|
},
|
|
3949
4119
|
fixable: "code",
|
|
3950
4120
|
messages: {
|
|
@@ -3955,11 +4125,11 @@ var avoid_shorthand_boolean_default = createRule({
|
|
|
3955
4125
|
],
|
|
3956
4126
|
schema: []
|
|
3957
4127
|
},
|
|
3958
|
-
name:
|
|
3959
|
-
create:
|
|
4128
|
+
name: RULE_NAME62,
|
|
4129
|
+
create: create62,
|
|
3960
4130
|
defaultOptions: []
|
|
3961
4131
|
});
|
|
3962
|
-
function
|
|
4132
|
+
function create62(context) {
|
|
3963
4133
|
return {
|
|
3964
4134
|
JSXAttribute(node) {
|
|
3965
4135
|
if (node.value == null) {
|
|
@@ -3967,7 +4137,7 @@ function create60(context) {
|
|
|
3967
4137
|
messageId: "avoidShorthandBoolean",
|
|
3968
4138
|
node,
|
|
3969
4139
|
data: {
|
|
3970
|
-
propName:
|
|
4140
|
+
propName: ER27.getAttributeName(context, node)
|
|
3971
4141
|
},
|
|
3972
4142
|
fix: (fixer) => fixer.insertTextAfter(node.name, `={true}`)
|
|
3973
4143
|
});
|
|
@@ -3975,15 +4145,15 @@ function create60(context) {
|
|
|
3975
4145
|
}
|
|
3976
4146
|
};
|
|
3977
4147
|
}
|
|
3978
|
-
var
|
|
3979
|
-
var
|
|
4148
|
+
var RULE_NAME63 = "avoid-shorthand-fragment";
|
|
4149
|
+
var RULE_FEATURES61 = [];
|
|
3980
4150
|
var avoid_shorthand_fragment_default = createRule({
|
|
3981
4151
|
meta: {
|
|
3982
4152
|
type: "problem",
|
|
3983
4153
|
deprecated: true,
|
|
3984
4154
|
docs: {
|
|
3985
4155
|
description: "Enforces explicit `<Fragment>` components instead of the shorthand `<>` or `</>` syntax.",
|
|
3986
|
-
[Symbol.for("rule_features")]:
|
|
4156
|
+
[Symbol.for("rule_features")]: RULE_FEATURES61
|
|
3987
4157
|
},
|
|
3988
4158
|
messages: {
|
|
3989
4159
|
avoidShorthandFragment: "Avoid using shorthand fragment syntax. Use '{{jsxFragmentFactory}}' component instead."
|
|
@@ -3993,11 +4163,11 @@ var avoid_shorthand_fragment_default = createRule({
|
|
|
3993
4163
|
],
|
|
3994
4164
|
schema: []
|
|
3995
4165
|
},
|
|
3996
|
-
name:
|
|
3997
|
-
create:
|
|
4166
|
+
name: RULE_NAME63,
|
|
4167
|
+
create: create63,
|
|
3998
4168
|
defaultOptions: []
|
|
3999
4169
|
});
|
|
4000
|
-
function
|
|
4170
|
+
function create63(context) {
|
|
4001
4171
|
const jsxConfigFromContext = JsxConfig.getFromContext(context);
|
|
4002
4172
|
const jsxConfigFromAnnotation = JsxConfig.getFromAnnotation(context);
|
|
4003
4173
|
const jsxConfig = {
|
|
@@ -4016,103 +4186,104 @@ function create61(context) {
|
|
|
4016
4186
|
}
|
|
4017
4187
|
};
|
|
4018
4188
|
}
|
|
4019
|
-
var
|
|
4020
|
-
var
|
|
4021
|
-
|
|
4022
|
-
];
|
|
4023
|
-
var prefer_shorthand_boolean_default = createRule({
|
|
4189
|
+
var RULE_NAME64 = "no-comment-textnodes";
|
|
4190
|
+
var RULE_FEATURES62 = [];
|
|
4191
|
+
var no_comment_textnodes_default = createRule({
|
|
4024
4192
|
meta: {
|
|
4025
4193
|
type: "problem",
|
|
4026
4194
|
deprecated: true,
|
|
4027
4195
|
docs: {
|
|
4028
|
-
description: "
|
|
4029
|
-
[Symbol.for("rule_features")]:
|
|
4196
|
+
description: "Prevents comments from being inserted as text nodes.",
|
|
4197
|
+
[Symbol.for("rule_features")]: RULE_FEATURES62
|
|
4030
4198
|
},
|
|
4031
|
-
fixable: "code",
|
|
4032
4199
|
messages: {
|
|
4033
|
-
|
|
4200
|
+
noCommentTextnodes: "Possible misused comment in text node. Comments inside children section of tag should be placed inside braces."
|
|
4034
4201
|
},
|
|
4035
4202
|
replacedBy: [
|
|
4036
|
-
"react-x/jsx-
|
|
4203
|
+
"react-x/jsx-no-comment-textnodes"
|
|
4037
4204
|
],
|
|
4038
4205
|
schema: []
|
|
4039
4206
|
},
|
|
4040
|
-
name:
|
|
4041
|
-
create:
|
|
4207
|
+
name: RULE_NAME64,
|
|
4208
|
+
create: create64,
|
|
4042
4209
|
defaultOptions: []
|
|
4043
4210
|
});
|
|
4044
|
-
function
|
|
4045
|
-
|
|
4046
|
-
JSXAttribute(node) {
|
|
4047
|
-
|
|
4048
|
-
|
|
4049
|
-
|
|
4050
|
-
|
|
4051
|
-
|
|
4052
|
-
|
|
4053
|
-
|
|
4054
|
-
|
|
4055
|
-
|
|
4056
|
-
|
|
4057
|
-
|
|
4058
|
-
|
|
4059
|
-
|
|
4060
|
-
|
|
4211
|
+
function create64(context) {
|
|
4212
|
+
function hasCommentLike(node) {
|
|
4213
|
+
if (AST13.isOneOf([AST_NODE_TYPES.JSXAttribute, AST_NODE_TYPES.JSXExpressionContainer])(node.parent)) {
|
|
4214
|
+
return false;
|
|
4215
|
+
}
|
|
4216
|
+
const rawValue = context.sourceCode.getText(node);
|
|
4217
|
+
return /^\s*\/(?:\/|\*)/mu.test(rawValue);
|
|
4218
|
+
}
|
|
4219
|
+
const visitorFunction = (node) => {
|
|
4220
|
+
if (!AST13.isOneOf([AST_NODE_TYPES.JSXElement, AST_NODE_TYPES.JSXFragment])(node.parent)) {
|
|
4221
|
+
return;
|
|
4222
|
+
}
|
|
4223
|
+
if (!hasCommentLike(node)) {
|
|
4224
|
+
return;
|
|
4225
|
+
}
|
|
4226
|
+
if (!node.parent.type.includes("JSX")) {
|
|
4227
|
+
return;
|
|
4061
4228
|
}
|
|
4229
|
+
context.report({
|
|
4230
|
+
messageId: "noCommentTextnodes",
|
|
4231
|
+
node
|
|
4232
|
+
});
|
|
4233
|
+
};
|
|
4234
|
+
return {
|
|
4235
|
+
JSXText: visitorFunction,
|
|
4236
|
+
Literal: visitorFunction
|
|
4062
4237
|
};
|
|
4063
4238
|
}
|
|
4064
|
-
var
|
|
4065
|
-
var
|
|
4066
|
-
"
|
|
4239
|
+
var RULE_NAME65 = "no-complex-conditional-rendering";
|
|
4240
|
+
var RULE_FEATURES63 = [
|
|
4241
|
+
"EXP"
|
|
4067
4242
|
];
|
|
4068
|
-
var
|
|
4243
|
+
var no_complex_conditional_rendering_default = createRule({
|
|
4069
4244
|
meta: {
|
|
4070
4245
|
type: "problem",
|
|
4071
4246
|
deprecated: true,
|
|
4072
4247
|
docs: {
|
|
4073
|
-
description: "
|
|
4074
|
-
[Symbol.for("rule_features")]:
|
|
4248
|
+
description: "Disallow complex conditional rendering in JSX expressions.",
|
|
4249
|
+
[Symbol.for("rule_features")]: RULE_FEATURES63
|
|
4075
4250
|
},
|
|
4076
|
-
fixable: "code",
|
|
4077
4251
|
messages: {
|
|
4078
|
-
|
|
4252
|
+
noComplexConditionalRendering: "Avoid complex conditional rendering. Extract the logic into separate elements or components."
|
|
4079
4253
|
},
|
|
4080
|
-
replacedBy: [
|
|
4081
|
-
"react-x/jsx-shorthand-fragment"
|
|
4082
|
-
],
|
|
4083
4254
|
schema: []
|
|
4084
4255
|
},
|
|
4085
|
-
name:
|
|
4086
|
-
create:
|
|
4256
|
+
name: RULE_NAME65,
|
|
4257
|
+
create: create65,
|
|
4087
4258
|
defaultOptions: []
|
|
4088
4259
|
});
|
|
4089
|
-
function
|
|
4090
|
-
|
|
4091
|
-
|
|
4092
|
-
|
|
4093
|
-
|
|
4094
|
-
if (hasAttributes) {
|
|
4095
|
-
return;
|
|
4096
|
-
}
|
|
4097
|
-
context.report({
|
|
4098
|
-
messageId: "preferShorthandFragment",
|
|
4099
|
-
node,
|
|
4100
|
-
fix: (fixer) => {
|
|
4101
|
-
const { closingElement, openingElement } = node;
|
|
4102
|
-
if (closingElement == null) {
|
|
4103
|
-
return [];
|
|
4104
|
-
}
|
|
4105
|
-
return [
|
|
4106
|
-
fixer.replaceTextRange([openingElement.range[0], openingElement.range[1]], "<>"),
|
|
4107
|
-
fixer.replaceTextRange([closingElement.range[0], closingElement.range[1]], "</>")
|
|
4108
|
-
];
|
|
4109
|
-
}
|
|
4110
|
-
});
|
|
4260
|
+
function create65(context) {
|
|
4261
|
+
const visitorFunction = (node) => {
|
|
4262
|
+
const jsxExpContainer = node.parent?.parent;
|
|
4263
|
+
if (!AST13.is(AST_NODE_TYPES.JSXExpressionContainer)(jsxExpContainer)) {
|
|
4264
|
+
return;
|
|
4111
4265
|
}
|
|
4266
|
+
if (!AST13.isOneOf([AST_NODE_TYPES.JSXElement, AST_NODE_TYPES.JSXFragment])(jsxExpContainer.parent)) {
|
|
4267
|
+
return;
|
|
4268
|
+
}
|
|
4269
|
+
if (!jsxExpContainer.parent.children.includes(jsxExpContainer)) {
|
|
4270
|
+
return;
|
|
4271
|
+
}
|
|
4272
|
+
context.report({
|
|
4273
|
+
messageId: "noComplexConditionalRendering",
|
|
4274
|
+
node: jsxExpContainer
|
|
4275
|
+
});
|
|
4276
|
+
};
|
|
4277
|
+
return {
|
|
4278
|
+
"JSXExpressionContainer > ConditionalExpression > ConditionalExpression": visitorFunction,
|
|
4279
|
+
"JSXExpressionContainer > ConditionalExpression > LogicalExpression": visitorFunction,
|
|
4280
|
+
"JSXExpressionContainer > LogicalExpression > ConditionalExpression": visitorFunction,
|
|
4281
|
+
"JSXExpressionContainer > LogicalExpression[operator='&&'] > LogicalExpression[operator='||']": visitorFunction,
|
|
4282
|
+
"JSXExpressionContainer > LogicalExpression[operator='||'] > LogicalExpression[operator='&&']": visitorFunction
|
|
4112
4283
|
};
|
|
4113
4284
|
}
|
|
4114
|
-
var
|
|
4115
|
-
var
|
|
4285
|
+
var RULE_NAME66 = "prefer-react-namespace-import";
|
|
4286
|
+
var RULE_FEATURES64 = [
|
|
4116
4287
|
"FIX"
|
|
4117
4288
|
];
|
|
4118
4289
|
var prefer_react_namespace_import_default = createRule({
|
|
@@ -4121,7 +4292,7 @@ var prefer_react_namespace_import_default = createRule({
|
|
|
4121
4292
|
deprecated: true,
|
|
4122
4293
|
docs: {
|
|
4123
4294
|
description: "Enforces React is imported via a namespace import.",
|
|
4124
|
-
[Symbol.for("rule_features")]:
|
|
4295
|
+
[Symbol.for("rule_features")]: RULE_FEATURES64
|
|
4125
4296
|
},
|
|
4126
4297
|
fixable: "code",
|
|
4127
4298
|
messages: {
|
|
@@ -4132,11 +4303,11 @@ var prefer_react_namespace_import_default = createRule({
|
|
|
4132
4303
|
],
|
|
4133
4304
|
schema: []
|
|
4134
4305
|
},
|
|
4135
|
-
name:
|
|
4136
|
-
create:
|
|
4306
|
+
name: RULE_NAME66,
|
|
4307
|
+
create: create66,
|
|
4137
4308
|
defaultOptions: []
|
|
4138
4309
|
});
|
|
4139
|
-
function
|
|
4310
|
+
function create66(context) {
|
|
4140
4311
|
const { importSource } = getSettingsFromContext(context);
|
|
4141
4312
|
return {
|
|
4142
4313
|
[`ImportDeclaration[source.value="${importSource}"] ImportDefaultSpecifier`](node) {
|
|
@@ -4171,100 +4342,99 @@ function create64(context) {
|
|
|
4171
4342
|
}
|
|
4172
4343
|
};
|
|
4173
4344
|
}
|
|
4174
|
-
var
|
|
4175
|
-
var
|
|
4176
|
-
|
|
4345
|
+
var RULE_NAME67 = "prefer-shorthand-boolean";
|
|
4346
|
+
var RULE_FEATURES65 = [
|
|
4347
|
+
"FIX"
|
|
4348
|
+
];
|
|
4349
|
+
var prefer_shorthand_boolean_default = createRule({
|
|
4177
4350
|
meta: {
|
|
4178
4351
|
type: "problem",
|
|
4179
4352
|
deprecated: true,
|
|
4180
4353
|
docs: {
|
|
4181
|
-
description: "
|
|
4182
|
-
[Symbol.for("rule_features")]:
|
|
4354
|
+
description: "Enforces shorthand syntax for boolean attributes.",
|
|
4355
|
+
[Symbol.for("rule_features")]: RULE_FEATURES65
|
|
4183
4356
|
},
|
|
4357
|
+
fixable: "code",
|
|
4184
4358
|
messages: {
|
|
4185
|
-
|
|
4359
|
+
preferShorthandBoolean: "Use shorthand boolean attribute '{{propName}}'."
|
|
4186
4360
|
},
|
|
4187
4361
|
replacedBy: [
|
|
4188
|
-
"react-x/jsx-
|
|
4362
|
+
"react-x/jsx-shorthand-boolean"
|
|
4189
4363
|
],
|
|
4190
4364
|
schema: []
|
|
4191
4365
|
},
|
|
4192
|
-
name:
|
|
4193
|
-
create:
|
|
4366
|
+
name: RULE_NAME67,
|
|
4367
|
+
create: create67,
|
|
4194
4368
|
defaultOptions: []
|
|
4195
4369
|
});
|
|
4196
|
-
function
|
|
4197
|
-
function hasCommentLike(node) {
|
|
4198
|
-
if (AST13.isOneOf([AST_NODE_TYPES.JSXAttribute, AST_NODE_TYPES.JSXExpressionContainer])(node.parent)) {
|
|
4199
|
-
return false;
|
|
4200
|
-
}
|
|
4201
|
-
const rawValue = context.sourceCode.getText(node);
|
|
4202
|
-
return /^\s*\/(?:\/|\*)/mu.test(rawValue);
|
|
4203
|
-
}
|
|
4204
|
-
const visitorFunction = (node) => {
|
|
4205
|
-
if (!AST13.isOneOf([AST_NODE_TYPES.JSXElement, AST_NODE_TYPES.JSXFragment])(node.parent)) {
|
|
4206
|
-
return;
|
|
4207
|
-
}
|
|
4208
|
-
if (!hasCommentLike(node)) {
|
|
4209
|
-
return;
|
|
4210
|
-
}
|
|
4211
|
-
if (!node.parent.type.includes("JSX")) {
|
|
4212
|
-
return;
|
|
4213
|
-
}
|
|
4214
|
-
context.report({
|
|
4215
|
-
messageId: "noCommentTextnodes",
|
|
4216
|
-
node
|
|
4217
|
-
});
|
|
4218
|
-
};
|
|
4370
|
+
function create67(context) {
|
|
4219
4371
|
return {
|
|
4220
|
-
|
|
4221
|
-
|
|
4372
|
+
JSXAttribute(node) {
|
|
4373
|
+
const { value } = node;
|
|
4374
|
+
const propName = ER27.getAttributeName(context, node);
|
|
4375
|
+
const hasValueTrue = value?.type === AST_NODE_TYPES.JSXExpressionContainer && value.expression.type === AST_NODE_TYPES.Literal && value.expression.value === true;
|
|
4376
|
+
if (!hasValueTrue) {
|
|
4377
|
+
return;
|
|
4378
|
+
}
|
|
4379
|
+
context.report({
|
|
4380
|
+
messageId: "preferShorthandBoolean",
|
|
4381
|
+
node: node.value ?? node,
|
|
4382
|
+
data: {
|
|
4383
|
+
propName
|
|
4384
|
+
},
|
|
4385
|
+
fix: (fixer) => fixer.removeRange([node.name.range[1], value.range[1]])
|
|
4386
|
+
});
|
|
4387
|
+
}
|
|
4222
4388
|
};
|
|
4223
4389
|
}
|
|
4224
|
-
var
|
|
4225
|
-
var
|
|
4226
|
-
"
|
|
4390
|
+
var RULE_NAME68 = "prefer-shorthand-fragment";
|
|
4391
|
+
var RULE_FEATURES66 = [
|
|
4392
|
+
"FIX"
|
|
4227
4393
|
];
|
|
4228
|
-
var
|
|
4394
|
+
var prefer_shorthand_fragment_default = createRule({
|
|
4229
4395
|
meta: {
|
|
4230
4396
|
type: "problem",
|
|
4231
4397
|
deprecated: true,
|
|
4232
4398
|
docs: {
|
|
4233
|
-
description: "
|
|
4234
|
-
[Symbol.for("rule_features")]:
|
|
4399
|
+
description: "Enforces shorthand syntax for fragments.",
|
|
4400
|
+
[Symbol.for("rule_features")]: RULE_FEATURES66
|
|
4235
4401
|
},
|
|
4402
|
+
fixable: "code",
|
|
4236
4403
|
messages: {
|
|
4237
|
-
|
|
4404
|
+
preferShorthandFragment: "Use fragment shorthand syntax instead of 'Fragment' component."
|
|
4238
4405
|
},
|
|
4406
|
+
replacedBy: [
|
|
4407
|
+
"react-x/jsx-shorthand-fragment"
|
|
4408
|
+
],
|
|
4239
4409
|
schema: []
|
|
4240
4410
|
},
|
|
4241
|
-
name:
|
|
4242
|
-
create:
|
|
4411
|
+
name: RULE_NAME68,
|
|
4412
|
+
create: create68,
|
|
4243
4413
|
defaultOptions: []
|
|
4244
4414
|
});
|
|
4245
|
-
function
|
|
4246
|
-
const visitorFunction = (node) => {
|
|
4247
|
-
const jsxExpContainer = node.parent?.parent;
|
|
4248
|
-
if (!AST13.is(AST_NODE_TYPES.JSXExpressionContainer)(jsxExpContainer)) {
|
|
4249
|
-
return;
|
|
4250
|
-
}
|
|
4251
|
-
if (!AST13.isOneOf([AST_NODE_TYPES.JSXElement, AST_NODE_TYPES.JSXFragment])(jsxExpContainer.parent)) {
|
|
4252
|
-
return;
|
|
4253
|
-
}
|
|
4254
|
-
if (!jsxExpContainer.parent.children.includes(jsxExpContainer)) {
|
|
4255
|
-
return;
|
|
4256
|
-
}
|
|
4257
|
-
context.report({
|
|
4258
|
-
messageId: "noComplexConditionalRendering",
|
|
4259
|
-
node: jsxExpContainer
|
|
4260
|
-
});
|
|
4261
|
-
};
|
|
4415
|
+
function create68(context) {
|
|
4262
4416
|
return {
|
|
4263
|
-
|
|
4264
|
-
|
|
4265
|
-
|
|
4266
|
-
|
|
4267
|
-
|
|
4417
|
+
JSXElement(node) {
|
|
4418
|
+
if (!ER27.isFragmentElement(context, node)) return;
|
|
4419
|
+
const hasAttributes = node.openingElement.attributes.length > 0;
|
|
4420
|
+
if (hasAttributes) {
|
|
4421
|
+
return;
|
|
4422
|
+
}
|
|
4423
|
+
context.report({
|
|
4424
|
+
messageId: "preferShorthandFragment",
|
|
4425
|
+
node,
|
|
4426
|
+
fix: (fixer) => {
|
|
4427
|
+
const { closingElement, openingElement } = node;
|
|
4428
|
+
if (closingElement == null) {
|
|
4429
|
+
return [];
|
|
4430
|
+
}
|
|
4431
|
+
return [
|
|
4432
|
+
fixer.replaceTextRange([openingElement.range[0], openingElement.range[1]], "<>"),
|
|
4433
|
+
fixer.replaceTextRange([closingElement.range[0], closingElement.range[1]], "</>")
|
|
4434
|
+
];
|
|
4435
|
+
}
|
|
4436
|
+
});
|
|
4437
|
+
}
|
|
4268
4438
|
};
|
|
4269
4439
|
}
|
|
4270
4440
|
|
|
@@ -4302,6 +4472,7 @@ var plugin = {
|
|
|
4302
4472
|
"no-default-props": no_default_props_default,
|
|
4303
4473
|
"no-direct-mutation-state": no_direct_mutation_state_default,
|
|
4304
4474
|
"no-duplicate-key": no_duplicate_key_default,
|
|
4475
|
+
"no-forbidden-props": no_forbidden_props_default,
|
|
4305
4476
|
"no-forward-ref": no_forward_ref_default,
|
|
4306
4477
|
"no-implicit-key": no_implicit_key_default,
|
|
4307
4478
|
"no-leaked-conditional-rendering": no_leaked_conditional_rendering_default,
|
|
@@ -4326,6 +4497,7 @@ var plugin = {
|
|
|
4326
4497
|
"no-unstable-context-value": no_unstable_context_value_default,
|
|
4327
4498
|
"no-unstable-default-props": no_unstable_default_props_default,
|
|
4328
4499
|
"no-unused-class-component-members": no_unused_class_component_members_default,
|
|
4500
|
+
"no-unused-props": no_unused_props_default,
|
|
4329
4501
|
"no-unused-state": no_unused_state_default,
|
|
4330
4502
|
"no-use-context": no_use_context_default,
|
|
4331
4503
|
"no-useless-forward-ref": no_useless_forward_ref_default,
|