@murky-web/oxlint-plugin-solid 1.5.1 → 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.
- package/README.md +161 -16
- package/THIRD_PARTY_NOTICES.md +7 -4
- package/package.json +5 -2
- package/src/compat.mjs +3 -0
- package/src/index.mjs +23 -0
- package/src/rules/components_return_once.mjs +131 -84
- package/src/rules/event_handlers.mjs +33 -13
- package/src/rules/filename_matches_export.mjs +292 -0
- package/src/rules/function_size.mjs +189 -0
- package/src/rules/imports.mjs +5 -2
- package/src/rules/init_declarations.mjs +139 -0
- package/src/rules/jsx_no_duplicate_props.mjs +36 -8
- package/src/rules/jsx_no_script_url.mjs +3 -2
- package/src/rules/jsx_no_undef.mjs +8 -11
- package/src/rules/no_array_handlers.mjs +35 -6
- package/src/rules/no_cleanup_in_effect_apply.mjs +154 -0
- package/src/rules/no_destructure.mjs +76 -4
- package/src/rules/no_innerhtml.mjs +51 -18
- package/src/rules/no_module_scope_reactive_primitive.mjs +73 -0
- package/src/rules/no_owned_primitives_in_ref.mjs +23 -2
- package/src/rules/no_proxy_apis.mjs +41 -12
- package/src/rules/no_react_deps.mjs +394 -38
- package/src/rules/no_react_specific_props.mjs +33 -4
- package/src/rules/no_server_import_in_client.mjs +1 -1
- package/src/rules/no_setter_in_effect.mjs +145 -22
- package/src/rules/no_single_arg_create_effect.mjs +55 -0
- package/src/rules/no_unassigned_vars.mjs +99 -0
- package/src/rules/no_unknown_namespaces.mjs +96 -17
- package/src/rules/no_untracked_effect_read.mjs +65 -28
- package/src/rules/no_write_in_pure_computation.mjs +273 -0
- package/src/rules/prefer_arrow_components.mjs +30 -4
- package/src/rules/prefer_class_object.mjs +37 -5
- package/src/rules/prefer_destructuring.mjs +164 -0
- package/src/rules/prefer_for.mjs +34 -4
- package/src/rules/prefer_ref_shorthand.mjs +142 -0
- package/src/rules/prefer_show.mjs +48 -17
- package/src/rules/reactive_async.mjs +55 -8
- package/src/rules/reactivity.mjs +1160 -291
- package/src/rules/self_closing_comp.mjs +7 -2
- package/src/rules/strict_void_return.mjs +43 -13
- package/src/rules/style_prop.mjs +38 -9
- package/src/rules/typed_merge_defaults.mjs +88 -0
- package/src/rules/validate_jsx_nesting.mjs +2 -2
- package/src/utils.mjs +51 -20
|
@@ -1,59 +1,415 @@
|
|
|
1
|
-
|
|
1
|
+
// Solid 2.0 has no dependency arrays. `createEffect(compute, effectFn)` tracks
|
|
2
|
+
// what compute reads and runs effectFn untracked; `createMemo(fn, options)`
|
|
3
|
+
// tracks what fn reads. A React-style array lands where Solid expects the
|
|
4
|
+
// effect function or the options object.
|
|
5
|
+
import { getSourceCode } from "../compat.mjs";
|
|
6
|
+
import {
|
|
7
|
+
appendImports,
|
|
8
|
+
getGetterName,
|
|
9
|
+
isFunctionNode,
|
|
10
|
+
isPropsByName,
|
|
11
|
+
localName,
|
|
12
|
+
messageCode,
|
|
13
|
+
trace,
|
|
14
|
+
trackImports,
|
|
15
|
+
walkOwnBody
|
|
16
|
+
} from "../utils.mjs";
|
|
17
|
+
|
|
18
|
+
const EFFECTS = ["createEffect", "createRenderEffect"];
|
|
19
|
+
const ACCESSOR_PAIRS = ["createSignal", "createOptimistic"];
|
|
20
|
+
const SECOND = 1;
|
|
21
|
+
const THIRD = 2;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The normalized read `node` stands for: `a()` for a call without arguments,
|
|
25
|
+
* `props.id` for a props member. Null for anything else.
|
|
26
|
+
*/
|
|
27
|
+
function readText(node) {
|
|
28
|
+
if (
|
|
29
|
+
node?.type === "CallExpression" &&
|
|
30
|
+
node.callee.type === "Identifier" &&
|
|
31
|
+
node.arguments.length === 0
|
|
32
|
+
) {
|
|
33
|
+
return `${node.callee.name}()`;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (
|
|
37
|
+
node?.type === "MemberExpression" &&
|
|
38
|
+
!node.computed &&
|
|
39
|
+
node.object.type === "Identifier" &&
|
|
40
|
+
isPropsByName(node.object.name) &&
|
|
41
|
+
node.property.type === "Identifier"
|
|
42
|
+
) {
|
|
43
|
+
return `${node.object.name}.${node.property.name}`;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Each dep as `{ key, read }`: accessor `a` -> `a: a()`, `a()` -> `a: a()`,
|
|
51
|
+
* `props.id` -> `id: props.id`. Null unless every dep resolves and no two claim
|
|
52
|
+
* the same key.
|
|
53
|
+
*/
|
|
54
|
+
function resolveDeps(array, accessors) {
|
|
55
|
+
const byKey = new Map();
|
|
56
|
+
for (const element of array.elements) {
|
|
57
|
+
const read =
|
|
58
|
+
element?.type === "Identifier" && accessors.has(element.name)
|
|
59
|
+
? `${element.name}()`
|
|
60
|
+
: readText(element);
|
|
61
|
+
if (read === null) {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const key = localName(read.replace(/\(\)$/u, ""));
|
|
66
|
+
if (byKey.has(key) && byKey.get(key) !== read) {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
byKey.set(key, read);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return [...byKey].map(([key, read]) => ({ key, read }));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** A name that is not a variable reference: `obj.id`, `{ id: 1 }`. */
|
|
76
|
+
function isNonReference(node) {
|
|
77
|
+
const { parent } = node;
|
|
78
|
+
|
|
79
|
+
return (
|
|
80
|
+
(parent?.type === "MemberExpression" &&
|
|
81
|
+
parent.property === node &&
|
|
82
|
+
!parent.computed) ||
|
|
83
|
+
(parent?.type === "Property" &&
|
|
84
|
+
parent.key === node &&
|
|
85
|
+
!parent.computed &&
|
|
86
|
+
!parent.shorthand)
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* The function's body with each dep read replaced by its parameter, or null
|
|
92
|
+
* when a parameter would shadow a name the body still uses.
|
|
93
|
+
*/
|
|
94
|
+
function rewriteBody(fn, deps, sourceCode) {
|
|
95
|
+
const keyByRead = new Map(deps.map(({ key, read }) => [read, key]));
|
|
96
|
+
const keys = new Set(deps.map(({ key }) => key));
|
|
97
|
+
const edits = [];
|
|
98
|
+
let clean = true;
|
|
99
|
+
|
|
100
|
+
// Nested functions are not rewritten (a read there is a live read, not
|
|
101
|
+
// the snapshot), but a parameter would still shadow their names.
|
|
102
|
+
const visit = (node, nested) => {
|
|
103
|
+
const read = readText(node);
|
|
104
|
+
if (!nested && keyByRead.has(read)) {
|
|
105
|
+
edits.push({ key: keyByRead.get(read), range: node.range });
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (
|
|
109
|
+
node.type === "Identifier" &&
|
|
110
|
+
keys.has(node.name) &&
|
|
111
|
+
!isNonReference(node)
|
|
112
|
+
) {
|
|
113
|
+
clean = false;
|
|
114
|
+
}
|
|
115
|
+
for (const [field, value] of Object.entries(node)) {
|
|
116
|
+
if (field === "parent") {
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
for (const child of [value].flat()) {
|
|
120
|
+
if (typeof child?.type === "string") {
|
|
121
|
+
visit(child, nested || isFunctionNode(child));
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
visit(fn.body, false);
|
|
127
|
+
if (!clean) {
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const [start] = fn.body.range;
|
|
132
|
+
let text = sourceCode.getText(fn.body);
|
|
133
|
+
for (const { key, range } of edits.toSorted(
|
|
134
|
+
(left, right) => right.range[0] - left.range[0]
|
|
135
|
+
)) {
|
|
136
|
+
text = `${text.slice(0, range[0] - start)}${key}${text.slice(range[1] - start)}`;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// `() => ({ … })` loses its parentheses in getText.
|
|
140
|
+
return fn.body.type !== "BlockStatement" && text.startsWith("{")
|
|
141
|
+
? `(${text})`
|
|
142
|
+
: text;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function computeText(deps) {
|
|
146
|
+
return `() => ({ ${deps.map(({ key, read }) => `${key}: ${read}`).join(", ")} })`;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function paramsText(deps) {
|
|
150
|
+
return `{ ${deps.map(({ key }) => key).join(", ")} }`;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** `createEffect(() => ({ a: a() }), ({ a }) => { … })` for the message. */
|
|
154
|
+
function effectFixText(name, deps) {
|
|
155
|
+
return deps
|
|
156
|
+
? `${name}(${computeText(deps)}, (${paramsText(deps)}) => { … })`
|
|
157
|
+
: `${name}(() => ({ value: source() }), ({ value }) => { … })`;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** The effect function the single function becomes. */
|
|
161
|
+
function effectFunctionText(fn, deps, body) {
|
|
162
|
+
const prefix = fn.async ? "async " : "";
|
|
163
|
+
if (fn.type === "ArrowFunctionExpression") {
|
|
164
|
+
return `${prefix}(${paramsText(deps)}) => ${body}`;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return `${prefix}function${fn.generator ? "*" : ""} (${paramsText(deps)}) ${body}`;
|
|
168
|
+
}
|
|
169
|
+
|
|
2
170
|
export default {
|
|
3
171
|
meta: {
|
|
4
172
|
type: "problem",
|
|
5
173
|
docs: {
|
|
6
174
|
description:
|
|
7
|
-
"Disallow
|
|
8
|
-
url: "https://github.com/
|
|
175
|
+
"Disallow dependency arrays in `createEffect`, `createRenderEffect` and `createMemo`.",
|
|
176
|
+
url: "https://github.com/MurkyTheMurloc/web_dev_tools/blob/main/docs/solid-2-effects.md"
|
|
9
177
|
},
|
|
10
178
|
fixable: "code",
|
|
179
|
+
hasSuggestions: true,
|
|
11
180
|
schema: [],
|
|
12
181
|
messages: {
|
|
13
|
-
|
|
14
|
-
"
|
|
182
|
+
effectDeps:
|
|
183
|
+
"`{{name}}` gets the dependency array `{{deps}}`, but Solid 2.0 has no dependency arrays: the compute function tracks what it reads, and the second argument must be the effect function. Fix: `{{fix}}`, reading each dependency in the compute function and moving the body into the effect function, which uses the parameters and still returns its cleanup. Do not: only delete the array (a one-argument `{{name}}` throws MISSING_EFFECT_FN), keep reading signals in the effect function (it runs untracked, so the effect stops re-running), wrap reads in `untrack()`, or disable the rule.",
|
|
184
|
+
effectMountDeps:
|
|
185
|
+
"`{{name}}` gets the empty dependency array `[]`, React's run-once idiom, but Solid 2.0 has no dependency arrays and expects the effect function there. Fix: `onSettled(() => { …; return cleanup; })` for one-time setup after mount; it runs once the render has settled and runs the returned cleanup on disposal. Do not: only delete the array (a one-argument `{{name}}` throws MISSING_EFFECT_FN), call `onCleanup` inside `onSettled` (Solid throws CLEANUP_IN_FORBIDDEN_SCOPE), or disable the rule.",
|
|
186
|
+
effectOptionsDeps:
|
|
187
|
+
"`{{name}}` gets the dependency array `{{deps}}` in the options slot, so it does nothing: the effect re-runs on what its compute function reads. Fix: delete `{{deps}}` and read those values in the compute function, `{{fix}}`. Do not: read them in the effect function (it runs untracked), wrap reads in `untrack()`, or disable the rule.",
|
|
188
|
+
memoDeps:
|
|
189
|
+
"`{{name}}` gets the dependency array `{{deps}}`, but Solid 2.0 has no dependency arrays: the memo tracks what its function reads, and the array lands in the options slot. Fix: delete `{{deps}}`, `{{fix}}`{{unread}}. Do not: move the array into the options object, wrap reads in `untrack()`, or disable the rule.",
|
|
190
|
+
deleteDeps: "Delete the dependency array.",
|
|
191
|
+
splitEffect:
|
|
192
|
+
"Split into a compute function and an effect function.",
|
|
193
|
+
useOnSettled: "Use `onSettled` for the one-time setup."
|
|
15
194
|
}
|
|
16
195
|
},
|
|
17
196
|
defaultOptions: [],
|
|
18
197
|
create(context) {
|
|
19
|
-
/** Tracks imports from 'solid-js', handling aliases. */
|
|
20
198
|
const { matchImport, handleImportDeclaration } = trackImports();
|
|
199
|
+
const sourceCode = getSourceCode(context);
|
|
200
|
+
// Names that hold an accessor, so `[count]` can become `count()`.
|
|
201
|
+
const accessors = new Set();
|
|
202
|
+
let solidImport = null;
|
|
203
|
+
let onSettledName = null;
|
|
204
|
+
|
|
205
|
+
function reportEffect(node, fn, array) {
|
|
206
|
+
const name = node.callee.name;
|
|
207
|
+
const arg = node.arguments[SECOND];
|
|
208
|
+
const inline = arg === array && fn === node.arguments[0];
|
|
209
|
+
|
|
210
|
+
if (array.elements.length === 0) {
|
|
211
|
+
const importNode = onSettledName ? null : solidImport;
|
|
212
|
+
const canFix =
|
|
213
|
+
node.arguments.length === 2 &&
|
|
214
|
+
arg === array &&
|
|
215
|
+
(onSettledName !== null || importNode !== null);
|
|
216
|
+
context.report({
|
|
217
|
+
data: { name },
|
|
218
|
+
messageId: "effectMountDeps",
|
|
219
|
+
node: arg,
|
|
220
|
+
suggest: canFix
|
|
221
|
+
? [
|
|
222
|
+
{
|
|
223
|
+
messageId: "useOnSettled",
|
|
224
|
+
fix: (fixer) => [
|
|
225
|
+
fixer.replaceText(
|
|
226
|
+
node,
|
|
227
|
+
`${onSettledName ?? "onSettled"}(${sourceCode.getText(node.arguments[0])})`
|
|
228
|
+
),
|
|
229
|
+
...(importNode
|
|
230
|
+
? [
|
|
231
|
+
appendImports(
|
|
232
|
+
fixer,
|
|
233
|
+
sourceCode,
|
|
234
|
+
importNode,
|
|
235
|
+
["onSettled"]
|
|
236
|
+
)
|
|
237
|
+
]
|
|
238
|
+
: [])
|
|
239
|
+
]
|
|
240
|
+
}
|
|
241
|
+
]
|
|
242
|
+
: []
|
|
243
|
+
});
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
const deps = resolveDeps(array, accessors);
|
|
248
|
+
const body = deps && inline && rewriteBody(fn, deps, sourceCode);
|
|
249
|
+
context.report({
|
|
250
|
+
data: {
|
|
251
|
+
deps: messageCode(sourceCode.getText(arg), "[…]"),
|
|
252
|
+
fix: effectFixText(name, deps),
|
|
253
|
+
name
|
|
254
|
+
},
|
|
255
|
+
messageId: "effectDeps",
|
|
256
|
+
node: arg,
|
|
257
|
+
// Never an autofix: the rewrite moves reads between phases.
|
|
258
|
+
suggest: body
|
|
259
|
+
? [
|
|
260
|
+
{
|
|
261
|
+
messageId: "splitEffect",
|
|
262
|
+
fix: (fixer) =>
|
|
263
|
+
fixer.replaceTextRange(
|
|
264
|
+
[fn.range[0], array.range[1]],
|
|
265
|
+
`${computeText(deps)}, ${effectFunctionText(fn, deps, body)}`
|
|
266
|
+
)
|
|
267
|
+
}
|
|
268
|
+
]
|
|
269
|
+
: []
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function reportEffectOptions(node, array) {
|
|
274
|
+
const name = node.callee.name;
|
|
275
|
+
const arg = node.arguments[THIRD];
|
|
276
|
+
context.report({
|
|
277
|
+
data: {
|
|
278
|
+
deps: messageCode(sourceCode.getText(arg), "[…]"),
|
|
279
|
+
fix: effectFixText(name, resolveDeps(array, accessors)),
|
|
280
|
+
name
|
|
281
|
+
},
|
|
282
|
+
messageId: "effectOptionsDeps",
|
|
283
|
+
node: arg,
|
|
284
|
+
suggest:
|
|
285
|
+
arg === array
|
|
286
|
+
? [
|
|
287
|
+
{
|
|
288
|
+
messageId: "deleteDeps",
|
|
289
|
+
fix: (fixer) =>
|
|
290
|
+
fixer.removeRange([
|
|
291
|
+
node.arguments[SECOND].range[1],
|
|
292
|
+
arg.range[1]
|
|
293
|
+
])
|
|
294
|
+
}
|
|
295
|
+
]
|
|
296
|
+
: []
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
function reportMemo(node, fn, array, index) {
|
|
301
|
+
const arg = node.arguments[index];
|
|
302
|
+
// What the memo's function reads itself.
|
|
303
|
+
const reads = new Set();
|
|
304
|
+
if (isFunctionNode(fn)) {
|
|
305
|
+
walkOwnBody(fn.body, (candidate) => {
|
|
306
|
+
const read = readText(candidate);
|
|
307
|
+
if (read) {
|
|
308
|
+
reads.add(read);
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
const unread = array.elements.flatMap((element) => {
|
|
313
|
+
const read =
|
|
314
|
+
element?.type === "Identifier"
|
|
315
|
+
? `${element.name}()`
|
|
316
|
+
: readText(element);
|
|
317
|
+
|
|
318
|
+
return read && reads.has(read)
|
|
319
|
+
? []
|
|
320
|
+
: [messageCode(sourceCode.getText(element), "…")];
|
|
321
|
+
});
|
|
322
|
+
const remove = (fixer) => fixer.remove(arg);
|
|
323
|
+
context.report({
|
|
324
|
+
data: {
|
|
325
|
+
deps: messageCode(sourceCode.getText(arg), "[…]"),
|
|
326
|
+
fix: `${node.callee.name}(${messageCode(sourceCode.getText(node.arguments[0]), "() => …")})`,
|
|
327
|
+
name: node.callee.name,
|
|
328
|
+
unread:
|
|
329
|
+
unread.length === 0
|
|
330
|
+
? ""
|
|
331
|
+
: `; ${unread.map((text) => `\`${text}\``).join(", ")} ${unread.length === 1 ? "is" : "are"} not read in the function, so read ${unread.length === 1 ? "it" : "them"} there if the memo must recompute when ${unread.length === 1 ? "it changes" : "they change"}`
|
|
332
|
+
},
|
|
333
|
+
// Safe only when the function already reads every dep.
|
|
334
|
+
fix: arg === array && unread.length === 0 ? remove : undefined,
|
|
335
|
+
messageId: "memoDeps",
|
|
336
|
+
node: arg,
|
|
337
|
+
suggest:
|
|
338
|
+
arg === array && unread.length > 0
|
|
339
|
+
? [{ messageId: "deleteDeps", fix: remove }]
|
|
340
|
+
: []
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
|
|
21
344
|
return {
|
|
22
|
-
ImportDeclaration
|
|
345
|
+
ImportDeclaration(node) {
|
|
346
|
+
handleImportDeclaration(node);
|
|
347
|
+
if (node.source.value === "solid-js") {
|
|
348
|
+
solidImport ??= node;
|
|
349
|
+
for (const specifier of node.specifiers) {
|
|
350
|
+
if (specifier.imported?.name === "onSettled") {
|
|
351
|
+
onSettledName = specifier.local.name;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
},
|
|
356
|
+
VariableDeclarator(node) {
|
|
357
|
+
if (
|
|
358
|
+
node.init?.type !== "CallExpression" ||
|
|
359
|
+
node.init.callee.type !== "Identifier"
|
|
360
|
+
) {
|
|
361
|
+
return;
|
|
362
|
+
}
|
|
363
|
+
if (matchImport(ACCESSOR_PAIRS, node.init.callee.name)) {
|
|
364
|
+
const getter = getGetterName(node);
|
|
365
|
+
if (getter) {
|
|
366
|
+
accessors.add(getter);
|
|
367
|
+
}
|
|
368
|
+
} else if (
|
|
369
|
+
matchImport("createMemo", node.init.callee.name) &&
|
|
370
|
+
node.id.type === "Identifier"
|
|
371
|
+
) {
|
|
372
|
+
accessors.add(node.id.name);
|
|
373
|
+
}
|
|
374
|
+
},
|
|
23
375
|
CallExpression(node) {
|
|
24
376
|
if (
|
|
25
|
-
node.callee.type
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
node.callee.name
|
|
29
|
-
) &&
|
|
30
|
-
node.arguments.length === 2 &&
|
|
31
|
-
node.arguments.every((arg) => arg.type !== "SpreadElement")
|
|
377
|
+
node.callee.type !== "Identifier" ||
|
|
378
|
+
node.arguments.length < 2 ||
|
|
379
|
+
node.arguments.some((arg) => arg.type === "SpreadElement")
|
|
32
380
|
) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
)
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
const isEffect = Boolean(
|
|
384
|
+
matchImport(EFFECTS, node.callee.name)
|
|
385
|
+
);
|
|
386
|
+
if (!isEffect && !matchImport("createMemo", node.callee.name)) {
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
// Trace variables to their values; a reported variable is
|
|
391
|
+
// highlighted at the call, not at its declaration.
|
|
392
|
+
const [fn, second, third] = node.arguments.map((arg) =>
|
|
393
|
+
trace(arg, context)
|
|
394
|
+
);
|
|
395
|
+
if (
|
|
396
|
+
second.type === "ArrayExpression" &&
|
|
397
|
+
isFunctionNode(fn) &&
|
|
398
|
+
// With a parameter, the second argument can be a seed.
|
|
399
|
+
fn.params.length === 0
|
|
400
|
+
) {
|
|
401
|
+
if (isEffect) {
|
|
402
|
+
reportEffect(node, fn, second);
|
|
403
|
+
} else {
|
|
404
|
+
reportMemo(node, fn, second, SECOND);
|
|
405
|
+
}
|
|
406
|
+
return;
|
|
407
|
+
}
|
|
408
|
+
if (third?.type === "ArrayExpression") {
|
|
409
|
+
if (isEffect) {
|
|
410
|
+
reportEffectOptions(node, third);
|
|
411
|
+
} else {
|
|
412
|
+
reportMemo(node, fn, third, THIRD);
|
|
57
413
|
}
|
|
58
414
|
}
|
|
59
415
|
}
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getSourceCode } from "../compat.mjs";
|
|
2
|
+
import {
|
|
3
|
+
isDOMElementName,
|
|
4
|
+
jsxGetProp,
|
|
5
|
+
jsxHasProp,
|
|
6
|
+
messageCode
|
|
7
|
+
} from "../utils.mjs";
|
|
2
8
|
|
|
3
9
|
const REACT_SPECIFIC_PROPS = [
|
|
4
10
|
{ from: "className", to: "class" },
|
|
@@ -15,8 +21,8 @@ export const noReactSpecificPropsRule = {
|
|
|
15
21
|
fixable: "code",
|
|
16
22
|
messages: {
|
|
17
23
|
noUselessKey:
|
|
18
|
-
"
|
|
19
|
-
prefer: "
|
|
24
|
+
"`key` on `<{{element}}>` is React's list key. Solid gives it no meaning and sets it as a plain `key` attribute; `<For>` keys rows by item identity. Fix: remove `{{key}}`; to key a list by a field, `<For each={items()} keyed={(item) => item.id}>`.",
|
|
25
|
+
prefer: "`{{ from }}` is React's name for `{{ to }}`, and Solid 2.0 has no such alias: {{ effect }}. Fix: `{{ fix }}`{{ merge }}."
|
|
20
26
|
},
|
|
21
27
|
schema: [],
|
|
22
28
|
type: "problem"
|
|
@@ -37,8 +43,24 @@ export const noReactSpecificPropsRule = {
|
|
|
37
43
|
}
|
|
38
44
|
: undefined;
|
|
39
45
|
|
|
46
|
+
const hasTarget = jsxHasProp(node.attributes, to);
|
|
47
|
+
const value = attribute.value
|
|
48
|
+
? `=${getSourceCode(context).getText(attribute.value)}`
|
|
49
|
+
: "";
|
|
40
50
|
context.report({
|
|
41
|
-
data: {
|
|
51
|
+
data: {
|
|
52
|
+
from,
|
|
53
|
+
to,
|
|
54
|
+
effect:
|
|
55
|
+
node.name.type === "JSXIdentifier" &&
|
|
56
|
+
isDOMElementName(node.name.name)
|
|
57
|
+
? `it sets an unknown \`${from}\` attribute and the element gets no \`${to}\``
|
|
58
|
+
: `the component receives a \`${from}\` prop, not \`${to}\``,
|
|
59
|
+
fix: messageCode(`${to}${value}`, `${to}={…}`),
|
|
60
|
+
merge: hasTarget
|
|
61
|
+
? `, merged into the \`${to}\` the element already has`
|
|
62
|
+
: ""
|
|
63
|
+
},
|
|
42
64
|
fix,
|
|
43
65
|
messageId: "prefer",
|
|
44
66
|
node: attribute
|
|
@@ -55,6 +77,13 @@ export const noReactSpecificPropsRule = {
|
|
|
55
77
|
}
|
|
56
78
|
|
|
57
79
|
context.report({
|
|
80
|
+
data: {
|
|
81
|
+
element: node.name.name,
|
|
82
|
+
key: messageCode(
|
|
83
|
+
getSourceCode(context).getText(keyProp),
|
|
84
|
+
"key"
|
|
85
|
+
)
|
|
86
|
+
},
|
|
58
87
|
fix(fixer) {
|
|
59
88
|
return fixer.remove(keyProp);
|
|
60
89
|
},
|
|
@@ -303,7 +303,7 @@ export const noServerImportInClientRule = {
|
|
|
303
303
|
schema: [],
|
|
304
304
|
messages: {
|
|
305
305
|
serverImportInClient:
|
|
306
|
-
'
|
|
306
|
+
'`{{specifier}}` is under src/server/ without a `"use server"` directive, so this import ships server-only code (database clients, secrets) to the browser. Fix: import a server function module instead, one that starts with `"use server";` and exports async functions; for types only, `import type`. Do not: add `"use server"` to `{{specifier}}`; each exported function becomes a browser-callable endpoint.'
|
|
307
307
|
}
|
|
308
308
|
},
|
|
309
309
|
defaultOptions: [],
|