@murky-web/oxlint-plugin-solid 0.1.3 → 1.0.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/package.json +1 -1
- package/src/index.mjs +2 -2
- package/src/rules/event_handlers.mjs +1 -1
- package/src/rules/imports.mjs +66 -79
- package/src/rules/jsx_no_undef.mjs +12 -1
- package/src/rules/no_destructure.mjs +18 -13
- package/src/rules/no_proxy_apis.mjs +28 -5
- package/src/rules/no_unknown_namespaces.mjs +37 -27
- package/src/rules/prefer_arrow_components.mjs +3 -0
- package/src/rules/prefer_class_object.mjs +98 -0
- package/src/rules/prefer_for.mjs +1 -1
- package/src/rules/reactivity.mjs +56 -22
- package/src/utils.mjs +4 -1
- package/src/rules/prefer_classlist.mjs +0 -89
package/package.json
CHANGED
package/src/index.mjs
CHANGED
|
@@ -13,7 +13,7 @@ import noReactDepsRule from "./rules/no_react_deps.mjs";
|
|
|
13
13
|
import { noReactSpecificPropsRule } from "./rules/no_react_specific_props.mjs";
|
|
14
14
|
import noUnknownNamespacesRule from "./rules/no_unknown_namespaces.mjs";
|
|
15
15
|
import { preferArrowComponentsRule } from "./rules/prefer_arrow_components.mjs";
|
|
16
|
-
import
|
|
16
|
+
import preferClassObjectRule from "./rules/prefer_class_object.mjs";
|
|
17
17
|
import preferForRule from "./rules/prefer_for.mjs";
|
|
18
18
|
import preferShowRule from "./rules/prefer_show.mjs";
|
|
19
19
|
import reactivityRule from "./rules/reactivity.mjs";
|
|
@@ -42,7 +42,7 @@ const extendedPlugin = {
|
|
|
42
42
|
"no-react-specific-props": noReactSpecificPropsRule,
|
|
43
43
|
"no-unknown-namespaces": noUnknownNamespacesRule,
|
|
44
44
|
"prefer-arrow-components": preferArrowComponentsRule,
|
|
45
|
-
"prefer-
|
|
45
|
+
"prefer-class-object": preferClassObjectRule,
|
|
46
46
|
"prefer-for": preferForRule,
|
|
47
47
|
"prefer-show": preferShowRule,
|
|
48
48
|
reactivity: reactivityRule,
|
|
@@ -114,7 +114,7 @@ export default createRule({
|
|
|
114
114
|
],
|
|
115
115
|
messages: {
|
|
116
116
|
"detected-attr":
|
|
117
|
-
'The {{name}} prop is named as an event handler (starts with "on"), but Solid knows its value ({{staticValue}}) is a string or number, so it will be treated as an attribute. If this is intentional, name
|
|
117
|
+
'The {{name}} prop is named as an event handler (starts with "on"), but Solid knows its value ({{staticValue}}) is a string or number, so it will be treated as an attribute. If this is intentional, use the plain attribute name instead of an on-prefixed one.',
|
|
118
118
|
naming: "The {{name}} prop is ambiguous. If it is an event handler, change it to {{handlerName}}. If it is an attribute, change it to {{attrName}}.",
|
|
119
119
|
capitalization:
|
|
120
120
|
"The {{name}} prop should be renamed to {{fixedName}} for readability.",
|
package/src/rules/imports.mjs
CHANGED
|
@@ -3,120 +3,107 @@ import { ESLintUtils } from "@typescript-eslint/utils";
|
|
|
3
3
|
import { getSourceCode } from "../compat.mjs";
|
|
4
4
|
import { appendImports, insertImports, removeSpecifier } from "../utils.mjs";
|
|
5
5
|
const createRule = ESLintUtils.RuleCreator.withoutDocs;
|
|
6
|
-
//
|
|
6
|
+
// Solid 2.0 moved the renderers into `@solidjs/*` packages and pulled the store
|
|
7
|
+
// APIs into the core. Symbols that are legitimately exported from more than one
|
|
8
|
+
// package (the control-flow components, `ComponentProps`) are deliberately left
|
|
9
|
+
// out of these maps: there is no single correct source to point at.
|
|
7
10
|
const primitiveMap = new Map();
|
|
8
11
|
for (const primitive of [
|
|
9
|
-
"
|
|
12
|
+
"action",
|
|
13
|
+
"affects",
|
|
14
|
+
"children",
|
|
15
|
+
"createContext",
|
|
10
16
|
"createEffect",
|
|
11
17
|
"createMemo",
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"batch",
|
|
18
|
-
"on",
|
|
18
|
+
"createOptimistic",
|
|
19
|
+
"createOptimisticStore",
|
|
20
|
+
"createProjection",
|
|
21
|
+
"createReaction",
|
|
22
|
+
"createRenderEffect",
|
|
19
23
|
"createRoot",
|
|
24
|
+
"createSignal",
|
|
25
|
+
"createStore",
|
|
26
|
+
"createUniqueId",
|
|
27
|
+
"deep",
|
|
28
|
+
"DEV",
|
|
29
|
+
"flush",
|
|
30
|
+
"getObserver",
|
|
20
31
|
"getOwner",
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"observable",
|
|
26
|
-
"from",
|
|
32
|
+
"isEqual",
|
|
33
|
+
"isPending",
|
|
34
|
+
"latest",
|
|
35
|
+
"lazy",
|
|
27
36
|
"mapArray",
|
|
28
|
-
"
|
|
29
|
-
"
|
|
37
|
+
"merge",
|
|
38
|
+
"omit",
|
|
39
|
+
"onCleanup",
|
|
40
|
+
"onSettled",
|
|
41
|
+
"reconcile",
|
|
42
|
+
"refresh",
|
|
43
|
+
"resolve",
|
|
44
|
+
"runWithOwner",
|
|
45
|
+
"snapshot",
|
|
46
|
+
"storePath",
|
|
47
|
+
"untrack",
|
|
48
|
+
"until",
|
|
30
49
|
"useContext",
|
|
31
|
-
"children",
|
|
32
|
-
"lazy",
|
|
33
|
-
"createUniqueId",
|
|
34
|
-
"createDeferred",
|
|
35
|
-
"createRenderEffect",
|
|
36
|
-
"createComputed",
|
|
37
|
-
"createReaction",
|
|
38
|
-
"createSelector",
|
|
39
|
-
"DEV",
|
|
40
|
-
"For",
|
|
41
|
-
"Show",
|
|
42
|
-
"Switch",
|
|
43
|
-
"Match",
|
|
44
|
-
"Index",
|
|
45
|
-
"ErrorBoundary",
|
|
46
|
-
"Suspense",
|
|
47
|
-
"SuspenseList",
|
|
48
50
|
]) {
|
|
49
51
|
primitiveMap.set(primitive, "solid-js");
|
|
50
52
|
}
|
|
51
53
|
for (const primitive of [
|
|
54
|
+
"clientOnly",
|
|
55
|
+
"delegateEvents",
|
|
56
|
+
"dynamic",
|
|
57
|
+
"Dynamic",
|
|
58
|
+
"generateHydrationScript",
|
|
59
|
+
"getRequestEvent",
|
|
60
|
+
"httpHeader",
|
|
61
|
+
"httpStatus",
|
|
62
|
+
"hydrate",
|
|
63
|
+
"HydrationScript",
|
|
64
|
+
"isServer",
|
|
52
65
|
"Portal",
|
|
66
|
+
"redirect",
|
|
67
|
+
"reload",
|
|
53
68
|
"render",
|
|
54
|
-
"hydrate",
|
|
55
|
-
"renderToString",
|
|
56
69
|
"renderToStream",
|
|
57
|
-
"
|
|
58
|
-
"renderToStringAsync",
|
|
59
|
-
"generateHydrationScript",
|
|
60
|
-
"HydrationScript",
|
|
61
|
-
"Dynamic",
|
|
62
|
-
]) {
|
|
63
|
-
primitiveMap.set(primitive, "solid-js/web");
|
|
64
|
-
}
|
|
65
|
-
for (const primitive of [
|
|
66
|
-
"createStore",
|
|
67
|
-
"produce",
|
|
68
|
-
"reconcile",
|
|
69
|
-
"unwrap",
|
|
70
|
-
"createMutable",
|
|
71
|
-
"modifyMutable",
|
|
70
|
+
"renderToString",
|
|
72
71
|
]) {
|
|
73
|
-
primitiveMap.set(primitive, "
|
|
72
|
+
primitiveMap.set(primitive, "@solidjs/web");
|
|
74
73
|
}
|
|
75
74
|
// Set up map of type imports to module
|
|
76
75
|
const typeMap = new Map();
|
|
77
76
|
for (const type of [
|
|
78
|
-
"Signal",
|
|
79
77
|
"Accessor",
|
|
80
|
-
"
|
|
81
|
-
"Resource",
|
|
82
|
-
"ResourceActions",
|
|
83
|
-
"ResourceOptions",
|
|
84
|
-
"ResourceReturn",
|
|
85
|
-
"ResourceFetcher",
|
|
86
|
-
"InitializedResourceReturn",
|
|
78
|
+
"ChildrenReturn",
|
|
87
79
|
"Component",
|
|
88
|
-
"
|
|
89
|
-
"
|
|
90
|
-
"ParentProps",
|
|
91
|
-
"ParentComponent",
|
|
92
|
-
"FlowProps",
|
|
80
|
+
"Context",
|
|
81
|
+
"Element",
|
|
93
82
|
"FlowComponent",
|
|
94
|
-
"
|
|
95
|
-
"
|
|
83
|
+
"FlowProps",
|
|
84
|
+
"MatchProps",
|
|
85
|
+
"ParentComponent",
|
|
86
|
+
"ParentProps",
|
|
96
87
|
"Ref",
|
|
97
|
-
"MergeProps",
|
|
98
|
-
"SplitPrips",
|
|
99
|
-
"Context",
|
|
100
|
-
"JSX",
|
|
101
88
|
"ResolvedChildren",
|
|
102
|
-
"
|
|
89
|
+
"Signal",
|
|
90
|
+
"ValidComponent",
|
|
91
|
+
"VoidComponent",
|
|
92
|
+
"VoidProps",
|
|
103
93
|
]) {
|
|
104
94
|
typeMap.set(type, "solid-js");
|
|
105
95
|
}
|
|
106
|
-
for (const type of [
|
|
107
|
-
typeMap.set(type, "
|
|
108
|
-
}
|
|
109
|
-
for (const type of ["StoreNode", "Store", "SetStoreFunction"]) {
|
|
110
|
-
typeMap.set(type, "solid-js/store");
|
|
96
|
+
for (const type of ["ClassValue", "IntrinsicElement", "JSX", "RequestEvent"]) {
|
|
97
|
+
typeMap.set(type, "@solidjs/web");
|
|
111
98
|
}
|
|
112
|
-
const sourceRegex = /^solid-js(
|
|
99
|
+
const sourceRegex = /^(?:solid-js|@solidjs\/(?:web|h|html|universal))$/;
|
|
113
100
|
const isSource = (source) => sourceRegex.test(source);
|
|
114
101
|
export default createRule({
|
|
115
102
|
meta: {
|
|
116
103
|
type: "suggestion",
|
|
117
104
|
docs: {
|
|
118
105
|
description:
|
|
119
|
-
'Enforce consistent imports from "solid-js"
|
|
106
|
+
'Enforce consistent imports from "solid-js" and the `@solidjs/*` renderer packages.',
|
|
120
107
|
url: "https://github.com/solidjs-community/eslint-plugin-solid/blob/main/packages/eslint-plugin-solid/docs/imports.md",
|
|
121
108
|
},
|
|
122
109
|
fixable: "code",
|
|
@@ -9,7 +9,18 @@ import {
|
|
|
9
9
|
} from "../utils.mjs";
|
|
10
10
|
const createRule = ESLintUtils.RuleCreator.withoutDocs;
|
|
11
11
|
// Currently all of the control flow components are from 'solid-js'.
|
|
12
|
-
|
|
12
|
+
// Solid 2.0 dropped `Index` (use `<For keyed={false}>`) and renamed the
|
|
13
|
+
// async/error boundaries. All of these are exported from `solid-js`.
|
|
14
|
+
const AUTO_COMPONENTS = [
|
|
15
|
+
"Show",
|
|
16
|
+
"For",
|
|
17
|
+
"Switch",
|
|
18
|
+
"Match",
|
|
19
|
+
"Loading",
|
|
20
|
+
"Errored",
|
|
21
|
+
"Repeat",
|
|
22
|
+
"Reveal",
|
|
23
|
+
];
|
|
13
24
|
const SOURCE_MODULE = "solid-js";
|
|
14
25
|
export default createRule({
|
|
15
26
|
meta: {
|
|
@@ -93,10 +93,11 @@ export default createRule({
|
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
95
|
const hasDefaults = propertyInfo.some((info) => info.init);
|
|
96
|
-
// Replace destructured props with a `props` identifier
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
96
|
+
// Replace destructured props with a `props` identifier. Only the
|
|
97
|
+
// defaults case needs a second binding, because `merge` produces a
|
|
98
|
+
// new object; `omit` returns just the rest, so the parameter itself
|
|
99
|
+
// still carries the named props.
|
|
100
|
+
const origProps = hasDefaults ? "_" + propsName : propsName;
|
|
100
101
|
if (props.typeAnnotation) {
|
|
101
102
|
// in `{ prop1, prop2 }: Props`, leave `: Props` alone
|
|
102
103
|
const range = [props.range[0], props.typeAnnotation.range[0]];
|
|
@@ -113,24 +114,28 @@ export default createRule({
|
|
|
113
114
|
`${info.computed ? "[" : ""}${sourceCode.getText(info.real)}${info.computed ? "]" : ""}: ${sourceCode.getText(info.init)}`,
|
|
114
115
|
)
|
|
115
116
|
.join(", ");
|
|
116
|
-
|
|
117
|
-
|
|
117
|
+
// `omit(props, "a", "b")` takes the keys as varargs, where Solid
|
|
118
|
+
// 1.x `splitProps(props, ["a", "b"])` took an array.
|
|
119
|
+
const omitArgs = () =>
|
|
120
|
+
propertyInfo
|
|
118
121
|
.map((info) =>
|
|
119
122
|
info.real.type === "Identifier"
|
|
120
123
|
? JSON.stringify(info.real.name)
|
|
121
124
|
: sourceCode.getText(info.real),
|
|
122
125
|
)
|
|
123
|
-
.join(", ")
|
|
126
|
+
.join(", ");
|
|
127
|
+
const restName = () =>
|
|
128
|
+
(rest.argument.type === "Identifier" && rest.argument.name) ||
|
|
129
|
+
"rest";
|
|
124
130
|
let lineToInsert = "";
|
|
125
131
|
if (hasDefaults && rest) {
|
|
126
|
-
//
|
|
127
|
-
lineToInsert = ` const
|
|
132
|
+
// Merge the defaults, then take the rest off the merged object.
|
|
133
|
+
lineToInsert = ` const ${propsName} = merge({ ${defaultsObjectString()} }, ${origProps});\n const ${restName()} = omit(${propsName}, ${omitArgs()});\n`;
|
|
128
134
|
} else if (hasDefaults) {
|
|
129
|
-
|
|
130
|
-
lineToInsert = ` const ${propsName} = mergeProps({ ${defaultsObjectString()} }, ${origProps});\n`;
|
|
135
|
+
lineToInsert = ` const ${propsName} = merge({ ${defaultsObjectString()} }, ${origProps});\n`;
|
|
131
136
|
} else if (rest) {
|
|
132
|
-
//
|
|
133
|
-
lineToInsert = ` const
|
|
137
|
+
// `props` already carries the named props; only the rest is new.
|
|
138
|
+
lineToInsert = ` const ${restName()} = omit(${origProps}, ${omitArgs()});\n`;
|
|
134
139
|
}
|
|
135
140
|
if (lineToInsert) {
|
|
136
141
|
const body = func.body;
|
|
@@ -7,6 +7,13 @@ import {
|
|
|
7
7
|
trace,
|
|
8
8
|
} from "../utils.mjs";
|
|
9
9
|
const createRule = ESLintUtils.RuleCreator.withoutDocs;
|
|
10
|
+
|
|
11
|
+
// Store APIs that hand back a Proxy. Solid 2.0 exports these from `solid-js`.
|
|
12
|
+
const PROXY_BACKED_STORE_APIS = new Set([
|
|
13
|
+
"createStore",
|
|
14
|
+
"createProjection",
|
|
15
|
+
"createOptimisticStore",
|
|
16
|
+
]);
|
|
10
17
|
export default createRule({
|
|
11
18
|
meta: {
|
|
12
19
|
type: "problem",
|
|
@@ -36,11 +43,27 @@ export default createRule({
|
|
|
36
43
|
ImportDeclaration(node) {
|
|
37
44
|
handleImportDeclaration(node); // track import aliases
|
|
38
45
|
const source = node.source.value;
|
|
46
|
+
// Solid 1.x isolated the Proxy-backed store APIs behind
|
|
47
|
+
// `solid-js/store`, so the import path alone was the signal.
|
|
48
|
+
// Solid 2.0 moved them into `solid-js`, which every file
|
|
49
|
+
// imports, so match the specifier names instead.
|
|
39
50
|
if (source === "solid-js/store") {
|
|
40
|
-
context.report({
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
51
|
+
context.report({ node, messageId: "noStore" });
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (source !== "solid-js") {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
for (const specifier of node.specifiers) {
|
|
58
|
+
if (
|
|
59
|
+
specifier.type === "ImportSpecifier" &&
|
|
60
|
+
PROXY_BACKED_STORE_APIS.has(specifier.imported.name)
|
|
61
|
+
) {
|
|
62
|
+
context.report({
|
|
63
|
+
node: specifier,
|
|
64
|
+
messageId: "noStore",
|
|
65
|
+
});
|
|
66
|
+
}
|
|
44
67
|
}
|
|
45
68
|
},
|
|
46
69
|
"JSXSpreadAttribute MemberExpression"(node) {
|
|
@@ -51,7 +74,7 @@ export default createRule({
|
|
|
51
74
|
},
|
|
52
75
|
CallExpression(node) {
|
|
53
76
|
if (node.callee.type === "Identifier") {
|
|
54
|
-
if (matchImport("mergeProps", node.callee.name)) {
|
|
77
|
+
if (matchImport(["merge", "mergeProps"], node.callee.name)) {
|
|
55
78
|
node.arguments
|
|
56
79
|
.filter((arg) => {
|
|
57
80
|
if (arg.type === "SpreadElement") return true;
|
|
@@ -2,16 +2,28 @@ import { ESLintUtils } from "@typescript-eslint/utils";
|
|
|
2
2
|
|
|
3
3
|
import { isDOMElementName } from "../utils.mjs";
|
|
4
4
|
const createRule = ESLintUtils.RuleCreator.withoutDocs;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
5
|
+
// Solid 2.0 removed every Solid-specific JSX namespace. What is left are the
|
|
6
|
+
// XML namespaces the DOM itself defines.
|
|
7
|
+
const xmlNamespaces = ["xmlns", "xlink"];
|
|
8
|
+
// Removed namespace -> what to write instead.
|
|
9
|
+
const replacements = {
|
|
10
|
+
attr: "the standard attribute",
|
|
11
|
+
bool: "the standard attribute (booleans are presence/absence)",
|
|
12
|
+
class: "the `class` prop with an object or array value",
|
|
13
|
+
on: "a camel-case event prop such as `onClick`, or a ref callback with `addEventListener` when listener options are needed",
|
|
14
|
+
oncapture:
|
|
15
|
+
"a camel-case event prop, or a ref callback with `addEventListener` when capture is needed",
|
|
16
|
+
prop: "the standard property",
|
|
17
|
+
style: "the `style` prop with an object value",
|
|
18
|
+
use: "a ref callback or directive factory, composing with a ref array",
|
|
19
|
+
};
|
|
8
20
|
export default createRule({
|
|
9
21
|
meta: {
|
|
10
22
|
type: "problem",
|
|
11
23
|
docs: {
|
|
12
24
|
description:
|
|
13
|
-
"
|
|
14
|
-
url: "https://
|
|
25
|
+
"Disallow Solid's removed JSX attribute namespaces. Solid 2.0 dropped `on:`, `oncapture:`, `use:`, `prop:`, `attr:`, `bool:`, `class:` and `style:`.",
|
|
26
|
+
url: "https://docs.solidjs.com/",
|
|
15
27
|
},
|
|
16
28
|
hasSuggestions: true,
|
|
17
29
|
schema: [
|
|
@@ -34,10 +46,9 @@ export default createRule({
|
|
|
34
46
|
},
|
|
35
47
|
],
|
|
36
48
|
messages: {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
.
|
|
40
|
-
style: "Using the '{{namespace}}:' special prefix is potentially confusing, prefer the '{{namespace}}' prop instead.",
|
|
49
|
+
removed: "'{{namespace}}:' was removed in Solid 2.0. Use {{replacement}} instead.",
|
|
50
|
+
unknown:
|
|
51
|
+
"'{{namespace}}:' is not a namespace Solid understands. Solid 2.0 has no special JSX prefixes.",
|
|
41
52
|
component: "Namespaced props have no effect on components.",
|
|
42
53
|
"component-suggest":
|
|
43
54
|
"Replace {{namespace}}:{{name}} with {{name}}.",
|
|
@@ -74,26 +85,25 @@ export default createRule({
|
|
|
74
85
|
}
|
|
75
86
|
const namespace = node.namespace?.name;
|
|
76
87
|
if (
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
otherNamespaces.includes(namespace) ||
|
|
80
|
-
explicitlyAllowedNamespaces?.includes(namespace)
|
|
81
|
-
)
|
|
88
|
+
xmlNamespaces.includes(namespace) ||
|
|
89
|
+
explicitlyAllowedNamespaces?.includes(namespace)
|
|
82
90
|
) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
data: { namespace },
|
|
94
|
-
});
|
|
95
|
-
}
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const replacement = replacements[namespace];
|
|
94
|
+
if (replacement) {
|
|
95
|
+
context.report({
|
|
96
|
+
node,
|
|
97
|
+
messageId: "removed",
|
|
98
|
+
data: { namespace, replacement },
|
|
99
|
+
});
|
|
100
|
+
return;
|
|
96
101
|
}
|
|
102
|
+
context.report({
|
|
103
|
+
node,
|
|
104
|
+
messageId: "unknown",
|
|
105
|
+
data: { namespace },
|
|
106
|
+
});
|
|
97
107
|
},
|
|
98
108
|
};
|
|
99
109
|
},
|
|
@@ -27,6 +27,9 @@ function hasJsxElementReturnType(node) {
|
|
|
27
27
|
) return true;
|
|
28
28
|
// JSX.Element via plain identifier (rare but possible)
|
|
29
29
|
if (rt.type === "TSTypeReference" && rt.typeName?.name === "JSXElement") return true;
|
|
30
|
+
// Solid 2.0: `Element` from solid-js is the renderer-neutral return type,
|
|
31
|
+
// and `JSX` now lives in the renderer package.
|
|
32
|
+
if (rt.type === "TSTypeReference" && rt.typeName?.name === "Element") return true;
|
|
30
33
|
return false;
|
|
31
34
|
}
|
|
32
35
|
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
2
|
+
|
|
3
|
+
import { jsxPropName } from "../utils.mjs";
|
|
4
|
+
const createRule = ESLintUtils.RuleCreator.withoutDocs;
|
|
5
|
+
const DEFAULT_CLASSNAMES = ["cn", "clsx", "classnames"];
|
|
6
|
+
export default createRule({
|
|
7
|
+
meta: {
|
|
8
|
+
type: "problem",
|
|
9
|
+
docs: {
|
|
10
|
+
description:
|
|
11
|
+
"Enforce the `class` object/array form over the removed `classlist` prop or a classnames helper. Solid 2.0 accepts `{ [class: string]: boolean }` on `class` directly.",
|
|
12
|
+
url: "https://docs.solidjs.com/",
|
|
13
|
+
},
|
|
14
|
+
fixable: "code",
|
|
15
|
+
schema: [
|
|
16
|
+
{
|
|
17
|
+
type: "object",
|
|
18
|
+
properties: {
|
|
19
|
+
classnames: {
|
|
20
|
+
type: "array",
|
|
21
|
+
description:
|
|
22
|
+
"An array of names to treat as `classnames` functions",
|
|
23
|
+
default: DEFAULT_CLASSNAMES,
|
|
24
|
+
items: {
|
|
25
|
+
type: "string",
|
|
26
|
+
},
|
|
27
|
+
minItems: 1,
|
|
28
|
+
uniqueItems: true,
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
additionalProperties: false,
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
messages: {
|
|
35
|
+
classlistRemoved:
|
|
36
|
+
"The `classlist` prop was removed in Solid 2.0. Pass the object to `class` instead.",
|
|
37
|
+
preferClassObject:
|
|
38
|
+
"Pass the object to `class` directly instead of through {{ classnames }}.",
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
defaultOptions: [],
|
|
42
|
+
create(context) {
|
|
43
|
+
const classnames =
|
|
44
|
+
context.options[0]?.classnames ?? DEFAULT_CLASSNAMES;
|
|
45
|
+
return {
|
|
46
|
+
JSXAttribute(node) {
|
|
47
|
+
const name = jsxPropName(node);
|
|
48
|
+
|
|
49
|
+
// `classlist={{...}}` no longer exists; the object belongs on `class`.
|
|
50
|
+
if (name === "classlist") {
|
|
51
|
+
context.report({
|
|
52
|
+
node,
|
|
53
|
+
messageId: "classlistRemoved",
|
|
54
|
+
fix: (fixer) =>
|
|
55
|
+
fixer.replaceText(node.name, "class"),
|
|
56
|
+
});
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (name !== "class" && name !== "className") {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (node.value?.type !== "JSXExpressionContainer") {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// `class={cn({ ... })}` -> `class={{ ... }}`
|
|
68
|
+
const expr = node.value.expression;
|
|
69
|
+
if (
|
|
70
|
+
expr.type === "CallExpression" &&
|
|
71
|
+
expr.callee.type === "Identifier" &&
|
|
72
|
+
classnames.includes(expr.callee.name) &&
|
|
73
|
+
expr.arguments.length === 1 &&
|
|
74
|
+
expr.arguments[0].type === "ObjectExpression"
|
|
75
|
+
) {
|
|
76
|
+
context.report({
|
|
77
|
+
node,
|
|
78
|
+
messageId: "preferClassObject",
|
|
79
|
+
data: { classnames: expr.callee.name },
|
|
80
|
+
fix: (fixer) => {
|
|
81
|
+
const objectRange = expr.arguments[0].range;
|
|
82
|
+
return [
|
|
83
|
+
fixer.replaceTextRange(
|
|
84
|
+
[node.range[0], objectRange[0]],
|
|
85
|
+
"class={",
|
|
86
|
+
),
|
|
87
|
+
fixer.replaceTextRange(
|
|
88
|
+
[objectRange[1], node.range[1]],
|
|
89
|
+
"}",
|
|
90
|
+
),
|
|
91
|
+
];
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
},
|
|
98
|
+
});
|
package/src/rules/prefer_for.mjs
CHANGED
|
@@ -17,7 +17,7 @@ export default createRule({
|
|
|
17
17
|
preferFor:
|
|
18
18
|
"Use Solid's `<For />` component for efficiently rendering lists. Array#map causes DOM elements to be recreated.",
|
|
19
19
|
preferForOrIndex:
|
|
20
|
-
"Use Solid's `<For />` component
|
|
20
|
+
"Use Solid's `<For />` component for rendering lists (`keyed={false}` for the index-based form). Array#map causes DOM elements to be recreated.",
|
|
21
21
|
},
|
|
22
22
|
},
|
|
23
23
|
defaultOptions: [],
|
package/src/rules/reactivity.mjs
CHANGED
|
@@ -21,6 +21,11 @@ import {
|
|
|
21
21
|
} from "../utils.mjs";
|
|
22
22
|
const { getFunctionHeadLocation } = ASTUtils;
|
|
23
23
|
const createRule = ESLintUtils.RuleCreator.withoutDocs;
|
|
24
|
+
|
|
25
|
+
// Solid 2.0 removed `createResource`, `createMutable`, `indexArray` and
|
|
26
|
+
// `<Index>`. Their branches below are kept structurally but matched against
|
|
27
|
+
// `__removed_*` names so they can never fire; delete them once no Solid 1
|
|
28
|
+
// code is linted with this plugin any more.
|
|
24
29
|
class ScopeStackItem {
|
|
25
30
|
/** the node for the current scope, or program if global scope */
|
|
26
31
|
node;
|
|
@@ -624,7 +629,7 @@ export default createRule({
|
|
|
624
629
|
) {
|
|
625
630
|
if (
|
|
626
631
|
node.callee.type === "Identifier" &&
|
|
627
|
-
matchImport(["
|
|
632
|
+
matchImport(["flush"], node.callee.name)
|
|
628
633
|
) {
|
|
629
634
|
// These Solid APIs take callbacks that run in the current scope
|
|
630
635
|
scopeStack.syncCallbacks.add(node.arguments[0]);
|
|
@@ -673,7 +678,7 @@ export default createRule({
|
|
|
673
678
|
}
|
|
674
679
|
}
|
|
675
680
|
} else if (
|
|
676
|
-
matchImport(["mapArray", "
|
|
681
|
+
matchImport(["mapArray", "repeat"], node.callee.name)
|
|
677
682
|
) {
|
|
678
683
|
const arg1 = node.arguments[1];
|
|
679
684
|
if (isFunctionNode(arg1)) {
|
|
@@ -696,7 +701,7 @@ export default createRule({
|
|
|
696
701
|
) {
|
|
697
702
|
const { callee } = init;
|
|
698
703
|
if (
|
|
699
|
-
matchImport(["createSignal"
|
|
704
|
+
matchImport(["createSignal"], callee.name)
|
|
700
705
|
) {
|
|
701
706
|
const signal = id && getNthDestructuredVar(id, 0, context);
|
|
702
707
|
if (signal) {
|
|
@@ -705,7 +710,7 @@ export default createRule({
|
|
|
705
710
|
warnShouldDestructure(id ?? init, "first");
|
|
706
711
|
}
|
|
707
712
|
} else if (
|
|
708
|
-
matchImport(["createMemo", "
|
|
713
|
+
matchImport(["createMemo", "createProjection"], callee.name)
|
|
709
714
|
) {
|
|
710
715
|
const memo = id && getReturnedVar(id, context);
|
|
711
716
|
// memos act like signals
|
|
@@ -722,7 +727,7 @@ export default createRule({
|
|
|
722
727
|
} else {
|
|
723
728
|
warnShouldDestructure(id ?? init, "first");
|
|
724
729
|
}
|
|
725
|
-
} else if (matchImport("
|
|
730
|
+
} else if (matchImport("merge", callee.name)) {
|
|
726
731
|
const merged = id && getReturnedVar(id, context);
|
|
727
732
|
if (merged) {
|
|
728
733
|
scopeStack.pushProps(merged, currentScope().node);
|
|
@@ -754,7 +759,7 @@ export default createRule({
|
|
|
754
759
|
scopeStack.pushProps(vars, currentScope().node);
|
|
755
760
|
}
|
|
756
761
|
}
|
|
757
|
-
} else if (matchImport("
|
|
762
|
+
} else if (matchImport("__removed_createResource", callee.name)) {
|
|
758
763
|
// createResource return value has reactive .loading and .error
|
|
759
764
|
const resourceReturn =
|
|
760
765
|
id && getNthDestructuredVar(id, 0, context);
|
|
@@ -764,7 +769,7 @@ export default createRule({
|
|
|
764
769
|
currentScope().node,
|
|
765
770
|
);
|
|
766
771
|
}
|
|
767
|
-
} else if (matchImport("
|
|
772
|
+
} else if (matchImport("__removed_createMutable", callee.name)) {
|
|
768
773
|
const mutable = id && getReturnedVar(id, context);
|
|
769
774
|
if (mutable) {
|
|
770
775
|
scopeStack.pushProps(mutable, currentScope().node);
|
|
@@ -784,7 +789,7 @@ export default createRule({
|
|
|
784
789
|
scopeStack.pushSignal(indexSignal);
|
|
785
790
|
}
|
|
786
791
|
}
|
|
787
|
-
} else if (matchImport("
|
|
792
|
+
} else if (matchImport("__removed_indexArray", callee.name)) {
|
|
788
793
|
const arg1 = init.arguments[1];
|
|
789
794
|
if (
|
|
790
795
|
isFunctionNode(arg1) &&
|
|
@@ -956,27 +961,56 @@ export default createRule({
|
|
|
956
961
|
[
|
|
957
962
|
"createMemo",
|
|
958
963
|
"children",
|
|
959
|
-
"
|
|
960
|
-
"
|
|
961
|
-
"createDeferred",
|
|
962
|
-
"createComputed",
|
|
963
|
-
"createSelector",
|
|
964
|
+
"createTrackedEffect",
|
|
965
|
+
"createProjection",
|
|
964
966
|
"untrack",
|
|
965
967
|
"mapArray",
|
|
966
|
-
"
|
|
967
|
-
"
|
|
968
|
+
"isPending",
|
|
969
|
+
"latest",
|
|
970
|
+
"resolve",
|
|
968
971
|
],
|
|
969
972
|
callee.name,
|
|
970
973
|
) ||
|
|
971
|
-
|
|
972
|
-
node.arguments.length >= 2)
|
|
974
|
+
false /* Solid 2.0 removed createResource */
|
|
973
975
|
) {
|
|
974
|
-
//
|
|
975
|
-
// `source` first argument may be a signal
|
|
976
|
+
// The whole first argument is the tracked function.
|
|
976
977
|
pushTrackedScope(arg0, "function");
|
|
977
978
|
} else if (
|
|
978
979
|
matchImport(
|
|
979
|
-
["
|
|
980
|
+
["createEffect", "createRenderEffect"],
|
|
981
|
+
callee.name,
|
|
982
|
+
)
|
|
983
|
+
) {
|
|
984
|
+
// Solid 2.0 split these into `(compute, apply)`. The
|
|
985
|
+
// compute phase tracks; the apply phase runs untracked
|
|
986
|
+
// and may return a cleanup, so reads there poll rather
|
|
987
|
+
// than subscribe. `createEffect` also accepts an effect
|
|
988
|
+
// bundle object in place of a plain apply function.
|
|
989
|
+
pushTrackedScope(arg0, "function");
|
|
990
|
+
if (arg1) {
|
|
991
|
+
if (arg1.type === "ObjectExpression") {
|
|
992
|
+
for (const property of arg1.properties) {
|
|
993
|
+
if (
|
|
994
|
+
property.type === "Property" &&
|
|
995
|
+
isFunctionNode(property.value)
|
|
996
|
+
) {
|
|
997
|
+
pushTrackedScope(
|
|
998
|
+
property.value,
|
|
999
|
+
"called-function",
|
|
1000
|
+
);
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
} else {
|
|
1004
|
+
pushTrackedScope(arg1, "called-function");
|
|
1005
|
+
}
|
|
1006
|
+
}
|
|
1007
|
+
} else if (matchImport(["createReaction"], callee.name)) {
|
|
1008
|
+
// `createReaction(effectFn)` takes the untracked effect
|
|
1009
|
+
// and returns the tracking function.
|
|
1010
|
+
pushTrackedScope(arg0, "called-function");
|
|
1011
|
+
} else if (
|
|
1012
|
+
matchImport(
|
|
1013
|
+
["onSettled", "onCleanup"],
|
|
980
1014
|
callee.name,
|
|
981
1015
|
) ||
|
|
982
1016
|
[
|
|
@@ -993,7 +1027,7 @@ export default createRule({
|
|
|
993
1027
|
// to poll the current value. Consider them called-function tracked
|
|
994
1028
|
// scopes for our purposes.
|
|
995
1029
|
pushTrackedScope(arg0, "called-function");
|
|
996
|
-
} else if (matchImport("
|
|
1030
|
+
} else if (matchImport("__removed_on", callee.name)) {
|
|
997
1031
|
// on accepts a signal or an array of signals as its first argument,
|
|
998
1032
|
// and a tracking function as its second
|
|
999
1033
|
if (arg0) {
|
|
@@ -1259,7 +1293,7 @@ export default createRule({
|
|
|
1259
1293
|
);
|
|
1260
1294
|
}
|
|
1261
1295
|
} else if (
|
|
1262
|
-
matchImport("
|
|
1296
|
+
matchImport("__removed_Index", tagName) &&
|
|
1263
1297
|
node.params.length >= 1 &&
|
|
1264
1298
|
node.params[0].type === "Identifier"
|
|
1265
1299
|
) {
|
package/src/utils.mjs
CHANGED
|
@@ -158,7 +158,10 @@ export function getCommentAfter(node, sourceCode) {
|
|
|
158
158
|
});
|
|
159
159
|
}
|
|
160
160
|
|
|
161
|
-
|
|
161
|
+
// Solid 2.0 split the runtime across packages: `solid-js` keeps the core and
|
|
162
|
+
// the store APIs, while `@solidjs/web`, `@solidjs/h`, `@solidjs/html` and
|
|
163
|
+
// `@solidjs/universal` own the renderers. Match both layouts.
|
|
164
|
+
export function trackImports(fromModule = /^(?:solid-js|@solidjs\/[a-z-]+)(?:\/|$)/) {
|
|
162
165
|
const importMap = new Map();
|
|
163
166
|
|
|
164
167
|
function handleImportDeclaration(node) {
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
2
|
-
|
|
3
|
-
import { jsxHasProp, jsxPropName } from "../utils.mjs";
|
|
4
|
-
const createRule = ESLintUtils.RuleCreator.withoutDocs;
|
|
5
|
-
export default createRule({
|
|
6
|
-
meta: {
|
|
7
|
-
type: "problem",
|
|
8
|
-
docs: {
|
|
9
|
-
description:
|
|
10
|
-
"Enforce using the classlist prop over importing a classnames helper. The classlist prop accepts an object `{ [class: string]: boolean }` just like classnames.",
|
|
11
|
-
url: "https://github.com/solidjs-community/eslint-plugin-solid/blob/main/packages/eslint-plugin-solid/docs/prefer-classlist.md",
|
|
12
|
-
},
|
|
13
|
-
fixable: "code",
|
|
14
|
-
deprecated: true,
|
|
15
|
-
schema: [
|
|
16
|
-
{
|
|
17
|
-
type: "object",
|
|
18
|
-
properties: {
|
|
19
|
-
classnames: {
|
|
20
|
-
type: "array",
|
|
21
|
-
description:
|
|
22
|
-
"An array of names to treat as `classnames` functions",
|
|
23
|
-
default: ["cn", "clsx", "classnames"],
|
|
24
|
-
items: {
|
|
25
|
-
type: "string",
|
|
26
|
-
},
|
|
27
|
-
minItems: 1,
|
|
28
|
-
uniqueItems: true,
|
|
29
|
-
},
|
|
30
|
-
},
|
|
31
|
-
additionalProperties: false,
|
|
32
|
-
},
|
|
33
|
-
],
|
|
34
|
-
messages: {
|
|
35
|
-
preferClasslist:
|
|
36
|
-
"The classlist prop should be used instead of {{ classnames }} to efficiently set classes based on an object.",
|
|
37
|
-
},
|
|
38
|
-
},
|
|
39
|
-
defaultOptions: [],
|
|
40
|
-
create(context) {
|
|
41
|
-
const classnames = context.options[0]?.classnames ?? [
|
|
42
|
-
"cn",
|
|
43
|
-
"clsx",
|
|
44
|
-
"classnames",
|
|
45
|
-
];
|
|
46
|
-
return {
|
|
47
|
-
JSXAttribute(node) {
|
|
48
|
-
if (
|
|
49
|
-
["class", "className"].indexOf(jsxPropName(node)) === -1 ||
|
|
50
|
-
jsxHasProp(node.parent?.attributes ?? [], "classlist")
|
|
51
|
-
) {
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
if (node.value?.type === "JSXExpressionContainer") {
|
|
55
|
-
const expr = node.value.expression;
|
|
56
|
-
if (
|
|
57
|
-
expr.type === "CallExpression" &&
|
|
58
|
-
expr.callee.type === "Identifier" &&
|
|
59
|
-
classnames.indexOf(expr.callee.name) !== -1 &&
|
|
60
|
-
expr.arguments.length === 1 &&
|
|
61
|
-
expr.arguments[0].type === "ObjectExpression"
|
|
62
|
-
) {
|
|
63
|
-
context.report({
|
|
64
|
-
node,
|
|
65
|
-
messageId: "preferClasslist",
|
|
66
|
-
data: {
|
|
67
|
-
classnames: expr.callee.name,
|
|
68
|
-
},
|
|
69
|
-
fix: (fixer) => {
|
|
70
|
-
const attrRange = node.range;
|
|
71
|
-
const objectRange = expr.arguments[0].range;
|
|
72
|
-
return [
|
|
73
|
-
fixer.replaceTextRange(
|
|
74
|
-
[attrRange[0], objectRange[0]],
|
|
75
|
-
"classlist={",
|
|
76
|
-
),
|
|
77
|
-
fixer.replaceTextRange(
|
|
78
|
-
[objectRange[1], attrRange[1]],
|
|
79
|
-
"}",
|
|
80
|
-
),
|
|
81
|
-
];
|
|
82
|
-
},
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
},
|
|
87
|
-
};
|
|
88
|
-
},
|
|
89
|
-
});
|