@murky-web/oxlint-plugin-solid 0.1.2 → 0.1.3
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/package.json
CHANGED
|
@@ -338,14 +338,14 @@ function buildReplacementText({
|
|
|
338
338
|
typeReference,
|
|
339
339
|
usesChildren,
|
|
340
340
|
functionNode,
|
|
341
|
+
isExported,
|
|
341
342
|
}) {
|
|
342
|
-
const
|
|
343
|
-
const childrenComment = usesChildren ? "" : "";
|
|
343
|
+
const exportPrefix = isExported ? "export " : "";
|
|
344
344
|
const propsSuffix = getPropsSuffix(typeReference);
|
|
345
345
|
const paramsText = propsParam.text;
|
|
346
346
|
const bodyText = sourceCode.getText(functionNode.body);
|
|
347
347
|
|
|
348
|
-
return
|
|
348
|
+
return `${exportPrefix}const ${componentName}: ${localTypeName}${propsSuffix} = (${paramsText}) => ${bodyText}`;
|
|
349
349
|
}
|
|
350
350
|
|
|
351
351
|
function createRuleFix({
|
|
@@ -357,10 +357,12 @@ function createRuleFix({
|
|
|
357
357
|
typeReference,
|
|
358
358
|
usesChildren,
|
|
359
359
|
}) {
|
|
360
|
+
const isExported = functionNode.parent?.type === "ExportNamedDeclaration";
|
|
360
361
|
const componentName = functionNode.id.name;
|
|
361
362
|
const replacementText = buildReplacementText({
|
|
362
363
|
componentName,
|
|
363
364
|
functionNode,
|
|
365
|
+
isExported,
|
|
364
366
|
localTypeName,
|
|
365
367
|
propsParam,
|
|
366
368
|
sourceCode,
|
|
@@ -368,7 +370,10 @@ function createRuleFix({
|
|
|
368
370
|
usesChildren,
|
|
369
371
|
});
|
|
370
372
|
|
|
371
|
-
|
|
373
|
+
// For exported functions, replace the ExportNamedDeclaration (the parent).
|
|
374
|
+
// For non-exported functions, replace only the FunctionDeclaration itself.
|
|
375
|
+
const nodeToReplace = isExported ? functionNode.parent : functionNode;
|
|
376
|
+
return fixer.replaceText(nodeToReplace, replacementText);
|
|
372
377
|
}
|
|
373
378
|
|
|
374
379
|
export const preferArrowComponentsRule = {
|
|
@@ -412,30 +417,53 @@ export const preferArrowComponentsRule = {
|
|
|
412
417
|
usesPropsChildren(node, propsParam.name);
|
|
413
418
|
const desiredTypeName = getDesiredSolidTypeName(usesChildren);
|
|
414
419
|
|
|
420
|
+
const { importDeclaration, localTypeName } = getSolidTypeImportInfo(
|
|
421
|
+
programNode,
|
|
422
|
+
desiredTypeName,
|
|
423
|
+
);
|
|
424
|
+
const resolvedTypeName = localTypeName !== "" ? localTypeName : desiredTypeName;
|
|
425
|
+
const needsNewImport = localTypeName === "" && !importDeclaration;
|
|
426
|
+
|
|
415
427
|
context.report({
|
|
416
428
|
fix(fixer) {
|
|
417
|
-
const
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
})
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
429
|
+
const isExported = node.parent?.type === "ExportNamedDeclaration";
|
|
430
|
+
const componentName = node.id.name;
|
|
431
|
+
const propsSuffix = getPropsSuffix(typeReference);
|
|
432
|
+
const paramsText = propsParam.text;
|
|
433
|
+
const bodyText = sourceCode.getText(node.body);
|
|
434
|
+
const exportPrefix = isExported ? "export " : "";
|
|
435
|
+
|
|
436
|
+
// If we need a new import AND the function is not exported,
|
|
437
|
+
// prepend the import declaration directly into the replacement text
|
|
438
|
+
// to avoid multi-range fix conflicts.
|
|
439
|
+
const importPrefix = needsNewImport
|
|
440
|
+
? `import type { ${desiredTypeName} } from "solid-js";\n`
|
|
441
|
+
: "";
|
|
442
|
+
|
|
443
|
+
const replacementText = `${importPrefix}${exportPrefix}const ${componentName}: ${resolvedTypeName}${propsSuffix} = (${paramsText}) => ${bodyText}`;
|
|
444
|
+
const nodeToReplace = isExported ? node.parent : node;
|
|
445
|
+
|
|
446
|
+
if (!needsNewImport && localTypeName === "" && importDeclaration) {
|
|
447
|
+
// Need to add to existing import — use two fixes only when
|
|
448
|
+
// the import is AFTER the function (safe, no overlap).
|
|
449
|
+
// Otherwise embed the import in the replacement.
|
|
450
|
+
const importEnd = importDeclaration.range?.[1] ?? 0;
|
|
451
|
+
const funcStart = nodeToReplace.range?.[0] ?? 0;
|
|
452
|
+
if (importEnd < funcStart) {
|
|
453
|
+
const typeKeyword = getTypeKeyword(importDeclaration, sourceCode);
|
|
454
|
+
const namedSpecifiers = getNamedImportSpecifiers(importDeclaration);
|
|
455
|
+
const lastSpec = namedSpecifiers.at(LAST_INDEX);
|
|
456
|
+
const importOp = lastSpec
|
|
457
|
+
? fixer.insertTextAfter(lastSpec, `, ${typeKeyword}${desiredTypeName}`)
|
|
458
|
+
: fixer.insertTextBefore(importDeclaration, `import type { ${desiredTypeName} } from "solid-js";\n`);
|
|
459
|
+
return [
|
|
460
|
+
fixer.replaceText(nodeToReplace, replacementText),
|
|
461
|
+
importOp,
|
|
462
|
+
];
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
return fixer.replaceText(nodeToReplace, replacementText);
|
|
439
467
|
},
|
|
440
468
|
message:
|
|
441
469
|
"Prefer export const components typed as Component<Props> or ParentComponent<Props>.",
|