eslint-plugin-react-x 1.40.2 → 1.40.3-beta.1

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.40.2";
144
+ var version = "1.40.3-beta.1";
145
145
  var createRule = utils.ESLintUtils.RuleCreator(shared.getDocsUrl("x"));
146
146
 
147
147
  // src/rules/avoid-shorthand-boolean.ts
@@ -1772,7 +1772,7 @@ function create30(context) {
1772
1772
  {
1773
1773
  collectDisplayName: true,
1774
1774
  collectHookCalls: false,
1775
- hint: ER21__namespace.DEFAULT_COMPONENT_HINT
1775
+ hint: ER21__namespace.DEFAULT_COMPONENT_DETECTION_HINT
1776
1776
  }
1777
1777
  );
1778
1778
  return {
@@ -2004,7 +2004,7 @@ var no_nested_component_definitions_default = createRule({
2004
2004
  defaultOptions: []
2005
2005
  });
2006
2006
  function create33(context) {
2007
- const hint = ER21__namespace.ComponentCollectorHint.SkipArrayMapArgument | ER21__namespace.ComponentCollectorHint.SkipNullLiteral | ER21__namespace.ComponentCollectorHint.SkipUndefined | ER21__namespace.ComponentCollectorHint.SkipBooleanLiteral | ER21__namespace.ComponentCollectorHint.SkipStringLiteral | ER21__namespace.ComponentCollectorHint.SkipNumberLiteral | ER21__namespace.ComponentCollectorHint.StrictLogical | ER21__namespace.ComponentCollectorHint.StrictConditional;
2007
+ const hint = ER21__namespace.ComponentDetectionHint.SkipArrayMapArgument | ER21__namespace.ComponentDetectionHint.SkipNullLiteral | ER21__namespace.ComponentDetectionHint.SkipUndefined | ER21__namespace.ComponentDetectionHint.SkipBooleanLiteral | ER21__namespace.ComponentDetectionHint.SkipStringLiteral | ER21__namespace.ComponentDetectionHint.SkipNumberLiteral | ER21__namespace.ComponentDetectionHint.StrictLogical | ER21__namespace.ComponentDetectionHint.StrictConditional;
2008
2008
  const collector = ER21__namespace.useComponentCollector(context, { hint });
2009
2009
  const collectorLegacy = ER21__namespace.useComponentCollectorLegacy();
2010
2010
  return {
@@ -3122,14 +3122,20 @@ function create49(context, [option]) {
3122
3122
  const { allowExpressions = true } = option;
3123
3123
  return {
3124
3124
  JSXElement(node) {
3125
- if (!JSX8__namespace.isFragmentElement(node)) return;
3126
- doCheck(context, node, allowExpressions);
3125
+ if (!JSX8__namespace.isJsxFragmentElement(node)) return;
3126
+ checkNode(context, node, allowExpressions);
3127
3127
  },
3128
3128
  JSXFragment(node) {
3129
- doCheck(context, node, allowExpressions);
3129
+ checkNode(context, node, allowExpressions);
3130
3130
  }
3131
3131
  };
3132
3132
  }
3133
+ function isWhiteSpace(node) {
3134
+ return typeof node.value === "string" && node.raw.trim() === "";
3135
+ }
3136
+ function isPaddingSpaces(node) {
3137
+ return JSX8__namespace.isJsxText(node) && isWhiteSpace(node) && node.raw.includes("\n");
3138
+ }
3133
3139
  function trimLikeReact(text) {
3134
3140
  const leadingSpaces = /^\s*/.exec(text)?.[0] ?? "";
3135
3141
  const trailingSpaces = /\s*$/.exec(text)?.[0] ?? "";
@@ -3137,38 +3143,19 @@ function trimLikeReact(text) {
3137
3143
  const end = trailingSpaces.includes("\n") ? text.length - trailingSpaces.length : text.length;
3138
3144
  return text.slice(start, end);
3139
3145
  }
3140
- function doCheck(context, node, allowExpressions) {
3141
- function fix(fixer) {
3142
- if (node.parent.type !== types.AST_NODE_TYPES.JSXElement && node.parent.type !== types.AST_NODE_TYPES.JSXFragment) {
3143
- if (node.children.length === 0) {
3144
- return null;
3145
- }
3146
- if (node.children.some(
3147
- (child) => JSX8__namespace.isLiteral(child) && !JSX8__namespace.isWhiteSpace(child) || AST11__namespace.is(types.AST_NODE_TYPES.JSXExpressionContainer)(child)
3148
- )) {
3149
- return null;
3150
- }
3151
- }
3152
- if (JSX8__namespace.isUserDefinedElement(node.parent)) {
3153
- return null;
3154
- }
3155
- const opener = node.type === types.AST_NODE_TYPES.JSXFragment ? node.openingFragment : node.openingElement;
3156
- const closer = node.type === types.AST_NODE_TYPES.JSXFragment ? node.closingFragment : node.closingElement;
3157
- const childrenText = opener.type === types.AST_NODE_TYPES.JSXOpeningElement && opener.selfClosing ? "" : context.sourceCode.getText().slice(opener.range[1], closer?.range[0]);
3158
- return fixer.replaceText(node, trimLikeReact(childrenText));
3159
- }
3146
+ function checkNode(context, node, allowExpressions) {
3160
3147
  const initialScope = context.sourceCode.getScope(node);
3161
- if (JSX8__namespace.isKeyedElement(node, initialScope)) {
3148
+ if (JSX8__namespace.isJsxKeyedElement(node, initialScope)) {
3162
3149
  return;
3163
3150
  }
3164
- if (JSX8__namespace.isBuiltInElement(node.parent)) {
3151
+ if (JSX8__namespace.isJsxBuiltInElement(node.parent)) {
3165
3152
  context.report({
3166
3153
  messageId: "uselessFragment",
3167
3154
  node,
3168
3155
  data: {
3169
3156
  reason: "placed inside a built-in component"
3170
3157
  },
3171
- fix
3158
+ fix: getFix2(context, node)
3172
3159
  });
3173
3160
  }
3174
3161
  if (node.children.length === 0) {
@@ -3178,14 +3165,14 @@ function doCheck(context, node, allowExpressions) {
3178
3165
  data: {
3179
3166
  reason: "contains less than two children"
3180
3167
  },
3181
- fix
3168
+ fix: getFix2(context, node)
3182
3169
  });
3183
3170
  return;
3184
3171
  }
3185
3172
  const isChildElement = AST11__namespace.isOneOf([types.AST_NODE_TYPES.JSXElement, types.AST_NODE_TYPES.JSXFragment])(node.parent);
3186
3173
  switch (true) {
3187
3174
  // <Foo content={<>ee eeee eeee ...</>} />
3188
- case (allowExpressions && !isChildElement && node.children.length === 1 && JSX8__namespace.isLiteral(node.children.at(0))): {
3175
+ case (allowExpressions && !isChildElement && node.children.length === 1 && JSX8__namespace.isJsxText(node.children.at(0))): {
3189
3176
  return;
3190
3177
  }
3191
3178
  // <Foo><>hello, world</></Foo>
@@ -3196,7 +3183,7 @@ function doCheck(context, node, allowExpressions) {
3196
3183
  data: {
3197
3184
  reason: "contains less than two children"
3198
3185
  },
3199
- fix
3186
+ fix: getFix2(context, node)
3200
3187
  });
3201
3188
  return;
3202
3189
  }
@@ -3207,12 +3194,12 @@ function doCheck(context, node, allowExpressions) {
3207
3194
  data: {
3208
3195
  reason: "contains less than two children"
3209
3196
  },
3210
- fix
3197
+ fix: getFix2(context, node)
3211
3198
  });
3212
3199
  return;
3213
3200
  }
3214
3201
  }
3215
- const nonPaddingChildren = node.children.filter((child) => !JSX8__namespace.isPaddingSpaces(child));
3202
+ const nonPaddingChildren = node.children.filter((child) => !isPaddingSpaces(child));
3216
3203
  const firstNonPaddingChild = nonPaddingChildren.at(0);
3217
3204
  switch (true) {
3218
3205
  case nonPaddingChildren.length === 0:
@@ -3223,13 +3210,34 @@ function doCheck(context, node, allowExpressions) {
3223
3210
  data: {
3224
3211
  reason: "contains less than two children"
3225
3212
  },
3226
- fix
3213
+ fix: getFix2(context, node)
3227
3214
  });
3228
3215
  return;
3229
3216
  }
3230
3217
  }
3231
3218
  return;
3232
3219
  }
3220
+ function getFix2(context, node) {
3221
+ if (!canFix(node)) return null;
3222
+ return (fixer) => {
3223
+ const opener = node.type === types.AST_NODE_TYPES.JSXFragment ? node.openingFragment : node.openingElement;
3224
+ const closer = node.type === types.AST_NODE_TYPES.JSXFragment ? node.closingFragment : node.closingElement;
3225
+ const childrenText = opener.type === types.AST_NODE_TYPES.JSXOpeningElement && opener.selfClosing ? "" : context.sourceCode.getText().slice(opener.range[1], closer?.range[0]);
3226
+ return fixer.replaceText(node, trimLikeReact(childrenText));
3227
+ };
3228
+ }
3229
+ function canFix(node) {
3230
+ if (node.parent.type === types.AST_NODE_TYPES.JSXElement || node.parent.type === types.AST_NODE_TYPES.JSXFragment) {
3231
+ return !JSX8__namespace.isJsxUserDefinedElement(node.parent);
3232
+ }
3233
+ if (node.children.length === 0) {
3234
+ return false;
3235
+ }
3236
+ if (node.children.some((child) => JSX8__namespace.isJsxText(child) && !isWhiteSpace(child) || AST11__namespace.is(types.AST_NODE_TYPES.JSXExpressionContainer)(child))) {
3237
+ return false;
3238
+ }
3239
+ return true;
3240
+ }
3233
3241
  var RULE_NAME50 = "prefer-destructuring-assignment";
3234
3242
  var RULE_FEATURES49 = [];
3235
3243
  function isMemberExpressionWithObjectName(node) {
@@ -3482,7 +3490,7 @@ var prefer_shorthand_fragment_default = createRule({
3482
3490
  function create54(context) {
3483
3491
  return {
3484
3492
  JSXElement(node) {
3485
- if (!JSX8__namespace.isFragmentElement(node)) return;
3493
+ if (!JSX8__namespace.isJsxFragmentElement(node)) return;
3486
3494
  const hasAttributes = node.openingElement.attributes.length > 0;
3487
3495
  if (hasAttributes) {
3488
3496
  return;
package/dist/index.mjs CHANGED
@@ -113,7 +113,7 @@ var settings3 = {
113
113
 
114
114
  // package.json
115
115
  var name4 = "eslint-plugin-react-x";
116
- var version = "1.40.2";
116
+ var version = "1.40.3-beta.1";
117
117
  var createRule = ESLintUtils.RuleCreator(getDocsUrl("x"));
118
118
 
119
119
  // src/rules/avoid-shorthand-boolean.ts
@@ -1744,7 +1744,7 @@ function create30(context) {
1744
1744
  {
1745
1745
  collectDisplayName: true,
1746
1746
  collectHookCalls: false,
1747
- hint: ER21.DEFAULT_COMPONENT_HINT
1747
+ hint: ER21.DEFAULT_COMPONENT_DETECTION_HINT
1748
1748
  }
1749
1749
  );
1750
1750
  return {
@@ -1976,7 +1976,7 @@ var no_nested_component_definitions_default = createRule({
1976
1976
  defaultOptions: []
1977
1977
  });
1978
1978
  function create33(context) {
1979
- const hint = ER21.ComponentCollectorHint.SkipArrayMapArgument | ER21.ComponentCollectorHint.SkipNullLiteral | ER21.ComponentCollectorHint.SkipUndefined | ER21.ComponentCollectorHint.SkipBooleanLiteral | ER21.ComponentCollectorHint.SkipStringLiteral | ER21.ComponentCollectorHint.SkipNumberLiteral | ER21.ComponentCollectorHint.StrictLogical | ER21.ComponentCollectorHint.StrictConditional;
1979
+ const hint = ER21.ComponentDetectionHint.SkipArrayMapArgument | ER21.ComponentDetectionHint.SkipNullLiteral | ER21.ComponentDetectionHint.SkipUndefined | ER21.ComponentDetectionHint.SkipBooleanLiteral | ER21.ComponentDetectionHint.SkipStringLiteral | ER21.ComponentDetectionHint.SkipNumberLiteral | ER21.ComponentDetectionHint.StrictLogical | ER21.ComponentDetectionHint.StrictConditional;
1980
1980
  const collector = ER21.useComponentCollector(context, { hint });
1981
1981
  const collectorLegacy = ER21.useComponentCollectorLegacy();
1982
1982
  return {
@@ -3094,14 +3094,20 @@ function create49(context, [option]) {
3094
3094
  const { allowExpressions = true } = option;
3095
3095
  return {
3096
3096
  JSXElement(node) {
3097
- if (!JSX8.isFragmentElement(node)) return;
3098
- doCheck(context, node, allowExpressions);
3097
+ if (!JSX8.isJsxFragmentElement(node)) return;
3098
+ checkNode(context, node, allowExpressions);
3099
3099
  },
3100
3100
  JSXFragment(node) {
3101
- doCheck(context, node, allowExpressions);
3101
+ checkNode(context, node, allowExpressions);
3102
3102
  }
3103
3103
  };
3104
3104
  }
3105
+ function isWhiteSpace(node) {
3106
+ return typeof node.value === "string" && node.raw.trim() === "";
3107
+ }
3108
+ function isPaddingSpaces(node) {
3109
+ return JSX8.isJsxText(node) && isWhiteSpace(node) && node.raw.includes("\n");
3110
+ }
3105
3111
  function trimLikeReact(text) {
3106
3112
  const leadingSpaces = /^\s*/.exec(text)?.[0] ?? "";
3107
3113
  const trailingSpaces = /\s*$/.exec(text)?.[0] ?? "";
@@ -3109,38 +3115,19 @@ function trimLikeReact(text) {
3109
3115
  const end = trailingSpaces.includes("\n") ? text.length - trailingSpaces.length : text.length;
3110
3116
  return text.slice(start, end);
3111
3117
  }
3112
- function doCheck(context, node, allowExpressions) {
3113
- function fix(fixer) {
3114
- if (node.parent.type !== AST_NODE_TYPES.JSXElement && node.parent.type !== AST_NODE_TYPES.JSXFragment) {
3115
- if (node.children.length === 0) {
3116
- return null;
3117
- }
3118
- if (node.children.some(
3119
- (child) => JSX8.isLiteral(child) && !JSX8.isWhiteSpace(child) || AST11.is(AST_NODE_TYPES.JSXExpressionContainer)(child)
3120
- )) {
3121
- return null;
3122
- }
3123
- }
3124
- if (JSX8.isUserDefinedElement(node.parent)) {
3125
- return null;
3126
- }
3127
- const opener = node.type === AST_NODE_TYPES.JSXFragment ? node.openingFragment : node.openingElement;
3128
- const closer = node.type === AST_NODE_TYPES.JSXFragment ? node.closingFragment : node.closingElement;
3129
- const childrenText = opener.type === AST_NODE_TYPES.JSXOpeningElement && opener.selfClosing ? "" : context.sourceCode.getText().slice(opener.range[1], closer?.range[0]);
3130
- return fixer.replaceText(node, trimLikeReact(childrenText));
3131
- }
3118
+ function checkNode(context, node, allowExpressions) {
3132
3119
  const initialScope = context.sourceCode.getScope(node);
3133
- if (JSX8.isKeyedElement(node, initialScope)) {
3120
+ if (JSX8.isJsxKeyedElement(node, initialScope)) {
3134
3121
  return;
3135
3122
  }
3136
- if (JSX8.isBuiltInElement(node.parent)) {
3123
+ if (JSX8.isJsxBuiltInElement(node.parent)) {
3137
3124
  context.report({
3138
3125
  messageId: "uselessFragment",
3139
3126
  node,
3140
3127
  data: {
3141
3128
  reason: "placed inside a built-in component"
3142
3129
  },
3143
- fix
3130
+ fix: getFix2(context, node)
3144
3131
  });
3145
3132
  }
3146
3133
  if (node.children.length === 0) {
@@ -3150,14 +3137,14 @@ function doCheck(context, node, allowExpressions) {
3150
3137
  data: {
3151
3138
  reason: "contains less than two children"
3152
3139
  },
3153
- fix
3140
+ fix: getFix2(context, node)
3154
3141
  });
3155
3142
  return;
3156
3143
  }
3157
3144
  const isChildElement = AST11.isOneOf([AST_NODE_TYPES.JSXElement, AST_NODE_TYPES.JSXFragment])(node.parent);
3158
3145
  switch (true) {
3159
3146
  // <Foo content={<>ee eeee eeee ...</>} />
3160
- case (allowExpressions && !isChildElement && node.children.length === 1 && JSX8.isLiteral(node.children.at(0))): {
3147
+ case (allowExpressions && !isChildElement && node.children.length === 1 && JSX8.isJsxText(node.children.at(0))): {
3161
3148
  return;
3162
3149
  }
3163
3150
  // <Foo><>hello, world</></Foo>
@@ -3168,7 +3155,7 @@ function doCheck(context, node, allowExpressions) {
3168
3155
  data: {
3169
3156
  reason: "contains less than two children"
3170
3157
  },
3171
- fix
3158
+ fix: getFix2(context, node)
3172
3159
  });
3173
3160
  return;
3174
3161
  }
@@ -3179,12 +3166,12 @@ function doCheck(context, node, allowExpressions) {
3179
3166
  data: {
3180
3167
  reason: "contains less than two children"
3181
3168
  },
3182
- fix
3169
+ fix: getFix2(context, node)
3183
3170
  });
3184
3171
  return;
3185
3172
  }
3186
3173
  }
3187
- const nonPaddingChildren = node.children.filter((child) => !JSX8.isPaddingSpaces(child));
3174
+ const nonPaddingChildren = node.children.filter((child) => !isPaddingSpaces(child));
3188
3175
  const firstNonPaddingChild = nonPaddingChildren.at(0);
3189
3176
  switch (true) {
3190
3177
  case nonPaddingChildren.length === 0:
@@ -3195,13 +3182,34 @@ function doCheck(context, node, allowExpressions) {
3195
3182
  data: {
3196
3183
  reason: "contains less than two children"
3197
3184
  },
3198
- fix
3185
+ fix: getFix2(context, node)
3199
3186
  });
3200
3187
  return;
3201
3188
  }
3202
3189
  }
3203
3190
  return;
3204
3191
  }
3192
+ function getFix2(context, node) {
3193
+ if (!canFix(node)) return null;
3194
+ return (fixer) => {
3195
+ const opener = node.type === AST_NODE_TYPES.JSXFragment ? node.openingFragment : node.openingElement;
3196
+ const closer = node.type === AST_NODE_TYPES.JSXFragment ? node.closingFragment : node.closingElement;
3197
+ const childrenText = opener.type === AST_NODE_TYPES.JSXOpeningElement && opener.selfClosing ? "" : context.sourceCode.getText().slice(opener.range[1], closer?.range[0]);
3198
+ return fixer.replaceText(node, trimLikeReact(childrenText));
3199
+ };
3200
+ }
3201
+ function canFix(node) {
3202
+ if (node.parent.type === AST_NODE_TYPES.JSXElement || node.parent.type === AST_NODE_TYPES.JSXFragment) {
3203
+ return !JSX8.isJsxUserDefinedElement(node.parent);
3204
+ }
3205
+ if (node.children.length === 0) {
3206
+ return false;
3207
+ }
3208
+ if (node.children.some((child) => JSX8.isJsxText(child) && !isWhiteSpace(child) || AST11.is(AST_NODE_TYPES.JSXExpressionContainer)(child))) {
3209
+ return false;
3210
+ }
3211
+ return true;
3212
+ }
3205
3213
  var RULE_NAME50 = "prefer-destructuring-assignment";
3206
3214
  var RULE_FEATURES49 = [];
3207
3215
  function isMemberExpressionWithObjectName(node) {
@@ -3454,7 +3462,7 @@ var prefer_shorthand_fragment_default = createRule({
3454
3462
  function create54(context) {
3455
3463
  return {
3456
3464
  JSXElement(node) {
3457
- if (!JSX8.isFragmentElement(node)) return;
3465
+ if (!JSX8.isJsxFragmentElement(node)) return;
3458
3466
  const hasAttributes = node.openingElement.attributes.length > 0;
3459
3467
  if (hasAttributes) {
3460
3468
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-react-x",
3
- "version": "1.40.2",
3
+ "version": "1.40.3-beta.1",
4
4
  "description": "A set of composable linting rules for libraries and frameworks that use React as a UI runtime.",
5
5
  "keywords": [
6
6
  "react",
@@ -50,13 +50,13 @@
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/core": "1.40.2",
54
- "@eslint-react/eff": "1.40.2",
55
- "@eslint-react/ast": "1.40.2",
56
- "@eslint-react/jsx": "1.40.2",
57
- "@eslint-react/kit": "1.40.2",
58
- "@eslint-react/var": "1.40.2",
59
- "@eslint-react/shared": "1.40.2"
53
+ "@eslint-react/eff": "1.40.3-beta.1",
54
+ "@eslint-react/core": "1.40.3-beta.1",
55
+ "@eslint-react/ast": "1.40.3-beta.1",
56
+ "@eslint-react/jsx": "1.40.3-beta.1",
57
+ "@eslint-react/shared": "1.40.3-beta.1",
58
+ "@eslint-react/kit": "1.40.3-beta.1",
59
+ "@eslint-react/var": "1.40.3-beta.1"
60
60
  },
61
61
  "devDependencies": {
62
62
  "@types/react": "^19.1.0",