@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
package/src/utils.mjs
CHANGED
|
@@ -5,7 +5,7 @@ const PROPS_REGEX = /[pP]rops/;
|
|
|
5
5
|
const FUNCTION_TYPES = [
|
|
6
6
|
"FunctionExpression",
|
|
7
7
|
"ArrowFunctionExpression",
|
|
8
|
-
"FunctionDeclaration"
|
|
8
|
+
"FunctionDeclaration"
|
|
9
9
|
];
|
|
10
10
|
const PROGRAM_OR_FUNCTION_TYPES = ["Program", ...FUNCTION_TYPES];
|
|
11
11
|
|
|
@@ -13,30 +13,33 @@ export function isDOMElementName(name) {
|
|
|
13
13
|
return DOM_ELEMENT_REGEX.test(name);
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
export function formatList(strings) {
|
|
21
|
-
if (strings.length === 0) {
|
|
22
|
-
return "";
|
|
16
|
+
/** `const [value, setValue] = createSignal(...)` -> "value". */
|
|
17
|
+
export function getGetterName(declarator) {
|
|
18
|
+
if (declarator.id.type !== "ArrayPattern") {
|
|
19
|
+
return null;
|
|
23
20
|
}
|
|
24
21
|
|
|
25
|
-
|
|
26
|
-
return `'${strings[0]}'`;
|
|
27
|
-
}
|
|
22
|
+
const [element] = declarator.id.elements;
|
|
28
23
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
24
|
+
return element?.type === "Identifier" ? element.name : null;
|
|
25
|
+
}
|
|
32
26
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
27
|
+
/** `count` -> `count`, `props.value` -> `value`. */
|
|
28
|
+
export function localName(name) {
|
|
29
|
+
return name.slice(name.lastIndexOf(".") + 1);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function isPropsByName(name) {
|
|
33
|
+
return PROPS_REGEX.test(name);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Code quoted in a lint message: the text itself when it fits on one short
|
|
37
|
+
// line, else the fallback pattern, so a message never carries a whole block.
|
|
38
|
+
const MESSAGE_CODE_MAX_LENGTH = 100;
|
|
39
|
+
export function messageCode(text, fallback) {
|
|
40
|
+
return text.length <= MESSAGE_CODE_MAX_LENGTH && !text.includes("\n")
|
|
41
|
+
? text
|
|
42
|
+
: fallback;
|
|
40
43
|
}
|
|
41
44
|
|
|
42
45
|
export function find(node, predicate) {
|
|
@@ -158,11 +161,39 @@ export function getCommentAfter(node, sourceCode) {
|
|
|
158
161
|
});
|
|
159
162
|
}
|
|
160
163
|
|
|
164
|
+
/**
|
|
165
|
+
* Matches names against exact strings, `*` wildcards (`use*Store`) and regexes
|
|
166
|
+
* written as "/pattern/" strings.
|
|
167
|
+
*/
|
|
168
|
+
export function createNameMatcher(patterns) {
|
|
169
|
+
const matchers = patterns.map((entry) => {
|
|
170
|
+
if (entry.length > 2 && entry.startsWith("/") && entry.endsWith("/")) {
|
|
171
|
+
try {
|
|
172
|
+
return new RegExp(entry.slice(1, -1));
|
|
173
|
+
} catch {
|
|
174
|
+
return entry;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
if (entry.includes("*")) {
|
|
178
|
+
const escaped = entry
|
|
179
|
+
.split("*")
|
|
180
|
+
.map((part) => part.replace(/[.+?^${}()|[\]\\]/g, "\\$&"))
|
|
181
|
+
.join("[a-zA-Z0-9_$]*");
|
|
182
|
+
return new RegExp(`^${escaped}$`);
|
|
183
|
+
}
|
|
184
|
+
return entry;
|
|
185
|
+
});
|
|
186
|
+
return (name) =>
|
|
187
|
+
matchers.some((matcher) =>
|
|
188
|
+
typeof matcher === "string" ? matcher === name : matcher.test(name)
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
|
|
161
192
|
// Solid 2.0 split the runtime across packages: `solid-js` keeps the core and
|
|
162
193
|
// the store APIs, while `@solidjs/web`, `@solidjs/h`, `@solidjs/html` and
|
|
163
194
|
// `@solidjs/universal` own the renderers. Match both layouts.
|
|
164
195
|
export function trackImports(
|
|
165
|
-
fromModule = /^(?:solid-js|@solidjs\/[a-z-]+)(?:\/|$)
|
|
196
|
+
fromModule = /^(?:solid-js|@solidjs\/[a-z-]+)(?:\/|$)/
|
|
166
197
|
) {
|
|
167
198
|
const importMap = new Map();
|
|
168
199
|
|
|
@@ -187,7 +218,7 @@ export function trackImports(
|
|
|
187
218
|
|
|
188
219
|
return {
|
|
189
220
|
handleImportDeclaration,
|
|
190
|
-
matchImport
|
|
221
|
+
matchImport
|
|
191
222
|
};
|
|
192
223
|
}
|
|
193
224
|
|
|
@@ -214,7 +245,7 @@ export function appendImports(fixer, sourceCode, importNode, identifiers) {
|
|
|
214
245
|
) {
|
|
215
246
|
return fixer.insertTextAfter(
|
|
216
247
|
importNode,
|
|
217
|
-
`\nimport ${importNode.importKind === "type" ? "type " : ""}{ ${identifiersString} } from ${sourceCode.getText(importNode.source)}
|
|
248
|
+
`\nimport ${importNode.importKind === "type" ? "type " : ""}{ ${identifiersString} } from ${sourceCode.getText(importNode.source)};`
|
|
218
249
|
);
|
|
219
250
|
}
|
|
220
251
|
|
|
@@ -225,7 +256,7 @@ export function appendImports(fixer, sourceCode, importNode, identifiers) {
|
|
|
225
256
|
if (defaultSpecifier) {
|
|
226
257
|
return fixer.insertTextAfter(
|
|
227
258
|
defaultSpecifier,
|
|
228
|
-
`, { ${identifiersString} }
|
|
259
|
+
`, { ${identifiersString} }`
|
|
229
260
|
);
|
|
230
261
|
}
|
|
231
262
|
|
|
@@ -233,8 +264,8 @@ export function appendImports(fixer, sourceCode, importNode, identifiers) {
|
|
|
233
264
|
const [importToken, maybeBrace] = sourceCode.getFirstTokens(
|
|
234
265
|
importNode,
|
|
235
266
|
{
|
|
236
|
-
count: 2
|
|
237
|
-
}
|
|
267
|
+
count: 2
|
|
268
|
+
}
|
|
238
269
|
);
|
|
239
270
|
|
|
240
271
|
if (maybeBrace?.value === "{") {
|
|
@@ -244,7 +275,7 @@ export function appendImports(fixer, sourceCode, importNode, identifiers) {
|
|
|
244
275
|
return importToken
|
|
245
276
|
? fixer.insertTextAfter(
|
|
246
277
|
importToken,
|
|
247
|
-
` { ${identifiersString} } from
|
|
278
|
+
` { ${identifiersString} } from`
|
|
248
279
|
)
|
|
249
280
|
: null;
|
|
250
281
|
}
|
|
@@ -258,7 +289,7 @@ export function insertImports(
|
|
|
258
289
|
source,
|
|
259
290
|
identifiers,
|
|
260
291
|
aboveImport,
|
|
261
|
-
isType = false
|
|
292
|
+
isType = false
|
|
262
293
|
) {
|
|
263
294
|
const identifiersString = identifiers.join(", ");
|
|
264
295
|
const programNode = sourceCode.ast;
|
|
@@ -271,7 +302,7 @@ export function insertImports(
|
|
|
271
302
|
if (firstImport) {
|
|
272
303
|
return fixer.insertTextBeforeRange(
|
|
273
304
|
(getCommentBefore(firstImport, sourceCode) ?? firstImport).range,
|
|
274
|
-
`import ${isType ? "type " : ""}{ ${identifiersString} } from "${source}";\n
|
|
305
|
+
`import ${isType ? "type " : ""}{ ${identifiersString} } from "${source}";\n`
|
|
275
306
|
);
|
|
276
307
|
}
|
|
277
308
|
|
|
@@ -286,7 +317,7 @@ export function insertImports(
|
|
|
286
317
|
return fixer.insertTextBeforeRange(
|
|
287
318
|
(getCommentBefore(firstStatement, sourceCode) ?? firstStatement)
|
|
288
319
|
.range,
|
|
289
|
-
importText
|
|
320
|
+
importText
|
|
290
321
|
);
|
|
291
322
|
}
|
|
292
323
|
|
|
@@ -308,11 +339,11 @@ export function removeSpecifier(fixer, sourceCode, specifier, pure = true) {
|
|
|
308
339
|
if (maybeComma?.value === ",") {
|
|
309
340
|
// The space after the comma goes too, or `{ a, b }` turns into `{ b }`.
|
|
310
341
|
const spaceAfter = /^\s*/u.exec(
|
|
311
|
-
sourceCode.text.slice(maybeComma.range[1])
|
|
342
|
+
sourceCode.text.slice(maybeComma.range[1])
|
|
312
343
|
);
|
|
313
344
|
return fixer.removeRange([
|
|
314
345
|
specifier.range[0],
|
|
315
|
-
maybeComma.range[1] + (spaceAfter?.[0].length ?? 0)
|
|
346
|
+
maybeComma.range[1] + (spaceAfter?.[0].length ?? 0)
|
|
316
347
|
]);
|
|
317
348
|
}
|
|
318
349
|
|
|
@@ -322,7 +353,7 @@ export function removeSpecifier(fixer, sourceCode, specifier, pure = true) {
|
|
|
322
353
|
if (maybeCommaBefore?.value === ",") {
|
|
323
354
|
return fixer.removeRange([
|
|
324
355
|
maybeCommaBefore.range[0],
|
|
325
|
-
specifier.range[1]
|
|
356
|
+
specifier.range[1]
|
|
326
357
|
]);
|
|
327
358
|
}
|
|
328
359
|
|