eslint-plugin-react-jsx 5.30.0-beta.8 → 5.30.0-beta.9

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 +26 -32
  2. package/package.json +6 -6
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { DEFAULT_ESLINT_REACT_SETTINGS } from "@eslint-react/shared";
2
2
  import * as ESLintUtils from "@typescript-eslint/utils/eslint-utils";
3
- import { complete, getText } from "@eslint-react/eslint";
3
+ import { getText } from "@eslint-react/eslint";
4
4
  import { collapseMultilineText, findAttribute, findCreateElementProp, getChildren, getElementFullType, hasAnyAttribute, hasMeaningfulChildren, isFragmentElement, isHostElement, isMeaningfulChild, isPlainAttribute, isWhitespaceText, parseCreateElementCall } from "@eslint-react/jsx";
5
5
  import { Check } from "@eslint-react/ast";
6
6
  import { AST_NODE_TYPES } from "@typescript-eslint/types";
@@ -19,7 +19,7 @@ var __exportAll = (all, no_symbols) => {
19
19
  };
20
20
  // package.json
21
21
  var name$2 = "eslint-plugin-react-jsx";
22
- var version = "5.30.0-beta.8";
22
+ var version = "5.30.0-beta.9";
23
23
  // src/utils/create-rule.ts
24
24
  function getDocsUrl(ruleName) {
25
25
  return `https://eslint-react.xyz/docs/rules/jsx-${ruleName}`;
@@ -402,59 +402,54 @@ function create$1(context) {
402
402
  });
403
403
  } };
404
404
  }
405
- // src/rules/no-useless-fragment/no-useless-fragment.ts
406
- const RULE_NAME = "no-useless-fragment";
407
- const defaultOptions = [{
408
- allowEmptyFragment: false,
409
- allowExpressions: true
410
- }];
411
- const schema = [{
412
- type: "object",
413
- additionalProperties: false,
414
- properties: {
415
- allowEmptyFragment: {
416
- type: "boolean",
417
- description: "Allow empty fragments"
418
- },
419
- allowExpressions: {
420
- type: "boolean",
421
- description: "Allow fragments with a single expression child"
422
- }
423
- }
424
- }];
425
405
  var no_useless_fragment_default = createRule({
426
406
  meta: {
427
407
  type: "suggestion",
428
- defaultOptions: [...defaultOptions],
408
+ defaultOptions: [{}],
429
409
  docs: { description: "Disallows useless fragment elements." },
430
410
  fixable: "code",
431
411
  messages: { default: "A fragment {{reason}} is useless." },
432
- schema
412
+ schema: [{
413
+ type: "object",
414
+ additionalProperties: false,
415
+ properties: {
416
+ allowEmptyFragment: {
417
+ type: "boolean",
418
+ description: "Allow empty fragments"
419
+ },
420
+ allowExpressions: {
421
+ type: "boolean",
422
+ description: "Allow fragments with a single expression child"
423
+ }
424
+ }
425
+ }]
433
426
  },
434
- name: RULE_NAME,
427
+ name: "no-useless-fragment",
435
428
  create
436
429
  });
437
430
  function create(context) {
438
- const options = complete(context.options[0], defaultOptions[0]);
431
+ const options = { ...context.options[0] ?? {} };
432
+ const allowEmptyFragment = options.allowEmptyFragment ??= false;
433
+ const allowExpressions = options.allowExpressions ??= true;
439
434
  const { jsxFragmentFactory } = core.getJSXConfig(context);
440
435
  return {
441
436
  JSXElement(node) {
442
437
  if (!isFragmentElement(node, jsxFragmentFactory)) return;
443
438
  if (hasIdentityAttribute(node)) return;
444
- visitFragment(context, node, options);
439
+ visitFragment(context, node, allowEmptyFragment, allowExpressions);
445
440
  },
446
441
  JSXFragment(node) {
447
- visitFragment(context, node, options);
442
+ visitFragment(context, node, allowEmptyFragment, allowExpressions);
448
443
  }
449
444
  };
450
445
  }
451
446
  function hasIdentityAttribute(node) {
452
447
  return node.openingElement.attributes.some((a) => a.type === AST_NODE_TYPES.JSXSpreadAttribute) || hasAnyAttribute(node, ["key", "ref"]);
453
448
  }
454
- function visitFragment(context, node, options) {
449
+ function visitFragment(context, node, allowEmptyFragment, allowExpressions) {
455
450
  const reasons = [];
456
451
  if (isHostElement(node.parent)) reasons.push("placed inside a host component");
457
- if (isContentUseless(node, options)) reasons.push("contains less than two children");
452
+ if (isContentUseless(node, allowEmptyFragment, allowExpressions)) reasons.push("contains less than two children");
458
453
  if (reasons.length === 0) return;
459
454
  const fix = buildFix(context, node);
460
455
  for (const reason of reasons) context.report({
@@ -464,8 +459,7 @@ function visitFragment(context, node, options) {
464
459
  node
465
460
  });
466
461
  }
467
- function isContentUseless(node, options) {
468
- const { allowEmptyFragment, allowExpressions } = options;
462
+ function isContentUseless(node, allowEmptyFragment, allowExpressions) {
469
463
  if (node.children.length === 0) return !allowEmptyFragment;
470
464
  const insideJSX = Check.isJSXElementOrFragment(node.parent);
471
465
  if (allowExpressions && !insideJSX && node.children.length === 1 && node.children[0]?.type === AST_NODE_TYPES.JSXText) return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-react-jsx",
3
- "version": "5.30.0-beta.8",
3
+ "version": "5.30.0-beta.9",
4
4
  "description": "ESLint React's ESLint plugin for React Flavored JSX rules.",
5
5
  "keywords": [
6
6
  "react",
@@ -37,11 +37,11 @@
37
37
  "dist"
38
38
  ],
39
39
  "dependencies": {
40
- "@eslint-react/ast": "5.30.0-beta.8",
41
- "@eslint-react/core": "5.30.0-beta.8",
42
- "@eslint-react/eslint": "5.30.0-beta.8",
43
- "@eslint-react/jsx": "5.30.0-beta.8",
44
- "@eslint-react/shared": "5.30.0-beta.8",
40
+ "@eslint-react/ast": "5.30.0-beta.9",
41
+ "@eslint-react/core": "5.30.0-beta.9",
42
+ "@eslint-react/eslint": "5.30.0-beta.9",
43
+ "@eslint-react/jsx": "5.30.0-beta.9",
44
+ "@eslint-react/shared": "5.30.0-beta.9",
45
45
  "@typescript-eslint/types": "^8.72.1",
46
46
  "@typescript-eslint/utils": "^8.72.1"
47
47
  },