eslint-plugin-react-x 1.22.1 → 1.22.2-beta.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +152 -216
- package/dist/index.mjs +153 -217
- package/package.json +13 -13
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var eff = require('@eslint-react/eff');
|
|
4
|
-
var
|
|
4
|
+
var JSX7 = require('@eslint-react/jsx');
|
|
5
5
|
var shared = require('@eslint-react/shared');
|
|
6
6
|
var AST11 = require('@eslint-react/ast');
|
|
7
7
|
var core = require('@eslint-react/core');
|
|
@@ -35,14 +35,14 @@ function _interopNamespace(e) {
|
|
|
35
35
|
return Object.freeze(n);
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
var
|
|
38
|
+
var JSX7__namespace = /*#__PURE__*/_interopNamespace(JSX7);
|
|
39
39
|
var AST11__namespace = /*#__PURE__*/_interopNamespace(AST11);
|
|
40
40
|
var VAR__namespace = /*#__PURE__*/_interopNamespace(VAR);
|
|
41
41
|
var ts__default = /*#__PURE__*/_interopDefault(ts);
|
|
42
42
|
|
|
43
43
|
// package.json
|
|
44
44
|
var name = "eslint-plugin-react-x";
|
|
45
|
-
var version = "1.22.
|
|
45
|
+
var version = "1.22.2-beta.11";
|
|
46
46
|
var createRule = shared.createRuleForPlugin("x");
|
|
47
47
|
|
|
48
48
|
// src/rules/avoid-shorthand-boolean.ts
|
|
@@ -70,7 +70,7 @@ var avoid_shorthand_boolean_default = createRule({
|
|
|
70
70
|
messageId: "avoidShorthandBoolean",
|
|
71
71
|
node,
|
|
72
72
|
data: {
|
|
73
|
-
propName:
|
|
73
|
+
propName: JSX7__namespace.getPropName(node)
|
|
74
74
|
},
|
|
75
75
|
fix: (fixer) => fixer.insertTextAfter(node.name, `={true}`)
|
|
76
76
|
});
|
|
@@ -151,7 +151,7 @@ var RULE_FEATURES4 = [
|
|
|
151
151
|
"CHK"
|
|
152
152
|
];
|
|
153
153
|
function getName(node) {
|
|
154
|
-
if (node
|
|
154
|
+
if (AST11__namespace.isTypeExpression(node)) {
|
|
155
155
|
return getName(node.expression);
|
|
156
156
|
}
|
|
157
157
|
if (node.type === types.AST_NODE_TYPES.Identifier || node.type === types.AST_NODE_TYPES.PrivateIdentifier) {
|
|
@@ -327,12 +327,10 @@ var no_array_index_key_default = createRule({
|
|
|
327
327
|
name: RULE_NAME5,
|
|
328
328
|
create(context) {
|
|
329
329
|
const indexParamNames = [];
|
|
330
|
+
const isCreateOrCloneElementCall = eff.or(core.isCreateElementCall(context), core.isCloneElementCall(context));
|
|
330
331
|
function isArrayIndex(node) {
|
|
331
332
|
return node.type === types.AST_NODE_TYPES.Identifier && indexParamNames.some(eff.O.exists((name2) => name2 === node.name));
|
|
332
333
|
}
|
|
333
|
-
function isCreateOrCloneElementCall(node) {
|
|
334
|
-
return core.isCreateElementCall(node, context) || core.isCloneElementCall(node, context);
|
|
335
|
-
}
|
|
336
334
|
function getReportDescriptor(node) {
|
|
337
335
|
if (isArrayIndex(node)) return [{ messageId: "noArrayIndexKey", node }];
|
|
338
336
|
if (AST11__namespace.isOneOf([types.AST_NODE_TYPES.TemplateLiteral, types.AST_NODE_TYPES.BinaryExpression])(node)) {
|
|
@@ -537,7 +535,7 @@ var no_children_prop_default = createRule({
|
|
|
537
535
|
return {
|
|
538
536
|
JSXElement(node) {
|
|
539
537
|
const initialScope = context.sourceCode.getScope(node);
|
|
540
|
-
const prop =
|
|
538
|
+
const prop = JSX7__namespace.getProp(node.openingElement.attributes, "children", initialScope);
|
|
541
539
|
const reportDescriptor = eff.O.map(prop, (prop2) => ({ messageId: "noChildrenProp", node: prop2 }));
|
|
542
540
|
eff.O.map(reportDescriptor, context.report);
|
|
543
541
|
}
|
|
@@ -912,7 +910,7 @@ var no_context_provider_default = createRule({
|
|
|
912
910
|
if (compareVersions.compare(version2, "19.0.0", "<")) return {};
|
|
913
911
|
return {
|
|
914
912
|
JSXElement(node) {
|
|
915
|
-
const elementName =
|
|
913
|
+
const elementName = JSX7__namespace.getElementName(node.openingElement);
|
|
916
914
|
if (!elementName.endsWith(".Provider")) return;
|
|
917
915
|
context.report({
|
|
918
916
|
messageId: "noContextProvider",
|
|
@@ -1009,7 +1007,7 @@ var RULE_FEATURES22 = [
|
|
|
1009
1007
|
"CHK"
|
|
1010
1008
|
];
|
|
1011
1009
|
function getName2(node) {
|
|
1012
|
-
if (node
|
|
1010
|
+
if (AST11__namespace.isTypeExpression(node)) {
|
|
1013
1011
|
return getName2(node.expression);
|
|
1014
1012
|
}
|
|
1015
1013
|
if (node.type === types.AST_NODE_TYPES.Identifier || node.type === types.AST_NODE_TYPES.PrivateIdentifier) {
|
|
@@ -1123,116 +1121,61 @@ var no_duplicate_key_default = createRule({
|
|
|
1123
1121
|
},
|
|
1124
1122
|
name: RULE_NAME24,
|
|
1125
1123
|
create(context) {
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
if (
|
|
1132
|
-
|
|
1133
|
-
return eff.F.pipe(
|
|
1134
|
-
JSX8__namespace.findPropInAttributes(node.openingElement.attributes, initialScope)("key"),
|
|
1135
|
-
eff.O.flatMap((k) => "value" in k ? eff.O.fromNullable(k.value) : eff.O.none()),
|
|
1136
|
-
eff.O.flatMap((v) => {
|
|
1137
|
-
return isKeyEqual(v, v) ? eff.O.some({
|
|
1138
|
-
messageId: "noDuplicateKey",
|
|
1139
|
-
node: v,
|
|
1140
|
-
data: {
|
|
1141
|
-
value: context.sourceCode.getText(v)
|
|
1142
|
-
}
|
|
1143
|
-
}) : eff.O.none();
|
|
1144
|
-
})
|
|
1145
|
-
);
|
|
1146
|
-
}
|
|
1147
|
-
function checkExpression(node) {
|
|
1148
|
-
switch (node.type) {
|
|
1149
|
-
case types.AST_NODE_TYPES.ConditionalExpression:
|
|
1150
|
-
if (!("consequent" in node)) return eff.O.none();
|
|
1151
|
-
return eff.F.pipe(
|
|
1152
|
-
checkIteratorElement(node.consequent),
|
|
1153
|
-
eff.O.orElse(() => checkIteratorElement(node.alternate))
|
|
1154
|
-
);
|
|
1155
|
-
case types.AST_NODE_TYPES.JSXElement:
|
|
1156
|
-
case types.AST_NODE_TYPES.JSXFragment:
|
|
1157
|
-
return checkIteratorElement(node);
|
|
1158
|
-
case types.AST_NODE_TYPES.LogicalExpression:
|
|
1159
|
-
if (!("left" in node)) return eff.O.none();
|
|
1160
|
-
return eff.F.pipe(
|
|
1161
|
-
checkIteratorElement(node.left),
|
|
1162
|
-
eff.O.orElse(() => checkIteratorElement(node.right))
|
|
1163
|
-
);
|
|
1164
|
-
default:
|
|
1165
|
-
return eff.O.none();
|
|
1166
|
-
}
|
|
1167
|
-
}
|
|
1168
|
-
function checkBlockStatement(node) {
|
|
1169
|
-
return AST11__namespace.getNestedReturnStatements(node).reduce((acc, statement) => {
|
|
1170
|
-
if (!statement.argument) return acc;
|
|
1171
|
-
const maybeDescriptor = checkIteratorElement(statement.argument);
|
|
1172
|
-
if (eff.O.isNone(maybeDescriptor)) return acc;
|
|
1173
|
-
const descriptor = maybeDescriptor.value;
|
|
1174
|
-
return [...acc, descriptor];
|
|
1175
|
-
}, []);
|
|
1124
|
+
if (!context.sourceCode.getText().includes("key=")) return {};
|
|
1125
|
+
const keyedEntries = /* @__PURE__ */ new Map();
|
|
1126
|
+
function isKeyValueEqual(a, b) {
|
|
1127
|
+
const aValue = a.value;
|
|
1128
|
+
const bValue = b.value;
|
|
1129
|
+
if (aValue === null || bValue === null) return false;
|
|
1130
|
+
return AST11__namespace.isNodeEqual(aValue, bValue);
|
|
1176
1131
|
}
|
|
1177
|
-
const seen = /* @__PURE__ */ new WeakSet();
|
|
1178
1132
|
return {
|
|
1179
|
-
"
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1133
|
+
"JSXAttribute[name.name='key']"(node) {
|
|
1134
|
+
const jsxElement = node.parent.parent;
|
|
1135
|
+
switch (jsxElement.parent.type) {
|
|
1136
|
+
case types.AST_NODE_TYPES.ArrayExpression:
|
|
1137
|
+
case types.AST_NODE_TYPES.JSXElement:
|
|
1138
|
+
case types.AST_NODE_TYPES.JSXFragment: {
|
|
1139
|
+
const root = jsxElement.parent;
|
|
1140
|
+
const prevKeys = keyedEntries.get(root)?.keys ?? [];
|
|
1141
|
+
keyedEntries.set(root, {
|
|
1142
|
+
hasDuplicate: prevKeys.some((prevKey) => isKeyValueEqual(prevKey, node)),
|
|
1143
|
+
keys: [...prevKeys, node],
|
|
1144
|
+
root: jsxElement.parent
|
|
1187
1145
|
});
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
data: {
|
|
1205
|
-
value: context.sourceCode.getText(value)
|
|
1146
|
+
break;
|
|
1147
|
+
}
|
|
1148
|
+
default: {
|
|
1149
|
+
const entry = eff.F.pipe(
|
|
1150
|
+
eff.O.Do,
|
|
1151
|
+
eff.O.bind("call", () => AST11__namespace.traverseUpGuard(jsxElement, AST11__namespace.isMapCallLoose)),
|
|
1152
|
+
eff.O.bind("iter", ({ call }) => AST11__namespace.traverseUpStop(jsxElement, call, AST11__namespace.isFunction)),
|
|
1153
|
+
eff.O.bind("arg0", ({ call }) => eff.O.fromNullable(call.arguments[0]))
|
|
1154
|
+
);
|
|
1155
|
+
for (const { arg0, call, iter } of eff.O.toArray(entry)) {
|
|
1156
|
+
if (AST11__namespace.unwrapTypeExpression(arg0) !== iter) continue;
|
|
1157
|
+
keyedEntries.set(call, {
|
|
1158
|
+
hasDuplicate: node.value?.type === types.AST_NODE_TYPES.Literal,
|
|
1159
|
+
keys: [node],
|
|
1160
|
+
root: call
|
|
1161
|
+
});
|
|
1206
1162
|
}
|
|
1207
|
-
}
|
|
1163
|
+
}
|
|
1208
1164
|
}
|
|
1209
1165
|
},
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
}, node);
|
|
1222
|
-
if (!isMapCall && !isArrayFromCall) return;
|
|
1223
|
-
if (eff.MutRef.get(isWithinChildrenToArrayRef)) return;
|
|
1224
|
-
const fn = node.arguments[isMapCall ? 0 : 1];
|
|
1225
|
-
if (!AST11__namespace.isOneOf([types.AST_NODE_TYPES.ArrowFunctionExpression, types.AST_NODE_TYPES.FunctionExpression])(fn)) return;
|
|
1226
|
-
if (fn.body.type === types.AST_NODE_TYPES.BlockStatement) {
|
|
1227
|
-
for (const descriptor of checkBlockStatement(fn.body)) {
|
|
1228
|
-
context.report(descriptor);
|
|
1166
|
+
"Program:exit"() {
|
|
1167
|
+
for (const { hasDuplicate, keys } of keyedEntries.values()) {
|
|
1168
|
+
if (!hasDuplicate) continue;
|
|
1169
|
+
for (const key of keys) {
|
|
1170
|
+
context.report({
|
|
1171
|
+
messageId: "noDuplicateKey",
|
|
1172
|
+
node: key,
|
|
1173
|
+
data: {
|
|
1174
|
+
value: context.sourceCode.getText(key)
|
|
1175
|
+
}
|
|
1176
|
+
});
|
|
1229
1177
|
}
|
|
1230
|
-
return;
|
|
1231
1178
|
}
|
|
1232
|
-
eff.O.map(checkExpression(fn.body), context.report);
|
|
1233
|
-
},
|
|
1234
|
-
"CallExpression:exit"(node) {
|
|
1235
|
-
if (core.isChildrenToArrayCall(node, context)) eff.MutRef.set(isWithinChildrenToArrayRef, false);
|
|
1236
1179
|
}
|
|
1237
1180
|
};
|
|
1238
1181
|
},
|
|
@@ -1355,7 +1298,7 @@ var no_implicit_key_default = createRule({
|
|
|
1355
1298
|
create(context) {
|
|
1356
1299
|
function getReportDescriptor(node) {
|
|
1357
1300
|
const initialScope = context.sourceCode.getScope(node);
|
|
1358
|
-
const keyPropFound =
|
|
1301
|
+
const keyPropFound = JSX7__namespace.findPropInAttributes(node.attributes, initialScope)("key");
|
|
1359
1302
|
const keyPropOnElement = node.attributes.some(
|
|
1360
1303
|
(n) => AST11__namespace.is(types.AST_NODE_TYPES.JSXAttribute)(n) && n.name.name === "key"
|
|
1361
1304
|
);
|
|
@@ -1595,12 +1538,12 @@ var no_missing_key_default = createRule({
|
|
|
1595
1538
|
},
|
|
1596
1539
|
name: RULE_NAME29,
|
|
1597
1540
|
create(context) {
|
|
1598
|
-
const
|
|
1541
|
+
const state = { isWithinChildrenToArray: false };
|
|
1599
1542
|
function checkIteratorElement(node) {
|
|
1600
1543
|
switch (node.type) {
|
|
1601
1544
|
case types.AST_NODE_TYPES.JSXElement: {
|
|
1602
1545
|
const initialScope = context.sourceCode.getScope(node);
|
|
1603
|
-
if (!
|
|
1546
|
+
if (!JSX7__namespace.hasProp(node.openingElement.attributes, "key", initialScope)) {
|
|
1604
1547
|
return eff.O.some({
|
|
1605
1548
|
messageId: "noMissingKey",
|
|
1606
1549
|
node
|
|
@@ -1644,12 +1587,12 @@ var no_missing_key_default = createRule({
|
|
|
1644
1587
|
}
|
|
1645
1588
|
return {
|
|
1646
1589
|
ArrayExpression(node) {
|
|
1647
|
-
if (
|
|
1590
|
+
if (state.isWithinChildrenToArray) return;
|
|
1648
1591
|
const elements = node.elements.filter(AST11__namespace.is(types.AST_NODE_TYPES.JSXElement));
|
|
1649
1592
|
if (elements.length === 0) return;
|
|
1650
1593
|
const initialScope = context.sourceCode.getScope(node);
|
|
1651
1594
|
for (const element of elements) {
|
|
1652
|
-
if (!
|
|
1595
|
+
if (!JSX7__namespace.hasProp(element.openingElement.attributes, "key", initialScope)) {
|
|
1653
1596
|
context.report({
|
|
1654
1597
|
messageId: "noMissingKey",
|
|
1655
1598
|
node: element
|
|
@@ -1658,7 +1601,8 @@ var no_missing_key_default = createRule({
|
|
|
1658
1601
|
}
|
|
1659
1602
|
},
|
|
1660
1603
|
CallExpression(node) {
|
|
1661
|
-
|
|
1604
|
+
state.isWithinChildrenToArray ||= core.isChildrenToArrayCall(node, context);
|
|
1605
|
+
if (state.isWithinChildrenToArray) return;
|
|
1662
1606
|
const isMapCall = AST11__namespace.isMapCallLoose(node);
|
|
1663
1607
|
const isArrayFromCall = tsPattern.isMatching({
|
|
1664
1608
|
type: types.AST_NODE_TYPES.CallExpression,
|
|
@@ -1670,7 +1614,6 @@ var no_missing_key_default = createRule({
|
|
|
1670
1614
|
}
|
|
1671
1615
|
}, node);
|
|
1672
1616
|
if (!isMapCall && !isArrayFromCall) return;
|
|
1673
|
-
if (eff.MutRef.get(isWithinChildrenToArrayRef)) return;
|
|
1674
1617
|
const fn = node.arguments[isMapCall ? 0 : 1];
|
|
1675
1618
|
if (!AST11__namespace.isOneOf([types.AST_NODE_TYPES.ArrowFunctionExpression, types.AST_NODE_TYPES.FunctionExpression])(fn)) return;
|
|
1676
1619
|
if (fn.body.type === types.AST_NODE_TYPES.BlockStatement) {
|
|
@@ -1682,10 +1625,11 @@ var no_missing_key_default = createRule({
|
|
|
1682
1625
|
eff.O.map(checkExpression(fn.body), context.report);
|
|
1683
1626
|
},
|
|
1684
1627
|
"CallExpression:exit"(node) {
|
|
1685
|
-
if (core.isChildrenToArrayCall(node, context))
|
|
1628
|
+
if (!core.isChildrenToArrayCall(node, context)) return;
|
|
1629
|
+
state.isWithinChildrenToArray = false;
|
|
1686
1630
|
},
|
|
1687
1631
|
JSXFragment(node) {
|
|
1688
|
-
if (
|
|
1632
|
+
if (state.isWithinChildrenToArray) return;
|
|
1689
1633
|
if (node.parent.type === types.AST_NODE_TYPES.ArrayExpression) {
|
|
1690
1634
|
context.report({
|
|
1691
1635
|
messageId: "noMissingKeyWithFragment",
|
|
@@ -1736,7 +1680,7 @@ var no_nested_components_default = createRule({
|
|
|
1736
1680
|
if (eff.O.isNone(componentName)) continue;
|
|
1737
1681
|
const name2 = componentName.value;
|
|
1738
1682
|
const isInsideProperty = component.parent.type === types.AST_NODE_TYPES.Property;
|
|
1739
|
-
const isInsideJSXPropValue = component.parent.type === types.AST_NODE_TYPES.JSXAttribute || eff.O.isSome(
|
|
1683
|
+
const isInsideJSXPropValue = component.parent.type === types.AST_NODE_TYPES.JSXAttribute || eff.O.isSome(JSX7__namespace.traverseUpProp(node, (n) => n.value?.type === types.AST_NODE_TYPES.JSXExpressionContainer));
|
|
1740
1684
|
if (isInsideJSXPropValue) {
|
|
1741
1685
|
if (!core.isDeclaredInRenderPropLoose(component)) {
|
|
1742
1686
|
context.report({
|
|
@@ -1782,7 +1726,7 @@ var no_nested_components_default = createRule({
|
|
|
1782
1726
|
}
|
|
1783
1727
|
}
|
|
1784
1728
|
for (const { name: name2, node: component } of classComponents) {
|
|
1785
|
-
if (eff.O.isNone(AST11__namespace.traverseUp(component, (
|
|
1729
|
+
if (eff.O.isNone(AST11__namespace.traverseUp(component, eff.or(isClassComponent11, isFunctionComponent)))) {
|
|
1786
1730
|
continue;
|
|
1787
1731
|
}
|
|
1788
1732
|
context.report({
|
|
@@ -1912,22 +1856,25 @@ var no_set_state_in_component_did_mount_default = createRule({
|
|
|
1912
1856
|
if (!context.sourceCode.text.includes("componentDidMount")) return {};
|
|
1913
1857
|
function getReportDescriptor(node) {
|
|
1914
1858
|
if (!core.isThisSetState(node)) return eff.O.none();
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
AST11__namespace.
|
|
1859
|
+
return eff.F.pipe(
|
|
1860
|
+
eff.O.Do,
|
|
1861
|
+
eff.O.bind("clazz", () => AST11__namespace.traverseUpGuard(node, core.isClassComponent)),
|
|
1862
|
+
eff.O.bind("method", ({ clazz }) => AST11__namespace.traverseUpStop(node, clazz, isComponentDidMount)),
|
|
1863
|
+
eff.O.bind("methodScope", ({ method }) => eff.O.some(context.sourceCode.getScope(method))),
|
|
1864
|
+
eff.O.bind("upperScope", () => eff.O.fromNullable(context.sourceCode.getScope(node).upper)),
|
|
1865
|
+
eff.O.filter(
|
|
1866
|
+
({
|
|
1867
|
+
clazz,
|
|
1868
|
+
method,
|
|
1869
|
+
methodScope,
|
|
1870
|
+
upperScope
|
|
1871
|
+
}) => method.parent === clazz.body && upperScope === methodScope
|
|
1872
|
+
),
|
|
1873
|
+
eff.O.map(() => ({
|
|
1874
|
+
messageId: "noSetStateInComponentDidMount",
|
|
1875
|
+
node
|
|
1876
|
+
}))
|
|
1918
1877
|
);
|
|
1919
|
-
if (eff.O.isNone(maybeParentClass)) return eff.O.none();
|
|
1920
|
-
const parentClass = maybeParentClass.value;
|
|
1921
|
-
if (!core.isClassComponent(parentClass)) return eff.O.none();
|
|
1922
|
-
const maybeParentMethod = AST11__namespace.traverseUp(node, isComponentDidMount);
|
|
1923
|
-
if (eff.O.isNone(maybeParentMethod)) return eff.O.none();
|
|
1924
|
-
const parentMethod = maybeParentMethod.value;
|
|
1925
|
-
if (parentMethod.parent !== parentClass.body) return eff.O.none();
|
|
1926
|
-
if (context.sourceCode.getScope(node).upper !== context.sourceCode.getScope(parentMethod)) return eff.O.none();
|
|
1927
|
-
return eff.O.some({
|
|
1928
|
-
messageId: "noSetStateInComponentDidMount",
|
|
1929
|
-
node
|
|
1930
|
-
});
|
|
1931
1878
|
}
|
|
1932
1879
|
return {
|
|
1933
1880
|
CallExpression: eff.F.flow(getReportDescriptor, eff.O.map(context.report))
|
|
@@ -1959,22 +1906,19 @@ var no_set_state_in_component_did_update_default = createRule({
|
|
|
1959
1906
|
if (!context.sourceCode.text.includes("componentDidUpdate")) return {};
|
|
1960
1907
|
function getReportDescriptor(node) {
|
|
1961
1908
|
if (!core.isThisSetState(node)) return eff.O.none();
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
AST11__namespace.
|
|
1909
|
+
return eff.F.pipe(
|
|
1910
|
+
eff.O.Do,
|
|
1911
|
+
eff.O.bind("clazz", () => AST11__namespace.traverseUpGuard(node, core.isClassComponent)),
|
|
1912
|
+
eff.O.bind("method", ({ clazz }) => AST11__namespace.traverseUpStop(node, clazz, isComponentDidUpdate)),
|
|
1913
|
+
eff.O.bind("upperScope", () => eff.O.fromNullable(context.sourceCode.getScope(node).upper)),
|
|
1914
|
+
eff.O.filter(
|
|
1915
|
+
({ clazz, method, upperScope }) => method.parent === clazz.body && upperScope === context.sourceCode.getScope(method)
|
|
1916
|
+
),
|
|
1917
|
+
eff.O.map(() => ({
|
|
1918
|
+
messageId: "noSetStateInComponentDidUpdate",
|
|
1919
|
+
node
|
|
1920
|
+
}))
|
|
1965
1921
|
);
|
|
1966
|
-
if (eff.O.isNone(maybeParentClass)) return eff.O.none();
|
|
1967
|
-
const parentClass = maybeParentClass.value;
|
|
1968
|
-
if (!core.isClassComponent(parentClass)) return eff.O.none();
|
|
1969
|
-
const maybeParentMethod = AST11__namespace.traverseUp(node, isComponentDidUpdate);
|
|
1970
|
-
if (eff.O.isNone(maybeParentMethod)) return eff.O.none();
|
|
1971
|
-
const parentMethod = maybeParentMethod.value;
|
|
1972
|
-
if (parentMethod.parent !== parentClass.body) return eff.O.none();
|
|
1973
|
-
if (context.sourceCode.getScope(node).upper !== context.sourceCode.getScope(parentMethod)) return eff.O.none();
|
|
1974
|
-
return eff.O.some({
|
|
1975
|
-
messageId: "noSetStateInComponentDidUpdate",
|
|
1976
|
-
node
|
|
1977
|
-
});
|
|
1978
1922
|
}
|
|
1979
1923
|
return {
|
|
1980
1924
|
CallExpression: eff.F.flow(getReportDescriptor, eff.O.map(context.report))
|
|
@@ -2006,22 +1950,19 @@ var no_set_state_in_component_will_update_default = createRule({
|
|
|
2006
1950
|
if (!context.sourceCode.text.includes("componentWillUpdate")) return {};
|
|
2007
1951
|
function getReportDescriptor(node) {
|
|
2008
1952
|
if (!core.isThisSetState(node)) return eff.O.none();
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
AST11__namespace.
|
|
1953
|
+
return eff.F.pipe(
|
|
1954
|
+
eff.O.Do,
|
|
1955
|
+
eff.O.bind("clazz", () => AST11__namespace.traverseUpGuard(node, core.isClassComponent)),
|
|
1956
|
+
eff.O.bind("method", ({ clazz }) => AST11__namespace.traverseUpStop(node, clazz, isComponentWillUpdate3)),
|
|
1957
|
+
eff.O.bind("upperScope", () => eff.O.fromNullable(context.sourceCode.getScope(node).upper)),
|
|
1958
|
+
eff.O.filter(
|
|
1959
|
+
({ clazz, method, upperScope }) => method.parent === clazz.body && upperScope === context.sourceCode.getScope(method)
|
|
1960
|
+
),
|
|
1961
|
+
eff.O.map(() => ({
|
|
1962
|
+
messageId: "noSetStateInComponentWillUpdate",
|
|
1963
|
+
node
|
|
1964
|
+
}))
|
|
2012
1965
|
);
|
|
2013
|
-
if (eff.O.isNone(maybeParentClass)) return eff.O.none();
|
|
2014
|
-
const parentClass = maybeParentClass.value;
|
|
2015
|
-
if (!core.isClassComponent(parentClass)) return eff.O.none();
|
|
2016
|
-
const maybeParentMethod = AST11__namespace.traverseUp(node, isComponentWillUpdate3);
|
|
2017
|
-
if (eff.O.isNone(maybeParentMethod)) return eff.O.none();
|
|
2018
|
-
const parentMethod = maybeParentMethod.value;
|
|
2019
|
-
if (parentMethod.parent !== parentClass.body) return eff.O.none();
|
|
2020
|
-
if (context.sourceCode.getScope(node).upper !== context.sourceCode.getScope(parentMethod)) return eff.O.none();
|
|
2021
|
-
return eff.O.some({
|
|
2022
|
-
messageId: "noSetStateInComponentWillUpdate",
|
|
2023
|
-
node
|
|
2024
|
-
});
|
|
2025
1966
|
}
|
|
2026
1967
|
return {
|
|
2027
1968
|
CallExpression: eff.F.flow(getReportDescriptor, eff.O.map(context.report))
|
|
@@ -2219,39 +2160,40 @@ var no_unstable_context_value_default = createRule({
|
|
|
2219
2160
|
name: RULE_NAME40,
|
|
2220
2161
|
create(context) {
|
|
2221
2162
|
const { ctx, listeners } = core.useComponentCollector(context);
|
|
2222
|
-
const
|
|
2163
|
+
const constructions = /* @__PURE__ */ new Map();
|
|
2223
2164
|
return {
|
|
2224
2165
|
...listeners,
|
|
2225
2166
|
JSXOpeningElement(node) {
|
|
2226
2167
|
const openingElementName = node.name;
|
|
2227
2168
|
if (openingElementName.type !== types.AST_NODE_TYPES.JSXMemberExpression) return;
|
|
2228
2169
|
if (openingElementName.property.name !== "Provider") return;
|
|
2229
|
-
const
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2170
|
+
const constructionEntry = eff.F.pipe(
|
|
2171
|
+
eff.O.Do,
|
|
2172
|
+
eff.O.bind("function", ctx.getCurrentFunction),
|
|
2173
|
+
eff.O.bind("attribute", () => eff.O.fromNullable(
|
|
2174
|
+
node.attributes.find((attribute) => {
|
|
2175
|
+
return attribute.type === types.AST_NODE_TYPES.JSXAttribute && attribute.name.name === "value";
|
|
2176
|
+
})
|
|
2177
|
+
)),
|
|
2178
|
+
eff.O.bind("value", ({ attribute }) => "value" in attribute ? eff.O.some(attribute.value) : eff.O.none()),
|
|
2179
|
+
eff.O.bind("valueExpression", ({ value }) => value?.type === types.AST_NODE_TYPES.JSXExpressionContainer ? eff.O.some(value.expression) : eff.O.none()),
|
|
2180
|
+
eff.O.bind("construction", ({ valueExpression }) => {
|
|
2181
|
+
const initialScope = context.sourceCode.getScope(valueExpression);
|
|
2182
|
+
return eff.O.some(VAR__namespace.inspectConstruction(valueExpression, initialScope));
|
|
2183
|
+
}),
|
|
2184
|
+
eff.O.filter(({ construction }) => construction._tag !== "None")
|
|
2233
2185
|
);
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
const valueExpression = valueNode.expression;
|
|
2238
|
-
const initialScope = context.sourceCode.getScope(valueExpression);
|
|
2239
|
-
const construction = VAR__namespace.inspectConstruction(valueExpression, initialScope);
|
|
2240
|
-
if (construction._tag === "None") return;
|
|
2241
|
-
eff.O.map(
|
|
2242
|
-
ctx.getCurrentFunction(),
|
|
2243
|
-
([_, currentFn]) => possibleValueConstructions.set(currentFn, [
|
|
2244
|
-
...possibleValueConstructions.get(currentFn) ?? [],
|
|
2186
|
+
for (const { construction, function: [_, fNode] } of eff.O.toArray(constructionEntry)) {
|
|
2187
|
+
constructions.set(fNode, [
|
|
2188
|
+
...constructions.get(fNode) ?? [],
|
|
2245
2189
|
construction
|
|
2246
|
-
])
|
|
2247
|
-
|
|
2190
|
+
]);
|
|
2191
|
+
}
|
|
2248
2192
|
},
|
|
2249
2193
|
"Program:exit"(node) {
|
|
2250
2194
|
const components = ctx.getAllComponents(node).values();
|
|
2251
2195
|
for (const { node: component } of components) {
|
|
2252
|
-
const
|
|
2253
|
-
if (!constructions) continue;
|
|
2254
|
-
for (const construction of constructions) {
|
|
2196
|
+
for (const construction of constructions.get(component) ?? []) {
|
|
2255
2197
|
if (construction._tag === "None") continue;
|
|
2256
2198
|
const { node: constructionNode, _tag } = construction;
|
|
2257
2199
|
const messageId = _tag.startsWith("Function") ? "noUnstableContextValueWithFunction" : "noUnstableContextValueWithIdentifier";
|
|
@@ -2288,7 +2230,7 @@ var no_unstable_default_props_default = createRule({
|
|
|
2288
2230
|
name: RULE_NAME41,
|
|
2289
2231
|
create(context) {
|
|
2290
2232
|
const { ctx, listeners } = core.useComponentCollector(context);
|
|
2291
|
-
const
|
|
2233
|
+
const declarators = /* @__PURE__ */ new WeakMap();
|
|
2292
2234
|
return {
|
|
2293
2235
|
...listeners,
|
|
2294
2236
|
"Program:exit"(node) {
|
|
@@ -2298,10 +2240,7 @@ var no_unstable_default_props_default = createRule({
|
|
|
2298
2240
|
const [props] = params;
|
|
2299
2241
|
if (!props) continue;
|
|
2300
2242
|
const properties = tsPattern.match(props).with({ type: types.AST_NODE_TYPES.ObjectPattern }, ({ properties: properties2 }) => properties2).with({ type: types.AST_NODE_TYPES.Identifier }, ({ name: name2 }) => {
|
|
2301
|
-
|
|
2302
|
-
if (!variableDeclarators) return [];
|
|
2303
|
-
const declarators = variableDeclarators.filter((d) => d.init.name === name2);
|
|
2304
|
-
return declarators.flatMap((d) => d.id.properties);
|
|
2243
|
+
return declarators.get(component)?.filter((d) => d.init.name === name2).flatMap((d) => d.id.properties) ?? [];
|
|
2305
2244
|
}).otherwise(() => []);
|
|
2306
2245
|
for (const prop of properties) {
|
|
2307
2246
|
if (prop.type !== types.AST_NODE_TYPES.Property || prop.value.type !== types.AST_NODE_TYPES.AssignmentPattern) continue;
|
|
@@ -2326,13 +2265,10 @@ var no_unstable_default_props_default = createRule({
|
|
|
2326
2265
|
}
|
|
2327
2266
|
},
|
|
2328
2267
|
"VariableDeclarator[id.type='ObjectPattern'][init.type='Identifier']"(node) {
|
|
2329
|
-
eff.O.
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
node
|
|
2334
|
-
])
|
|
2335
|
-
);
|
|
2268
|
+
for (const [_, currentFn] of eff.O.toArray(ctx.getCurrentFunction())) {
|
|
2269
|
+
const prevDeclarators = declarators.get(currentFn) ?? [];
|
|
2270
|
+
declarators.set(currentFn, [...prevDeclarators, node]);
|
|
2271
|
+
}
|
|
2336
2272
|
}
|
|
2337
2273
|
};
|
|
2338
2274
|
},
|
|
@@ -2360,7 +2296,7 @@ var LIFECYCLE_METHODS = /* @__PURE__ */ new Set([
|
|
|
2360
2296
|
"UNSAFE_componentWillUpdate"
|
|
2361
2297
|
]);
|
|
2362
2298
|
function getName3(node) {
|
|
2363
|
-
if (node
|
|
2299
|
+
if (AST11__namespace.isTypeExpression(node)) {
|
|
2364
2300
|
return getName3(node.expression);
|
|
2365
2301
|
}
|
|
2366
2302
|
if (node.type === types.AST_NODE_TYPES.Identifier || node.type === types.AST_NODE_TYPES.PrivateIdentifier) {
|
|
@@ -2460,7 +2396,9 @@ var no_unused_class_component_members_default = createRule({
|
|
|
2460
2396
|
if (node.init && AST11__namespace.isThisExpression(node.init) && node.id.type === types.AST_NODE_TYPES.ObjectPattern) {
|
|
2461
2397
|
for (const prop of node.id.properties) {
|
|
2462
2398
|
if (prop.type === types.AST_NODE_TYPES.Property && AST11__namespace.isKeyLiteralLike(prop, prop.key)) {
|
|
2463
|
-
eff.O.
|
|
2399
|
+
for (const name2 of eff.O.toArray(getName3(prop.key))) {
|
|
2400
|
+
propertyUsages.get(currentClass)?.add(name2);
|
|
2401
|
+
}
|
|
2464
2402
|
}
|
|
2465
2403
|
}
|
|
2466
2404
|
}
|
|
@@ -2474,7 +2412,7 @@ var RULE_FEATURES43 = [
|
|
|
2474
2412
|
"CHK"
|
|
2475
2413
|
];
|
|
2476
2414
|
function getName4(node) {
|
|
2477
|
-
if (node
|
|
2415
|
+
if (AST11__namespace.isTypeExpression(node)) {
|
|
2478
2416
|
return getName4(node.expression);
|
|
2479
2417
|
}
|
|
2480
2418
|
if (node.type === types.AST_NODE_TYPES.Identifier || node.type === types.AST_NODE_TYPES.PrivateIdentifier) {
|
|
@@ -2617,18 +2555,18 @@ var no_unused_state_default = createRule({
|
|
|
2617
2555
|
var RULE_NAME44 = "no-useless-fragment";
|
|
2618
2556
|
function check(node, context, allowExpressions) {
|
|
2619
2557
|
const initialScope = context.sourceCode.getScope(node);
|
|
2620
|
-
if (
|
|
2621
|
-
if (
|
|
2558
|
+
if (JSX7__namespace.isKeyedElement(node, initialScope)) return;
|
|
2559
|
+
if (JSX7__namespace.isBuiltInElement(node.parent)) context.report({ messageId: "noUselessFragmentInBuiltIn", node });
|
|
2622
2560
|
if (node.children.length === 0) return context.report({ messageId: "noUselessFragment", node });
|
|
2623
2561
|
const isChildren = AST11__namespace.isOneOf([types.AST_NODE_TYPES.JSXElement, types.AST_NODE_TYPES.JSXFragment])(node.parent);
|
|
2624
2562
|
const [firstChildren] = node.children;
|
|
2625
|
-
if (allowExpressions && node.children.length === 1 &&
|
|
2563
|
+
if (allowExpressions && node.children.length === 1 && JSX7__namespace.isLiteral(firstChildren) && !isChildren) return;
|
|
2626
2564
|
if (!allowExpressions && isChildren) {
|
|
2627
2565
|
return context.report({ messageId: "noUselessFragment", node });
|
|
2628
2566
|
} else if (!allowExpressions && !isChildren && node.children.length === 1) {
|
|
2629
2567
|
return context.report({ messageId: "noUselessFragment", node });
|
|
2630
2568
|
}
|
|
2631
|
-
const nonPaddingChildren = node.children.filter((child) => !
|
|
2569
|
+
const nonPaddingChildren = node.children.filter((child) => !JSX7__namespace.isPaddingSpaces(child));
|
|
2632
2570
|
if (nonPaddingChildren.length > 1) return;
|
|
2633
2571
|
if (nonPaddingChildren.length === 0) return context.report({ messageId: "noUselessFragment", node });
|
|
2634
2572
|
const [first] = nonPaddingChildren;
|
|
@@ -2870,7 +2808,7 @@ var prefer_shorthand_boolean_default = createRule({
|
|
|
2870
2808
|
create(context) {
|
|
2871
2809
|
function getReportDescriptor(node) {
|
|
2872
2810
|
const { value } = node;
|
|
2873
|
-
const propName =
|
|
2811
|
+
const propName = JSX7__namespace.getPropName(node);
|
|
2874
2812
|
const hasValueTrue = value?.type === types.AST_NODE_TYPES.JSXExpressionContainer && value.expression.type === types.AST_NODE_TYPES.Literal && value.expression.value === true;
|
|
2875
2813
|
if (!hasValueTrue) return eff.O.none();
|
|
2876
2814
|
return eff.O.some({
|
|
@@ -2927,10 +2865,8 @@ var use_jsx_vars_default = createRule({
|
|
|
2927
2865
|
meta: {
|
|
2928
2866
|
type: "problem",
|
|
2929
2867
|
docs: {
|
|
2930
|
-
description
|
|
2931
|
-
|
|
2932
|
-
"helpes `eslint/no-unused-vars` to correctly mark JSX variables as used."
|
|
2933
|
-
),
|
|
2868
|
+
// eslint-disable-next-line eslint-plugin/require-meta-docs-description
|
|
2869
|
+
description: "helpes `eslint/no-unused-vars` to correctly mark JSX variables as used.",
|
|
2934
2870
|
[Symbol.for("rule_features")]: RULE_FEATURES49
|
|
2935
2871
|
},
|
|
2936
2872
|
messages: {
|
|
@@ -2953,9 +2889,9 @@ var use_jsx_vars_default = createRule({
|
|
|
2953
2889
|
return {
|
|
2954
2890
|
JSXOpeningElement(node) {
|
|
2955
2891
|
if (node.name.type === types.AST_NODE_TYPES.JSXIdentifier && /^[a-z]/u.test(node.name.name)) return;
|
|
2956
|
-
eff.O.
|
|
2892
|
+
for (const name2 of eff.O.toArray(getName5(node.name))) {
|
|
2957
2893
|
context.sourceCode.markVariableAsUsed(name2, node);
|
|
2958
|
-
}
|
|
2894
|
+
}
|
|
2959
2895
|
}
|
|
2960
2896
|
};
|
|
2961
2897
|
},
|