eslint-plugin-react-x 1.47.1 → 1.47.2-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 CHANGED
@@ -141,7 +141,7 @@ var settings3 = {
141
141
 
142
142
  // package.json
143
143
  var name4 = "eslint-plugin-react-x";
144
- var version = "1.47.1";
144
+ var version = "1.47.2-beta.0";
145
145
  var createRule = utils.ESLintUtils.RuleCreator(shared.getDocsUrl("x"));
146
146
 
147
147
  // src/rules/avoid-shorthand-boolean.ts
@@ -1453,9 +1453,10 @@ function create27(context) {
1453
1453
  if (!ER25__namespace.isForwardRefCall(context, node)) {
1454
1454
  return;
1455
1455
  }
1456
+ const id = AST8__namespace.getFunctionIdentifier(node);
1456
1457
  context.report({
1457
1458
  messageId: "noForwardRef",
1458
- node,
1459
+ node: id ?? node,
1459
1460
  fix: getFix(context, node)
1460
1461
  });
1461
1462
  }
@@ -1552,12 +1553,12 @@ function create28(context) {
1552
1553
  return {
1553
1554
  JSXOpeningElement(node) {
1554
1555
  const initialScope = context.sourceCode.getScope(node);
1555
- const keyPropFound = ER25__namespace.getAttribute(context, "key", node.attributes, initialScope);
1556
- const keyPropOnElement = node.attributes.some(
1556
+ const keyProp = ER25__namespace.getAttribute(context, "key", node.attributes, initialScope);
1557
+ const isKeyPropOnElement = node.attributes.some(
1557
1558
  (n) => n.type === types.AST_NODE_TYPES.JSXAttribute && n.name.type === types.AST_NODE_TYPES.JSXIdentifier && n.name.name === "key"
1558
1559
  );
1559
- if (keyPropFound != null && !keyPropOnElement) {
1560
- context.report({ messageId: "noImplicitKey", node: keyPropFound });
1560
+ if (keyProp != null && !isKeyPropOnElement) {
1561
+ context.report({ messageId: "noImplicitKey", node: keyProp });
1561
1562
  }
1562
1563
  }
1563
1564
  };
@@ -1761,9 +1762,10 @@ function create30(context) {
1761
1762
  continue;
1762
1763
  }
1763
1764
  if (displayName == null) {
1765
+ const id = AST8__namespace.getFunctionIdentifier(node);
1764
1766
  context.report({
1765
1767
  messageId: "noMissingComponentDisplayName",
1766
- node
1768
+ node: id ?? node
1767
1769
  });
1768
1770
  }
1769
1771
  }
@@ -1816,7 +1818,7 @@ function create31(context) {
1816
1818
  if (!hasDisplayNameAssignment) {
1817
1819
  context.report({
1818
1820
  messageId: "noMissingContextDisplayName",
1819
- node: call
1821
+ node: id
1820
1822
  });
1821
1823
  }
1822
1824
  }
@@ -3067,31 +3069,17 @@ var no_use_context_default = createRule({
3067
3069
  function create49(context) {
3068
3070
  if (!context.sourceCode.text.includes("useContext")) return {};
3069
3071
  const settings4 = shared.getSettingsFromContext(context);
3070
- const useContextAlias = /* @__PURE__ */ new Set();
3071
3072
  if (compareVersions.compare(settings4.version, "19.0.0", "<")) {
3072
3073
  return {};
3073
3074
  }
3075
+ const useContextNames = /* @__PURE__ */ new Set();
3076
+ const hookCalls = /* @__PURE__ */ new Set();
3074
3077
  return {
3075
3078
  CallExpression(node) {
3076
3079
  if (!ER25__namespace.isReactHookCall(node)) {
3077
3080
  return;
3078
3081
  }
3079
- if (!ER25__namespace.isReactHookCallWithNameAlias(context, "useContext", [...useContextAlias])(node)) {
3080
- return;
3081
- }
3082
- context.report({
3083
- messageId: "noUseContext",
3084
- node: node.callee,
3085
- fix(fixer) {
3086
- switch (node.callee.type) {
3087
- case types.AST_NODE_TYPES.Identifier:
3088
- return fixer.replaceText(node.callee, "use");
3089
- case types.AST_NODE_TYPES.MemberExpression:
3090
- return fixer.replaceText(node.callee.property, "use");
3091
- }
3092
- return null;
3093
- }
3094
- });
3082
+ hookCalls.add(node);
3095
3083
  },
3096
3084
  ImportDeclaration(node) {
3097
3085
  if (node.source.value !== settings4.importSource) {
@@ -3103,7 +3091,7 @@ function create49(context) {
3103
3091
  if (specifier.imported.type !== types.AST_NODE_TYPES.Identifier) continue;
3104
3092
  if (specifier.imported.name === "useContext") {
3105
3093
  if (specifier.local.name !== "useContext") {
3106
- useContextAlias.add(specifier.local.name);
3094
+ useContextNames.add(specifier.local.name);
3107
3095
  }
3108
3096
  context.report({
3109
3097
  messageId: "noUseContext",
@@ -3114,7 +3102,7 @@ function create49(context) {
3114
3102
  return [
3115
3103
  fixer.remove(specifier),
3116
3104
  ...tokenBefore?.value === "," ? [fixer.replaceTextRange([tokenBefore.range[1], specifier.range[0]], "")] : [],
3117
- ...getAssociatedTokens(
3105
+ ...getCorrelativeTokens(
3118
3106
  context,
3119
3107
  specifier
3120
3108
  ).map((token) => fixer.remove(token))
@@ -3125,22 +3113,41 @@ function create49(context) {
3125
3113
  });
3126
3114
  }
3127
3115
  }
3116
+ },
3117
+ "Program:exit"() {
3118
+ const isUseContextCall = ER25__namespace.isReactHookCallWithNameAlias(context, "useContext", [...useContextNames]);
3119
+ for (const node of hookCalls) {
3120
+ if (!isUseContextCall(node)) {
3121
+ continue;
3122
+ }
3123
+ context.report({
3124
+ messageId: "noUseContext",
3125
+ node: node.callee,
3126
+ fix(fixer) {
3127
+ switch (node.callee.type) {
3128
+ case types.AST_NODE_TYPES.Identifier:
3129
+ return fixer.replaceText(node.callee, "use");
3130
+ case types.AST_NODE_TYPES.MemberExpression:
3131
+ return fixer.replaceText(node.callee.property, "use");
3132
+ }
3133
+ return null;
3134
+ }
3135
+ });
3136
+ }
3128
3137
  }
3129
3138
  };
3130
3139
  }
3131
- function getAssociatedTokens(context, node) {
3132
- {
3133
- const tokenBefore = context.sourceCode.getTokenBefore(node);
3134
- const tokenAfter = context.sourceCode.getTokenAfter(node);
3135
- const tokens = [];
3136
- if (tokenAfter?.value !== "," && tokenBefore?.value === ",") {
3137
- tokens.push(tokenBefore);
3138
- }
3139
- if (tokenAfter?.value === ",") {
3140
- tokens.push(tokenAfter);
3141
- }
3142
- return tokens;
3140
+ function getCorrelativeTokens(context, node) {
3141
+ const tokenBefore = context.sourceCode.getTokenBefore(node);
3142
+ const tokenAfter = context.sourceCode.getTokenAfter(node);
3143
+ const tokens = [];
3144
+ if (tokenAfter?.value !== "," && tokenBefore?.value === ",") {
3145
+ tokens.push(tokenBefore);
3143
3146
  }
3147
+ if (tokenAfter?.value === ",") {
3148
+ tokens.push(tokenAfter);
3149
+ }
3150
+ return tokens;
3144
3151
  }
3145
3152
  var RULE_NAME50 = "no-useless-forward-ref";
3146
3153
  var RULE_FEATURES50 = [];
@@ -3176,7 +3183,7 @@ function create50(context) {
3176
3183
  }
3177
3184
  context.report({
3178
3185
  messageId: "noUselessForwardRef",
3179
- node: component
3186
+ node: node.callee
3180
3187
  });
3181
3188
  }
3182
3189
  };
@@ -3551,7 +3558,7 @@ function create55(context) {
3551
3558
  }
3552
3559
  context.report({
3553
3560
  messageId: "preferShorthandBoolean",
3554
- node,
3561
+ node: node.value ?? node,
3555
3562
  data: {
3556
3563
  propName
3557
3564
  },
package/dist/index.mjs CHANGED
@@ -114,7 +114,7 @@ var settings3 = {
114
114
 
115
115
  // package.json
116
116
  var name4 = "eslint-plugin-react-x";
117
- var version = "1.47.1";
117
+ var version = "1.47.2-beta.0";
118
118
  var createRule = ESLintUtils.RuleCreator(getDocsUrl("x"));
119
119
 
120
120
  // src/rules/avoid-shorthand-boolean.ts
@@ -1426,9 +1426,10 @@ function create27(context) {
1426
1426
  if (!ER25.isForwardRefCall(context, node)) {
1427
1427
  return;
1428
1428
  }
1429
+ const id = AST8.getFunctionIdentifier(node);
1429
1430
  context.report({
1430
1431
  messageId: "noForwardRef",
1431
- node,
1432
+ node: id ?? node,
1432
1433
  fix: getFix(context, node)
1433
1434
  });
1434
1435
  }
@@ -1525,12 +1526,12 @@ function create28(context) {
1525
1526
  return {
1526
1527
  JSXOpeningElement(node) {
1527
1528
  const initialScope = context.sourceCode.getScope(node);
1528
- const keyPropFound = ER25.getAttribute(context, "key", node.attributes, initialScope);
1529
- const keyPropOnElement = node.attributes.some(
1529
+ const keyProp = ER25.getAttribute(context, "key", node.attributes, initialScope);
1530
+ const isKeyPropOnElement = node.attributes.some(
1530
1531
  (n) => n.type === AST_NODE_TYPES.JSXAttribute && n.name.type === AST_NODE_TYPES.JSXIdentifier && n.name.name === "key"
1531
1532
  );
1532
- if (keyPropFound != null && !keyPropOnElement) {
1533
- context.report({ messageId: "noImplicitKey", node: keyPropFound });
1533
+ if (keyProp != null && !isKeyPropOnElement) {
1534
+ context.report({ messageId: "noImplicitKey", node: keyProp });
1534
1535
  }
1535
1536
  }
1536
1537
  };
@@ -1734,9 +1735,10 @@ function create30(context) {
1734
1735
  continue;
1735
1736
  }
1736
1737
  if (displayName == null) {
1738
+ const id = AST8.getFunctionIdentifier(node);
1737
1739
  context.report({
1738
1740
  messageId: "noMissingComponentDisplayName",
1739
- node
1741
+ node: id ?? node
1740
1742
  });
1741
1743
  }
1742
1744
  }
@@ -1789,7 +1791,7 @@ function create31(context) {
1789
1791
  if (!hasDisplayNameAssignment) {
1790
1792
  context.report({
1791
1793
  messageId: "noMissingContextDisplayName",
1792
- node: call
1794
+ node: id
1793
1795
  });
1794
1796
  }
1795
1797
  }
@@ -3040,31 +3042,17 @@ var no_use_context_default = createRule({
3040
3042
  function create49(context) {
3041
3043
  if (!context.sourceCode.text.includes("useContext")) return {};
3042
3044
  const settings4 = getSettingsFromContext(context);
3043
- const useContextAlias = /* @__PURE__ */ new Set();
3044
3045
  if (compare(settings4.version, "19.0.0", "<")) {
3045
3046
  return {};
3046
3047
  }
3048
+ const useContextNames = /* @__PURE__ */ new Set();
3049
+ const hookCalls = /* @__PURE__ */ new Set();
3047
3050
  return {
3048
3051
  CallExpression(node) {
3049
3052
  if (!ER25.isReactHookCall(node)) {
3050
3053
  return;
3051
3054
  }
3052
- if (!ER25.isReactHookCallWithNameAlias(context, "useContext", [...useContextAlias])(node)) {
3053
- return;
3054
- }
3055
- context.report({
3056
- messageId: "noUseContext",
3057
- node: node.callee,
3058
- fix(fixer) {
3059
- switch (node.callee.type) {
3060
- case AST_NODE_TYPES.Identifier:
3061
- return fixer.replaceText(node.callee, "use");
3062
- case AST_NODE_TYPES.MemberExpression:
3063
- return fixer.replaceText(node.callee.property, "use");
3064
- }
3065
- return null;
3066
- }
3067
- });
3055
+ hookCalls.add(node);
3068
3056
  },
3069
3057
  ImportDeclaration(node) {
3070
3058
  if (node.source.value !== settings4.importSource) {
@@ -3076,7 +3064,7 @@ function create49(context) {
3076
3064
  if (specifier.imported.type !== AST_NODE_TYPES.Identifier) continue;
3077
3065
  if (specifier.imported.name === "useContext") {
3078
3066
  if (specifier.local.name !== "useContext") {
3079
- useContextAlias.add(specifier.local.name);
3067
+ useContextNames.add(specifier.local.name);
3080
3068
  }
3081
3069
  context.report({
3082
3070
  messageId: "noUseContext",
@@ -3087,7 +3075,7 @@ function create49(context) {
3087
3075
  return [
3088
3076
  fixer.remove(specifier),
3089
3077
  ...tokenBefore?.value === "," ? [fixer.replaceTextRange([tokenBefore.range[1], specifier.range[0]], "")] : [],
3090
- ...getAssociatedTokens(
3078
+ ...getCorrelativeTokens(
3091
3079
  context,
3092
3080
  specifier
3093
3081
  ).map((token) => fixer.remove(token))
@@ -3098,22 +3086,41 @@ function create49(context) {
3098
3086
  });
3099
3087
  }
3100
3088
  }
3089
+ },
3090
+ "Program:exit"() {
3091
+ const isUseContextCall = ER25.isReactHookCallWithNameAlias(context, "useContext", [...useContextNames]);
3092
+ for (const node of hookCalls) {
3093
+ if (!isUseContextCall(node)) {
3094
+ continue;
3095
+ }
3096
+ context.report({
3097
+ messageId: "noUseContext",
3098
+ node: node.callee,
3099
+ fix(fixer) {
3100
+ switch (node.callee.type) {
3101
+ case AST_NODE_TYPES.Identifier:
3102
+ return fixer.replaceText(node.callee, "use");
3103
+ case AST_NODE_TYPES.MemberExpression:
3104
+ return fixer.replaceText(node.callee.property, "use");
3105
+ }
3106
+ return null;
3107
+ }
3108
+ });
3109
+ }
3101
3110
  }
3102
3111
  };
3103
3112
  }
3104
- function getAssociatedTokens(context, node) {
3105
- {
3106
- const tokenBefore = context.sourceCode.getTokenBefore(node);
3107
- const tokenAfter = context.sourceCode.getTokenAfter(node);
3108
- const tokens = [];
3109
- if (tokenAfter?.value !== "," && tokenBefore?.value === ",") {
3110
- tokens.push(tokenBefore);
3111
- }
3112
- if (tokenAfter?.value === ",") {
3113
- tokens.push(tokenAfter);
3114
- }
3115
- return tokens;
3113
+ function getCorrelativeTokens(context, node) {
3114
+ const tokenBefore = context.sourceCode.getTokenBefore(node);
3115
+ const tokenAfter = context.sourceCode.getTokenAfter(node);
3116
+ const tokens = [];
3117
+ if (tokenAfter?.value !== "," && tokenBefore?.value === ",") {
3118
+ tokens.push(tokenBefore);
3116
3119
  }
3120
+ if (tokenAfter?.value === ",") {
3121
+ tokens.push(tokenAfter);
3122
+ }
3123
+ return tokens;
3117
3124
  }
3118
3125
  var RULE_NAME50 = "no-useless-forward-ref";
3119
3126
  var RULE_FEATURES50 = [];
@@ -3149,7 +3156,7 @@ function create50(context) {
3149
3156
  }
3150
3157
  context.report({
3151
3158
  messageId: "noUselessForwardRef",
3152
- node: component
3159
+ node: node.callee
3153
3160
  });
3154
3161
  }
3155
3162
  };
@@ -3524,7 +3531,7 @@ function create55(context) {
3524
3531
  }
3525
3532
  context.report({
3526
3533
  messageId: "preferShorthandBoolean",
3527
- node,
3534
+ node: node.value ?? node,
3528
3535
  data: {
3529
3536
  propName
3530
3537
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-react-x",
3
- "version": "1.47.1",
3
+ "version": "1.47.2-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",
@@ -50,12 +50,12 @@
50
50
  "is-immutable-type": "^5.0.1",
51
51
  "string-ts": "^2.2.1",
52
52
  "ts-pattern": "^5.7.0",
53
- "@eslint-react/ast": "1.47.1",
54
- "@eslint-react/core": "1.47.1",
55
- "@eslint-react/eff": "1.47.1",
56
- "@eslint-react/kit": "1.47.1",
57
- "@eslint-react/var": "1.47.1",
58
- "@eslint-react/shared": "1.47.1"
53
+ "@eslint-react/ast": "1.47.2-beta.0",
54
+ "@eslint-react/core": "1.47.2-beta.0",
55
+ "@eslint-react/kit": "1.47.2-beta.0",
56
+ "@eslint-react/shared": "1.47.2-beta.0",
57
+ "@eslint-react/eff": "1.47.2-beta.0",
58
+ "@eslint-react/var": "1.47.2-beta.0"
59
59
  },
60
60
  "devDependencies": {
61
61
  "@types/react": "^19.1.1",