@murky-web/oxlint-plugin-solid 0.1.3 → 1.1.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 +136 -36
- 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;
|
|
@@ -210,7 +215,7 @@ export default createRule({
|
|
|
210
215
|
shouldAssign:
|
|
211
216
|
"For proper analysis, a variable should be used to capture the result of this function call.",
|
|
212
217
|
noAsyncTrackedScope:
|
|
213
|
-
"
|
|
218
|
+
"The reactive variable '{{name}}' is read after an await, so it registers no dependency and this computation will not re-run when it changes. Read every reactive input before the first async gap.",
|
|
214
219
|
},
|
|
215
220
|
},
|
|
216
221
|
defaultOptions: [
|
|
@@ -386,6 +391,65 @@ export default createRule({
|
|
|
386
391
|
}
|
|
387
392
|
};
|
|
388
393
|
/** Performs all analysis and reporting. */
|
|
394
|
+
const asyncGapCache = new Map();
|
|
395
|
+
const ASYNC_GAP_TYPES = new Set(["AwaitExpression", "YieldExpression"]);
|
|
396
|
+
/**
|
|
397
|
+
* Where a function first suspends, or null if it never does.
|
|
398
|
+
*
|
|
399
|
+
* `yield` counts alongside `await`: an async generator driven by `action`
|
|
400
|
+
* suspends there in exactly the same way, and a read afterwards is just as
|
|
401
|
+
* detached. Nested functions are skipped — their gaps are their own, and a
|
|
402
|
+
* callback defined after an await still runs with its own tracking.
|
|
403
|
+
*/
|
|
404
|
+
const firstAsyncGapStart = (node) => {
|
|
405
|
+
if (!isFunctionNode(node) || node.async !== true) {
|
|
406
|
+
return null;
|
|
407
|
+
}
|
|
408
|
+
if (asyncGapCache.has(node)) {
|
|
409
|
+
return asyncGapCache.get(node);
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
let earliest = null;
|
|
413
|
+
const pending = [node.body];
|
|
414
|
+
while (pending.length > 0) {
|
|
415
|
+
const current = pending.pop();
|
|
416
|
+
if (!current || typeof current !== "object") {
|
|
417
|
+
continue;
|
|
418
|
+
}
|
|
419
|
+
if (Array.isArray(current)) {
|
|
420
|
+
pending.push(...current);
|
|
421
|
+
continue;
|
|
422
|
+
}
|
|
423
|
+
if (typeof current.type !== "string") {
|
|
424
|
+
continue;
|
|
425
|
+
}
|
|
426
|
+
if (ASYNC_GAP_TYPES.has(current.type)) {
|
|
427
|
+
const start = Array.isArray(current.range)
|
|
428
|
+
? current.range[0]
|
|
429
|
+
: null;
|
|
430
|
+
if (start !== null && (earliest === null || start < earliest)) {
|
|
431
|
+
earliest = start;
|
|
432
|
+
}
|
|
433
|
+
// An await nested inside this one cannot start earlier.
|
|
434
|
+
continue;
|
|
435
|
+
}
|
|
436
|
+
for (const [key, value] of Object.entries(current)) {
|
|
437
|
+
if (key === "parent") {
|
|
438
|
+
continue;
|
|
439
|
+
}
|
|
440
|
+
if (
|
|
441
|
+
value &&
|
|
442
|
+
typeof value === "object" &&
|
|
443
|
+
!(typeof value.type === "string" && isFunctionNode(value))
|
|
444
|
+
) {
|
|
445
|
+
pending.push(value);
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
asyncGapCache.set(node, earliest);
|
|
451
|
+
return earliest;
|
|
452
|
+
};
|
|
389
453
|
const onFunctionExit = (currentScopeNode) => {
|
|
390
454
|
// If this function is a component, add its props as a reactive variable
|
|
391
455
|
if (isFunctionNode(currentScopeNode)) {
|
|
@@ -411,12 +475,32 @@ export default createRule({
|
|
|
411
475
|
) {
|
|
412
476
|
return;
|
|
413
477
|
}
|
|
478
|
+
// Solid 2.0 supports async computations — `createMemo(async () => …)` is
|
|
479
|
+
// the documented shape. What stays synchronous is dependency *tracking*:
|
|
480
|
+
// reads before the first await register, reads after it do not. So the
|
|
481
|
+
// hazard is not the `async` keyword, it is a reactive read on the far side
|
|
482
|
+
// of an async gap, which silently creates no dependency edge and leaves the
|
|
483
|
+
// computation unable to re-run. Solid's development build raises this at
|
|
484
|
+
// runtime; catching it here also covers production, where that check is
|
|
485
|
+
// compiled out.
|
|
486
|
+
const asyncGapStart = firstAsyncGapStart(currentScopeNode);
|
|
414
487
|
// Iterate through all usages of (derived) signals in the current scope
|
|
415
488
|
for (const {
|
|
416
489
|
reference,
|
|
417
490
|
declarationScope,
|
|
418
491
|
} of scopeStack.consumeSignalReferencesInScope()) {
|
|
419
492
|
const identifier = reference.identifier;
|
|
493
|
+
if (
|
|
494
|
+
asyncGapStart !== null &&
|
|
495
|
+
Array.isArray(identifier.range) &&
|
|
496
|
+
identifier.range[0] > asyncGapStart
|
|
497
|
+
) {
|
|
498
|
+
context.report({
|
|
499
|
+
node: identifier,
|
|
500
|
+
messageId: "noAsyncTrackedScope",
|
|
501
|
+
data: { name: identifier.name },
|
|
502
|
+
});
|
|
503
|
+
}
|
|
420
504
|
if (reference.isWrite()) {
|
|
421
505
|
// don't allow reassigning signals
|
|
422
506
|
context.report({
|
|
@@ -624,7 +708,7 @@ export default createRule({
|
|
|
624
708
|
) {
|
|
625
709
|
if (
|
|
626
710
|
node.callee.type === "Identifier" &&
|
|
627
|
-
matchImport(["
|
|
711
|
+
matchImport(["flush"], node.callee.name)
|
|
628
712
|
) {
|
|
629
713
|
// These Solid APIs take callbacks that run in the current scope
|
|
630
714
|
scopeStack.syncCallbacks.add(node.arguments[0]);
|
|
@@ -673,7 +757,7 @@ export default createRule({
|
|
|
673
757
|
}
|
|
674
758
|
}
|
|
675
759
|
} else if (
|
|
676
|
-
matchImport(["mapArray", "
|
|
760
|
+
matchImport(["mapArray", "repeat"], node.callee.name)
|
|
677
761
|
) {
|
|
678
762
|
const arg1 = node.arguments[1];
|
|
679
763
|
if (isFunctionNode(arg1)) {
|
|
@@ -696,7 +780,7 @@ export default createRule({
|
|
|
696
780
|
) {
|
|
697
781
|
const { callee } = init;
|
|
698
782
|
if (
|
|
699
|
-
matchImport(["createSignal"
|
|
783
|
+
matchImport(["createSignal"], callee.name)
|
|
700
784
|
) {
|
|
701
785
|
const signal = id && getNthDestructuredVar(id, 0, context);
|
|
702
786
|
if (signal) {
|
|
@@ -705,7 +789,7 @@ export default createRule({
|
|
|
705
789
|
warnShouldDestructure(id ?? init, "first");
|
|
706
790
|
}
|
|
707
791
|
} else if (
|
|
708
|
-
matchImport(["createMemo", "
|
|
792
|
+
matchImport(["createMemo", "createProjection"], callee.name)
|
|
709
793
|
) {
|
|
710
794
|
const memo = id && getReturnedVar(id, context);
|
|
711
795
|
// memos act like signals
|
|
@@ -722,7 +806,7 @@ export default createRule({
|
|
|
722
806
|
} else {
|
|
723
807
|
warnShouldDestructure(id ?? init, "first");
|
|
724
808
|
}
|
|
725
|
-
} else if (matchImport("
|
|
809
|
+
} else if (matchImport("merge", callee.name)) {
|
|
726
810
|
const merged = id && getReturnedVar(id, context);
|
|
727
811
|
if (merged) {
|
|
728
812
|
scopeStack.pushProps(merged, currentScope().node);
|
|
@@ -754,7 +838,7 @@ export default createRule({
|
|
|
754
838
|
scopeStack.pushProps(vars, currentScope().node);
|
|
755
839
|
}
|
|
756
840
|
}
|
|
757
|
-
} else if (matchImport("
|
|
841
|
+
} else if (matchImport("__removed_createResource", callee.name)) {
|
|
758
842
|
// createResource return value has reactive .loading and .error
|
|
759
843
|
const resourceReturn =
|
|
760
844
|
id && getNthDestructuredVar(id, 0, context);
|
|
@@ -764,7 +848,7 @@ export default createRule({
|
|
|
764
848
|
currentScope().node,
|
|
765
849
|
);
|
|
766
850
|
}
|
|
767
|
-
} else if (matchImport("
|
|
851
|
+
} else if (matchImport("__removed_createMutable", callee.name)) {
|
|
768
852
|
const mutable = id && getReturnedVar(id, context);
|
|
769
853
|
if (mutable) {
|
|
770
854
|
scopeStack.pushProps(mutable, currentScope().node);
|
|
@@ -784,7 +868,7 @@ export default createRule({
|
|
|
784
868
|
scopeStack.pushSignal(indexSignal);
|
|
785
869
|
}
|
|
786
870
|
}
|
|
787
|
-
} else if (matchImport("
|
|
871
|
+
} else if (matchImport("__removed_indexArray", callee.name)) {
|
|
788
872
|
const arg1 = init.arguments[1];
|
|
789
873
|
if (
|
|
790
874
|
isFunctionNode(arg1) &&
|
|
@@ -805,19 +889,6 @@ export default createRule({
|
|
|
805
889
|
const checkForTrackedScopes = (node) => {
|
|
806
890
|
const pushTrackedScope = (node, expect) => {
|
|
807
891
|
currentScope().trackedScopes.push({ node, expect });
|
|
808
|
-
if (
|
|
809
|
-
expect !== "called-function" &&
|
|
810
|
-
isFunctionNode(node) &&
|
|
811
|
-
node.async
|
|
812
|
-
) {
|
|
813
|
-
// From the docs: "[Solid's] approach only tracks synchronously. If you
|
|
814
|
-
// have a setTimeout or use an async function in your Effect the code
|
|
815
|
-
// that executes async after the fact won't be tracked."
|
|
816
|
-
context.report({
|
|
817
|
-
node,
|
|
818
|
-
messageId: "noAsyncTrackedScope",
|
|
819
|
-
});
|
|
820
|
-
}
|
|
821
892
|
};
|
|
822
893
|
// given some expression, mark any functions within it as tracking scopes, and do not traverse
|
|
823
894
|
// those functions
|
|
@@ -956,27 +1027,56 @@ export default createRule({
|
|
|
956
1027
|
[
|
|
957
1028
|
"createMemo",
|
|
958
1029
|
"children",
|
|
959
|
-
"
|
|
960
|
-
"
|
|
961
|
-
"createDeferred",
|
|
962
|
-
"createComputed",
|
|
963
|
-
"createSelector",
|
|
1030
|
+
"createTrackedEffect",
|
|
1031
|
+
"createProjection",
|
|
964
1032
|
"untrack",
|
|
965
1033
|
"mapArray",
|
|
966
|
-
"
|
|
967
|
-
"
|
|
1034
|
+
"isPending",
|
|
1035
|
+
"latest",
|
|
1036
|
+
"resolve",
|
|
968
1037
|
],
|
|
969
1038
|
callee.name,
|
|
970
1039
|
) ||
|
|
971
|
-
|
|
972
|
-
node.arguments.length >= 2)
|
|
1040
|
+
false /* Solid 2.0 removed createResource */
|
|
973
1041
|
) {
|
|
974
|
-
//
|
|
975
|
-
// `source` first argument may be a signal
|
|
1042
|
+
// The whole first argument is the tracked function.
|
|
976
1043
|
pushTrackedScope(arg0, "function");
|
|
977
1044
|
} else if (
|
|
978
1045
|
matchImport(
|
|
979
|
-
["
|
|
1046
|
+
["createEffect", "createRenderEffect"],
|
|
1047
|
+
callee.name,
|
|
1048
|
+
)
|
|
1049
|
+
) {
|
|
1050
|
+
// Solid 2.0 split these into `(compute, apply)`. The
|
|
1051
|
+
// compute phase tracks; the apply phase runs untracked
|
|
1052
|
+
// and may return a cleanup, so reads there poll rather
|
|
1053
|
+
// than subscribe. `createEffect` also accepts an effect
|
|
1054
|
+
// bundle object in place of a plain apply function.
|
|
1055
|
+
pushTrackedScope(arg0, "function");
|
|
1056
|
+
if (arg1) {
|
|
1057
|
+
if (arg1.type === "ObjectExpression") {
|
|
1058
|
+
for (const property of arg1.properties) {
|
|
1059
|
+
if (
|
|
1060
|
+
property.type === "Property" &&
|
|
1061
|
+
isFunctionNode(property.value)
|
|
1062
|
+
) {
|
|
1063
|
+
pushTrackedScope(
|
|
1064
|
+
property.value,
|
|
1065
|
+
"called-function",
|
|
1066
|
+
);
|
|
1067
|
+
}
|
|
1068
|
+
}
|
|
1069
|
+
} else {
|
|
1070
|
+
pushTrackedScope(arg1, "called-function");
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
} else if (matchImport(["createReaction"], callee.name)) {
|
|
1074
|
+
// `createReaction(effectFn)` takes the untracked effect
|
|
1075
|
+
// and returns the tracking function.
|
|
1076
|
+
pushTrackedScope(arg0, "called-function");
|
|
1077
|
+
} else if (
|
|
1078
|
+
matchImport(
|
|
1079
|
+
["onSettled", "onCleanup"],
|
|
980
1080
|
callee.name,
|
|
981
1081
|
) ||
|
|
982
1082
|
[
|
|
@@ -993,7 +1093,7 @@ export default createRule({
|
|
|
993
1093
|
// to poll the current value. Consider them called-function tracked
|
|
994
1094
|
// scopes for our purposes.
|
|
995
1095
|
pushTrackedScope(arg0, "called-function");
|
|
996
|
-
} else if (matchImport("
|
|
1096
|
+
} else if (matchImport("__removed_on", callee.name)) {
|
|
997
1097
|
// on accepts a signal or an array of signals as its first argument,
|
|
998
1098
|
// and a tracking function as its second
|
|
999
1099
|
if (arg0) {
|
|
@@ -1259,7 +1359,7 @@ export default createRule({
|
|
|
1259
1359
|
);
|
|
1260
1360
|
}
|
|
1261
1361
|
} else if (
|
|
1262
|
-
matchImport("
|
|
1362
|
+
matchImport("__removed_Index", tagName) &&
|
|
1263
1363
|
node.params.length >= 1 &&
|
|
1264
1364
|
node.params[0].type === "Identifier"
|
|
1265
1365
|
) {
|
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
|
-
});
|