@murky-web/oxlint-plugin-solid 1.1.0 → 1.3.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 +78 -1
- package/package.json +3 -4
- package/src/compat.mjs +2 -2
- package/src/index.mjs +12 -0
- package/src/rules/components_return_once.mjs +2 -5
- package/src/rules/event_handlers.mjs +3 -5
- package/src/rules/imports.mjs +9 -5
- package/src/rules/jsx_no_duplicate_props.mjs +3 -6
- package/src/rules/jsx_no_script_url.mjs +3 -5
- package/src/rules/jsx_no_undef.mjs +2 -5
- package/src/rules/jsx_uses_vars.mjs +2 -6
- package/src/rules/no_array_handlers.mjs +2 -6
- package/src/rules/no_destructure.mjs +3 -5
- package/src/rules/no_innerhtml.mjs +3 -5
- package/src/rules/no_owned_primitives_in_ref.mjs +122 -0
- package/src/rules/no_proxy_apis.mjs +2 -6
- package/src/rules/no_react_deps.mjs +3 -6
- package/src/rules/no_react_specific_props.mjs +2 -5
- package/src/rules/no_server_import_in_client.mjs +172 -0
- package/src/rules/no_setter_in_effect.mjs +168 -0
- package/src/rules/no_unknown_namespaces.mjs +2 -5
- package/src/rules/no_untracked_effect_read.mjs +175 -0
- package/src/rules/prefer_class_object.mjs +9 -9
- package/src/rules/prefer_for.mjs +3 -5
- package/src/rules/prefer_show.mjs +2 -5
- package/src/rules/reactive_async.mjs +237 -0
- package/src/rules/reactivity.mjs +10 -8
- package/src/rules/self_closing_comp.mjs +2 -5
- package/src/rules/strict_void_return.mjs +201 -0
- package/src/rules/style_prop.mjs +3 -5
- package/src/utils.mjs +33 -0
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
2
|
+
import { dirname, join, resolve, sep } from "node:path";
|
|
3
|
+
|
|
4
|
+
const SERVER_DIRECTORY = join("src", "server");
|
|
5
|
+
const EXTENSIONS = [".ts", ".tsx", ".mts", ".js", ".jsx", ".mjs"];
|
|
6
|
+
const CLIENT_FILE = /\.(?:[cm]?[jt]s|[jt]sx)$/;
|
|
7
|
+
const TEST_FILE = /\.(?:test|spec)\.[^/]+$/;
|
|
8
|
+
const ALIAS_PREFIX = "~/";
|
|
9
|
+
const USE_SERVER = /^(?:["']use server["'])/;
|
|
10
|
+
// Whitespace and comments may precede the directive; anything else means it is
|
|
11
|
+
// not the first statement.
|
|
12
|
+
const LEADING_TRIVIA = /^(?:\s+|\/\/[^\n]*|\/\*[\s\S]*?\*\/)+/;
|
|
13
|
+
|
|
14
|
+
/** Nearest directory at or above `directory` that holds a package.json. */
|
|
15
|
+
function findProjectRoot(directory) {
|
|
16
|
+
let current = directory;
|
|
17
|
+
|
|
18
|
+
while (!existsSync(join(current, "package.json"))) {
|
|
19
|
+
const parent = dirname(current);
|
|
20
|
+
if (parent === current) {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
current = parent;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return current;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function isFile(path) {
|
|
31
|
+
return existsSync(path) && statSync(path).isFile();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The file an import path points at, trying the extensions the bundler would.
|
|
36
|
+
* A `.js` specifier names the `.ts` source next to it.
|
|
37
|
+
*/
|
|
38
|
+
function findModuleFile(basePath) {
|
|
39
|
+
const withoutJsExtension = basePath.replace(/\.[cm]?jsx?$/, "");
|
|
40
|
+
const candidates = [
|
|
41
|
+
basePath,
|
|
42
|
+
...EXTENSIONS.map((extension) => `${basePath}${extension}`),
|
|
43
|
+
...EXTENSIONS.map((extension) => `${withoutJsExtension}${extension}`),
|
|
44
|
+
...EXTENSIONS.map((extension) => join(basePath, `index${extension}`)),
|
|
45
|
+
];
|
|
46
|
+
|
|
47
|
+
return candidates.find(isFile) ?? null;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function startsWithUseServer(filePath) {
|
|
51
|
+
let text = readFileSync(filePath, "utf8").replace(/^/, "");
|
|
52
|
+
|
|
53
|
+
for (;;) {
|
|
54
|
+
const trivia = LEADING_TRIVIA.exec(text);
|
|
55
|
+
if (!trivia) {
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
text = text.slice(trivia[0].length);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return USE_SERVER.test(text);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function isInside(path, directory) {
|
|
66
|
+
return path.startsWith(`${directory}${sep}`);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function resolveImport(specifier, filename, projectRoot) {
|
|
70
|
+
if (specifier.startsWith(ALIAS_PREFIX)) {
|
|
71
|
+
return resolve(
|
|
72
|
+
projectRoot,
|
|
73
|
+
"src",
|
|
74
|
+
specifier.slice(ALIAS_PREFIX.length),
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (specifier.startsWith("./") || specifier.startsWith("../")) {
|
|
79
|
+
return resolve(dirname(filename), specifier);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export const noServerImportInClientRule = {
|
|
86
|
+
meta: {
|
|
87
|
+
type: "problem",
|
|
88
|
+
docs: {
|
|
89
|
+
description:
|
|
90
|
+
"Disallow importing modules from src/server/ into client code unless they are use-server modules.",
|
|
91
|
+
url: "https://docs.solidjs.com/",
|
|
92
|
+
},
|
|
93
|
+
schema: [],
|
|
94
|
+
messages: {
|
|
95
|
+
serverImportInClient:
|
|
96
|
+
"'{{specifier}}' lives under src/server/ but does not start with the \"use server\" directive, so importing it into client code ships server-only code to the browser. Import a server function module instead (first statement `\"use server\";`, async exports only), and keep database clients and secrets inside it.",
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
defaultOptions: [],
|
|
100
|
+
create(context) {
|
|
101
|
+
const filename = resolve(context.filename ?? context.getFilename());
|
|
102
|
+
const projectRoot = findProjectRoot(dirname(filename));
|
|
103
|
+
|
|
104
|
+
// Server modules, tests and non-code files may import anything.
|
|
105
|
+
if (
|
|
106
|
+
projectRoot === null ||
|
|
107
|
+
!CLIENT_FILE.test(filename) ||
|
|
108
|
+
TEST_FILE.test(filename) ||
|
|
109
|
+
isInside(filename, join(projectRoot, SERVER_DIRECTORY))
|
|
110
|
+
) {
|
|
111
|
+
return {};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const serverDirectory = join(projectRoot, SERVER_DIRECTORY);
|
|
115
|
+
|
|
116
|
+
function check(sourceNode) {
|
|
117
|
+
if (
|
|
118
|
+
sourceNode?.type !== "Literal" ||
|
|
119
|
+
typeof sourceNode.value !== "string"
|
|
120
|
+
) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const basePath = resolveImport(
|
|
125
|
+
sourceNode.value,
|
|
126
|
+
filename,
|
|
127
|
+
projectRoot,
|
|
128
|
+
);
|
|
129
|
+
if (basePath === null) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const target = findModuleFile(basePath);
|
|
134
|
+
// A missing file is the resolver's problem, not this rule's.
|
|
135
|
+
if (
|
|
136
|
+
target === null ||
|
|
137
|
+
!isInside(target, serverDirectory) ||
|
|
138
|
+
startsWithUseServer(target)
|
|
139
|
+
) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
context.report({
|
|
144
|
+
node: sourceNode,
|
|
145
|
+
messageId: "serverImportInClient",
|
|
146
|
+
data: { specifier: sourceNode.value },
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return {
|
|
151
|
+
ImportDeclaration(node) {
|
|
152
|
+
// Types are erased, nothing reaches the bundle.
|
|
153
|
+
if (node.importKind !== "type") {
|
|
154
|
+
check(node.source);
|
|
155
|
+
}
|
|
156
|
+
},
|
|
157
|
+
ExportNamedDeclaration(node) {
|
|
158
|
+
if (node.exportKind !== "type") {
|
|
159
|
+
check(node.source);
|
|
160
|
+
}
|
|
161
|
+
},
|
|
162
|
+
ExportAllDeclaration(node) {
|
|
163
|
+
if (node.exportKind !== "type") {
|
|
164
|
+
check(node.source);
|
|
165
|
+
}
|
|
166
|
+
},
|
|
167
|
+
ImportExpression(node) {
|
|
168
|
+
check(node.source);
|
|
169
|
+
},
|
|
170
|
+
};
|
|
171
|
+
},
|
|
172
|
+
};
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { isFunctionNode, trackImports } from "../utils.mjs";
|
|
2
|
+
|
|
3
|
+
const SETTER_INDEX = 1;
|
|
4
|
+
|
|
5
|
+
/** `const [value, setValue] = createSignal(...)` -> "setValue". */
|
|
6
|
+
function getSetterName(declarator) {
|
|
7
|
+
if (declarator.id.type !== "ArrayPattern") {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const element = declarator.id.elements[SETTER_INDEX];
|
|
12
|
+
|
|
13
|
+
return element?.type === "Identifier" ? element.name : null;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The phase that runs untracked and performs the work. Solid 2.0 passes it as
|
|
18
|
+
* the second argument; a lone function is still the whole effect.
|
|
19
|
+
*/
|
|
20
|
+
function getEffectPhase(node) {
|
|
21
|
+
const [compute, apply] = node.arguments;
|
|
22
|
+
|
|
23
|
+
if (apply) {
|
|
24
|
+
return isFunctionNode(apply) ? apply : null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return isFunctionNode(compute) ? compute : null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function isSetterCall(node, setterNames) {
|
|
31
|
+
return (
|
|
32
|
+
node?.type === "CallExpression" &&
|
|
33
|
+
node.callee.type === "Identifier" &&
|
|
34
|
+
setterNames.has(node.callee.name)
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** True when any statement anywhere in the phase writes to a signal or store. */
|
|
39
|
+
function writesSignalsAnywhere(node, setterNames) {
|
|
40
|
+
if (node === null || typeof node !== "object") {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (isSetterCall(node, setterNames)) {
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return Object.entries(node).some(([key, value]) => {
|
|
49
|
+
// `parent` points back up the tree; following it would not terminate.
|
|
50
|
+
if (key === "parent") {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const candidates = Array.isArray(value) ? value : [value];
|
|
55
|
+
|
|
56
|
+
return candidates.some(
|
|
57
|
+
(candidate) =>
|
|
58
|
+
candidate !== null &&
|
|
59
|
+
typeof candidate === "object" &&
|
|
60
|
+
!isFunctionNode(candidate) &&
|
|
61
|
+
writesSignalsAnywhere(candidate, setterNames),
|
|
62
|
+
);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** True when the phase does nothing but write to signals or stores. */
|
|
67
|
+
function onlyWritesSignals(phase, setterNames) {
|
|
68
|
+
if (phase.body.type !== "BlockStatement") {
|
|
69
|
+
return isSetterCall(phase.body, setterNames);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const { body } = phase.body;
|
|
73
|
+
|
|
74
|
+
return (
|
|
75
|
+
body.length > 0 &&
|
|
76
|
+
body.every(
|
|
77
|
+
(statement) =>
|
|
78
|
+
statement.type === "ExpressionStatement" &&
|
|
79
|
+
isSetterCall(statement.expression, setterNames),
|
|
80
|
+
)
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export default {
|
|
85
|
+
meta: {
|
|
86
|
+
type: "problem",
|
|
87
|
+
docs: {
|
|
88
|
+
description:
|
|
89
|
+
"Disallow effects that only copy a reactive value into another signal or store.",
|
|
90
|
+
url: "https://docs.solidjs.com/",
|
|
91
|
+
},
|
|
92
|
+
schema: [],
|
|
93
|
+
messages: {
|
|
94
|
+
asyncSetterInEffect:
|
|
95
|
+
"This effect awaits and then writes the result into a signal or store. Return the value from a derivation instead: `createMemo(async () => ...)`, or the function form of `createStore` for nested data. Solid coordinates readiness, error propagation, and dropping superseded runs.",
|
|
96
|
+
noSetterInEffect:
|
|
97
|
+
"This effect only writes to a signal or store. Calculate the value where it is read instead: a derived function, `createMemo`, or a writable derived `createSignal(() => ...)` for a local override.",
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
defaultOptions: [],
|
|
101
|
+
create(context) {
|
|
102
|
+
const { matchImport, handleImportDeclaration } = trackImports();
|
|
103
|
+
const setterNames = new Set();
|
|
104
|
+
|
|
105
|
+
return {
|
|
106
|
+
ImportDeclaration: handleImportDeclaration,
|
|
107
|
+
VariableDeclarator(node) {
|
|
108
|
+
if (
|
|
109
|
+
node.init?.type !== "CallExpression" ||
|
|
110
|
+
node.init.callee.type !== "Identifier" ||
|
|
111
|
+
!matchImport(
|
|
112
|
+
["createSignal", "createStore"],
|
|
113
|
+
node.init.callee.name,
|
|
114
|
+
)
|
|
115
|
+
) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const setterName = getSetterName(node);
|
|
120
|
+
if (setterName) {
|
|
121
|
+
setterNames.add(setterName);
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
CallExpression(node) {
|
|
125
|
+
if (
|
|
126
|
+
node.callee.type !== "Identifier" ||
|
|
127
|
+
!matchImport(
|
|
128
|
+
["createEffect", "createRenderEffect"],
|
|
129
|
+
node.callee.name,
|
|
130
|
+
)
|
|
131
|
+
) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const phase = getEffectPhase(node);
|
|
136
|
+
if (!phase) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Asynchrony is checked first because it is the more specific
|
|
141
|
+
// diagnosis: `onlyWritesSignals` also matches a lone
|
|
142
|
+
// `setResults(await search(q))`, and the async message is the
|
|
143
|
+
// one that names readiness and superseded runs.
|
|
144
|
+
//
|
|
145
|
+
// `onlyWritesSignals` never sees the multi-statement shape at
|
|
146
|
+
// all — the `await` is not a setter call — which is why an
|
|
147
|
+
// async phase gets its own search.
|
|
148
|
+
if (
|
|
149
|
+
phase.async === true &&
|
|
150
|
+
writesSignalsAnywhere(phase.body, setterNames)
|
|
151
|
+
) {
|
|
152
|
+
context.report({
|
|
153
|
+
node: phase,
|
|
154
|
+
messageId: "asyncSetterInEffect",
|
|
155
|
+
});
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if (onlyWritesSignals(phase, setterNames)) {
|
|
160
|
+
context.report({
|
|
161
|
+
node: phase,
|
|
162
|
+
messageId: "noSetterInEffect",
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
},
|
|
166
|
+
};
|
|
167
|
+
},
|
|
168
|
+
};
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
2
|
-
|
|
3
1
|
import { isDOMElementName } from "../utils.mjs";
|
|
4
|
-
const createRule = ESLintUtils.RuleCreator.withoutDocs;
|
|
5
2
|
// Solid 2.0 removed every Solid-specific JSX namespace. What is left are the
|
|
6
3
|
// XML namespaces the DOM itself defines.
|
|
7
4
|
const xmlNamespaces = ["xmlns", "xlink"];
|
|
@@ -17,7 +14,7 @@ const replacements = {
|
|
|
17
14
|
style: "the `style` prop with an object value",
|
|
18
15
|
use: "a ref callback or directive factory, composing with a ref array",
|
|
19
16
|
};
|
|
20
|
-
export default
|
|
17
|
+
export default {
|
|
21
18
|
meta: {
|
|
22
19
|
type: "problem",
|
|
23
20
|
docs: {
|
|
@@ -107,4 +104,4 @@ export default createRule({
|
|
|
107
104
|
},
|
|
108
105
|
};
|
|
109
106
|
},
|
|
110
|
-
}
|
|
107
|
+
};
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { isFunctionNode, isPropsByName, trackImports } from "../utils.mjs";
|
|
2
|
+
|
|
3
|
+
const GETTER_INDEX = 0;
|
|
4
|
+
|
|
5
|
+
/** `const [value, setValue] = createSignal(...)` -> "value". */
|
|
6
|
+
function getGetterName(declarator) {
|
|
7
|
+
if (declarator.id.type !== "ArrayPattern") {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const element = declarator.id.elements[GETTER_INDEX];
|
|
12
|
+
|
|
13
|
+
return element?.type === "Identifier" ? element.name : null;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Every name a function's parameters bind, however they are destructured. */
|
|
17
|
+
function collectParameterNames(fn, into) {
|
|
18
|
+
const pending = [...fn.params];
|
|
19
|
+
|
|
20
|
+
while (pending.length > 0) {
|
|
21
|
+
const pattern = pending.pop();
|
|
22
|
+
if (pattern === null || typeof pattern !== "object") {
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (pattern.type === "Identifier") {
|
|
27
|
+
into.add(pattern.name);
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
for (const [key, value] of Object.entries(pattern)) {
|
|
32
|
+
if (key === "parent") {
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const candidates = Array.isArray(value) ? value : [value];
|
|
37
|
+
for (const candidate of candidates) {
|
|
38
|
+
if (candidate !== null && typeof candidate === "object") {
|
|
39
|
+
pending.push(candidate);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Walk the phase body, stopping at nested functions.
|
|
48
|
+
*
|
|
49
|
+
* A read inside a nested function runs whenever that function is called, which
|
|
50
|
+
* is a different question from whether this phase subscribes to it.
|
|
51
|
+
*/
|
|
52
|
+
function walkPhase(node, visit) {
|
|
53
|
+
if (node === null || typeof node !== "object") {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
visit(node);
|
|
58
|
+
|
|
59
|
+
for (const [key, value] of Object.entries(node)) {
|
|
60
|
+
if (key === "parent") {
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const candidates = Array.isArray(value) ? value : [value];
|
|
65
|
+
for (const candidate of candidates) {
|
|
66
|
+
if (
|
|
67
|
+
candidate !== null &&
|
|
68
|
+
typeof candidate === "object" &&
|
|
69
|
+
typeof candidate.type === "string" &&
|
|
70
|
+
!isFunctionNode(candidate)
|
|
71
|
+
) {
|
|
72
|
+
walkPhase(candidate, visit);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export default {
|
|
79
|
+
meta: {
|
|
80
|
+
type: "problem",
|
|
81
|
+
docs: {
|
|
82
|
+
description:
|
|
83
|
+
"Disallow reading reactive values in the untracked apply phase of an effect.",
|
|
84
|
+
url: "https://docs.solidjs.com/",
|
|
85
|
+
},
|
|
86
|
+
schema: [],
|
|
87
|
+
messages: {
|
|
88
|
+
untrackedEffectRead:
|
|
89
|
+
"'{{name}}' is read in the effect's apply phase, which runs untracked — changes to it will not re-run this effect. Read it in the compute phase and take it as an argument instead.",
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
defaultOptions: [],
|
|
93
|
+
create(context) {
|
|
94
|
+
const { matchImport, handleImportDeclaration } = trackImports();
|
|
95
|
+
const getterNames = new Set();
|
|
96
|
+
|
|
97
|
+
return {
|
|
98
|
+
ImportDeclaration: handleImportDeclaration,
|
|
99
|
+
VariableDeclarator(node) {
|
|
100
|
+
if (
|
|
101
|
+
node.init?.type !== "CallExpression" ||
|
|
102
|
+
node.init.callee.type !== "Identifier" ||
|
|
103
|
+
!matchImport(["createSignal"], node.init.callee.name)
|
|
104
|
+
) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const getterName = getGetterName(node);
|
|
109
|
+
if (getterName) {
|
|
110
|
+
getterNames.add(getterName);
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
CallExpression(node) {
|
|
114
|
+
if (
|
|
115
|
+
node.callee.type !== "Identifier" ||
|
|
116
|
+
!matchImport(
|
|
117
|
+
["createEffect", "createRenderEffect"],
|
|
118
|
+
node.callee.name,
|
|
119
|
+
)
|
|
120
|
+
) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Only the two-argument form has an apply phase. A lone
|
|
125
|
+
// function is the whole effect and tracks throughout.
|
|
126
|
+
const [compute, apply] = node.arguments;
|
|
127
|
+
if (!compute || !apply || !isFunctionNode(apply)) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// Whatever the compute phase handed over arrives as a
|
|
132
|
+
// parameter, so those names are already settled values.
|
|
133
|
+
const settled = new Set();
|
|
134
|
+
collectParameterNames(apply, settled);
|
|
135
|
+
|
|
136
|
+
walkPhase(apply.body, (candidate) => {
|
|
137
|
+
// `signal()` — a getter call that did not come through the
|
|
138
|
+
// compute phase.
|
|
139
|
+
if (
|
|
140
|
+
candidate.type === "CallExpression" &&
|
|
141
|
+
candidate.callee.type === "Identifier" &&
|
|
142
|
+
getterNames.has(candidate.callee.name) &&
|
|
143
|
+
!settled.has(candidate.callee.name)
|
|
144
|
+
) {
|
|
145
|
+
context.report({
|
|
146
|
+
node: candidate,
|
|
147
|
+
messageId: "untrackedEffectRead",
|
|
148
|
+
data: { name: candidate.callee.name },
|
|
149
|
+
});
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// `props.value` — a props read is reactive for the same
|
|
154
|
+
// reason and is just as invisible to the tracker here.
|
|
155
|
+
if (
|
|
156
|
+
candidate.type === "MemberExpression" &&
|
|
157
|
+
!candidate.computed &&
|
|
158
|
+
candidate.object.type === "Identifier" &&
|
|
159
|
+
isPropsByName(candidate.object.name) &&
|
|
160
|
+
!settled.has(candidate.object.name) &&
|
|
161
|
+
candidate.property.type === "Identifier"
|
|
162
|
+
) {
|
|
163
|
+
context.report({
|
|
164
|
+
node: candidate,
|
|
165
|
+
messageId: "untrackedEffectRead",
|
|
166
|
+
data: {
|
|
167
|
+
name: `${candidate.object.name}.${candidate.property.name}`,
|
|
168
|
+
},
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
},
|
|
173
|
+
};
|
|
174
|
+
},
|
|
175
|
+
};
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
2
|
-
|
|
3
1
|
import { jsxPropName } from "../utils.mjs";
|
|
4
|
-
const createRule = ESLintUtils.RuleCreator.withoutDocs;
|
|
5
2
|
const DEFAULT_CLASSNAMES = ["cn", "clsx", "classnames"];
|
|
6
|
-
export default
|
|
3
|
+
export default {
|
|
7
4
|
meta: {
|
|
8
5
|
type: "problem",
|
|
9
6
|
docs: {
|
|
10
7
|
description:
|
|
11
|
-
"Enforce the `class` object/array form over the removed `
|
|
8
|
+
"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
9
|
url: "https://docs.solidjs.com/",
|
|
13
10
|
},
|
|
14
11
|
fixable: "code",
|
|
@@ -33,7 +30,7 @@ export default createRule({
|
|
|
33
30
|
],
|
|
34
31
|
messages: {
|
|
35
32
|
classlistRemoved:
|
|
36
|
-
"The `
|
|
33
|
+
"The `classList` prop was removed in Solid 2.0. Pass the object to `class` instead.",
|
|
37
34
|
preferClassObject:
|
|
38
35
|
"Pass the object to `class` directly instead of through {{ classnames }}.",
|
|
39
36
|
},
|
|
@@ -46,8 +43,11 @@ export default createRule({
|
|
|
46
43
|
JSXAttribute(node) {
|
|
47
44
|
const name = jsxPropName(node);
|
|
48
45
|
|
|
49
|
-
// `
|
|
50
|
-
|
|
46
|
+
// `classList={{...}}` no longer exists; the object belongs on
|
|
47
|
+
// `class`. JSX prop names are case-sensitive, so matching only
|
|
48
|
+
// the lowercase spelling missed every real Solid 1 call site —
|
|
49
|
+
// which is the code this rule exists to migrate.
|
|
50
|
+
if (name === "classList" || name === "classlist") {
|
|
51
51
|
context.report({
|
|
52
52
|
node,
|
|
53
53
|
messageId: "classlistRemoved",
|
|
@@ -95,4 +95,4 @@ export default createRule({
|
|
|
95
95
|
},
|
|
96
96
|
};
|
|
97
97
|
},
|
|
98
|
-
}
|
|
98
|
+
};
|
package/src/rules/prefer_for.mjs
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getPropertyName } from "@eslint-community/eslint-utils";
|
|
2
2
|
|
|
3
3
|
import { isFunctionNode, isJSXElementOrFragment } from "../utils.mjs";
|
|
4
|
-
|
|
5
|
-
const { getPropertyName } = ASTUtils;
|
|
6
|
-
export default createRule({
|
|
4
|
+
export default {
|
|
7
5
|
meta: {
|
|
8
6
|
type: "problem",
|
|
9
7
|
docs: {
|
|
@@ -89,4 +87,4 @@ export default createRule({
|
|
|
89
87
|
},
|
|
90
88
|
};
|
|
91
89
|
},
|
|
92
|
-
}
|
|
90
|
+
};
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
2
|
-
|
|
3
1
|
import { getSourceCode } from "../compat.mjs";
|
|
4
2
|
import { isJSXElementOrFragment } from "../utils.mjs";
|
|
5
|
-
const createRule = ESLintUtils.RuleCreator.withoutDocs;
|
|
6
3
|
const EXPENSIVE_TYPES = ["JSXElement", "JSXFragment", "Identifier"];
|
|
7
|
-
export default
|
|
4
|
+
export default {
|
|
8
5
|
meta: {
|
|
9
6
|
type: "problem",
|
|
10
7
|
docs: {
|
|
@@ -89,4 +86,4 @@ export default createRule({
|
|
|
89
86
|
},
|
|
90
87
|
};
|
|
91
88
|
},
|
|
92
|
-
}
|
|
89
|
+
};
|