@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.
- package/README.md +163 -18
- package/THIRD_PARTY_NOTICES.md +7 -4
- package/package.json +5 -2
- package/src/compat.mjs +3 -0
- package/src/index.mjs +26 -3
- package/src/rules/components_return_once.mjs +136 -89
- package/src/rules/event_handlers.mjs +55 -35
- package/src/rules/filename_matches_export.mjs +292 -0
- package/src/rules/function_size.mjs +189 -0
- package/src/rules/imports.mjs +24 -21
- package/src/rules/init_declarations.mjs +139 -0
- package/src/rules/jsx_no_duplicate_props.mjs +46 -18
- package/src/rules/jsx_no_script_url.mjs +7 -6
- package/src/rules/jsx_no_undef.mjs +35 -38
- package/src/rules/jsx_uses_vars.mjs +4 -4
- package/src/rules/no_array_handlers.mjs +38 -9
- package/src/rules/no_cleanup_in_effect_apply.mjs +154 -0
- package/src/rules/no_destructure.mjs +105 -35
- package/src/rules/no_innerhtml.mjs +64 -31
- package/src/rules/no_module_scope_reactive_primitive.mjs +73 -0
- package/src/rules/no_owned_primitives_in_ref.mjs +30 -9
- package/src/rules/no_proxy_apis.mjs +44 -15
- package/src/rules/no_react_deps.mjs +397 -41
- package/src/rules/no_react_specific_props.mjs +40 -11
- package/src/rules/no_server_import_in_client.mjs +9 -9
- package/src/rules/no_setter_in_effect.mjs +153 -30
- 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 +108 -29
- package/src/rules/no_untracked_effect_read.mjs +69 -32
- package/src/rules/no_write_in_pure_computation.mjs +273 -0
- package/src/rules/prefer_arrow_components.mjs +47 -21
- package/src/rules/prefer_class_object.mjs +52 -20
- package/src/rules/prefer_destructuring.mjs +164 -0
- package/src/rules/prefer_for.mjs +42 -12
- package/src/rules/prefer_ref_shorthand.mjs +142 -0
- package/src/rules/prefer_show.mjs +55 -24
- package/src/rules/reactive_async.mjs +64 -17
- package/src/rules/reactivity.mjs +1218 -350
- package/src/rules/self_closing_comp.mjs +23 -18
- package/src/rules/strict_void_return.mjs +50 -20
- package/src/rules/style_prop.mjs +53 -25
- package/src/rules/typed_merge_defaults.mjs +88 -0
- package/src/rules/validate_jsx_nesting.mjs +16 -16
- package/src/utils.mjs +65 -34
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { findVariable } from "../compat.mjs";
|
|
1
|
+
import { findVariable, getSourceCode } from "../compat.mjs";
|
|
2
2
|
import {
|
|
3
3
|
isFunctionNode,
|
|
4
4
|
isPropsByName,
|
|
5
5
|
trackImports,
|
|
6
|
-
walkOwnBody
|
|
6
|
+
walkOwnBody
|
|
7
7
|
} from "../utils.mjs";
|
|
8
8
|
|
|
9
9
|
/**
|
|
@@ -14,11 +14,13 @@ import {
|
|
|
14
14
|
const COMPUTATION_PRIMITIVES = [
|
|
15
15
|
"createDeferred",
|
|
16
16
|
"createMemo",
|
|
17
|
+
"dynamic",
|
|
18
|
+
"dynamicComponent",
|
|
17
19
|
"createOptimistic",
|
|
18
20
|
"createOptimisticStore",
|
|
19
21
|
"createProjection",
|
|
20
22
|
"createSignal",
|
|
21
|
-
"createStore"
|
|
23
|
+
"createStore"
|
|
22
24
|
];
|
|
23
25
|
|
|
24
26
|
/** The two-argument effects: the first function is the tracked compute phase. */
|
|
@@ -29,14 +31,14 @@ const ACCESSOR_PRIMITIVES = [
|
|
|
29
31
|
"createDeferred",
|
|
30
32
|
"createMemo",
|
|
31
33
|
"createOptimistic",
|
|
32
|
-
"createSignal"
|
|
34
|
+
"createSignal"
|
|
33
35
|
];
|
|
34
36
|
|
|
35
37
|
/** Primitives whose result is read by property access: `store.items`. */
|
|
36
38
|
const STORE_PRIMITIVES = [
|
|
37
39
|
"createOptimisticStore",
|
|
38
40
|
"createProjection",
|
|
39
|
-
"createStore"
|
|
41
|
+
"createStore"
|
|
40
42
|
];
|
|
41
43
|
|
|
42
44
|
const FIRST_ELEMENT = 0;
|
|
@@ -90,21 +92,31 @@ function isOnlyReturnAwait(callback, awaits) {
|
|
|
90
92
|
);
|
|
91
93
|
}
|
|
92
94
|
|
|
95
|
+
/** `id` -> `currentId`, `props.lang` -> `lang`. */
|
|
96
|
+
function localName(name) {
|
|
97
|
+
const dot = name.lastIndexOf(".");
|
|
98
|
+
if (dot !== -1) {
|
|
99
|
+
return name.slice(dot + 1);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return `current${name[0].toUpperCase()}${name.slice(1)}`;
|
|
103
|
+
}
|
|
104
|
+
|
|
93
105
|
export const reactiveAsyncRule = {
|
|
94
106
|
meta: {
|
|
95
107
|
type: "problem",
|
|
96
108
|
docs: {
|
|
97
109
|
description:
|
|
98
110
|
"Keep reads before the first await in async reactive computations and return promises without async.",
|
|
99
|
-
url: "https://docs.solidjs.com/"
|
|
111
|
+
url: "https://docs.solidjs.com/"
|
|
100
112
|
},
|
|
101
113
|
schema: [],
|
|
102
114
|
messages: {
|
|
103
115
|
untrackedReadAfterAwait:
|
|
104
|
-
"'{{name}}' is read after an `await` in this `{{primitive}}` callback
|
|
116
|
+
"'{{name}}' is first read after an `await` or `yield` in this `{{primitive}}` callback, so it is not a dependency and the result goes stale when it changes (Solid warns UNTRACKED_READ_AFTER_AWAIT in dev). Fix: read it before the first `await`, `const {{local}} = {{read}};` at the top of the callback, and use `{{local}}` where `{{read}}` is now; or read every input synchronously and move the async work into a helper, `{{primitive}}(() => load(…, {{read}}))`. Do not: wrap the read in `untrack()`; that keeps the stale result.",
|
|
105
117
|
redundantAsync:
|
|
106
|
-
"This `async` `{{primitive}}` callback only does `return await
|
|
107
|
-
}
|
|
118
|
+
"This `async` `{{primitive}}` callback only does `return await {{promise}}`, and the `await` adds nothing: Solid reads a returned promise like a value. Fix: return the promise, `{{primitive}}({{fix}})`. Do not: wrap it in `try` only to keep the `await`."
|
|
119
|
+
}
|
|
108
120
|
},
|
|
109
121
|
defaultOptions: [],
|
|
110
122
|
create(context) {
|
|
@@ -114,6 +126,12 @@ export const reactiveAsyncRule = {
|
|
|
114
126
|
// the same name is not mistaken for the signal.
|
|
115
127
|
const accessors = new Set();
|
|
116
128
|
const stores = new Set();
|
|
129
|
+
const sourceCode = getSourceCode(context);
|
|
130
|
+
/** Code as written, or `fallback` when it spans lines. */
|
|
131
|
+
const quote = (node, fallback) => {
|
|
132
|
+
const text = sourceCode.getText(node);
|
|
133
|
+
return text.includes("\n") ? fallback : text;
|
|
134
|
+
};
|
|
117
135
|
|
|
118
136
|
function bindingKind(identifier) {
|
|
119
137
|
const definition = findVariable(context, identifier)?.defs[0];
|
|
@@ -154,12 +172,20 @@ export const reactiveAsyncRule = {
|
|
|
154
172
|
|
|
155
173
|
function checkCallback(callback, primitive) {
|
|
156
174
|
const awaits = [];
|
|
175
|
+
// `await`, and `yield` in a generator computation: both suspend it.
|
|
176
|
+
const gaps = [];
|
|
157
177
|
const reads = [];
|
|
158
178
|
|
|
159
179
|
walkOwnBody(callback.body, (candidate) => {
|
|
160
180
|
if (candidate.type === "AwaitExpression") {
|
|
161
181
|
awaits.push(candidate);
|
|
162
182
|
}
|
|
183
|
+
if (
|
|
184
|
+
candidate.type === "AwaitExpression" ||
|
|
185
|
+
candidate.type === "YieldExpression"
|
|
186
|
+
) {
|
|
187
|
+
gaps.push(candidate);
|
|
188
|
+
}
|
|
163
189
|
|
|
164
190
|
const name = readName(candidate);
|
|
165
191
|
if (name !== null) {
|
|
@@ -167,7 +193,7 @@ export const reactiveAsyncRule = {
|
|
|
167
193
|
}
|
|
168
194
|
});
|
|
169
195
|
|
|
170
|
-
if (
|
|
196
|
+
if (gaps.length === 0) {
|
|
171
197
|
return;
|
|
172
198
|
}
|
|
173
199
|
|
|
@@ -178,19 +204,40 @@ export const reactiveAsyncRule = {
|
|
|
178
204
|
context.report({
|
|
179
205
|
node: callback,
|
|
180
206
|
messageId: "redundantAsync",
|
|
181
|
-
data: {
|
|
207
|
+
data: {
|
|
208
|
+
// .ts keeps `async`: typescript/promise-function-async
|
|
209
|
+
// asks for it on a promise-returning function there,
|
|
210
|
+
// and typescript/require-await accepts it without an
|
|
211
|
+
// await. .tsx/.jsx turn that rule off, so `async` goes.
|
|
212
|
+
fix: /\.[jt]sx$/u.test(context.filename ?? "")
|
|
213
|
+
? `() => ${quote(awaits[0].argument, "…")}`
|
|
214
|
+
: `async () => ${quote(awaits[0].argument, "…")}`,
|
|
215
|
+
primitive,
|
|
216
|
+
promise: quote(awaits[0].argument, "…")
|
|
217
|
+
}
|
|
182
218
|
});
|
|
183
219
|
}
|
|
184
220
|
|
|
185
221
|
// A read inside the awaited expression itself still runs before the
|
|
186
222
|
// await suspends, so the boundary is where the first await ends.
|
|
187
|
-
|
|
223
|
+
// Like the runtime, a source already read before it is a dependency
|
|
224
|
+
// and fine to read again; a late source is reported once.
|
|
225
|
+
const firstAwaitEnd = Math.min(...gaps.map(getEnd));
|
|
226
|
+
const tracked = new Set();
|
|
188
227
|
for (const read of reads) {
|
|
189
|
-
if (getStart(read.node)
|
|
228
|
+
if (getStart(read.node) < firstAwaitEnd) {
|
|
229
|
+
tracked.add(read.name);
|
|
230
|
+
} else if (!tracked.has(read.name)) {
|
|
231
|
+
tracked.add(read.name);
|
|
190
232
|
context.report({
|
|
191
233
|
node: read.node,
|
|
192
234
|
messageId: "untrackedReadAfterAwait",
|
|
193
|
-
data: {
|
|
235
|
+
data: {
|
|
236
|
+
local: localName(read.name),
|
|
237
|
+
name: read.name,
|
|
238
|
+
primitive,
|
|
239
|
+
read: quote(read.node, read.name)
|
|
240
|
+
}
|
|
194
241
|
});
|
|
195
242
|
}
|
|
196
243
|
}
|
|
@@ -230,7 +277,7 @@ export const reactiveAsyncRule = {
|
|
|
230
277
|
|
|
231
278
|
const computation = matchImport(
|
|
232
279
|
COMPUTATION_PRIMITIVES,
|
|
233
|
-
node.callee.name
|
|
280
|
+
node.callee.name
|
|
234
281
|
);
|
|
235
282
|
if (computation) {
|
|
236
283
|
checkCallback(first, computation);
|
|
@@ -242,7 +289,7 @@ export const reactiveAsyncRule = {
|
|
|
242
289
|
if (effect && isFunctionNode(second)) {
|
|
243
290
|
checkCallback(first, effect);
|
|
244
291
|
}
|
|
245
|
-
}
|
|
292
|
+
}
|
|
246
293
|
};
|
|
247
|
-
}
|
|
294
|
+
}
|
|
248
295
|
};
|