@murky-web/oxlint-plugin-solid 0.1.0 → 0.1.2
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
|
@@ -15,18 +15,44 @@ function isAstNode(value) {
|
|
|
15
15
|
);
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
function
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
);
|
|
18
|
+
function hasJsxElementReturnType(node) {
|
|
19
|
+
const rt = node.returnType?.typeAnnotation;
|
|
20
|
+
if (!rt) return false;
|
|
21
|
+
// JSX.Element
|
|
22
|
+
if (
|
|
23
|
+
rt.type === "TSTypeReference" &&
|
|
24
|
+
rt.typeName?.type === "TSQualifiedName" &&
|
|
25
|
+
rt.typeName.left?.name === "JSX" &&
|
|
26
|
+
rt.typeName.right?.name === "Element"
|
|
27
|
+
) return true;
|
|
28
|
+
// JSX.Element via plain identifier (rare but possible)
|
|
29
|
+
if (rt.type === "TSTypeReference" && rt.typeName?.name === "JSXElement") return true;
|
|
30
|
+
return false;
|
|
28
31
|
}
|
|
29
32
|
|
|
33
|
+
function isFunctionComponent(node) {
|
|
34
|
+
if (
|
|
35
|
+
node.type !== "FunctionDeclaration" ||
|
|
36
|
+
node.async === true ||
|
|
37
|
+
node.generator === true ||
|
|
38
|
+
node.typeParameters
|
|
39
|
+
) return false;
|
|
40
|
+
|
|
41
|
+
if (node.id?.type !== "Identifier") return false;
|
|
42
|
+
|
|
43
|
+
// exported PascalCase — classic component
|
|
44
|
+
const isExported = node.parent?.type === "ExportNamedDeclaration";
|
|
45
|
+
if (isExported && isPascalCaseComponentName(node.id.name)) return true;
|
|
46
|
+
|
|
47
|
+
// has JSX.Element return type annotation — intent is clear regardless of export/casing
|
|
48
|
+
if (hasJsxElementReturnType(node)) return true;
|
|
49
|
+
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Keep old name as alias so call sites don't need changing
|
|
54
|
+
const isExportedFunctionComponent = isFunctionComponent;
|
|
55
|
+
|
|
30
56
|
function isJsxLikeNode(node) {
|
|
31
57
|
return node?.type === "JSXElement" || node?.type === "JSXFragment";
|
|
32
58
|
}
|
|
@@ -69,7 +95,7 @@ function getImportedName(specifier) {
|
|
|
69
95
|
return specifier.imported.value;
|
|
70
96
|
}
|
|
71
97
|
|
|
72
|
-
function getPropsParam(functionNode) {
|
|
98
|
+
function getPropsParam(functionNode, sourceCode) {
|
|
73
99
|
if (functionNode.params.length === NO_PARAMETERS) {
|
|
74
100
|
return {
|
|
75
101
|
name: "",
|
|
@@ -82,14 +108,21 @@ function getPropsParam(functionNode) {
|
|
|
82
108
|
}
|
|
83
109
|
|
|
84
110
|
const [param] = functionNode.params;
|
|
85
|
-
if (param.type
|
|
86
|
-
return
|
|
111
|
+
if (param.type === "Identifier") {
|
|
112
|
+
return {
|
|
113
|
+
name: param.name,
|
|
114
|
+
text: param.name,
|
|
115
|
+
};
|
|
87
116
|
}
|
|
88
117
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
118
|
+
if (param.type === "ObjectPattern") {
|
|
119
|
+
return {
|
|
120
|
+
name: "",
|
|
121
|
+
text: sourceCode.getText(param),
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return FALSE_SENTINEL;
|
|
93
126
|
}
|
|
94
127
|
|
|
95
128
|
function getPropsSuffix(typeReference) {
|
|
@@ -116,11 +149,14 @@ function getTypeReferenceForProps(functionNode, sourceCode) {
|
|
|
116
149
|
}
|
|
117
150
|
|
|
118
151
|
const [param] = functionNode.params;
|
|
119
|
-
if (
|
|
120
|
-
|
|
152
|
+
if (
|
|
153
|
+
(param.type === "Identifier" || param.type === "ObjectPattern") &&
|
|
154
|
+
param.typeAnnotation
|
|
155
|
+
) {
|
|
156
|
+
return sourceCode.getText(param.typeAnnotation.typeAnnotation);
|
|
121
157
|
}
|
|
122
158
|
|
|
123
|
-
return
|
|
159
|
+
return FALSE_SENTINEL;
|
|
124
160
|
}
|
|
125
161
|
|
|
126
162
|
function findLocalTypeName(importDeclarations, desiredTypeName) {
|
|
@@ -359,7 +395,7 @@ export const preferArrowComponentsRule = {
|
|
|
359
395
|
return;
|
|
360
396
|
}
|
|
361
397
|
|
|
362
|
-
const propsParam = getPropsParam(node);
|
|
398
|
+
const propsParam = getPropsParam(node, sourceCode);
|
|
363
399
|
const typeReference = getTypeReferenceForProps(
|
|
364
400
|
node,
|
|
365
401
|
sourceCode,
|