eslint-plugin-react-x 2.7.0 → 2.7.1-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +45 -54
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -68,7 +68,7 @@ const rules$7 = {
|
|
|
68
68
|
//#endregion
|
|
69
69
|
//#region package.json
|
|
70
70
|
var name$6 = "eslint-plugin-react-x";
|
|
71
|
-
var version = "2.7.0";
|
|
71
|
+
var version = "2.7.1-beta.0";
|
|
72
72
|
|
|
73
73
|
//#endregion
|
|
74
74
|
//#region src/utils/create-rule.ts
|
|
@@ -1248,7 +1248,7 @@ function create$36(context) {
|
|
|
1248
1248
|
break;
|
|
1249
1249
|
}
|
|
1250
1250
|
default: {
|
|
1251
|
-
const call = AST.findParentNode(jsxElement,
|
|
1251
|
+
const call = AST.findParentNode(jsxElement, (n) => n.type === AST_NODE_TYPES.CallExpression && n.callee.type === AST_NODE_TYPES.MemberExpression && n.callee.property.type === AST_NODE_TYPES.Identifier && n.callee.property.name === "map");
|
|
1252
1252
|
const iter = AST.findParentNode(jsxElement, (n) => n === call || AST.isFunction(n));
|
|
1253
1253
|
if (!AST.isFunction(iter)) return;
|
|
1254
1254
|
const arg0 = call?.arguments[0];
|
|
@@ -1596,75 +1596,61 @@ var no_missing_key_default = createRule({
|
|
|
1596
1596
|
create: create$30,
|
|
1597
1597
|
defaultOptions: []
|
|
1598
1598
|
});
|
|
1599
|
-
function create$30(
|
|
1600
|
-
|
|
1601
|
-
function
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
node
|
|
1612
|
-
};
|
|
1613
|
-
default: return null;
|
|
1614
|
-
}
|
|
1599
|
+
function create$30(ctx) {
|
|
1600
|
+
let inChildrenToArray = false;
|
|
1601
|
+
function check(node) {
|
|
1602
|
+
if (node.type === AST_NODE_TYPES.JSXElement) return getJsxAttribute(ctx, node)("key") == null ? {
|
|
1603
|
+
messageId: "missingKey",
|
|
1604
|
+
node
|
|
1605
|
+
} : null;
|
|
1606
|
+
if (node.type === AST_NODE_TYPES.JSXFragment) return {
|
|
1607
|
+
messageId: "unexpectedFragmentSyntax",
|
|
1608
|
+
node
|
|
1609
|
+
};
|
|
1610
|
+
return null;
|
|
1615
1611
|
}
|
|
1616
|
-
function
|
|
1612
|
+
function checkExpr(node) {
|
|
1617
1613
|
switch (node.type) {
|
|
1618
|
-
case AST_NODE_TYPES.ConditionalExpression:
|
|
1619
|
-
|
|
1620
|
-
return null;
|
|
1614
|
+
case AST_NODE_TYPES.ConditionalExpression: return check(node.consequent) ?? check(node.alternate);
|
|
1615
|
+
case AST_NODE_TYPES.LogicalExpression: return check(node.left) ?? check(node.right);
|
|
1621
1616
|
case AST_NODE_TYPES.JSXElement:
|
|
1622
|
-
case AST_NODE_TYPES.JSXFragment: return
|
|
1623
|
-
case AST_NODE_TYPES.LogicalExpression:
|
|
1624
|
-
if ("left" in node) return checkIteratorElement(node.left) ?? checkIteratorElement(node.right);
|
|
1625
|
-
return null;
|
|
1617
|
+
case AST_NODE_TYPES.JSXFragment: return check(node);
|
|
1626
1618
|
default: return null;
|
|
1627
1619
|
}
|
|
1628
1620
|
}
|
|
1629
|
-
function
|
|
1630
|
-
|
|
1631
|
-
for (const statement of AST.getNestedReturnStatements(node)) {
|
|
1632
|
-
if (statement.argument == null) continue;
|
|
1633
|
-
const descriptor = checkIteratorElement(statement.argument);
|
|
1634
|
-
if (descriptor != null) descriptors.push(descriptor);
|
|
1635
|
-
}
|
|
1636
|
-
return descriptors;
|
|
1621
|
+
function checkBlock(node) {
|
|
1622
|
+
return AST.getNestedReturnStatements(node).filter((stmt) => stmt.argument != null).map((stmt) => check(stmt.argument)).filter((d) => d != null);
|
|
1637
1623
|
}
|
|
1638
1624
|
return {
|
|
1639
1625
|
ArrayExpression(node) {
|
|
1640
|
-
if (
|
|
1626
|
+
if (inChildrenToArray) return;
|
|
1641
1627
|
const elements = node.elements.filter(AST.is(AST_NODE_TYPES.JSXElement));
|
|
1642
1628
|
if (elements.length === 0) return;
|
|
1643
|
-
const
|
|
1644
|
-
for (const
|
|
1629
|
+
const scope = ctx.sourceCode.getScope(node);
|
|
1630
|
+
for (const el of elements) if (getJsxAttribute(ctx, el, scope)("key") == null) ctx.report({
|
|
1645
1631
|
messageId: "missingKey",
|
|
1646
|
-
node:
|
|
1632
|
+
node: el
|
|
1647
1633
|
});
|
|
1648
1634
|
},
|
|
1649
1635
|
CallExpression(node) {
|
|
1650
|
-
|
|
1651
|
-
if (
|
|
1652
|
-
|
|
1653
|
-
if (
|
|
1654
|
-
const
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1636
|
+
inChildrenToArray ||= isChildrenToArrayCall(ctx, node);
|
|
1637
|
+
if (inChildrenToArray) return;
|
|
1638
|
+
if (node.callee.type !== AST_NODE_TYPES.MemberExpression) return;
|
|
1639
|
+
if (node.callee.property.type !== AST_NODE_TYPES.Identifier) return;
|
|
1640
|
+
const name$9 = node.callee.property.name;
|
|
1641
|
+
const idx = name$9 === "from" ? 1 : name$9 === "map" ? 0 : -1;
|
|
1642
|
+
if (idx < 0) return;
|
|
1643
|
+
const cb = node.arguments[idx];
|
|
1644
|
+
if (!AST.isFunction(cb)) return;
|
|
1645
|
+
if (cb.body.type === AST_NODE_TYPES.BlockStatement) checkBlock(cb.body).forEach(report(ctx));
|
|
1646
|
+
else report(ctx)(checkExpr(cb.body));
|
|
1660
1647
|
},
|
|
1661
1648
|
"CallExpression:exit"(node) {
|
|
1662
|
-
if (
|
|
1663
|
-
state.isWithinChildrenToArray = false;
|
|
1649
|
+
if (isChildrenToArrayCall(ctx, node)) inChildrenToArray = false;
|
|
1664
1650
|
},
|
|
1665
1651
|
JSXFragment(node) {
|
|
1666
|
-
if (
|
|
1667
|
-
if (node.parent.type === AST_NODE_TYPES.ArrayExpression)
|
|
1652
|
+
if (inChildrenToArray) return;
|
|
1653
|
+
if (node.parent.type === AST_NODE_TYPES.ArrayExpression) ctx.report({
|
|
1668
1654
|
messageId: "unexpectedFragmentSyntax",
|
|
1669
1655
|
node
|
|
1670
1656
|
});
|
|
@@ -2168,8 +2154,13 @@ function create$20(context) {
|
|
|
2168
2154
|
function isArrayMethodCallback(node) {
|
|
2169
2155
|
const parent = node.parent;
|
|
2170
2156
|
if (parent?.type !== AST_NODE_TYPES.CallExpression) return false;
|
|
2171
|
-
if (
|
|
2172
|
-
|
|
2157
|
+
if (parent.callee.type !== AST_NODE_TYPES.MemberExpression || parent.callee.property.type !== AST_NODE_TYPES.Identifier) return false;
|
|
2158
|
+
switch (parent.callee.property.name) {
|
|
2159
|
+
case "map":
|
|
2160
|
+
case "flatMap": return parent.arguments[0] === node;
|
|
2161
|
+
case "from": return parent.arguments[1] === node;
|
|
2162
|
+
default: return false;
|
|
2163
|
+
}
|
|
2173
2164
|
}
|
|
2174
2165
|
|
|
2175
2166
|
//#endregion
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-react-x",
|
|
3
|
-
"version": "2.7.0",
|
|
3
|
+
"version": "2.7.1-beta.0",
|
|
4
4
|
"description": "A set of composable ESLint rules for for libraries and frameworks that use React as a UI runtime.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -46,11 +46,11 @@
|
|
|
46
46
|
"string-ts": "^2.3.1",
|
|
47
47
|
"ts-api-utils": "^2.4.0",
|
|
48
48
|
"ts-pattern": "^5.9.0",
|
|
49
|
-
"@eslint-react/
|
|
50
|
-
"@eslint-react/
|
|
51
|
-
"@eslint-react/
|
|
52
|
-
"@eslint-react/
|
|
53
|
-
"@eslint-react/var": "2.7.0"
|
|
49
|
+
"@eslint-react/ast": "2.7.1-beta.0",
|
|
50
|
+
"@eslint-react/core": "2.7.1-beta.0",
|
|
51
|
+
"@eslint-react/eff": "2.7.1-beta.0",
|
|
52
|
+
"@eslint-react/shared": "2.7.1-beta.0",
|
|
53
|
+
"@eslint-react/var": "2.7.1-beta.0"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@types/react": "^19.2.8",
|