eslint-plugin-react-x 2.3.3-next.0 → 2.3.4-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.
Files changed (2) hide show
  1. package/dist/index.js +37 -14
  2. package/package.json +7 -7
package/dist/index.js CHANGED
@@ -28,7 +28,7 @@ var __export = (all) => {
28
28
  //#endregion
29
29
  //#region package.json
30
30
  var name$6 = "eslint-plugin-react-x";
31
- var version = "2.3.3-next.0";
31
+ var version = "2.3.4-beta.0";
32
32
 
33
33
  //#endregion
34
34
  //#region src/utils/create-rule.ts
@@ -361,8 +361,8 @@ function create$57(context) {
361
361
  //#region src/rules/jsx-shorthand-boolean.ts
362
362
  const RULE_NAME$56 = "jsx-shorthand-boolean";
363
363
  const RULE_FEATURES$54 = ["CFG", "FIX"];
364
- const defaultOptions$3 = [1];
365
- const schema$1 = [{
364
+ const defaultOptions$4 = [1];
365
+ const schema$2 = [{
366
366
  type: "integer",
367
367
  enum: [-1, 1]
368
368
  }];
@@ -375,14 +375,14 @@ var jsx_shorthand_boolean_default = createRule({
375
375
  },
376
376
  fixable: "code",
377
377
  messages: { jsxShorthandBoolean: "{{message}}" },
378
- schema: schema$1
378
+ schema: schema$2
379
379
  },
380
380
  name: RULE_NAME$56,
381
381
  create: create$56,
382
- defaultOptions: defaultOptions$3
382
+ defaultOptions: defaultOptions$4
383
383
  });
384
384
  function create$56(context) {
385
- const policy = context.options[0] ?? defaultOptions$3[0];
385
+ const policy = context.options[0] ?? defaultOptions$4[0];
386
386
  return { JSXAttribute(node) {
387
387
  const { value } = node;
388
388
  const propName = getJsxAttributeName(context, node);
@@ -411,8 +411,8 @@ function create$56(context) {
411
411
  //#region src/rules/jsx-shorthand-fragment.ts
412
412
  const RULE_NAME$55 = "jsx-shorthand-fragment";
413
413
  const RULE_FEATURES$53 = ["CFG", "FIX"];
414
- const defaultOptions$2 = [1];
415
- const schema = [{
414
+ const defaultOptions$3 = [1];
415
+ const schema$1 = [{
416
416
  type: "integer",
417
417
  enum: [-1, 1]
418
418
  }];
@@ -425,14 +425,14 @@ var jsx_shorthand_fragment_default = createRule({
425
425
  },
426
426
  fixable: "code",
427
427
  messages: { jsxShorthandFragment: "{{message}}" },
428
- schema
428
+ schema: schema$1
429
429
  },
430
430
  name: RULE_NAME$55,
431
431
  create: create$55,
432
- defaultOptions: defaultOptions$2
432
+ defaultOptions: defaultOptions$3
433
433
  });
434
434
  function create$55(context) {
435
- const policy = context.options[0] ?? defaultOptions$2[0];
435
+ const policy = context.options[0] ?? defaultOptions$3[0];
436
436
  const { jsxFragmentFactory } = {
437
437
  ...getJsxConfigFromContext(context),
438
438
  ...getJsxConfigFromAnnotation(context)
@@ -2575,6 +2575,15 @@ function isContextName(name$7, isReact18OrBelow) {
2575
2575
  //#region src/rules/no-unstable-default-props.ts
2576
2576
  const RULE_NAME$11 = "no-unstable-default-props";
2577
2577
  const RULE_FEATURES$9 = [];
2578
+ const defaultOptions$2 = [{ safeDefaultProps: [] }];
2579
+ const schema = [{
2580
+ type: "object",
2581
+ additionalProperties: false,
2582
+ properties: { safeDefaultProps: {
2583
+ type: "array",
2584
+ items: { type: "string" }
2585
+ } }
2586
+ }];
2578
2587
  var no_unstable_default_props_default = createRule({
2579
2588
  meta: {
2580
2589
  type: "problem",
@@ -2583,15 +2592,25 @@ var no_unstable_default_props_default = createRule({
2583
2592
  [Symbol.for("rule_features")]: RULE_FEATURES$9
2584
2593
  },
2585
2594
  messages: { noUnstableDefaultProps: "A/an '{{forbiddenType}}' as default prop. This could lead to potential infinite render loop in React. Use a variable instead of '{{forbiddenType}}'." },
2586
- schema: []
2595
+ schema
2587
2596
  },
2588
2597
  name: RULE_NAME$11,
2589
2598
  create: create$11,
2590
- defaultOptions: []
2599
+ defaultOptions: defaultOptions$2
2591
2600
  });
2592
- function create$11(context) {
2601
+ function extractIdentifier(node) {
2602
+ if (node.type === AST_NODE_TYPES.NewExpression && node.callee.type === AST_NODE_TYPES.Identifier) return node.callee.name;
2603
+ if (node.type === AST_NODE_TYPES.CallExpression && node.callee.type === AST_NODE_TYPES.MemberExpression) {
2604
+ const { object } = node.callee;
2605
+ if (object.type === AST_NODE_TYPES.Identifier) return object.name;
2606
+ }
2607
+ return null;
2608
+ }
2609
+ function create$11(context, [options]) {
2593
2610
  const { ctx, listeners } = useComponentCollector(context);
2594
2611
  const declarators = /* @__PURE__ */ new WeakMap();
2612
+ const { safeDefaultProps = [] } = options;
2613
+ const safePatterns = safeDefaultProps.map((s) => toRegExp(s));
2595
2614
  return {
2596
2615
  ...listeners,
2597
2616
  [AST.SEL_OBJECT_DESTRUCTURING_VARIABLE_DECLARATOR](node) {
@@ -2615,6 +2634,10 @@ function create$11(context) {
2615
2634
  const construction = getObjectType(value, context.sourceCode.getScope(value));
2616
2635
  if (construction == null) continue;
2617
2636
  if (isReactHookCall(construction.node)) continue;
2637
+ if (safePatterns.length > 0) {
2638
+ const identifier = extractIdentifier(right);
2639
+ if (identifier != null && safePatterns.some((pattern) => pattern.test(identifier))) continue;
2640
+ }
2618
2641
  const forbiddenType = AST.toDelimiterFormat(right);
2619
2642
  context.report({
2620
2643
  messageId: "noUnstableDefaultProps",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-react-x",
3
- "version": "2.3.3-next.0",
3
+ "version": "2.3.4-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",
@@ -46,16 +46,16 @@
46
46
  "string-ts": "^2.2.1",
47
47
  "ts-api-utils": "^2.1.0",
48
48
  "ts-pattern": "^5.9.0",
49
- "@eslint-react/ast": "2.3.3-next.0",
50
- "@eslint-react/core": "2.3.3-next.0",
51
- "@eslint-react/eff": "2.3.3-next.0",
52
- "@eslint-react/shared": "2.3.3-next.0",
53
- "@eslint-react/var": "2.3.3-next.0"
49
+ "@eslint-react/ast": "2.3.4-beta.0",
50
+ "@eslint-react/core": "2.3.4-beta.0",
51
+ "@eslint-react/eff": "2.3.4-beta.0",
52
+ "@eslint-react/var": "2.3.4-beta.0",
53
+ "@eslint-react/shared": "2.3.4-beta.0"
54
54
  },
55
55
  "devDependencies": {
56
56
  "@types/react": "^19.2.2",
57
57
  "@types/react-dom": "^19.2.2",
58
- "tsdown": "^0.16.0",
58
+ "tsdown": "^0.16.1",
59
59
  "@local/configs": "0.0.0"
60
60
  },
61
61
  "peerDependencies": {