eslint-plugin-react-x 1.40.4-beta.5 → 1.40.4-beta.7

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.4-beta.5";
144
+ var version = "1.40.4-beta.7";
145
145
  var createRule = utils.ESLintUtils.RuleCreator(shared.getDocsUrl("x"));
146
146
 
147
147
  // src/rules/avoid-shorthand-boolean.ts
@@ -295,7 +295,7 @@ var jsx_uses_react_default = createRule({
295
295
  meta: {
296
296
  type: "problem",
297
297
  docs: {
298
- description: "Marks React variables as used when JSX is used in the file.",
298
+ description: "Marks React variables as used when JSX is used.",
299
299
  [Symbol.for("rule_features")]: RULE_FEATURES5
300
300
  },
301
301
  messages: {
@@ -308,30 +308,17 @@ var jsx_uses_react_default = createRule({
308
308
  defaultOptions: []
309
309
  });
310
310
  function create5(context) {
311
- const { jsx, jsxFactory, jsxFragmentFactory, reactNamespace } = kit.JsxRuntime.getJsxRuntimeOptionsFromContext(context);
312
- const jsxAnnotation = getJsxAnnotation(context);
311
+ const jsxOptions = kit.JsxRuntime.getJsxRuntimeOptions(context);
312
+ const jsxAnnotation = kit.JsxRuntime.getJsxRuntimeAnnotation(context);
313
+ const jsx = jsxAnnotation.jsxRuntime === "classic" ? ts.JsxEmit.React : jsxOptions.jsx;
313
314
  if (jsx === ts.JsxEmit.ReactJSX || jsx === ts.JsxEmit.ReactJSXDev) return {};
315
+ const jsxFactory = jsxAnnotation.jsx ?? jsxOptions.jsxFactory;
316
+ const jsxFragmentFactory = jsxAnnotation.jsxFrag ?? jsxOptions.jsxFragmentFactory;
314
317
  function handleJsxElement(node) {
315
- if (jsxAnnotation == null) {
316
- context.sourceCode.markVariableAsUsed(reactNamespace, node);
317
- context.sourceCode.markVariableAsUsed(jsxFactory, node);
318
- debugReport(context, node, reactNamespace);
319
- debugReport(context, node, jsxFactory);
320
- }
321
- if (jsxAnnotation?.jsx != null) {
322
- context.sourceCode.markVariableAsUsed(jsxAnnotation.jsx, node);
323
- debugReport(context, node, jsxAnnotation.jsx);
324
- }
318
+ context.sourceCode.markVariableAsUsed(jsxFactory, node);
325
319
  }
326
320
  function handleJsxFragment(node) {
327
- if (jsxAnnotation == null) {
328
- context.sourceCode.markVariableAsUsed(jsxFragmentFactory, node);
329
- debugReport(context, node, jsxFragmentFactory);
330
- }
331
- if (jsxAnnotation?.jsxFrag != null) {
332
- context.sourceCode.markVariableAsUsed(jsxAnnotation.jsxFrag, node);
333
- debugReport(context, node, jsxAnnotation.jsxFrag);
334
- }
321
+ context.sourceCode.markVariableAsUsed(jsxFragmentFactory, node);
335
322
  }
336
323
  return {
337
324
  JSXFragment: handleJsxFragment,
@@ -339,25 +326,6 @@ function create5(context) {
339
326
  JSXOpeningFragment: handleJsxElement
340
327
  };
341
328
  }
342
- function getJsxAnnotation(context) {
343
- if (!context.sourceCode.text.includes("@jsx")) return;
344
- const allComments = context.sourceCode.getAllComments();
345
- const jsxComment = allComments.find((n) => kit.RE_JSX_ANNOTATION.test(n.value));
346
- const jsxFragComment = allComments.find((n) => kit.RE_JSX_FRAG_ANNOTATION.test(n.value));
347
- const jsx = jsxComment?.value.match(kit.RE_JSX_ANNOTATION)?.[1];
348
- const jsxFrag = jsxFragComment?.value.match(kit.RE_JSX_FRAG_ANNOTATION)?.[1];
349
- return {
350
- jsx,
351
- jsxFrag
352
- };
353
- }
354
- function debugReport(context, node, name5) {
355
- context.report({
356
- messageId: "jsxUsesReact",
357
- node,
358
- data: { name: name5 }
359
- });
360
- }
361
329
  var RULE_NAME6 = "jsx-uses-vars";
362
330
  var RULE_FEATURES6 = [];
363
331
  var jsx_uses_vars_default = createRule({
@@ -543,7 +511,8 @@ function getMapIndexParamName(context, node) {
543
511
  return eff._;
544
512
  }
545
513
  const { name: name5 } = callee.property;
546
- if (!AST8__namespace.ITERATOR_FUNCTION_INDEX_PARAM_POSITION.has(name5)) {
514
+ const indexPosition = AST8__namespace.getArrayMethodIndexParamPosition(name5);
515
+ if (indexPosition === -1) {
547
516
  return eff._;
548
517
  }
549
518
  const callbackArg = node.arguments[isUsingReactChildren(context, node) ? 1 : 0];
@@ -554,14 +523,10 @@ function getMapIndexParamName(context, node) {
554
523
  return eff._;
555
524
  }
556
525
  const { params } = callbackArg;
557
- const indexParamPosition = AST8__namespace.ITERATOR_FUNCTION_INDEX_PARAM_POSITION.get(name5);
558
- if (indexParamPosition == null) {
559
- return eff._;
560
- }
561
- if (params.length < indexParamPosition + 1) {
526
+ if (params.length < indexPosition + 1) {
562
527
  return eff._;
563
528
  }
564
- const param = params.at(indexParamPosition);
529
+ const param = params.at(indexPosition);
565
530
  return param != null && "name" in param ? param.name : eff._;
566
531
  }
567
532
  function getIdentifiersFromBinaryExpression(side) {
@@ -1403,7 +1368,7 @@ function create26(context) {
1403
1368
  break;
1404
1369
  }
1405
1370
  default: {
1406
- const call = AST8__namespace.findParentNode(jsxElement, AST8__namespace.isArrayMapCallLoose);
1371
+ const call = AST8__namespace.findParentNode(jsxElement, AST8__namespace.isArrayMapCall);
1407
1372
  const iter = AST8__namespace.findParentNode(jsxElement, (n) => n === call || AST8__namespace.isFunction(n));
1408
1373
  if (!AST8__namespace.isFunction(iter)) return;
1409
1374
  const arg0 = call?.arguments[0];
@@ -1940,7 +1905,7 @@ function create32(context) {
1940
1905
  if (state.isWithinChildrenToArray) {
1941
1906
  return;
1942
1907
  }
1943
- const isMapCall = AST8__namespace.isArrayMapCallLoose(node);
1908
+ const isMapCall = AST8__namespace.isArrayMapCall(node);
1944
1909
  if (!isMapCall && !isArrayFromCall(node)) {
1945
1910
  return;
1946
1911
  }
@@ -3104,7 +3069,7 @@ function create49(context, [option]) {
3104
3069
  const { allowExpressions = true } = option;
3105
3070
  return {
3106
3071
  JSXElement(node) {
3107
- if (!JSX8__namespace.isJsxFragmentElement(node)) return;
3072
+ if (!JSX8__namespace.isFragmentElement(node)) return;
3108
3073
  checkNode(context, node, allowExpressions);
3109
3074
  },
3110
3075
  JSXFragment(node) {
@@ -3127,15 +3092,15 @@ function trimLikeReact(text) {
3127
3092
  }
3128
3093
  function checkNode(context, node, allowExpressions) {
3129
3094
  const initialScope = context.sourceCode.getScope(node);
3130
- if (JSX8__namespace.isJsxKeyedElement(node, initialScope)) {
3095
+ if (JSX8__namespace.isKeyedElement(node, initialScope)) {
3131
3096
  return;
3132
3097
  }
3133
- if (JSX8__namespace.isJsxBuiltInElement(node.parent)) {
3098
+ if (JSX8__namespace.isHostElement(node.parent)) {
3134
3099
  context.report({
3135
3100
  messageId: "uselessFragment",
3136
3101
  node,
3137
3102
  data: {
3138
- reason: "placed inside a built-in component"
3103
+ reason: "placed inside a host component"
3139
3104
  },
3140
3105
  fix: getFix2(context, node)
3141
3106
  });
@@ -3210,7 +3175,7 @@ function getFix2(context, node) {
3210
3175
  }
3211
3176
  function canFix(node) {
3212
3177
  if (node.parent.type === types.AST_NODE_TYPES.JSXElement || node.parent.type === types.AST_NODE_TYPES.JSXFragment) {
3213
- return !JSX8__namespace.isJsxUserDefinedElement(node.parent);
3178
+ return JSX8__namespace.isHostElement(node.parent);
3214
3179
  }
3215
3180
  if (node.children.length === 0) {
3216
3181
  return false;
@@ -3473,7 +3438,7 @@ var prefer_shorthand_fragment_default = createRule({
3473
3438
  function create54(context) {
3474
3439
  return {
3475
3440
  JSXElement(node) {
3476
- if (!JSX8__namespace.isJsxFragmentElement(node)) return;
3441
+ if (!JSX8__namespace.isFragmentElement(node)) return;
3477
3442
  const hasAttributes = node.openingElement.attributes.length > 0;
3478
3443
  if (hasAttributes) {
3479
3444
  return;
package/dist/index.mjs CHANGED
@@ -5,7 +5,7 @@ import { AST_NODE_TYPES } from '@typescript-eslint/types';
5
5
  import { _, flow, getOrUpdate, constTrue, constFalse } from '@eslint-react/eff';
6
6
  import * as VAR2 from '@eslint-react/var';
7
7
  import { match, isMatching, P } from 'ts-pattern';
8
- import { JsxRuntime, RE_JSX_ANNOTATION, RE_JSX_FRAG_ANNOTATION, createReport } from '@eslint-react/kit';
8
+ import { JsxRuntime, createReport } from '@eslint-react/kit';
9
9
  import ts, { JsxEmit } from 'typescript';
10
10
  import * as AST8 from '@eslint-react/ast';
11
11
  import * as ER21 from '@eslint-react/core';
@@ -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.4-beta.5";
116
+ var version = "1.40.4-beta.7";
117
117
  var createRule = ESLintUtils.RuleCreator(getDocsUrl("x"));
118
118
 
119
119
  // src/rules/avoid-shorthand-boolean.ts
@@ -267,7 +267,7 @@ var jsx_uses_react_default = createRule({
267
267
  meta: {
268
268
  type: "problem",
269
269
  docs: {
270
- description: "Marks React variables as used when JSX is used in the file.",
270
+ description: "Marks React variables as used when JSX is used.",
271
271
  [Symbol.for("rule_features")]: RULE_FEATURES5
272
272
  },
273
273
  messages: {
@@ -280,30 +280,17 @@ var jsx_uses_react_default = createRule({
280
280
  defaultOptions: []
281
281
  });
282
282
  function create5(context) {
283
- const { jsx, jsxFactory, jsxFragmentFactory, reactNamespace } = JsxRuntime.getJsxRuntimeOptionsFromContext(context);
284
- const jsxAnnotation = getJsxAnnotation(context);
283
+ const jsxOptions = JsxRuntime.getJsxRuntimeOptions(context);
284
+ const jsxAnnotation = JsxRuntime.getJsxRuntimeAnnotation(context);
285
+ const jsx = jsxAnnotation.jsxRuntime === "classic" ? JsxEmit.React : jsxOptions.jsx;
285
286
  if (jsx === JsxEmit.ReactJSX || jsx === JsxEmit.ReactJSXDev) return {};
287
+ const jsxFactory = jsxAnnotation.jsx ?? jsxOptions.jsxFactory;
288
+ const jsxFragmentFactory = jsxAnnotation.jsxFrag ?? jsxOptions.jsxFragmentFactory;
286
289
  function handleJsxElement(node) {
287
- if (jsxAnnotation == null) {
288
- context.sourceCode.markVariableAsUsed(reactNamespace, node);
289
- context.sourceCode.markVariableAsUsed(jsxFactory, node);
290
- debugReport(context, node, reactNamespace);
291
- debugReport(context, node, jsxFactory);
292
- }
293
- if (jsxAnnotation?.jsx != null) {
294
- context.sourceCode.markVariableAsUsed(jsxAnnotation.jsx, node);
295
- debugReport(context, node, jsxAnnotation.jsx);
296
- }
290
+ context.sourceCode.markVariableAsUsed(jsxFactory, node);
297
291
  }
298
292
  function handleJsxFragment(node) {
299
- if (jsxAnnotation == null) {
300
- context.sourceCode.markVariableAsUsed(jsxFragmentFactory, node);
301
- debugReport(context, node, jsxFragmentFactory);
302
- }
303
- if (jsxAnnotation?.jsxFrag != null) {
304
- context.sourceCode.markVariableAsUsed(jsxAnnotation.jsxFrag, node);
305
- debugReport(context, node, jsxAnnotation.jsxFrag);
306
- }
293
+ context.sourceCode.markVariableAsUsed(jsxFragmentFactory, node);
307
294
  }
308
295
  return {
309
296
  JSXFragment: handleJsxFragment,
@@ -311,25 +298,6 @@ function create5(context) {
311
298
  JSXOpeningFragment: handleJsxElement
312
299
  };
313
300
  }
314
- function getJsxAnnotation(context) {
315
- if (!context.sourceCode.text.includes("@jsx")) return;
316
- const allComments = context.sourceCode.getAllComments();
317
- const jsxComment = allComments.find((n) => RE_JSX_ANNOTATION.test(n.value));
318
- const jsxFragComment = allComments.find((n) => RE_JSX_FRAG_ANNOTATION.test(n.value));
319
- const jsx = jsxComment?.value.match(RE_JSX_ANNOTATION)?.[1];
320
- const jsxFrag = jsxFragComment?.value.match(RE_JSX_FRAG_ANNOTATION)?.[1];
321
- return {
322
- jsx,
323
- jsxFrag
324
- };
325
- }
326
- function debugReport(context, node, name5) {
327
- context.report({
328
- messageId: "jsxUsesReact",
329
- node,
330
- data: { name: name5 }
331
- });
332
- }
333
301
  var RULE_NAME6 = "jsx-uses-vars";
334
302
  var RULE_FEATURES6 = [];
335
303
  var jsx_uses_vars_default = createRule({
@@ -515,7 +483,8 @@ function getMapIndexParamName(context, node) {
515
483
  return _;
516
484
  }
517
485
  const { name: name5 } = callee.property;
518
- if (!AST8.ITERATOR_FUNCTION_INDEX_PARAM_POSITION.has(name5)) {
486
+ const indexPosition = AST8.getArrayMethodIndexParamPosition(name5);
487
+ if (indexPosition === -1) {
519
488
  return _;
520
489
  }
521
490
  const callbackArg = node.arguments[isUsingReactChildren(context, node) ? 1 : 0];
@@ -526,14 +495,10 @@ function getMapIndexParamName(context, node) {
526
495
  return _;
527
496
  }
528
497
  const { params } = callbackArg;
529
- const indexParamPosition = AST8.ITERATOR_FUNCTION_INDEX_PARAM_POSITION.get(name5);
530
- if (indexParamPosition == null) {
531
- return _;
532
- }
533
- if (params.length < indexParamPosition + 1) {
498
+ if (params.length < indexPosition + 1) {
534
499
  return _;
535
500
  }
536
- const param = params.at(indexParamPosition);
501
+ const param = params.at(indexPosition);
537
502
  return param != null && "name" in param ? param.name : _;
538
503
  }
539
504
  function getIdentifiersFromBinaryExpression(side) {
@@ -1375,7 +1340,7 @@ function create26(context) {
1375
1340
  break;
1376
1341
  }
1377
1342
  default: {
1378
- const call = AST8.findParentNode(jsxElement, AST8.isArrayMapCallLoose);
1343
+ const call = AST8.findParentNode(jsxElement, AST8.isArrayMapCall);
1379
1344
  const iter = AST8.findParentNode(jsxElement, (n) => n === call || AST8.isFunction(n));
1380
1345
  if (!AST8.isFunction(iter)) return;
1381
1346
  const arg0 = call?.arguments[0];
@@ -1912,7 +1877,7 @@ function create32(context) {
1912
1877
  if (state.isWithinChildrenToArray) {
1913
1878
  return;
1914
1879
  }
1915
- const isMapCall = AST8.isArrayMapCallLoose(node);
1880
+ const isMapCall = AST8.isArrayMapCall(node);
1916
1881
  if (!isMapCall && !isArrayFromCall(node)) {
1917
1882
  return;
1918
1883
  }
@@ -3076,7 +3041,7 @@ function create49(context, [option]) {
3076
3041
  const { allowExpressions = true } = option;
3077
3042
  return {
3078
3043
  JSXElement(node) {
3079
- if (!JSX8.isJsxFragmentElement(node)) return;
3044
+ if (!JSX8.isFragmentElement(node)) return;
3080
3045
  checkNode(context, node, allowExpressions);
3081
3046
  },
3082
3047
  JSXFragment(node) {
@@ -3099,15 +3064,15 @@ function trimLikeReact(text) {
3099
3064
  }
3100
3065
  function checkNode(context, node, allowExpressions) {
3101
3066
  const initialScope = context.sourceCode.getScope(node);
3102
- if (JSX8.isJsxKeyedElement(node, initialScope)) {
3067
+ if (JSX8.isKeyedElement(node, initialScope)) {
3103
3068
  return;
3104
3069
  }
3105
- if (JSX8.isJsxBuiltInElement(node.parent)) {
3070
+ if (JSX8.isHostElement(node.parent)) {
3106
3071
  context.report({
3107
3072
  messageId: "uselessFragment",
3108
3073
  node,
3109
3074
  data: {
3110
- reason: "placed inside a built-in component"
3075
+ reason: "placed inside a host component"
3111
3076
  },
3112
3077
  fix: getFix2(context, node)
3113
3078
  });
@@ -3182,7 +3147,7 @@ function getFix2(context, node) {
3182
3147
  }
3183
3148
  function canFix(node) {
3184
3149
  if (node.parent.type === AST_NODE_TYPES.JSXElement || node.parent.type === AST_NODE_TYPES.JSXFragment) {
3185
- return !JSX8.isJsxUserDefinedElement(node.parent);
3150
+ return JSX8.isHostElement(node.parent);
3186
3151
  }
3187
3152
  if (node.children.length === 0) {
3188
3153
  return false;
@@ -3445,7 +3410,7 @@ var prefer_shorthand_fragment_default = createRule({
3445
3410
  function create54(context) {
3446
3411
  return {
3447
3412
  JSXElement(node) {
3448
- if (!JSX8.isJsxFragmentElement(node)) return;
3413
+ if (!JSX8.isFragmentElement(node)) return;
3449
3414
  const hasAttributes = node.openingElement.attributes.length > 0;
3450
3415
  if (hasAttributes) {
3451
3416
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-react-x",
3
- "version": "1.40.4-beta.5",
3
+ "version": "1.40.4-beta.7",
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/ast": "1.40.4-beta.5",
54
- "@eslint-react/eff": "1.40.4-beta.5",
55
- "@eslint-react/core": "1.40.4-beta.5",
56
- "@eslint-react/jsx": "1.40.4-beta.5",
57
- "@eslint-react/shared": "1.40.4-beta.5",
58
- "@eslint-react/kit": "1.40.4-beta.5",
59
- "@eslint-react/var": "1.40.4-beta.5"
53
+ "@eslint-react/ast": "1.40.4-beta.7",
54
+ "@eslint-react/core": "1.40.4-beta.7",
55
+ "@eslint-react/eff": "1.40.4-beta.7",
56
+ "@eslint-react/kit": "1.40.4-beta.7",
57
+ "@eslint-react/jsx": "1.40.4-beta.7",
58
+ "@eslint-react/shared": "1.40.4-beta.7",
59
+ "@eslint-react/var": "1.40.4-beta.7"
60
60
  },
61
61
  "devDependencies": {
62
62
  "@types/react": "^19.1.0",