@murky-web/oxlint-plugin-solid 1.5.0 → 1.6.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 (45) hide show
  1. package/README.md +163 -18
  2. package/THIRD_PARTY_NOTICES.md +7 -4
  3. package/package.json +5 -2
  4. package/src/compat.mjs +3 -0
  5. package/src/index.mjs +26 -3
  6. package/src/rules/components_return_once.mjs +136 -89
  7. package/src/rules/event_handlers.mjs +55 -35
  8. package/src/rules/filename_matches_export.mjs +292 -0
  9. package/src/rules/function_size.mjs +189 -0
  10. package/src/rules/imports.mjs +24 -21
  11. package/src/rules/init_declarations.mjs +139 -0
  12. package/src/rules/jsx_no_duplicate_props.mjs +46 -18
  13. package/src/rules/jsx_no_script_url.mjs +7 -6
  14. package/src/rules/jsx_no_undef.mjs +35 -38
  15. package/src/rules/jsx_uses_vars.mjs +4 -4
  16. package/src/rules/no_array_handlers.mjs +38 -9
  17. package/src/rules/no_cleanup_in_effect_apply.mjs +154 -0
  18. package/src/rules/no_destructure.mjs +105 -35
  19. package/src/rules/no_innerhtml.mjs +64 -31
  20. package/src/rules/no_module_scope_reactive_primitive.mjs +73 -0
  21. package/src/rules/no_owned_primitives_in_ref.mjs +30 -9
  22. package/src/rules/no_proxy_apis.mjs +44 -15
  23. package/src/rules/no_react_deps.mjs +397 -41
  24. package/src/rules/no_react_specific_props.mjs +40 -11
  25. package/src/rules/no_server_import_in_client.mjs +9 -9
  26. package/src/rules/no_setter_in_effect.mjs +153 -30
  27. package/src/rules/no_single_arg_create_effect.mjs +55 -0
  28. package/src/rules/no_unassigned_vars.mjs +99 -0
  29. package/src/rules/no_unknown_namespaces.mjs +108 -29
  30. package/src/rules/no_untracked_effect_read.mjs +69 -32
  31. package/src/rules/no_write_in_pure_computation.mjs +273 -0
  32. package/src/rules/prefer_arrow_components.mjs +47 -21
  33. package/src/rules/prefer_class_object.mjs +52 -20
  34. package/src/rules/prefer_destructuring.mjs +164 -0
  35. package/src/rules/prefer_for.mjs +42 -12
  36. package/src/rules/prefer_ref_shorthand.mjs +142 -0
  37. package/src/rules/prefer_show.mjs +55 -24
  38. package/src/rules/reactive_async.mjs +64 -17
  39. package/src/rules/reactivity.mjs +1218 -350
  40. package/src/rules/self_closing_comp.mjs +23 -18
  41. package/src/rules/strict_void_return.mjs +50 -20
  42. package/src/rules/style_prop.mjs +53 -25
  43. package/src/rules/typed_merge_defaults.mjs +88 -0
  44. package/src/rules/validate_jsx_nesting.mjs +16 -16
  45. package/src/utils.mjs +65 -34
@@ -0,0 +1,292 @@
1
+ // A `.tsx`/`.jsx` file that exports a component is named after it
2
+ // (`Navigate.tsx` exports `Navigate`); one that only uses JSX stays snake_case
3
+ // (`solid_ssr_renderer.tsx`). unicorn/filename-case allows both cases for
4
+ // these files, this rule decides which one applies. Route folders follow the
5
+ // router's own naming and are skipped through `ignore`.
6
+ import { basename, relative } from "node:path";
7
+
8
+ const JSX_FILE = /\.[jt]sx$/u;
9
+ const PASCAL_NAME = /^[A-Z]/u;
10
+ // Router files follow the router's naming; fixtures and tests export many
11
+ // throwaway components and are named after what they test.
12
+ const DEFAULT_IGNORE = [
13
+ "**/pages/**",
14
+ "**/routes/**",
15
+ "**/*.fixture.*",
16
+ "**/*.test.*",
17
+ "**/*.spec.*"
18
+ ];
19
+
20
+ function isFunction(node) {
21
+ let inner = node;
22
+ // `const Counter = (() => …) satisfies Component`
23
+ while (
24
+ inner?.type === "TSAsExpression" ||
25
+ inner?.type === "TSSatisfiesExpression" ||
26
+ inner?.type === "ParenthesizedExpression"
27
+ ) {
28
+ inner = inner.expression;
29
+ }
30
+ return (
31
+ inner?.type === "ArrowFunctionExpression" ||
32
+ inner?.type === "FunctionExpression" ||
33
+ inner?.type === "FunctionDeclaration"
34
+ );
35
+ }
36
+
37
+ // ponytail: `**`, `*` and `?` only; no braces or character classes.
38
+ function globToRegExp(glob) {
39
+ const source = glob
40
+ .split(/(\*\*\/|\*\*|\*|\?)/u)
41
+ .map((part) => {
42
+ if (part === "**/") {
43
+ return "(?:.*/)?";
44
+ }
45
+ if (part === "**") {
46
+ return ".*";
47
+ }
48
+ if (part === "*") {
49
+ return "[^/]*";
50
+ }
51
+ if (part === "?") {
52
+ return "[^/]";
53
+ }
54
+ return part.replaceAll(/[.+^${}()|[\]\\]/gu, String.raw`\$&`);
55
+ })
56
+ .join("");
57
+ return new RegExp(`^${source}$`, "u");
58
+ }
59
+
60
+ export function toSnakeCase(name) {
61
+ const leading = /^_*/u.exec(name)[0];
62
+ return (
63
+ leading +
64
+ name
65
+ .slice(leading.length)
66
+ .replaceAll(/([a-z0-9])([A-Z])/gu, "$1_$2")
67
+ .replaceAll(/([A-Z]+)([A-Z][a-z])/gu, "$1_$2")
68
+ .replaceAll(/[\s-]+/gu, "_")
69
+ .replaceAll(/_+/gu, "_")
70
+ .toLowerCase()
71
+ );
72
+ }
73
+
74
+ // Top-level names bound to a function, exported or not, so `export { C }`
75
+ // and `export default C` can be resolved.
76
+ function collectFunctionBindings(program) {
77
+ const functions = new Set();
78
+ for (const statement of program.body) {
79
+ const declaration =
80
+ statement.type === "ExportNamedDeclaration"
81
+ ? statement.declaration
82
+ : statement;
83
+ if (declaration?.type === "FunctionDeclaration" && declaration.id) {
84
+ functions.add(declaration.id.name);
85
+ }
86
+ if (declaration?.type === "VariableDeclaration") {
87
+ for (const declarator of declaration.declarations) {
88
+ if (
89
+ declarator.id.type === "Identifier" &&
90
+ isFunction(declarator.init)
91
+ ) {
92
+ functions.add(declarator.id.name);
93
+ }
94
+ }
95
+ }
96
+ }
97
+ return functions;
98
+ }
99
+
100
+ // The exported components: `{ name, node }` for every PascalCase export bound
101
+ // to a function, and the default export separately. Type-only exports are
102
+ // left out. A PascalCase re-export of a local module (`export { default as
103
+ // Counter } from "./CounterComponent"`) counts as the component it names: the
104
+ // module it comes from is not visible here, and the name is the convention.
105
+ function collectComponents(program) {
106
+ const functions = collectFunctionBindings(program);
107
+ const named = [];
108
+ let defaultComponent = null;
109
+ for (const statement of program.body) {
110
+ if (
111
+ statement.type === "ExportNamedDeclaration" &&
112
+ statement.exportKind !== "type" &&
113
+ statement.source === null
114
+ ) {
115
+ const { declaration } = statement;
116
+ if (declaration?.type === "FunctionDeclaration" && declaration.id) {
117
+ named.push({ name: declaration.id.name, node: declaration.id });
118
+ }
119
+ if (declaration?.type === "VariableDeclaration") {
120
+ for (const declarator of declaration.declarations) {
121
+ if (
122
+ declarator.id.type === "Identifier" &&
123
+ isFunction(declarator.init)
124
+ ) {
125
+ named.push({
126
+ name: declarator.id.name,
127
+ node: declarator.id
128
+ });
129
+ }
130
+ }
131
+ }
132
+ for (const specifier of statement.specifiers) {
133
+ if (
134
+ specifier.exportKind !== "type" &&
135
+ functions.has(specifier.local.name) &&
136
+ specifier.exported.type === "Identifier" &&
137
+ specifier.exported.name !== "default"
138
+ ) {
139
+ named.push({
140
+ name: specifier.exported.name,
141
+ node: specifier.exported
142
+ });
143
+ }
144
+ }
145
+ }
146
+ if (
147
+ statement.type === "ExportNamedDeclaration" &&
148
+ statement.exportKind !== "type" &&
149
+ // A local module re-exported under its component's name; a
150
+ // re-export from a package (`export { Show } from "solid-js"`)
151
+ // is not this file's component.
152
+ typeof statement.source?.value === "string" &&
153
+ statement.source.value.startsWith(".")
154
+ ) {
155
+ for (const specifier of statement.specifiers) {
156
+ if (
157
+ specifier.exportKind !== "type" &&
158
+ specifier.exported.type === "Identifier" &&
159
+ /^[A-Z]/u.test(specifier.exported.name)
160
+ ) {
161
+ named.push({
162
+ name: specifier.exported.name,
163
+ node: specifier.exported
164
+ });
165
+ }
166
+ }
167
+ }
168
+ if (statement.type === "ExportDefaultDeclaration") {
169
+ const { declaration } = statement;
170
+ if (isFunction(declaration) && declaration.id) {
171
+ defaultComponent = {
172
+ name: declaration.id.name,
173
+ node: declaration.id
174
+ };
175
+ }
176
+ if (
177
+ declaration.type === "Identifier" &&
178
+ functions.has(declaration.name)
179
+ ) {
180
+ defaultComponent = {
181
+ name: declaration.name,
182
+ node: declaration
183
+ };
184
+ }
185
+ }
186
+ }
187
+ const isComponent = (entry) => PASCAL_NAME.test(entry.name);
188
+ return {
189
+ defaultComponent:
190
+ defaultComponent !== null && isComponent(defaultComponent)
191
+ ? defaultComponent
192
+ : null,
193
+ named: named.filter(isComponent)
194
+ };
195
+ }
196
+
197
+ export default {
198
+ meta: {
199
+ type: "suggestion",
200
+ docs: {
201
+ description:
202
+ "Name a `.tsx`/`.jsx` file after the component it exports, and keep files without a component snake_case.",
203
+ url: "https://github.com/MurkyTheMurloc/web_dev_tools/tree/main/packages/oxlint-plugin-solid#solidfilename-matches-export"
204
+ },
205
+ schema: [
206
+ {
207
+ type: "object",
208
+ properties: {
209
+ ignore: {
210
+ type: "array",
211
+ items: { type: "string" },
212
+ description:
213
+ "Globs of files the rule skips; route folders follow the router's naming."
214
+ }
215
+ },
216
+ additionalProperties: false
217
+ }
218
+ ],
219
+ messages: {
220
+ componentName:
221
+ "The file `{{file}}` exports the component `{{component}}`, so imports and the file tree disagree on its name and searching for the component does not find the file. Fix: rename the file to `{{expected}}`. Do not: rename the export to match the file; the component's name is the source of truth.",
222
+ snakeCase:
223
+ "The file `{{file}}` exports no component, but a PascalCase name marks a component file, so readers and agents look for a component that is not there. Fix: rename the file to `{{expected}}`. Do not: export a component only to justify the name."
224
+ }
225
+ },
226
+ defaultOptions: [],
227
+ create(context) {
228
+ const filename = context.filename ?? context.getFilename();
229
+ const file = basename(filename);
230
+ if (!JSX_FILE.test(file)) {
231
+ return {};
232
+ }
233
+ const ignore = (context.options[0]?.ignore ?? DEFAULT_IGNORE).map(
234
+ globToRegExp
235
+ );
236
+ const paths = [
237
+ filename.replaceAll("\\", "/"),
238
+ relative(context.cwd ?? process.cwd(), filename).replaceAll(
239
+ "\\",
240
+ "/"
241
+ )
242
+ ];
243
+ if (ignore.some((glob) => paths.some((path) => glob.test(path)))) {
244
+ return {};
245
+ }
246
+ // `Counter.island.tsx`, `island_hydration.test.tsx`: the name is the
247
+ // part before the first dot, the rest stays as it is.
248
+ const dot = file.indexOf(".");
249
+ const base = file.slice(0, dot);
250
+ const rest = file.slice(dot);
251
+ if (base === "index") {
252
+ return {};
253
+ }
254
+
255
+ return {
256
+ Program(program) {
257
+ const { defaultComponent, named } = collectComponents(program);
258
+ if (defaultComponent !== null || named.length > 0) {
259
+ const target = defaultComponent ?? named[0];
260
+ if (
261
+ defaultComponent === null
262
+ ? named.some((entry) => entry.name === base)
263
+ : defaultComponent.name === base
264
+ ) {
265
+ return;
266
+ }
267
+ context.report({
268
+ data: {
269
+ component: target.name,
270
+ expected: `${target.name}${rest}`,
271
+ file
272
+ },
273
+ messageId: "componentName",
274
+ node: target.node
275
+ });
276
+ return;
277
+ }
278
+ const expected = toSnakeCase(base);
279
+ if (expected !== base) {
280
+ context.report({
281
+ data: { expected: `${expected}${rest}`, file },
282
+ loc: {
283
+ end: { column: 0, line: 1 },
284
+ start: { column: 0, line: 1 }
285
+ },
286
+ messageId: "snakeCase"
287
+ });
288
+ }
289
+ }
290
+ };
291
+ }
292
+ };
@@ -0,0 +1,189 @@
1
+ // eslint's max-lines-per-function (skipBlankLines, skipComments, IIFEs) with a
2
+ // message per kind of function. oxlint can neither change a built-in rule's
3
+ // message nor wrap it from a JS plugin, so the counting is redone here. A Solid
4
+ // component runs once, so extracting from it costs nothing; the messages name
5
+ // what to extract and where, and the two ways extraction breaks reactivity
6
+ // (destructured props, a primitive that gets a value instead of an accessor).
7
+ import { getFunctionHeadLocation } from "@eslint-community/eslint-utils";
8
+
9
+ import { getSourceCode } from "../compat.mjs";
10
+ import { getFunctionName } from "../utils.mjs";
11
+
12
+ const DEFAULT_MAX = 60;
13
+ const DEFAULT_MAX_COMPONENT = 80;
14
+ const COMPONENT_NAME = /^[A-Z]/u;
15
+ const PRIMITIVE_NAME = /^(?:create|use)[A-Z0-9]/u;
16
+ const JSX_FILE = /\.[jt]sx$/u;
17
+ const DO_NOT_SPLIT =
18
+ "If splitting would scatter one cohesive unit, leave it and add a one-line comment above `{{name}}` saying why.";
19
+
20
+ // Code lines of the file as a prefix sum: `counts[line]` is the number of
21
+ // lines up to and including `line` that keep text once comments are blanked.
22
+ function countCodeLines(sourceCode) {
23
+ const text = sourceCode.text.split("");
24
+ const comments = sourceCode.getAllComments?.() ?? sourceCode.ast.comments;
25
+ for (const comment of comments) {
26
+ const [start, end] = comment.range ?? [comment.start, comment.end];
27
+ for (let index = start; index < end; index += 1) {
28
+ if (text[index] !== "\n") {
29
+ text[index] = " ";
30
+ }
31
+ }
32
+ }
33
+ const counts = [0];
34
+ for (const line of text.join("").split("\n")) {
35
+ counts.push(counts.at(-1) + (line.trim() === "" ? 0 : 1));
36
+ }
37
+
38
+ return counts;
39
+ }
40
+
41
+ function nameOf(node, sourceCode) {
42
+ const name = getFunctionName(node);
43
+ if (name !== null) {
44
+ return name;
45
+ }
46
+ const { parent } = node;
47
+ if (
48
+ (parent.type === "Property" ||
49
+ parent.type === "MethodDefinition" ||
50
+ parent.type === "PropertyDefinition") &&
51
+ !parent.computed
52
+ ) {
53
+ return parent.key.name ?? String(parent.key.value);
54
+ }
55
+ if (parent.type === "AssignmentExpression") {
56
+ return sourceCode.getText(parent.left);
57
+ }
58
+ if (parent.type === "CallExpression" && parent.callee !== node) {
59
+ return `${sourceCode.getText(parent.callee)} callback`;
60
+ }
61
+ if (parent.type === "ExportDefaultDeclaration") {
62
+ return "default export";
63
+ }
64
+
65
+ return "anonymous function";
66
+ }
67
+
68
+ export default {
69
+ meta: {
70
+ type: "suggestion",
71
+ docs: {
72
+ description:
73
+ "Limit the code lines of a function, with a stricter message for components and `createX` primitives.",
74
+ url: "https://github.com/MurkyTheMurloc/web_dev_tools/tree/main/packages/oxlint-plugin-solid#solidfunction-size"
75
+ },
76
+ schema: [
77
+ {
78
+ type: "object",
79
+ properties: {
80
+ max: {
81
+ type: "integer",
82
+ minimum: 1,
83
+ description:
84
+ "Code lines for a function or primitive (blank and comment lines don't count)."
85
+ },
86
+ maxComponent: {
87
+ type: "integer",
88
+ minimum: 1,
89
+ description:
90
+ "Code lines for a component: a PascalCase function with JSX in a `.tsx`/`.jsx` file."
91
+ }
92
+ },
93
+ additionalProperties: false
94
+ }
95
+ ],
96
+ messages: {
97
+ function: `\`{{name}}\` has {{lines}} code lines (max {{max}}; blank and comment lines don't count), so several jobs share one body and none can be tested or reused alone. Fix: move each self-contained step (lines {{start}}–{{end}} first) into a named pure helper that takes its inputs as parameters and returns a value; put a helper used by more than one file in its own snake_case \`.ts\`. ${DO_NOT_SPLIT} Do not: delete comments, join lines, split into \`{{name}}Part1\`/\`Part2\` that just run in sequence, or add \`// oxlint-disable\`.`,
98
+ component: `Component \`{{name}}\` has {{lines}} code lines (max {{max}}), so several pieces of UI and their state can't be reused or tested separately. Fix: move repeated or self-contained JSX into a sub-component in its own PascalCase \`.tsx\` that receives values (\`<Slot label={label()} />\`, read as \`props.label\`); move signals, memos and effects that belong together into a \`createX\` primitive in a snake_case \`.ts\` that takes accessors (\`createX(() => props.id)\`) and returns accessors. ${DO_NOT_SPLIT} Do not: destructure props, pass \`props.x\` or \`count()\` into a helper or primitive (it is read once), delete comments, join lines, or add \`// oxlint-disable\`.`,
99
+ primitive: `Primitive \`{{name}}\` has {{lines}} code lines (max {{max}}; blank and comment lines don't count), so several concerns share one owner and none can be reused or tested alone. Fix: split it by concern into smaller \`createX\` primitives (lines {{start}}–{{end}} first) in snake_case \`.ts\` files that take accessors (\`createX(() => props.id)\`) and return accessors, and let \`{{name}}\` compose them. ${DO_NOT_SPLIT} Do not: pass \`props.x\` or \`count()\` into a primitive (it is read once), return plain values instead of accessors, delete comments, join lines, or add \`// oxlint-disable\`.`
100
+ }
101
+ },
102
+ defaultOptions: [],
103
+ create(context) {
104
+ const sourceCode = getSourceCode(context);
105
+ const max = context.options[0]?.max ?? DEFAULT_MAX;
106
+ const maxComponent =
107
+ context.options[0]?.maxComponent ?? DEFAULT_MAX_COMPONENT;
108
+ const jsxFile = JSX_FILE.test(
109
+ context.filename ?? context.getFilename()
110
+ );
111
+ const smallest = Math.min(max, jsxFile ? maxComponent : max);
112
+ // One frame per open function; JSX marks every enclosing frame.
113
+ const stack = [];
114
+ let counts = null;
115
+ const codeLines = (node) => {
116
+ counts ??= countCodeLines(sourceCode);
117
+
118
+ return counts[node.loc.end.line] - counts[node.loc.start.line - 1];
119
+ };
120
+
121
+ // The longest top-level statement is where an agent starts extracting.
122
+ const longestStatement = (node) => {
123
+ const statements =
124
+ node.body.type === "BlockStatement" && node.body.body.length > 0
125
+ ? node.body.body
126
+ : [node.body];
127
+
128
+ return statements.reduce((longest, statement) => {
129
+ return codeLines(statement) > codeLines(longest)
130
+ ? statement
131
+ : longest;
132
+ });
133
+ };
134
+
135
+ const exit = (node) => {
136
+ const { hasJsx } = stack.pop();
137
+ if (
138
+ node.body === null ||
139
+ node.loc.end.line - node.loc.start.line + 1 <= smallest
140
+ ) {
141
+ return;
142
+ }
143
+ const name = nameOf(node, sourceCode);
144
+ const component = jsxFile && hasJsx && COMPONENT_NAME.test(name);
145
+ const limit = component ? maxComponent : max;
146
+ const lines = codeLines(node);
147
+ if (lines <= limit) {
148
+ return;
149
+ }
150
+ const start = longestStatement(node);
151
+ let messageId = "function";
152
+ if (component) {
153
+ messageId = "component";
154
+ } else if (PRIMITIVE_NAME.test(name)) {
155
+ messageId = "primitive";
156
+ }
157
+ context.report({
158
+ data: {
159
+ end: start.loc.end.line,
160
+ lines,
161
+ max: limit,
162
+ name,
163
+ start: start.loc.start.line
164
+ },
165
+ loc: getFunctionHeadLocation(node, sourceCode),
166
+ messageId
167
+ });
168
+ };
169
+ const enter = () => {
170
+ stack.push({ hasJsx: false });
171
+ };
172
+ const markJsx = () => {
173
+ for (const frame of stack) {
174
+ frame.hasJsx = true;
175
+ }
176
+ };
177
+
178
+ return {
179
+ ArrowFunctionExpression: enter,
180
+ "ArrowFunctionExpression:exit": exit,
181
+ FunctionDeclaration: enter,
182
+ "FunctionDeclaration:exit": exit,
183
+ FunctionExpression: enter,
184
+ "FunctionExpression:exit": exit,
185
+ JSXElement: markJsx,
186
+ JSXFragment: markJsx
187
+ };
188
+ }
189
+ };
@@ -3,7 +3,7 @@ import {
3
3
  appendImports,
4
4
  canTakeSpecifier,
5
5
  insertImports,
6
- removeSpecifier,
6
+ removeSpecifier
7
7
  } from "../utils.mjs";
8
8
  // Solid 2.0 moved the renderers into `@solidjs/*` packages and pulled the store
9
9
  // APIs into the core. Symbols that are legitimately exported from more than one
@@ -53,7 +53,7 @@ for (const primitive of [
53
53
  "snapshot",
54
54
  "untrack",
55
55
  "until",
56
- "useContext",
56
+ "useContext"
57
57
  ]) {
58
58
  primitiveMap.set(primitive, "solid-js");
59
59
  }
@@ -74,7 +74,7 @@ for (const primitive of [
74
74
  "reload",
75
75
  "render",
76
76
  "renderToStream",
77
- "renderToString",
77
+ "renderToString"
78
78
  ]) {
79
79
  primitiveMap.set(primitive, "@solidjs/web");
80
80
  }
@@ -95,7 +95,7 @@ for (const type of [
95
95
  "ResolvedChildren",
96
96
  "Signal",
97
97
  "VoidComponent",
98
- "VoidProps",
98
+ "VoidProps"
99
99
  ]) {
100
100
  typeMap.set(type, "solid-js");
101
101
  }
@@ -123,7 +123,7 @@ const findTarget = (program, source, isType) => {
123
123
  (node) =>
124
124
  node.type === "ImportDeclaration" &&
125
125
  node.source.value === source &&
126
- canTakeSpecifier(node, isType),
126
+ canTakeSpecifier(node, isType)
127
127
  );
128
128
  return (
129
129
  (isType ? candidates.find(isTypeDeclaration) : undefined) ??
@@ -136,13 +136,14 @@ export default {
136
136
  docs: {
137
137
  description:
138
138
  'Enforce consistent imports from "solid-js" and the `@solidjs/*` renderer packages.',
139
- url: "https://github.com/solidjs-community/eslint-plugin-solid/blob/main/packages/eslint-plugin-solid/docs/imports.md",
139
+ url: "https://github.com/solidjs-community/eslint-plugin-solid/blob/main/packages/eslint-plugin-solid/docs/imports.md"
140
140
  },
141
141
  fixable: "code",
142
142
  schema: [],
143
143
  messages: {
144
- "prefer-source": 'Prefer importing {{name}} from "{{source}}".',
145
- },
144
+ "prefer-source":
145
+ "`{{name}}` is imported from `{{from}}`, but Solid 2.0 defines it in `{{source}}`; where `{{from}}` does not re-export it, the import is a build error or `undefined`. Fix: `{{fix}}`."
146
+ }
146
147
  },
147
148
  defaultOptions: [],
148
149
  create(context) {
@@ -163,7 +164,9 @@ export default {
163
164
  messageId: "prefer-source",
164
165
  data: {
165
166
  name: specifier.imported.name,
167
+ from: source,
166
168
  source: correctSource,
169
+ fix: `import ${isType ? "type " : ""}{ ${specifierText(specifier, false)} } from "${correctSource}";`
167
170
  },
168
171
  fix(fixer) {
169
172
  const sourceCode = getSourceCode(context);
@@ -176,14 +179,14 @@ export default {
176
179
  const correctDeclaration = findTarget(
177
180
  program,
178
181
  correctSource,
179
- isType,
182
+ isType
180
183
  );
181
184
  if (correctDeclaration) {
182
185
  return [
183
186
  removeSpecifier(
184
187
  fixer,
185
188
  sourceCode,
186
- specifier,
189
+ specifier
187
190
  ),
188
191
  appendImports(
189
192
  fixer,
@@ -194,10 +197,10 @@ export default {
194
197
  specifier,
195
198
  isType &&
196
199
  correctDeclaration.importKind !==
197
- "type",
198
- ),
199
- ],
200
- ),
200
+ "type"
201
+ )
202
+ ]
203
+ )
201
204
  ].filter(Boolean);
202
205
  }
203
206
  const firstSolidDeclaration =
@@ -205,13 +208,13 @@ export default {
205
208
  (node) =>
206
209
  node.type ===
207
210
  "ImportDeclaration" &&
208
- isSource(node.source.value),
211
+ isSource(node.source.value)
209
212
  );
210
213
  return [
211
214
  removeSpecifier(
212
215
  fixer,
213
216
  sourceCode,
214
- specifier,
217
+ specifier
215
218
  ),
216
219
  insertImports(
217
220
  fixer,
@@ -219,15 +222,15 @@ export default {
219
222
  correctSource,
220
223
  [specifierText(specifier, false)],
221
224
  firstSolidDeclaration,
222
- isType,
223
- ),
225
+ isType
226
+ )
224
227
  ];
225
- },
228
+ }
226
229
  });
227
230
  }
228
231
  }
229
232
  }
230
- },
233
+ }
231
234
  };
232
- },
235
+ }
233
236
  };