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