eslint-plugin-react-dom 5.30.0-beta.8 → 5.30.0-rc.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 +103 -56
  2. package/package.json +8 -8
package/dist/index.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import { DEFAULT_ESLINT_REACT_SETTINGS, RE_JAVASCRIPT_PROTOCOL, getSettingsFromContext } from "@eslint-react/shared";
2
2
  import * as ESLintUtils from "@typescript-eslint/utils/eslint-utils";
3
3
  import { findAttribute, getAttributeStaticValue, getAttributeStaticValueByName, getAttributeValue, getAttributeValueByName, getElementFullType, hasAnyAttribute, hasAttribute, isEmptyExpressionContainer, isHostElement, isPaddingWhitespace, isPlainAttribute } from "@eslint-react/jsx";
4
- import { complete, getText } from "@eslint-react/eslint";
4
+ import { getText } from "@eslint-react/eslint";
5
5
  import { Check, Extract } from "@eslint-react/ast";
6
- import { AST_NODE_TYPES } from "@typescript-eslint/types";
6
+ import { AST_NODE_TYPES, AST_TOKEN_TYPES } from "@typescript-eslint/types";
7
7
  import { createImportLookup } from "@eslint-react/var";
8
8
  import { compare } from "compare-versions";
9
9
  // \0rolldown/runtime.js
@@ -19,7 +19,7 @@ var __exportAll = (all, no_symbols) => {
19
19
  };
20
20
  // package.json
21
21
  var name$2 = "eslint-plugin-react-dom";
22
- var version = "5.30.0-beta.8";
22
+ var version = "5.30.0-rc.0";
23
23
  // src/utils/create-rule.ts
24
24
  function getDocsUrl(ruleName) {
25
25
  return `https://eslint-react.xyz/docs/rules/dom-${ruleName}`;
@@ -123,6 +123,48 @@ function create$12(context) {
123
123
  });
124
124
  } };
125
125
  }
126
+ // src/utils/add-import-fix.ts
127
+ function addImportFix(context, fixer, name, source) {
128
+ const { ast } = context.sourceCode;
129
+ let lastImport = null;
130
+ let lastDirective = null;
131
+ let sameSourceImport = null;
132
+ for (const statement of ast.body) {
133
+ if (Check.isDirective(statement)) {
134
+ lastDirective = statement;
135
+ continue;
136
+ }
137
+ if (statement.type !== AST_NODE_TYPES.ImportDeclaration) continue;
138
+ lastImport = statement;
139
+ if (statement.importKind === "type") continue;
140
+ for (const specifier of statement.specifiers) {
141
+ if (specifier.type === AST_NODE_TYPES.ImportSpecifier && specifier.importKind === "type") continue;
142
+ if (specifier.local.name !== name) continue;
143
+ return null;
144
+ }
145
+ if (statement.source.value !== source) continue;
146
+ sameSourceImport ??= statement;
147
+ }
148
+ const lastNamedSpecifier = (sameSourceImport?.specifiers.filter((s) => s.type === AST_NODE_TYPES.ImportSpecifier) ?? []).at(-1);
149
+ if (lastNamedSpecifier != null) return fixer.insertTextAfter(lastNamedSpecifier, `, ${name}`);
150
+ const text = `import { ${name} } from "${source}";`;
151
+ const eol = context.sourceCode.text.includes("\r\n") ? "\r\n" : "\n";
152
+ if (lastImport != null) return fixer.insertTextAfterRange(getLineEndAnchor(context, lastImport), `${eol}${text}`);
153
+ if (lastDirective != null) return fixer.insertTextAfterRange(getLineEndAnchor(context, lastDirective), `${eol}${text}`);
154
+ const lastComment = (ast.body[0] == null ? ast.comments : context.sourceCode.getCommentsBefore(ast.body[0])).at(-1);
155
+ if (lastComment != null) return fixer.insertTextAfter(lastComment, `${eol}${text}`);
156
+ return fixer.insertTextBefore(ast, `${text}${eol}`);
157
+ }
158
+ function getLineEndAnchor(context, node) {
159
+ let anchor = node;
160
+ for (;;) {
161
+ const next = context.sourceCode.getTokenAfter(anchor, { includeComments: true });
162
+ if (next == null || next.type !== AST_TOKEN_TYPES.Line && next.type !== AST_TOKEN_TYPES.Block) break;
163
+ if (next.loc.start.line !== anchor.loc.end.line) break;
164
+ anchor = next;
165
+ }
166
+ return anchor.range;
167
+ }
126
168
  var no_hydrate_default = createRule({
127
169
  meta: {
128
170
  type: "problem",
@@ -151,8 +193,14 @@ function create$11(context) {
151
193
  function buildFix$2(context, node) {
152
194
  return (fixer) => {
153
195
  const [arg0, arg1] = node.arguments;
154
- if (arg0 == null || arg1 == null) return null;
155
- return [fixer.insertTextBefore(context.sourceCode.ast, "import { hydrateRoot } from \"react-dom/client\";\n"), fixer.replaceText(node, `hydrateRoot(${getText(context, arg1)}, ${getText(context, arg0)})`)];
196
+ if (arg0 == null) return null;
197
+ if (arg1 == null) return null;
198
+ if (node.arguments.length !== 2) return null;
199
+ if (arg0.type === AST_NODE_TYPES.SpreadElement) return null;
200
+ if (arg1.type === AST_NODE_TYPES.SpreadElement) return null;
201
+ if (node.parent.type !== AST_NODE_TYPES.ExpressionStatement) return null;
202
+ const importFix = addImportFix(context, fixer, "hydrateRoot", "react-dom/client");
203
+ return [...importFix == null ? [] : [importFix], fixer.replaceText(node, `hydrateRoot(${getText(context, arg1)}, ${getText(context, arg0)})`)];
156
204
  };
157
205
  }
158
206
  // ../../.pkgs/eff/dist/index.js
@@ -434,8 +482,14 @@ function create$7(context) {
434
482
  function buildFix$1(context, node) {
435
483
  return (fixer) => {
436
484
  const [arg0, arg1] = node.arguments;
437
- if (arg0 == null || arg1 == null) return null;
438
- return [fixer.insertTextBefore(context.sourceCode.ast, "import { createRoot } from \"react-dom/client\";\n"), fixer.replaceText(node, `createRoot(${getText(context, arg1)}).render(${getText(context, arg0)})`)];
485
+ if (arg0 == null) return null;
486
+ if (arg1 == null) return null;
487
+ if (node.arguments.length !== 2) return null;
488
+ if (arg0.type === AST_NODE_TYPES.SpreadElement) return null;
489
+ if (arg1.type === AST_NODE_TYPES.SpreadElement) return null;
490
+ if (node.parent.type !== AST_NODE_TYPES.ExpressionStatement) return null;
491
+ const importFix = addImportFix(context, fixer, "createRoot", "react-dom/client");
492
+ return [...importFix == null ? [] : [importFix], fixer.replaceText(node, `createRoot(${getText(context, arg1)}).render(${getText(context, arg0)})`)];
439
493
  };
440
494
  }
441
495
  var no_script_url_default = createRule({
@@ -1479,47 +1533,41 @@ function getStandardName(name, context) {
1479
1533
  const lookup = getStandardNameLookup(version);
1480
1534
  return lookup.exact.get(name) ?? lookup.lower.get(name.toLowerCase()) ?? null;
1481
1535
  }
1482
- // src/rules/no-unknown-property/no-unknown-property.ts
1483
- const RULE_NAME$4 = "no-unknown-property";
1484
- const defaultOptions$1 = [{
1485
- ignore: [],
1486
- requireDataLowercase: false
1487
- }];
1488
- const schema$1 = [{
1489
- type: "object",
1490
- additionalProperties: false,
1491
- properties: {
1492
- ignore: {
1493
- type: "array",
1494
- description: "Property names to ignore.",
1495
- items: { type: "string" }
1496
- },
1497
- requireDataLowercase: {
1498
- type: "boolean",
1499
- description: "Require lowercase names for data-* attributes."
1500
- }
1501
- }
1502
- }];
1503
- const messages = {
1504
- "data-lowercase-required": "React does not recognize data-* props with uppercase characters on a DOM element. Found '{{name}}', use '{{lowerCaseName}}' instead",
1505
- "invalid-prop-on-tag": "Invalid property '{{name}}' found on tag '{{tagName}}', but it is only allowed on: {{allowedTags}}",
1506
- "unknown-prop": "Unknown property '{{name}}' found",
1507
- "unknown-prop-with-standard-name": "Unknown property '{{name}}' found, use '{{standardName}}' instead"
1508
- };
1509
1536
  var no_unknown_property_default = createRule({
1510
1537
  meta: {
1511
1538
  type: "problem",
1512
- defaultOptions: [...defaultOptions$1],
1539
+ defaultOptions: [{}],
1513
1540
  docs: { description: "Disallows unknown 'DOM' properties." },
1514
1541
  fixable: "code",
1515
- messages,
1516
- schema: schema$1
1542
+ messages: {
1543
+ "data-lowercase-required": "React does not recognize data-* props with uppercase characters on a DOM element. Found '{{name}}', use '{{lowerCaseName}}' instead",
1544
+ "invalid-prop-on-tag": "Invalid property '{{name}}' found on tag '{{tagName}}', but it is only allowed on: {{allowedTags}}",
1545
+ "unknown-prop": "Unknown property '{{name}}' found",
1546
+ "unknown-prop-with-standard-name": "Unknown property '{{name}}' found, use '{{standardName}}' instead"
1547
+ },
1548
+ schema: [{
1549
+ type: "object",
1550
+ additionalProperties: false,
1551
+ properties: {
1552
+ ignore: {
1553
+ type: "array",
1554
+ description: "Property names to ignore.",
1555
+ items: { type: "string" }
1556
+ },
1557
+ requireDataLowercase: {
1558
+ type: "boolean",
1559
+ description: "Require lowercase names for data-* attributes."
1560
+ }
1561
+ }
1562
+ }]
1517
1563
  },
1518
- name: RULE_NAME$4,
1564
+ name: "no-unknown-property",
1519
1565
  create: create$4
1520
1566
  });
1521
1567
  function create$4(context) {
1522
- const { ignore, requireDataLowercase } = complete(context.options[0], defaultOptions$1[0]);
1568
+ const options = context.options[0] ?? {};
1569
+ const ignore = options.ignore ?? [];
1570
+ const requireDataLowercase = options.requireDataLowercase ?? false;
1523
1571
  let attributeTagsMap = null;
1524
1572
  return { JSXAttribute(node) {
1525
1573
  const actualName = getText(context, node.name);
@@ -1599,7 +1647,9 @@ function create$3(context) {
1599
1647
  const sandboxValue = getAttributeValueByName(node, "sandbox");
1600
1648
  if (sandboxValue == null) return;
1601
1649
  const value = getAttributeStaticValue(context, sandboxValue);
1602
- if (!isString(value) || !UNSAFE_SANDBOX_VALUES.every((a) => value.includes(a))) return;
1650
+ if (!isString(value)) return;
1651
+ const tokens = new Set(value.split(/\s+/u));
1652
+ if (!UNSAFE_SANDBOX_VALUES.every((a) => tokens.has(a))) return;
1603
1653
  context.report({
1604
1654
  messageId: "default",
1605
1655
  node: getAttributeReportNode(sandboxValue)
@@ -1616,21 +1666,10 @@ function isSafeRel(value, allowReferrer) {
1616
1666
  if (/\bnoreferrer\b/u.test(value)) return true;
1617
1667
  return allowReferrer && /\bnoopener\b/u.test(value);
1618
1668
  }
1619
- // src/rules/no-unsafe-target-blank/no-unsafe-target-blank.ts
1620
- const RULE_NAME$2 = "no-unsafe-target-blank";
1621
- const defaultOptions = [{ allowReferrer: false }];
1622
- const schema = [{
1623
- type: "object",
1624
- additionalProperties: false,
1625
- properties: { allowReferrer: {
1626
- type: "boolean",
1627
- description: "Allow 'rel=\"noopener\"' without 'noreferrer' so referrer information is preserved."
1628
- } }
1629
- }];
1630
1669
  var no_unsafe_target_blank_default = createRule({
1631
1670
  meta: {
1632
1671
  type: "problem",
1633
- defaultOptions: [...defaultOptions],
1672
+ defaultOptions: [{}],
1634
1673
  docs: { description: "Disallows 'target=\"_blank\"' without 'rel=\"noreferrer\"'." },
1635
1674
  fixable: "code",
1636
1675
  hasSuggestions: true,
@@ -1638,13 +1677,20 @@ var no_unsafe_target_blank_default = createRule({
1638
1677
  default: `Using 'target="_blank"' on an external link without '{{rel}}' is a security risk.`,
1639
1678
  suggest: `Add '{{rel}}' to the link to prevent security risks.`
1640
1679
  },
1641
- schema
1680
+ schema: [{
1681
+ type: "object",
1682
+ additionalProperties: false,
1683
+ properties: { allowReferrer: {
1684
+ type: "boolean",
1685
+ description: "Allow 'rel=\"noopener\"' without 'noreferrer' so referrer information is preserved."
1686
+ } }
1687
+ }]
1642
1688
  },
1643
- name: RULE_NAME$2,
1689
+ name: "no-unsafe-target-blank",
1644
1690
  create: create$2
1645
1691
  });
1646
1692
  function create$2(context) {
1647
- const { allowReferrer } = complete(context.options[0], defaultOptions[0]);
1693
+ const allowReferrer = (context.options[0] ?? {}).allowReferrer ?? false;
1648
1694
  const resolver = createJSXElementResolver(context);
1649
1695
  const requiredRelAttribute = `rel="${allowReferrer ? "noopener" : "noreferrer"}"`;
1650
1696
  return { JSXElement(node) {
@@ -1707,7 +1753,8 @@ function create$1(context) {
1707
1753
  }
1708
1754
  function buildFix(context, node, importSource) {
1709
1755
  return (fixer) => {
1710
- return [fixer.insertTextBefore(context.sourceCode.ast, `import { useActionState } from "${importSource}";\n`), fixer.replaceText(node.callee, "useActionState")];
1756
+ const importFix = addImportFix(context, fixer, "useActionState", importSource);
1757
+ return [...importFix == null ? [] : [importFix], fixer.replaceText(node.callee, "useActionState")];
1711
1758
  };
1712
1759
  }
1713
1760
  // src/rules/no-void-elements-with-children/lib.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-react-dom",
3
- "version": "5.30.0-beta.8",
3
+ "version": "5.30.0-rc.0",
4
4
  "description": "ESLint React's ESLint plugin for DOM related 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/eslint": "5.30.0-beta.8",
42
- "@eslint-react/jsx": "5.30.0-beta.8",
43
- "@eslint-react/shared": "5.30.0-beta.8",
44
- "@eslint-react/var": "5.30.0-beta.8",
40
+ "@eslint-react/ast": "5.30.0-rc.0",
41
+ "@eslint-react/eslint": "5.30.0-rc.0",
42
+ "@eslint-react/jsx": "5.30.0-rc.0",
43
+ "@eslint-react/shared": "5.30.0-rc.0",
44
+ "@eslint-react/var": "5.30.0-rc.0",
45
45
  "@typescript-eslint/types": "^8.72.1",
46
46
  "@typescript-eslint/utils": "^8.72.1",
47
47
  "compare-versions": "^6.1.1",
@@ -56,8 +56,8 @@
56
56
  "@types/react": "^19.3.0",
57
57
  "@types/react-dom": "^19.3.0",
58
58
  "dedent": "^1.7.2",
59
- "eslint": "^10.13.0",
60
- "tsdown": "^0.23.2",
59
+ "eslint": "^10.14.0",
60
+ "tsdown": "^0.23.5",
61
61
  "typescript": "6.0.3"
62
62
  },
63
63
  "peerDependencies": {