@murky-web/oxlint-plugin-solid 1.3.0 → 1.4.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 +103 -48
- package/THIRD_PARTY_NOTICES.md +54 -0
- package/package.json +29 -25
- package/src/index.mjs +1 -1
- package/src/rules/event_handlers.mjs +6 -12
- package/src/rules/imports.mjs +59 -22
- package/src/rules/jsx_no_script_url.mjs +7 -3
- package/src/rules/jsx_no_undef.mjs +1 -0
- package/src/rules/no_destructure.mjs +393 -24
- package/src/rules/no_proxy_apis.mjs +3 -1
- package/src/rules/no_server_import_in_client.mjs +249 -36
- package/src/rules/no_unknown_namespaces.mjs +2 -1
- package/src/rules/prefer_arrow_components.mjs +232 -196
- package/src/rules/prefer_class_object.mjs +12 -4
- package/src/rules/reactive_async.mjs +16 -5
- package/src/rules/reactivity.mjs +66 -30
- package/src/rules/self_closing_comp.mjs +2 -2
- package/src/rules/style_prop.mjs +4 -1
- package/src/rules/validate_jsx_nesting.mjs +480 -7
- package/src/utils.mjs +77 -12
|
@@ -2,38 +2,115 @@ import { existsSync, readFileSync, statSync } from "node:fs";
|
|
|
2
2
|
import { dirname, join, resolve, sep } from "node:path";
|
|
3
3
|
|
|
4
4
|
const SERVER_DIRECTORY = join("src", "server");
|
|
5
|
+
const GIT_ENTRY = ".git";
|
|
6
|
+
const PACKAGE_MANIFEST = "package.json";
|
|
5
7
|
const EXTENSIONS = [".ts", ".tsx", ".mts", ".js", ".jsx", ".mjs"];
|
|
6
8
|
const CLIENT_FILE = /\.(?:[cm]?[jt]s|[jt]sx)$/;
|
|
7
9
|
const TEST_FILE = /\.(?:test|spec)\.[^/]+$/;
|
|
8
10
|
const ALIAS_PREFIX = "~/";
|
|
9
|
-
const
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
|
|
11
|
+
const USE_SERVER_DIRECTIVE = "use server";
|
|
12
|
+
// The byte order mark, the line terminators (LF, CR, U+2028, U+2029) and the
|
|
13
|
+
// white space of ECMAScript (tab, VT, FF, BOM and every Unicode Zs, which
|
|
14
|
+
// includes the plain space). The code points that cannot be seen are written
|
|
15
|
+
// as escapes, so no invisible character sits in the source.
|
|
16
|
+
const BYTE_ORDER_MARK = /^\u{FEFF}/u;
|
|
17
|
+
const LINE_BREAK = /[\n\r\u{2028}\u{2029}]/u;
|
|
18
|
+
const WHITESPACE = /[\t\v\f\u{FEFF}\p{Zs}]/u;
|
|
19
|
+
// A whole identifier, so that `in_progress()` is not the operator `in`.
|
|
20
|
+
const WORD = /^[\p{ID_Continue}$\u{200C}\u{200D}]+/u;
|
|
21
|
+
// One more than the longest operator word, so a longer identifier that starts
|
|
22
|
+
// with one (`instanceofx`) is not cut down to it.
|
|
23
|
+
const LONGEST_OPERATOR_WORD = 10;
|
|
24
|
+
const WORD_SLICE_LENGTH = LONGEST_OPERATOR_WORD + 1;
|
|
25
|
+
// Words that go on with an expression after a string: `"use server" in x`.
|
|
26
|
+
const OPERATOR_WORDS = new Set(["as", "in", "instanceof", "satisfies"]);
|
|
27
|
+
// The first character of what follows a string on the next line, when it goes
|
|
28
|
+
// on with the string as an expression (`.length`, `(...)`, `* 2`, a tagged
|
|
29
|
+
// template, ...) instead of starting a new statement.
|
|
30
|
+
const CONTINUING_CHARACTERS = new Set([
|
|
31
|
+
".",
|
|
32
|
+
"(",
|
|
33
|
+
"[",
|
|
34
|
+
"*",
|
|
35
|
+
"%",
|
|
36
|
+
"<",
|
|
37
|
+
">",
|
|
38
|
+
"=",
|
|
39
|
+
"?",
|
|
40
|
+
",",
|
|
41
|
+
"&",
|
|
42
|
+
"|",
|
|
43
|
+
"^",
|
|
44
|
+
"/",
|
|
45
|
+
"`",
|
|
46
|
+
]);
|
|
13
47
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
48
|
+
function isDirectory(path) {
|
|
49
|
+
return existsSync(path) && statSync(path).isDirectory();
|
|
50
|
+
}
|
|
17
51
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
52
|
+
function isFile(path) {
|
|
53
|
+
return existsSync(path) && statSync(path).isFile();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Whether `directory` is where a repository or a workspace ends: it holds a
|
|
58
|
+
* `.git` or a package.json with `workspaces`. A `src/server` further up belongs
|
|
59
|
+
* to something else (a home directory, an outer checkout).
|
|
60
|
+
*/
|
|
61
|
+
function isProjectBoundary(directory) {
|
|
62
|
+
if (existsSync(join(directory, GIT_ENTRY))) {
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
23
65
|
|
|
24
|
-
|
|
66
|
+
const manifest = join(directory, PACKAGE_MANIFEST);
|
|
67
|
+
if (!isFile(manifest)) {
|
|
68
|
+
return false;
|
|
25
69
|
}
|
|
26
70
|
|
|
27
|
-
|
|
71
|
+
try {
|
|
72
|
+
const { workspaces } = JSON.parse(readFileSync(manifest, "utf8"));
|
|
73
|
+
return typeof workspaces === "object" && workspaces !== null;
|
|
74
|
+
} catch {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
28
77
|
}
|
|
29
78
|
|
|
30
|
-
|
|
31
|
-
|
|
79
|
+
// Directory -> the project root found from it (or null). One oxlint run lints
|
|
80
|
+
// many files of the same folders, and every lookup stats each folder above.
|
|
81
|
+
const projectRootCache = new Map();
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Nearest directory at or above `directory` that holds `src/server`: the
|
|
85
|
+
* project the client file belongs to. The nearest package.json is not it: one
|
|
86
|
+
* can sit in any folder below the project, and it does not say where the server
|
|
87
|
+
* code is. The walk stops at the first folder with a `.git` or a package.json
|
|
88
|
+
* with `workspaces`. The answer is cached for the life of the process: a
|
|
89
|
+
* `src/server` made while a language server runs is found after a restart.
|
|
90
|
+
*/
|
|
91
|
+
function findProjectRoot(directory) {
|
|
92
|
+
if (projectRootCache.has(directory)) {
|
|
93
|
+
return projectRootCache.get(directory);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
let root = null;
|
|
97
|
+
if (isDirectory(join(directory, SERVER_DIRECTORY))) {
|
|
98
|
+
root = directory;
|
|
99
|
+
} else if (!isProjectBoundary(directory)) {
|
|
100
|
+
const parent = dirname(directory);
|
|
101
|
+
if (parent !== directory) {
|
|
102
|
+
root = findProjectRoot(parent);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
projectRootCache.set(directory, root);
|
|
107
|
+
|
|
108
|
+
return root;
|
|
32
109
|
}
|
|
33
110
|
|
|
34
111
|
/**
|
|
35
|
-
* The file an import path points at, trying the extensions the bundler would.
|
|
36
|
-
*
|
|
112
|
+
* The file an import path points at, trying the extensions the bundler would. A
|
|
113
|
+
* `.js` specifier names the `.ts` source next to it.
|
|
37
114
|
*/
|
|
38
115
|
function findModuleFile(basePath) {
|
|
39
116
|
const withoutJsExtension = basePath.replace(/\.[cm]?jsx?$/, "");
|
|
@@ -47,19 +124,131 @@ function findModuleFile(basePath) {
|
|
|
47
124
|
return candidates.find(isFile) ?? null;
|
|
48
125
|
}
|
|
49
126
|
|
|
50
|
-
|
|
51
|
-
|
|
127
|
+
/**
|
|
128
|
+
* The index after the whitespace and comments that start at `start`, and
|
|
129
|
+
* whether a line break was among them.
|
|
130
|
+
*/
|
|
131
|
+
function skipTrivia(text, start) {
|
|
132
|
+
let index = start;
|
|
133
|
+
let sawLineBreak = false;
|
|
52
134
|
|
|
53
|
-
|
|
54
|
-
const
|
|
55
|
-
if (
|
|
135
|
+
while (index < text.length) {
|
|
136
|
+
const character = text[index];
|
|
137
|
+
if (LINE_BREAK.test(character)) {
|
|
138
|
+
sawLineBreak = true;
|
|
139
|
+
index += 1;
|
|
140
|
+
} else if (WHITESPACE.test(character)) {
|
|
141
|
+
index += 1;
|
|
142
|
+
} else if (text.startsWith("//", index)) {
|
|
143
|
+
while (index < text.length && !LINE_BREAK.test(text[index])) {
|
|
144
|
+
index += 1;
|
|
145
|
+
}
|
|
146
|
+
} else if (text.startsWith("/*", index)) {
|
|
147
|
+
const end = text.indexOf("*/", index + 2);
|
|
148
|
+
const stop = end === -1 ? text.length : end + 2;
|
|
149
|
+
sawLineBreak ||= LINE_BREAK.test(text.slice(index, stop));
|
|
150
|
+
index = stop;
|
|
151
|
+
} else {
|
|
56
152
|
break;
|
|
57
153
|
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return { index, sawLineBreak };
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Whether the code at `index`, on a new line, goes on with the expression
|
|
161
|
+
* before it, so that no semicolon is inserted there.
|
|
162
|
+
*/
|
|
163
|
+
function continuesExpression(text, index) {
|
|
164
|
+
const character = text[index];
|
|
165
|
+
if (character === "+" || character === "-") {
|
|
166
|
+
// `++x` and `--x` start a statement of their own.
|
|
167
|
+
return text[index + 1] !== character;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (character === "!") {
|
|
171
|
+
return text[index + 1] === "=";
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (CONTINUING_CHARACTERS.has(character)) {
|
|
175
|
+
return true;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// The whole word: `in_progress()` starts a statement, `in x` does not.
|
|
179
|
+
const word = WORD.exec(text.slice(index, index + WORD_SLICE_LENGTH));
|
|
180
|
+
|
|
181
|
+
return word !== null && OPERATOR_WORDS.has(word[0]);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* The index of the string literal's closing quote, or -1 when the line ends
|
|
186
|
+
* first: a string literal cannot span lines.
|
|
187
|
+
*/
|
|
188
|
+
function findStringEnd(text, start) {
|
|
189
|
+
const quote = text[start];
|
|
190
|
+
let end = start + 1;
|
|
191
|
+
|
|
192
|
+
while (end < text.length && text[end] !== quote) {
|
|
193
|
+
if (LINE_BREAK.test(text[end])) {
|
|
194
|
+
return -1;
|
|
195
|
+
}
|
|
58
196
|
|
|
59
|
-
|
|
197
|
+
end += text[end] === "\\" ? 2 : 1;
|
|
60
198
|
}
|
|
61
199
|
|
|
62
|
-
return
|
|
200
|
+
return end < text.length ? end : -1;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Whether `"use server"` is one of the directives that open the module: the
|
|
205
|
+
* directive prologue, which is every string-literal statement at the top (`"use
|
|
206
|
+
* strict"; "use server";`) and ends with the first statement that is anything
|
|
207
|
+
* else. `"use server".length;`, `("use server");` and an escaped
|
|
208
|
+
* `"use\x20server"` are an expression and another directive, not this one.
|
|
209
|
+
*/
|
|
210
|
+
function hasUseServerDirective(source) {
|
|
211
|
+
const text = source.replace(BYTE_ORDER_MARK, "");
|
|
212
|
+
let index = 0;
|
|
213
|
+
if (text.startsWith("#!")) {
|
|
214
|
+
const lineEnd = text.search(LINE_BREAK);
|
|
215
|
+
index = lineEnd === -1 ? text.length : lineEnd;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
while (index < text.length) {
|
|
219
|
+
index = skipTrivia(text, index).index;
|
|
220
|
+
const quote = text[index];
|
|
221
|
+
if (quote !== '"' && quote !== "'") {
|
|
222
|
+
return false;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
const end = findStringEnd(text, index);
|
|
226
|
+
if (end === -1) {
|
|
227
|
+
return false;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
const after = skipTrivia(text, end + 1);
|
|
231
|
+
const next = text[after.index];
|
|
232
|
+
const endsStatement =
|
|
233
|
+
next === ";" ||
|
|
234
|
+
after.index >= text.length ||
|
|
235
|
+
(after.sawLineBreak && !continuesExpression(text, after.index));
|
|
236
|
+
if (!endsStatement) {
|
|
237
|
+
return false;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
if (text.slice(index + 1, end) === USE_SERVER_DIRECTIVE) {
|
|
241
|
+
return true;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
index = next === ";" ? after.index + 1 : after.index;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
return false;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
function startsWithUseServer(filePath) {
|
|
251
|
+
return hasUseServerDirective(readFileSync(filePath, "utf8"));
|
|
63
252
|
}
|
|
64
253
|
|
|
65
254
|
function isInside(path, directory) {
|
|
@@ -82,6 +271,27 @@ function resolveImport(specifier, filename, projectRoot) {
|
|
|
82
271
|
return null;
|
|
83
272
|
}
|
|
84
273
|
|
|
274
|
+
/**
|
|
275
|
+
* The module specifier a node spells out: a string literal, or a template
|
|
276
|
+
* literal without substitutions (`` `~/server/db` ``). Null for anything that
|
|
277
|
+
* is only known at run time.
|
|
278
|
+
*/
|
|
279
|
+
function getStaticSpecifier(node) {
|
|
280
|
+
if (node?.type === "Literal" && typeof node.value === "string") {
|
|
281
|
+
return node.value;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
if (
|
|
285
|
+
node?.type === "TemplateLiteral" &&
|
|
286
|
+
node.expressions.length === 0 &&
|
|
287
|
+
node.quasis.length === 1
|
|
288
|
+
) {
|
|
289
|
+
return node.quasis[0].value.cooked ?? null;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
return null;
|
|
293
|
+
}
|
|
294
|
+
|
|
85
295
|
export const noServerImportInClientRule = {
|
|
86
296
|
meta: {
|
|
87
297
|
type: "problem",
|
|
@@ -93,7 +303,7 @@ export const noServerImportInClientRule = {
|
|
|
93
303
|
schema: [],
|
|
94
304
|
messages: {
|
|
95
305
|
serverImportInClient:
|
|
96
|
-
|
|
306
|
+
'\'{{specifier}}\' lives under src/server/ but does not have the "use server" directive, so importing it into client code ships server-only code to the browser. Import a server function module instead (a `"use server";` directive at the top, async exports only), and keep database clients and secrets inside it.',
|
|
97
307
|
},
|
|
98
308
|
},
|
|
99
309
|
defaultOptions: [],
|
|
@@ -114,18 +324,12 @@ export const noServerImportInClientRule = {
|
|
|
114
324
|
const serverDirectory = join(projectRoot, SERVER_DIRECTORY);
|
|
115
325
|
|
|
116
326
|
function check(sourceNode) {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
typeof sourceNode.value !== "string"
|
|
120
|
-
) {
|
|
327
|
+
const specifier = getStaticSpecifier(sourceNode);
|
|
328
|
+
if (specifier === null) {
|
|
121
329
|
return;
|
|
122
330
|
}
|
|
123
331
|
|
|
124
|
-
const basePath = resolveImport(
|
|
125
|
-
sourceNode.value,
|
|
126
|
-
filename,
|
|
127
|
-
projectRoot,
|
|
128
|
-
);
|
|
332
|
+
const basePath = resolveImport(specifier, filename, projectRoot);
|
|
129
333
|
if (basePath === null) {
|
|
130
334
|
return;
|
|
131
335
|
}
|
|
@@ -143,7 +347,7 @@ export const noServerImportInClientRule = {
|
|
|
143
347
|
context.report({
|
|
144
348
|
node: sourceNode,
|
|
145
349
|
messageId: "serverImportInClient",
|
|
146
|
-
data: { specifier
|
|
350
|
+
data: { specifier },
|
|
147
351
|
});
|
|
148
352
|
}
|
|
149
353
|
|
|
@@ -167,6 +371,15 @@ export const noServerImportInClientRule = {
|
|
|
167
371
|
ImportExpression(node) {
|
|
168
372
|
check(node.source);
|
|
169
373
|
},
|
|
374
|
+
CallExpression(node) {
|
|
375
|
+
if (
|
|
376
|
+
node.callee.type === "Identifier" &&
|
|
377
|
+
node.callee.name === "require" &&
|
|
378
|
+
node.arguments.length === 1
|
|
379
|
+
) {
|
|
380
|
+
check(node.arguments[0]);
|
|
381
|
+
}
|
|
382
|
+
},
|
|
170
383
|
};
|
|
171
384
|
},
|
|
172
385
|
};
|
|
@@ -43,7 +43,8 @@ export default {
|
|
|
43
43
|
},
|
|
44
44
|
],
|
|
45
45
|
messages: {
|
|
46
|
-
removed:
|
|
46
|
+
removed:
|
|
47
|
+
"'{{namespace}}:' was removed in Solid 2.0. Use {{replacement}} instead.",
|
|
47
48
|
unknown:
|
|
48
49
|
"'{{namespace}}:' is not a namespace Solid understands. Solid 2.0 has no special JSX prefixes.",
|
|
49
50
|
component: "Namespaced props have no effect on components.",
|