eslint-plugin-react-x 2.7.5-next.9 → 2.8.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 +22 -41
- 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.
|
|
71
|
+
var version = "2.8.1-beta.0";
|
|
72
72
|
|
|
73
73
|
//#endregion
|
|
74
74
|
//#region src/utils/create-rule.ts
|
|
@@ -1483,7 +1483,6 @@ function create$32(context) {
|
|
|
1483
1483
|
if (!context.sourceCode.text.includes("memo") && !context.sourceCode.text.includes("forwardRef")) return {};
|
|
1484
1484
|
const { ctx, visitor } = useComponentCollector(context, {
|
|
1485
1485
|
collectDisplayName: true,
|
|
1486
|
-
collectHookCalls: false,
|
|
1487
1486
|
hint: DEFAULT_COMPONENT_DETECTION_HINT
|
|
1488
1487
|
});
|
|
1489
1488
|
return defineRuleListener(visitor, { "Program:exit"(program) {
|
|
@@ -2074,7 +2073,7 @@ const RULE_NAME$20 = "no-unnecessary-key";
|
|
|
2074
2073
|
var no_unnecessary_key_default = createRule({
|
|
2075
2074
|
meta: {
|
|
2076
2075
|
type: "problem",
|
|
2077
|
-
docs: { description: "Disallows unnecessary 'key' props on elements." },
|
|
2076
|
+
docs: { description: "Disallows unnecessary 'key' props on nested child elements when rendering lists." },
|
|
2078
2077
|
messages: { noUnnecessaryKey: "Unnecessary `key` prop on this element. {{reason}}" },
|
|
2079
2078
|
schema: []
|
|
2080
2079
|
},
|
|
@@ -2088,44 +2087,26 @@ function create$20(context) {
|
|
|
2088
2087
|
...getJsxConfigFromContext(context),
|
|
2089
2088
|
...getJsxConfigFromAnnotation(context)
|
|
2090
2089
|
};
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
if (
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
context.report({
|
|
2112
|
-
messageId: "noUnnecessaryKey",
|
|
2113
|
-
node,
|
|
2114
|
-
data: { reason: "A parent element already has a `key` prop in the same list rendering context." }
|
|
2115
|
-
});
|
|
2116
|
-
},
|
|
2117
|
-
"Program:exit"(node) {
|
|
2118
|
-
const components = ctx.getAllComponents(node);
|
|
2119
|
-
for (const key of constantKeys) {
|
|
2120
|
-
if (AST.findParentNode(key, (n) => AST.isConditional(n) || AST.isControlFlow(n) || findEnclosingAssignmentTarget(n) != null || components.some((comp) => comp.node === n && comp.rets.length > 1)) != null) continue;
|
|
2121
|
-
context.report({
|
|
2122
|
-
messageId: "noUnnecessaryKey",
|
|
2123
|
-
node: key,
|
|
2124
|
-
data: { reason: "The `key` prop is not needed outside of dynamic rendering contexts." }
|
|
2125
|
-
});
|
|
2126
|
-
}
|
|
2127
|
-
}
|
|
2128
|
-
});
|
|
2090
|
+
return { JSXAttribute(node) {
|
|
2091
|
+
if (node.name.name !== "key") return;
|
|
2092
|
+
const jsxElement = node.parent.parent;
|
|
2093
|
+
if (isJsxFragmentElement(context, jsxElement, jsxConfig)) return;
|
|
2094
|
+
if (jsxElement.openingElement.attributes.some((attr) => attr.type === AST_NODE_TYPES.JSXSpreadAttribute)) return;
|
|
2095
|
+
if (AST.findParentNode(jsxElement, (n) => isRenderFunctionLoose(context, n)) != null) return;
|
|
2096
|
+
const mapCallback = AST.findParentNode(jsxElement, isArrayMethodCallback);
|
|
2097
|
+
if (mapCallback == null || AST.findParentNode(jsxElement, AST.isFunction) !== mapCallback) return;
|
|
2098
|
+
if (context.sourceCode.getScope(mapCallback) !== context.sourceCode.getScope(jsxElement)) return;
|
|
2099
|
+
const keyedElementOrElse = AST.findParentNode(jsxElement, (n) => {
|
|
2100
|
+
if (n === mapCallback) return true;
|
|
2101
|
+
return AST.isJSXElement(n) && getJsxAttribute(context, n)("key") != null;
|
|
2102
|
+
});
|
|
2103
|
+
if (keyedElementOrElse == null || keyedElementOrElse === mapCallback) return;
|
|
2104
|
+
context.report({
|
|
2105
|
+
messageId: "noUnnecessaryKey",
|
|
2106
|
+
node,
|
|
2107
|
+
data: { reason: "A parent element already has a `key` prop in the same list rendering context." }
|
|
2108
|
+
});
|
|
2109
|
+
} };
|
|
2129
2110
|
}
|
|
2130
2111
|
function getArrayMethodCallbackPosition(methodName) {
|
|
2131
2112
|
switch (methodName) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-react-x",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.8.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/ast": "2.
|
|
50
|
-
"@eslint-react/
|
|
51
|
-
"@eslint-react/
|
|
52
|
-
"@eslint-react/var": "2.
|
|
53
|
-
"@eslint-react/
|
|
49
|
+
"@eslint-react/ast": "2.8.1-beta.0",
|
|
50
|
+
"@eslint-react/eff": "2.8.1-beta.0",
|
|
51
|
+
"@eslint-react/shared": "2.8.1-beta.0",
|
|
52
|
+
"@eslint-react/var": "2.8.1-beta.0",
|
|
53
|
+
"@eslint-react/core": "2.8.1-beta.0"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@types/react": "^19.2.10",
|