eslint-plugin-react-x 2.5.6-next.4 → 2.5.6-next.5

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 +33 -14
  2. package/package.json +6 -6
package/dist/index.js CHANGED
@@ -34,7 +34,7 @@ var __exportAll = (all, symbols) => {
34
34
  //#endregion
35
35
  //#region package.json
36
36
  var name$6 = "eslint-plugin-react-x";
37
- var version = "2.5.6-next.4";
37
+ var version = "2.5.6-next.5";
38
38
 
39
39
  //#endregion
40
40
  //#region src/utils/create-rule.ts
@@ -426,12 +426,13 @@ var jsx_shorthand_fragment_default = createRule({
426
426
  });
427
427
  function create$55(context) {
428
428
  const policy = context.options[0] ?? defaultOptions$3[0];
429
- const { jsxFragmentFactory } = {
429
+ const jsxConfig = {
430
430
  ...getJsxConfigFromContext(context),
431
431
  ...getJsxConfigFromAnnotation(context)
432
432
  };
433
+ const { jsxFragmentFactory } = jsxConfig;
433
434
  return match(policy).with(1, () => ({ JSXElement(node) {
434
- if (!isJsxFragmentElement(context, node)) return;
435
+ if (!isJsxFragmentElement(context, node, jsxConfig)) return;
435
436
  if (node.openingElement.attributes.length > 0) return;
436
437
  context.report({
437
438
  messageId: "jsxShorthandFragment",
@@ -2059,8 +2060,8 @@ const RULE_NAME$19 = "no-unnecessary-key";
2059
2060
  var no_unnecessary_key_default = createRule({
2060
2061
  meta: {
2061
2062
  type: "problem",
2062
- docs: { description: "Prevents 'key' from being placed on non-top-level elements in list rendering." },
2063
- messages: { noUnnecessaryKey: "Unnecessary `key` prop on this element. The `key` should be on the top-level element returned from the array." },
2063
+ docs: { description: "Disallows unnecessary `key` props on elements." },
2064
+ messages: { noUnnecessaryKey: "Unnecessary `key` prop on this element. {{reason}}" },
2064
2065
  schema: []
2065
2066
  },
2066
2067
  name: RULE_NAME$19,
@@ -2069,20 +2070,34 @@ var no_unnecessary_key_default = createRule({
2069
2070
  });
2070
2071
  function create$19(context) {
2071
2072
  if (!context.sourceCode.text.includes("key=")) return {};
2073
+ const jsxConfig = {
2074
+ ...getJsxConfigFromContext(context),
2075
+ ...getJsxConfigFromAnnotation(context)
2076
+ };
2072
2077
  return { JSXAttribute(node) {
2073
2078
  if (node.name.name !== "key") return;
2074
2079
  const jsxElement = node.parent.parent;
2075
- const initialScope = context.sourceCode.getScope(jsxElement);
2076
- const pMapCallback = AST.findParentNode(jsxElement, isMapCallback);
2077
- if (pMapCallback == null || context.sourceCode.getScope(pMapCallback) !== initialScope) return;
2078
- const pKeyedElementOrElse = AST.findParentNode(jsxElement, (n) => {
2079
- if (n === pMapCallback) return true;
2080
- return AST.isJSXElement(n) && n.openingElement.attributes.some((n$1) => n$1.type === AST_NODE_TYPES.JSXAttribute && n$1.name.type === AST_NODE_TYPES.JSXIdentifier && n$1.name.name === "key");
2080
+ if (isJsxFragmentElement(context, jsxElement, jsxConfig)) return;
2081
+ if (jsxElement.openingElement.attributes.some((attr) => attr.type === AST_NODE_TYPES.JSXSpreadAttribute)) return;
2082
+ const mapCallback = AST.findParentNode(jsxElement, isMapCallback);
2083
+ if (mapCallback == null || AST.findParentNode(jsxElement, AST.isFunction) !== mapCallback) {
2084
+ if (!(AST.findParentNode(jsxElement, (n) => AST.isConditional(n) || AST.isControlFlow(n) || getInstanceId(n) != null) != null)) context.report({
2085
+ messageId: "noUnnecessaryKey",
2086
+ node,
2087
+ data: { reason: "The `key` prop is not needed outside of dynamic rendering contexts." }
2088
+ });
2089
+ return;
2090
+ }
2091
+ if (context.sourceCode.getScope(mapCallback) !== context.sourceCode.getScope(jsxElement)) return;
2092
+ const keyedElementOrElse = AST.findParentNode(jsxElement, (n) => {
2093
+ if (n === mapCallback) return true;
2094
+ return AST.isJSXElement(n) && getJsxAttribute(context, n)("key") != null;
2081
2095
  });
2082
- if (pKeyedElementOrElse == null || pKeyedElementOrElse === pMapCallback) return;
2096
+ if (keyedElementOrElse == null || keyedElementOrElse === mapCallback) return;
2083
2097
  context.report({
2084
2098
  messageId: "noUnnecessaryKey",
2085
- node
2099
+ node,
2100
+ data: { reason: "A parent element already has a `key` prop in the same list rendering context." }
2086
2101
  });
2087
2102
  } };
2088
2103
  }
@@ -3009,6 +3024,10 @@ var no_useless_fragment_default = createRule({
3009
3024
  });
3010
3025
  function create$5(context, [option]) {
3011
3026
  const { allowEmptyFragment = false, allowExpressions = true } = option;
3027
+ const jsxConfig = {
3028
+ ...getJsxConfigFromContext(context),
3029
+ ...getJsxConfigFromAnnotation(context)
3030
+ };
3012
3031
  /**
3013
3032
  * Check if a fragment node is useless and should be reported
3014
3033
  */
@@ -3078,7 +3097,7 @@ function create$5(context, [option]) {
3078
3097
  }
3079
3098
  return {
3080
3099
  JSXElement(node) {
3081
- if (!isJsxFragmentElement(context, node)) return;
3100
+ if (!isJsxFragmentElement(context, node, jsxConfig)) return;
3082
3101
  checkNode(context, node);
3083
3102
  },
3084
3103
  JSXFragment(node) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-react-x",
3
- "version": "2.5.6-next.4",
3
+ "version": "2.5.6-next.5",
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/core": "2.5.6-next.4",
50
- "@eslint-react/eff": "2.5.6-next.4",
51
- "@eslint-react/ast": "2.5.6-next.4",
52
- "@eslint-react/var": "2.5.6-next.4",
53
- "@eslint-react/shared": "2.5.6-next.4"
49
+ "@eslint-react/ast": "2.5.6-next.5",
50
+ "@eslint-react/core": "2.5.6-next.5",
51
+ "@eslint-react/eff": "2.5.6-next.5",
52
+ "@eslint-react/shared": "2.5.6-next.5",
53
+ "@eslint-react/var": "2.5.6-next.5"
54
54
  },
55
55
  "devDependencies": {
56
56
  "@types/react": "^19.2.8",