eslint-plugin-react-dom 5.30.0-beta.20 → 5.30.0-beta.22

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 +62 -7
  2. package/package.json +6 -6
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ 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
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.20";
22
+ var version = "5.30.0-beta.22";
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({
@@ -1697,7 +1751,8 @@ function create$1(context) {
1697
1751
  }
1698
1752
  function buildFix(context, node, importSource) {
1699
1753
  return (fixer) => {
1700
- return [fixer.insertTextBefore(context.sourceCode.ast, `import { useActionState } from "${importSource}";\n`), fixer.replaceText(node.callee, "useActionState")];
1754
+ const importFix = addImportFix(context, fixer, "useActionState", importSource);
1755
+ return [...importFix == null ? [] : [importFix], fixer.replaceText(node.callee, "useActionState")];
1701
1756
  };
1702
1757
  }
1703
1758
  // 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.20",
3
+ "version": "5.30.0-beta.22",
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.20",
41
- "@eslint-react/eslint": "5.30.0-beta.20",
42
- "@eslint-react/jsx": "5.30.0-beta.20",
43
- "@eslint-react/shared": "5.30.0-beta.20",
44
- "@eslint-react/var": "5.30.0-beta.20",
40
+ "@eslint-react/ast": "5.30.0-beta.22",
41
+ "@eslint-react/eslint": "5.30.0-beta.22",
42
+ "@eslint-react/jsx": "5.30.0-beta.22",
43
+ "@eslint-react/shared": "5.30.0-beta.22",
44
+ "@eslint-react/var": "5.30.0-beta.22",
45
45
  "@typescript-eslint/types": "^8.72.1",
46
46
  "@typescript-eslint/utils": "^8.72.1",
47
47
  "compare-versions": "^6.1.1",