eslint-plugin-react-x 2.0.0-next.47 → 2.0.0-next.48

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.d.ts CHANGED
@@ -69,12 +69,18 @@ declare const _default: {
69
69
  readonly "no-unused-state": _typescript_eslint_utils_ts_eslint.RuleModule<"noUnusedState", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
70
70
  readonly "no-use-context": _typescript_eslint_utils_ts_eslint.RuleModule<"noUseContext", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
71
71
  readonly "no-useless-forward-ref": _typescript_eslint_utils_ts_eslint.RuleModule<"noUselessForwardRef", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
72
+ readonly "no-useless-fragment": _typescript_eslint_utils_ts_eslint.RuleModule<"uselessFragment", readonly [{
73
+ allowExpressions: boolean;
74
+ }], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
72
75
  readonly "prefer-destructuring-assignment": _typescript_eslint_utils_ts_eslint.RuleModule<"preferDestructuringAssignment", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
73
76
  readonly "prefer-namespace-import": _typescript_eslint_utils_ts_eslint.RuleModule<"preferNamespaceImport", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
74
77
  readonly "prefer-read-only-props": _typescript_eslint_utils_ts_eslint.RuleModule<"preferReadOnlyProps", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
75
78
  readonly "prefer-use-state-lazy-initialization": _typescript_eslint_utils_ts_eslint.RuleModule<"preferUseStateLazyInitialization", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
76
79
  readonly "avoid-shorthand-boolean": _typescript_eslint_utils_ts_eslint.RuleModule<"avoidShorthandBoolean", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
77
80
  readonly "avoid-shorthand-fragment": _typescript_eslint_utils_ts_eslint.RuleModule<"avoidShorthandFragment", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
81
+ readonly "no-comment-textnodes": _typescript_eslint_utils_ts_eslint.RuleModule<"noCommentTextnodes", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
82
+ readonly "no-complex-conditional-rendering": _typescript_eslint_utils_ts_eslint.RuleModule<"noComplexConditionalRendering", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
83
+ readonly "prefer-react-namespace-import": _typescript_eslint_utils_ts_eslint.RuleModule<"preferReactNamespaceImport", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
78
84
  readonly "prefer-shorthand-boolean": _typescript_eslint_utils_ts_eslint.RuleModule<"preferShorthandBoolean", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
79
85
  readonly "prefer-shorthand-fragment": _typescript_eslint_utils_ts_eslint.RuleModule<"preferShorthandFragment", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
80
86
  };
@@ -149,12 +155,18 @@ declare const _default: {
149
155
  readonly "no-unused-state": _typescript_eslint_utils_ts_eslint.RuleModule<"noUnusedState", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
150
156
  readonly "no-use-context": _typescript_eslint_utils_ts_eslint.RuleModule<"noUseContext", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
151
157
  readonly "no-useless-forward-ref": _typescript_eslint_utils_ts_eslint.RuleModule<"noUselessForwardRef", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
158
+ readonly "no-useless-fragment": _typescript_eslint_utils_ts_eslint.RuleModule<"uselessFragment", readonly [{
159
+ allowExpressions: boolean;
160
+ }], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
152
161
  readonly "prefer-destructuring-assignment": _typescript_eslint_utils_ts_eslint.RuleModule<"preferDestructuringAssignment", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
153
162
  readonly "prefer-namespace-import": _typescript_eslint_utils_ts_eslint.RuleModule<"preferNamespaceImport", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
154
163
  readonly "prefer-read-only-props": _typescript_eslint_utils_ts_eslint.RuleModule<"preferReadOnlyProps", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
155
164
  readonly "prefer-use-state-lazy-initialization": _typescript_eslint_utils_ts_eslint.RuleModule<"preferUseStateLazyInitialization", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
156
165
  readonly "avoid-shorthand-boolean": _typescript_eslint_utils_ts_eslint.RuleModule<"avoidShorthandBoolean", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
157
166
  readonly "avoid-shorthand-fragment": _typescript_eslint_utils_ts_eslint.RuleModule<"avoidShorthandFragment", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
167
+ readonly "no-comment-textnodes": _typescript_eslint_utils_ts_eslint.RuleModule<"noCommentTextnodes", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
168
+ readonly "no-complex-conditional-rendering": _typescript_eslint_utils_ts_eslint.RuleModule<"noComplexConditionalRendering", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
169
+ readonly "prefer-react-namespace-import": _typescript_eslint_utils_ts_eslint.RuleModule<"preferReactNamespaceImport", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
158
170
  readonly "prefer-shorthand-boolean": _typescript_eslint_utils_ts_eslint.RuleModule<"preferShorthandBoolean", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
159
171
  readonly "prefer-shorthand-fragment": _typescript_eslint_utils_ts_eslint.RuleModule<"preferShorthandFragment", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
160
172
  };
@@ -229,12 +241,18 @@ declare const _default: {
229
241
  readonly "no-unused-state": _typescript_eslint_utils_ts_eslint.RuleModule<"noUnusedState", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
230
242
  readonly "no-use-context": _typescript_eslint_utils_ts_eslint.RuleModule<"noUseContext", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
231
243
  readonly "no-useless-forward-ref": _typescript_eslint_utils_ts_eslint.RuleModule<"noUselessForwardRef", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
244
+ readonly "no-useless-fragment": _typescript_eslint_utils_ts_eslint.RuleModule<"uselessFragment", readonly [{
245
+ allowExpressions: boolean;
246
+ }], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
232
247
  readonly "prefer-destructuring-assignment": _typescript_eslint_utils_ts_eslint.RuleModule<"preferDestructuringAssignment", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
233
248
  readonly "prefer-namespace-import": _typescript_eslint_utils_ts_eslint.RuleModule<"preferNamespaceImport", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
234
249
  readonly "prefer-read-only-props": _typescript_eslint_utils_ts_eslint.RuleModule<"preferReadOnlyProps", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
235
250
  readonly "prefer-use-state-lazy-initialization": _typescript_eslint_utils_ts_eslint.RuleModule<"preferUseStateLazyInitialization", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
236
251
  readonly "avoid-shorthand-boolean": _typescript_eslint_utils_ts_eslint.RuleModule<"avoidShorthandBoolean", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
237
252
  readonly "avoid-shorthand-fragment": _typescript_eslint_utils_ts_eslint.RuleModule<"avoidShorthandFragment", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
253
+ readonly "no-comment-textnodes": _typescript_eslint_utils_ts_eslint.RuleModule<"noCommentTextnodes", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
254
+ readonly "no-complex-conditional-rendering": _typescript_eslint_utils_ts_eslint.RuleModule<"noComplexConditionalRendering", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
255
+ readonly "prefer-react-namespace-import": _typescript_eslint_utils_ts_eslint.RuleModule<"preferReactNamespaceImport", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
238
256
  readonly "prefer-shorthand-boolean": _typescript_eslint_utils_ts_eslint.RuleModule<"preferShorthandBoolean", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
239
257
  readonly "prefer-shorthand-fragment": _typescript_eslint_utils_ts_eslint.RuleModule<"preferShorthandFragment", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
240
258
  };
@@ -307,12 +325,18 @@ declare const _default: {
307
325
  readonly "no-unused-state": _typescript_eslint_utils_ts_eslint.RuleModule<"noUnusedState", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
308
326
  readonly "no-use-context": _typescript_eslint_utils_ts_eslint.RuleModule<"noUseContext", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
309
327
  readonly "no-useless-forward-ref": _typescript_eslint_utils_ts_eslint.RuleModule<"noUselessForwardRef", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
328
+ readonly "no-useless-fragment": _typescript_eslint_utils_ts_eslint.RuleModule<"uselessFragment", readonly [{
329
+ allowExpressions: boolean;
330
+ }], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
310
331
  readonly "prefer-destructuring-assignment": _typescript_eslint_utils_ts_eslint.RuleModule<"preferDestructuringAssignment", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
311
332
  readonly "prefer-namespace-import": _typescript_eslint_utils_ts_eslint.RuleModule<"preferNamespaceImport", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
312
333
  readonly "prefer-read-only-props": _typescript_eslint_utils_ts_eslint.RuleModule<"preferReadOnlyProps", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
313
334
  readonly "prefer-use-state-lazy-initialization": _typescript_eslint_utils_ts_eslint.RuleModule<"preferUseStateLazyInitialization", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
314
335
  readonly "avoid-shorthand-boolean": _typescript_eslint_utils_ts_eslint.RuleModule<"avoidShorthandBoolean", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
315
336
  readonly "avoid-shorthand-fragment": _typescript_eslint_utils_ts_eslint.RuleModule<"avoidShorthandFragment", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
337
+ readonly "no-comment-textnodes": _typescript_eslint_utils_ts_eslint.RuleModule<"noCommentTextnodes", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
338
+ readonly "no-complex-conditional-rendering": _typescript_eslint_utils_ts_eslint.RuleModule<"noComplexConditionalRendering", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
339
+ readonly "prefer-react-namespace-import": _typescript_eslint_utils_ts_eslint.RuleModule<"preferReactNamespaceImport", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
316
340
  readonly "prefer-shorthand-boolean": _typescript_eslint_utils_ts_eslint.RuleModule<"preferShorthandBoolean", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
317
341
  readonly "prefer-shorthand-fragment": _typescript_eslint_utils_ts_eslint.RuleModule<"preferShorthandFragment", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
318
342
  };
package/dist/index.js CHANGED
@@ -125,7 +125,7 @@ var settings3 = {
125
125
 
126
126
  // package.json
127
127
  var name4 = "eslint-plugin-react-x";
128
- var version = "2.0.0-next.47";
128
+ var version = "2.0.0-next.48";
129
129
  var createRule = ESLintUtils.RuleCreator(getDocsUrl("x"));
130
130
 
131
131
  // src/rules/jsx-key-before-spread.ts
@@ -3527,7 +3527,157 @@ function create54(context) {
3527
3527
  }
3528
3528
  };
3529
3529
  }
3530
- var RULE_NAME55 = "prefer-destructuring-assignment";
3530
+ var RULE_NAME55 = "no-useless-fragment";
3531
+ var defaultOptions3 = [{
3532
+ allowExpressions: true
3533
+ }];
3534
+ var no_useless_fragment_default = createRule({
3535
+ meta: {
3536
+ type: "problem",
3537
+ defaultOptions: [...defaultOptions3],
3538
+ docs: {
3539
+ description: "Disallow useless fragment elements."
3540
+ },
3541
+ fixable: "code",
3542
+ messages: {
3543
+ uselessFragment: "A fragment {{reason}} is useless."
3544
+ },
3545
+ schema: [{
3546
+ type: "object",
3547
+ additionalProperties: false,
3548
+ properties: {
3549
+ allowExpressions: {
3550
+ type: "boolean",
3551
+ description: "Allow fragments with a single expression child"
3552
+ }
3553
+ }
3554
+ }]
3555
+ },
3556
+ name: RULE_NAME55,
3557
+ create: create55,
3558
+ defaultOptions: defaultOptions3
3559
+ });
3560
+ function create55(context, [option]) {
3561
+ const { allowExpressions = true } = option;
3562
+ return {
3563
+ JSXElement(node) {
3564
+ if (!ER26.isFragmentElement(context, node)) return;
3565
+ checkNode(context, node, allowExpressions);
3566
+ },
3567
+ JSXFragment(node) {
3568
+ checkNode(context, node, allowExpressions);
3569
+ }
3570
+ };
3571
+ }
3572
+ function isWhiteSpace(node) {
3573
+ return typeof node.value === "string" && node.raw.trim() === "";
3574
+ }
3575
+ function isPaddingSpaces(node) {
3576
+ return ER26.isJsxText(node) && isWhiteSpace(node) && node.raw.includes("\n");
3577
+ }
3578
+ function trimLikeReact(text) {
3579
+ const leadingSpaces = /^\s*/.exec(text)?.[0] ?? "";
3580
+ const trailingSpaces = /\s*$/.exec(text)?.[0] ?? "";
3581
+ const start = leadingSpaces.includes("\n") ? leadingSpaces.length : 0;
3582
+ const end = trailingSpaces.includes("\n") ? text.length - trailingSpaces.length : text.length;
3583
+ return text.slice(start, end);
3584
+ }
3585
+ function checkNode(context, node, allowExpressions) {
3586
+ const initialScope = context.sourceCode.getScope(node);
3587
+ if (ER26.isKeyedElement(context, node, initialScope)) {
3588
+ return;
3589
+ }
3590
+ if (ER26.isHostElement(context, node.parent)) {
3591
+ context.report({
3592
+ messageId: "uselessFragment",
3593
+ node,
3594
+ data: {
3595
+ reason: "placed inside a host component"
3596
+ },
3597
+ fix: getFix2(context, node)
3598
+ });
3599
+ }
3600
+ if (node.children.length === 0) {
3601
+ context.report({
3602
+ messageId: "uselessFragment",
3603
+ node,
3604
+ data: {
3605
+ reason: "contains less than two children"
3606
+ },
3607
+ fix: getFix2(context, node)
3608
+ });
3609
+ return;
3610
+ }
3611
+ const isChildElement = AST13.isOneOf([AST_NODE_TYPES.JSXElement, AST_NODE_TYPES.JSXFragment])(node.parent);
3612
+ switch (true) {
3613
+ // <Foo content={<>ee eeee eeee ...</>} />
3614
+ case (allowExpressions && !isChildElement && node.children.length === 1 && ER26.isJsxText(node.children.at(0))): {
3615
+ return;
3616
+ }
3617
+ // <Foo><>hello, world</></Foo>
3618
+ case (!allowExpressions && isChildElement): {
3619
+ context.report({
3620
+ messageId: "uselessFragment",
3621
+ node,
3622
+ data: {
3623
+ reason: "contains less than two children"
3624
+ },
3625
+ fix: getFix2(context, node)
3626
+ });
3627
+ return;
3628
+ }
3629
+ case (!allowExpressions && !isChildElement && node.children.length === 1): {
3630
+ context.report({
3631
+ messageId: "uselessFragment",
3632
+ node,
3633
+ data: {
3634
+ reason: "contains less than two children"
3635
+ },
3636
+ fix: getFix2(context, node)
3637
+ });
3638
+ return;
3639
+ }
3640
+ }
3641
+ const nonPaddingChildren = node.children.filter((child) => !isPaddingSpaces(child));
3642
+ const firstNonPaddingChild = nonPaddingChildren.at(0);
3643
+ switch (true) {
3644
+ case nonPaddingChildren.length === 0:
3645
+ case (nonPaddingChildren.length === 1 && firstNonPaddingChild?.type !== AST_NODE_TYPES.JSXExpressionContainer): {
3646
+ context.report({
3647
+ messageId: "uselessFragment",
3648
+ node,
3649
+ data: {
3650
+ reason: "contains less than two children"
3651
+ },
3652
+ fix: getFix2(context, node)
3653
+ });
3654
+ return;
3655
+ }
3656
+ }
3657
+ return;
3658
+ }
3659
+ function getFix2(context, node) {
3660
+ if (!canFix(context, node)) return null;
3661
+ return (fixer) => {
3662
+ const opener = node.type === AST_NODE_TYPES.JSXFragment ? node.openingFragment : node.openingElement;
3663
+ const closer = node.type === AST_NODE_TYPES.JSXFragment ? node.closingFragment : node.closingElement;
3664
+ const childrenText = opener.type === AST_NODE_TYPES.JSXOpeningElement && opener.selfClosing ? "" : context.sourceCode.getText().slice(opener.range[1], closer?.range[0]);
3665
+ return fixer.replaceText(node, trimLikeReact(childrenText));
3666
+ };
3667
+ }
3668
+ function canFix(context, node) {
3669
+ if (node.parent.type === AST_NODE_TYPES.JSXElement || node.parent.type === AST_NODE_TYPES.JSXFragment) {
3670
+ return ER26.isHostElement(context, node.parent);
3671
+ }
3672
+ if (node.children.length === 0) {
3673
+ return false;
3674
+ }
3675
+ if (node.children.some((child) => ER26.isJsxText(child) && !isWhiteSpace(child) || AST13.is(AST_NODE_TYPES.JSXExpressionContainer)(child))) {
3676
+ return false;
3677
+ }
3678
+ return true;
3679
+ }
3680
+ var RULE_NAME56 = "prefer-destructuring-assignment";
3531
3681
  var RULE_FEATURES55 = [];
3532
3682
  function isMemberExpressionWithObjectName(node) {
3533
3683
  return node.object.type === AST_NODE_TYPES.Identifier && "name" in node.object;
@@ -3544,11 +3694,11 @@ var prefer_destructuring_assignment_default = createRule({
3544
3694
  },
3545
3695
  schema: []
3546
3696
  },
3547
- name: RULE_NAME55,
3548
- create: create55,
3697
+ name: RULE_NAME56,
3698
+ create: create56,
3549
3699
  defaultOptions: []
3550
3700
  });
3551
- function create55(context) {
3701
+ function create56(context) {
3552
3702
  const { ctx, listeners } = ER26.useComponentCollector(context);
3553
3703
  const memberExpressionWithNames = [];
3554
3704
  return {
@@ -3608,7 +3758,7 @@ function create55(context) {
3608
3758
  }
3609
3759
  };
3610
3760
  }
3611
- var RULE_NAME56 = "prefer-namespace-import";
3761
+ var RULE_NAME57 = "prefer-namespace-import";
3612
3762
  var RULE_FEATURES56 = [
3613
3763
  "FIX"
3614
3764
  ];
@@ -3625,11 +3775,11 @@ var prefer_namespace_import_default = createRule({
3625
3775
  },
3626
3776
  schema: []
3627
3777
  },
3628
- name: RULE_NAME56,
3629
- create: create56,
3778
+ name: RULE_NAME57,
3779
+ create: create57,
3630
3780
  defaultOptions: []
3631
3781
  });
3632
- function create56(context) {
3782
+ function create57(context) {
3633
3783
  const { importSource } = getSettingsFromContext(context);
3634
3784
  return {
3635
3785
  [`ImportDeclaration[source.value="${importSource}"] ImportDefaultSpecifier`](node) {
@@ -3664,7 +3814,7 @@ function create56(context) {
3664
3814
  }
3665
3815
  };
3666
3816
  }
3667
- var RULE_NAME57 = "prefer-read-only-props";
3817
+ var RULE_NAME58 = "prefer-read-only-props";
3668
3818
  var RULE_FEATURES57 = [
3669
3819
  "TSC",
3670
3820
  "EXP"
@@ -3681,11 +3831,11 @@ var prefer_read_only_props_default = createRule({
3681
3831
  },
3682
3832
  schema: []
3683
3833
  },
3684
- name: RULE_NAME57,
3685
- create: create57,
3834
+ name: RULE_NAME58,
3835
+ create: create58,
3686
3836
  defaultOptions: []
3687
3837
  });
3688
- function create57(context) {
3838
+ function create58(context) {
3689
3839
  const services = ESLintUtils.getParserServices(context, false);
3690
3840
  const { ctx, listeners } = ER26.useComponentCollector(context);
3691
3841
  return {
@@ -3717,7 +3867,7 @@ function isTypeReadonlyLoose(services, type) {
3717
3867
  return true;
3718
3868
  }
3719
3869
  }
3720
- var RULE_NAME58 = "prefer-use-state-lazy-initialization";
3870
+ var RULE_NAME59 = "prefer-use-state-lazy-initialization";
3721
3871
  var RULE_FEATURES58 = [
3722
3872
  "EXP"
3723
3873
  ];
@@ -3738,11 +3888,11 @@ var prefer_use_state_lazy_initialization_default = createRule({
3738
3888
  },
3739
3889
  schema: []
3740
3890
  },
3741
- name: RULE_NAME58,
3742
- create: create58,
3891
+ name: RULE_NAME59,
3892
+ create: create59,
3743
3893
  defaultOptions: []
3744
3894
  });
3745
- function create58(context) {
3895
+ function create59(context) {
3746
3896
  const alias = getSettingsFromContext(context).additionalHooks.useState ?? [];
3747
3897
  const isUseStateCall = ER26.isReactHookCallWithNameAlias(context, "useState", alias);
3748
3898
  return {
@@ -3779,11 +3929,12 @@ function create58(context) {
3779
3929
  }
3780
3930
  };
3781
3931
  }
3782
- var RULE_NAME59 = "avoid-shorthand-boolean";
3932
+ var RULE_NAME60 = "avoid-shorthand-boolean";
3783
3933
  var RULE_FEATURES59 = [];
3784
3934
  var avoid_shorthand_boolean_default = createRule({
3785
3935
  meta: {
3786
3936
  type: "problem",
3937
+ deprecated: true,
3787
3938
  docs: {
3788
3939
  description: "Enforces explicit boolean values for boolean attributes.",
3789
3940
  [Symbol.for("rule_features")]: RULE_FEATURES59
@@ -3792,13 +3943,16 @@ var avoid_shorthand_boolean_default = createRule({
3792
3943
  messages: {
3793
3944
  avoidShorthandBoolean: "Avoid using shorthand boolean attribute '{{propName}}'. Use '{{propName}}={true}' instead."
3794
3945
  },
3946
+ replacedBy: [
3947
+ "react-x/jsx-shorthand-boolean"
3948
+ ],
3795
3949
  schema: []
3796
3950
  },
3797
- name: RULE_NAME59,
3798
- create: create59,
3951
+ name: RULE_NAME60,
3952
+ create: create60,
3799
3953
  defaultOptions: []
3800
3954
  });
3801
- function create59(context) {
3955
+ function create60(context) {
3802
3956
  return {
3803
3957
  JSXAttribute(node) {
3804
3958
  if (node.value == null) {
@@ -3814,11 +3968,12 @@ function create59(context) {
3814
3968
  }
3815
3969
  };
3816
3970
  }
3817
- var RULE_NAME60 = "avoid-shorthand-fragment";
3971
+ var RULE_NAME61 = "avoid-shorthand-fragment";
3818
3972
  var RULE_FEATURES60 = [];
3819
3973
  var avoid_shorthand_fragment_default = createRule({
3820
3974
  meta: {
3821
3975
  type: "problem",
3976
+ deprecated: true,
3822
3977
  docs: {
3823
3978
  description: "Enforces explicit `<Fragment>` components instead of the shorthand `<>` or `</>` syntax.",
3824
3979
  [Symbol.for("rule_features")]: RULE_FEATURES60
@@ -3826,13 +3981,16 @@ var avoid_shorthand_fragment_default = createRule({
3826
3981
  messages: {
3827
3982
  avoidShorthandFragment: "Avoid using shorthand fragment syntax. Use '{{jsxFragmentFactory}}' component instead."
3828
3983
  },
3984
+ replacedBy: [
3985
+ "react-x/jsx-shorthand-fragment"
3986
+ ],
3829
3987
  schema: []
3830
3988
  },
3831
- name: RULE_NAME60,
3832
- create: create60,
3989
+ name: RULE_NAME61,
3990
+ create: create61,
3833
3991
  defaultOptions: []
3834
3992
  });
3835
- function create60(context) {
3993
+ function create61(context) {
3836
3994
  const jsxConfigFromContext = JsxConfig.getFromContext(context);
3837
3995
  const jsxConfigFromAnnotation = JsxConfig.getFromAnnotation(context);
3838
3996
  const jsxConfig = {
@@ -3851,13 +4009,14 @@ function create60(context) {
3851
4009
  }
3852
4010
  };
3853
4011
  }
3854
- var RULE_NAME61 = "prefer-shorthand-boolean";
4012
+ var RULE_NAME62 = "prefer-shorthand-boolean";
3855
4013
  var RULE_FEATURES61 = [
3856
4014
  "FIX"
3857
4015
  ];
3858
4016
  var prefer_shorthand_boolean_default = createRule({
3859
4017
  meta: {
3860
4018
  type: "problem",
4019
+ deprecated: true,
3861
4020
  docs: {
3862
4021
  description: "Enforces shorthand syntax for boolean attributes.",
3863
4022
  [Symbol.for("rule_features")]: RULE_FEATURES61
@@ -3866,13 +4025,16 @@ var prefer_shorthand_boolean_default = createRule({
3866
4025
  messages: {
3867
4026
  preferShorthandBoolean: "Use shorthand boolean attribute '{{propName}}'."
3868
4027
  },
4028
+ replacedBy: [
4029
+ "react-x/jsx-shorthand-boolean"
4030
+ ],
3869
4031
  schema: []
3870
4032
  },
3871
- name: RULE_NAME61,
3872
- create: create61,
4033
+ name: RULE_NAME62,
4034
+ create: create62,
3873
4035
  defaultOptions: []
3874
4036
  });
3875
- function create61(context) {
4037
+ function create62(context) {
3876
4038
  return {
3877
4039
  JSXAttribute(node) {
3878
4040
  const { value } = node;
@@ -3892,13 +4054,14 @@ function create61(context) {
3892
4054
  }
3893
4055
  };
3894
4056
  }
3895
- var RULE_NAME62 = "prefer-shorthand-fragment";
4057
+ var RULE_NAME63 = "prefer-shorthand-fragment";
3896
4058
  var RULE_FEATURES62 = [
3897
4059
  "FIX"
3898
4060
  ];
3899
4061
  var prefer_shorthand_fragment_default = createRule({
3900
4062
  meta: {
3901
4063
  type: "problem",
4064
+ deprecated: true,
3902
4065
  docs: {
3903
4066
  description: "Enforces shorthand syntax for fragments.",
3904
4067
  [Symbol.for("rule_features")]: RULE_FEATURES62
@@ -3907,13 +4070,16 @@ var prefer_shorthand_fragment_default = createRule({
3907
4070
  messages: {
3908
4071
  preferShorthandFragment: "Use fragment shorthand syntax instead of 'Fragment' component."
3909
4072
  },
4073
+ replacedBy: [
4074
+ "react-x/jsx-shorthand-fragment"
4075
+ ],
3910
4076
  schema: []
3911
4077
  },
3912
- name: RULE_NAME62,
3913
- create: create62,
4078
+ name: RULE_NAME63,
4079
+ create: create63,
3914
4080
  defaultOptions: []
3915
4081
  });
3916
- function create62(context) {
4082
+ function create63(context) {
3917
4083
  return {
3918
4084
  JSXElement(node) {
3919
4085
  if (!ER26.isFragmentElement(context, node)) return;
@@ -3938,6 +4104,162 @@ function create62(context) {
3938
4104
  }
3939
4105
  };
3940
4106
  }
4107
+ var RULE_NAME64 = "prefer-react-namespace-import";
4108
+ var RULE_FEATURES63 = [
4109
+ "FIX"
4110
+ ];
4111
+ var prefer_react_namespace_import_default = createRule({
4112
+ meta: {
4113
+ type: "problem",
4114
+ deprecated: true,
4115
+ docs: {
4116
+ description: "Enforces React is imported via a namespace import.",
4117
+ [Symbol.for("rule_features")]: RULE_FEATURES63
4118
+ },
4119
+ fixable: "code",
4120
+ messages: {
4121
+ preferReactNamespaceImport: `Prefer importing React as 'import * as React from "{{importSource}}"';`
4122
+ },
4123
+ replacedBy: [
4124
+ "react-x/prefer-namespace-import"
4125
+ ],
4126
+ schema: []
4127
+ },
4128
+ name: RULE_NAME64,
4129
+ create: create64,
4130
+ defaultOptions: []
4131
+ });
4132
+ function create64(context) {
4133
+ const { importSource } = getSettingsFromContext(context);
4134
+ return {
4135
+ [`ImportDeclaration[source.value="${importSource}"] ImportDefaultSpecifier`](node) {
4136
+ const hasOtherSpecifiers = node.parent.specifiers.length > 1;
4137
+ context.report({
4138
+ messageId: "preferReactNamespaceImport",
4139
+ node: hasOtherSpecifiers ? node : node.parent,
4140
+ data: { importSource },
4141
+ fix(fixer) {
4142
+ const importDeclarationText = context.sourceCode.getText(node.parent);
4143
+ const semi = importDeclarationText.endsWith(";") ? ";" : "";
4144
+ const quote = node.parent.source.raw.at(0) ?? "'";
4145
+ const isTypeImport = node.parent.importKind === "type";
4146
+ const importStringPrefix = `import${isTypeImport ? " type" : ""}`;
4147
+ const importSourceQuoted = `${quote}${importSource}${quote}`;
4148
+ if (!hasOtherSpecifiers) {
4149
+ return fixer.replaceText(
4150
+ node.parent,
4151
+ `${importStringPrefix} * as ${node.local.name} from ${importSourceQuoted}${semi}`
4152
+ );
4153
+ }
4154
+ const specifiers = importDeclarationText.slice(importDeclarationText.indexOf("{"), importDeclarationText.indexOf("}") + 1);
4155
+ return fixer.replaceText(
4156
+ node.parent,
4157
+ [
4158
+ `${importStringPrefix} * as ${node.local.name} from ${importSourceQuoted}${semi}`,
4159
+ `${importStringPrefix} ${specifiers} from ${importSourceQuoted}${semi}`
4160
+ ].join("\n")
4161
+ );
4162
+ }
4163
+ });
4164
+ }
4165
+ };
4166
+ }
4167
+ var RULE_NAME65 = "no-comment-textnodes";
4168
+ var RULE_FEATURES64 = [];
4169
+ var no_comment_textnodes_default = createRule({
4170
+ meta: {
4171
+ type: "problem",
4172
+ deprecated: true,
4173
+ docs: {
4174
+ description: "Prevents comments from being inserted as text nodes.",
4175
+ [Symbol.for("rule_features")]: RULE_FEATURES64
4176
+ },
4177
+ messages: {
4178
+ noCommentTextnodes: "Possible misused comment in text node. Comments inside children section of tag should be placed inside braces."
4179
+ },
4180
+ replacedBy: [
4181
+ "react-x/jsx-no-comment-textnodes"
4182
+ ],
4183
+ schema: []
4184
+ },
4185
+ name: RULE_NAME65,
4186
+ create: create65,
4187
+ defaultOptions: []
4188
+ });
4189
+ function create65(context) {
4190
+ function hasCommentLike(node) {
4191
+ if (AST13.isOneOf([AST_NODE_TYPES.JSXAttribute, AST_NODE_TYPES.JSXExpressionContainer])(node.parent)) {
4192
+ return false;
4193
+ }
4194
+ const rawValue = context.sourceCode.getText(node);
4195
+ return /^\s*\/(?:\/|\*)/mu.test(rawValue);
4196
+ }
4197
+ const visitorFunction = (node) => {
4198
+ if (!AST13.isOneOf([AST_NODE_TYPES.JSXElement, AST_NODE_TYPES.JSXFragment])(node.parent)) {
4199
+ return;
4200
+ }
4201
+ if (!hasCommentLike(node)) {
4202
+ return;
4203
+ }
4204
+ if (!node.parent.type.includes("JSX")) {
4205
+ return;
4206
+ }
4207
+ context.report({
4208
+ messageId: "noCommentTextnodes",
4209
+ node
4210
+ });
4211
+ };
4212
+ return {
4213
+ JSXText: visitorFunction,
4214
+ Literal: visitorFunction
4215
+ };
4216
+ }
4217
+ var RULE_NAME66 = "no-complex-conditional-rendering";
4218
+ var RULE_FEATURES65 = [
4219
+ "EXP"
4220
+ ];
4221
+ var no_complex_conditional_rendering_default = createRule({
4222
+ meta: {
4223
+ type: "problem",
4224
+ deprecated: true,
4225
+ docs: {
4226
+ description: "Disallow complex conditional rendering in JSX expressions.",
4227
+ [Symbol.for("rule_features")]: RULE_FEATURES65
4228
+ },
4229
+ messages: {
4230
+ noComplexConditionalRendering: "Avoid complex conditional rendering. Extract the logic into separate elements or components."
4231
+ },
4232
+ schema: []
4233
+ },
4234
+ name: RULE_NAME66,
4235
+ create: create66,
4236
+ defaultOptions: []
4237
+ });
4238
+ function create66(context) {
4239
+ const visitorFunction = (node) => {
4240
+ const jsxExpContainer = node.parent?.parent;
4241
+ if (!AST13.is(AST_NODE_TYPES.JSXExpressionContainer)(jsxExpContainer)) {
4242
+ return;
4243
+ }
4244
+ if (!AST13.isOneOf([AST_NODE_TYPES.JSXElement, AST_NODE_TYPES.JSXFragment])(jsxExpContainer.parent)) {
4245
+ return;
4246
+ }
4247
+ if (!jsxExpContainer.parent.children.includes(jsxExpContainer)) {
4248
+ return;
4249
+ }
4250
+ context.report({
4251
+ messageId: "noComplexConditionalRendering",
4252
+ node: jsxExpContainer
4253
+ });
4254
+ };
4255
+ return {
4256
+ "JSXExpressionContainer > ConditionalExpression > ConditionalExpression": visitorFunction,
4257
+ "JSXExpressionContainer > ConditionalExpression > LogicalExpression": visitorFunction,
4258
+ "JSXExpressionContainer > LogicalExpression > ConditionalExpression": visitorFunction,
4259
+ "JSXExpressionContainer > LogicalExpression[operator='&&'] > LogicalExpression[operator='||']": visitorFunction,
4260
+ "JSXExpressionContainer > LogicalExpression[operator='||'] > LogicalExpression[operator='&&']": visitorFunction
4261
+ };
4262
+ }
3941
4263
 
3942
4264
  // src/plugin.ts
3943
4265
  var plugin = {
@@ -4000,6 +4322,7 @@ var plugin = {
4000
4322
  "no-unused-state": no_unused_state_default,
4001
4323
  "no-use-context": no_use_context_default,
4002
4324
  "no-useless-forward-ref": no_useless_forward_ref_default,
4325
+ "no-useless-fragment": no_useless_fragment_default,
4003
4326
  "prefer-destructuring-assignment": prefer_destructuring_assignment_default,
4004
4327
  "prefer-namespace-import": prefer_namespace_import_default,
4005
4328
  "prefer-read-only-props": prefer_read_only_props_default,
@@ -4007,6 +4330,9 @@ var plugin = {
4007
4330
  // Removed rules
4008
4331
  "avoid-shorthand-boolean": avoid_shorthand_boolean_default,
4009
4332
  "avoid-shorthand-fragment": avoid_shorthand_fragment_default,
4333
+ "no-comment-textnodes": no_comment_textnodes_default,
4334
+ "no-complex-conditional-rendering": no_complex_conditional_rendering_default,
4335
+ "prefer-react-namespace-import": prefer_react_namespace_import_default,
4010
4336
  "prefer-shorthand-boolean": prefer_shorthand_boolean_default,
4011
4337
  "prefer-shorthand-fragment": prefer_shorthand_fragment_default
4012
4338
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-react-x",
3
- "version": "2.0.0-next.47",
3
+ "version": "2.0.0-next.48",
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",
@@ -42,12 +42,12 @@
42
42
  "is-immutable-type": "^5.0.1",
43
43
  "string-ts": "^2.2.1",
44
44
  "ts-pattern": "^5.7.1",
45
- "@eslint-react/ast": "2.0.0-next.47",
46
- "@eslint-react/core": "2.0.0-next.47",
47
- "@eslint-react/eff": "2.0.0-next.47",
48
- "@eslint-react/kit": "2.0.0-next.47",
49
- "@eslint-react/shared": "2.0.0-next.47",
50
- "@eslint-react/var": "2.0.0-next.47"
45
+ "@eslint-react/eff": "2.0.0-next.48",
46
+ "@eslint-react/ast": "2.0.0-next.48",
47
+ "@eslint-react/core": "2.0.0-next.48",
48
+ "@eslint-react/var": "2.0.0-next.48",
49
+ "@eslint-react/shared": "2.0.0-next.48",
50
+ "@eslint-react/kit": "2.0.0-next.48"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@types/react": "^19.1.8",