@murky-web/typebuddy 2.1.0 → 3.0.1
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 +184 -72
- package/dist/collections.js +1 -2
- package/dist/empty.js +34 -13
- package/dist/guards.js +33 -9
- package/dist/ids.js +6 -6
- package/dist/oxlint.js +7 -7
- package/dist/parse.js +39 -15
- package/dist/result.js +6 -6
- package/dist/rules/async_rule.js +39 -25
- package/dist/rules/deliberate_throw.js +5 -6
- package/dist/rules/maybe_promise_rule.js +99 -40
- package/dist/rules/maybe_rule.js +7 -5
- package/dist/rules/nullable_rule.js +7 -5
- package/dist/rules/optional_rule.js +8 -4
- package/dist/rules/own_subtree.js +1 -2
- package/dist/rules/test_file.js +63 -0
- package/dist/rules/typebuddy_import.js +242 -35
- package/dist/rules/use_server.js +1 -2
- package/globals.d.ts +49 -44
- package/jsr.json +24 -23
- package/oxlint/index.ts +9 -7
- package/package.json +92 -91
- package/rules/async_rule.ts +91 -75
- package/rules/deliberate_throw.ts +11 -11
- package/rules/maybe_promise_rule.ts +238 -111
- package/rules/maybe_rule.ts +76 -49
- package/rules/nullable_rule.ts +77 -52
- package/rules/optional_rule.ts +79 -53
- package/rules/own_subtree.ts +33 -33
- package/rules/test_file.ts +114 -0
- package/rules/typebuddy_import.ts +479 -87
- package/rules/use_server.ts +5 -4
- package/src/collections.ts +1 -1
- package/src/empty.ts +58 -20
- package/src/guards.ts +100 -34
- package/src/ids.ts +10 -4
- package/src/index.ts +1 -18
- package/src/parse.ts +108 -29
- package/src/public_api.ts +22 -0
- package/src/result.ts +8 -7
- package/src/types/globals.ts +11 -11
- package/src/types/index.ts +21 -21
- package/src/types/json.ts +48 -11
- package/src/types/maybe_promise.ts +17 -12
- package/src/types/nullable.ts +2 -2
- package/src/types/optional.ts +6 -6
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
// rules/typebuddy_import.ts
|
|
2
2
|
const PACKAGE_NAME = "@murky-web/typebuddy";
|
|
3
|
+
/**
|
|
4
|
+
* The entries that export `ok` and `err`. The result helpers live in their own
|
|
5
|
+
* entry so a caller that only needs them does not pull the guards along, and a
|
|
6
|
+
* file that imports them from there already has what the fix is about to add.
|
|
7
|
+
*/
|
|
8
|
+
const RESULT_HELPER_SOURCES = /* @__PURE__ */ new Set([PACKAGE_NAME, `${PACKAGE_NAME}/result`]);
|
|
9
|
+
const TYPE_SOURCES = /* @__PURE__ */ new Set([PACKAGE_NAME]);
|
|
3
10
|
function isNode(value) {
|
|
4
11
|
return typeof value === "object" && value !== null && "type" in value;
|
|
5
12
|
}
|
|
6
|
-
function isIdentifierNamed(node, name) {
|
|
7
|
-
return isNode(node) && node.type === "Identifier" && node["name"] === name;
|
|
8
|
-
}
|
|
9
13
|
function isImportDeclaration(node) {
|
|
10
14
|
return isNode(node) && node.type === "ImportDeclaration";
|
|
11
15
|
}
|
|
@@ -14,6 +18,11 @@ function getStringLiteralValue(node) {
|
|
|
14
18
|
if ((node.type === "Literal" || node.type === "StringLiteral") && typeof node["value"] === "string") return node["value"];
|
|
15
19
|
return null;
|
|
16
20
|
}
|
|
21
|
+
function getModuleExportName(node) {
|
|
22
|
+
if (!isNode(node)) return null;
|
|
23
|
+
if (node.type === "Identifier" && typeof node["name"] === "string") return node["name"];
|
|
24
|
+
return getStringLiteralValue(node);
|
|
25
|
+
}
|
|
17
26
|
function getProgram(node) {
|
|
18
27
|
if (!isNode(node)) return null;
|
|
19
28
|
let current = node;
|
|
@@ -24,56 +33,254 @@ function getProgramBody(program) {
|
|
|
24
33
|
if (!Array.isArray(program["body"])) return [];
|
|
25
34
|
return program["body"].filter(isNode);
|
|
26
35
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
+
/** `"use client"`, `"use cache"`, `"use strict"`: the directive prologue. */
|
|
37
|
+
function isDirective(statement) {
|
|
38
|
+
return statement.type === "ExpressionStatement" && typeof statement["directive"] === "string";
|
|
39
|
+
}
|
|
40
|
+
const MODULE_STATEMENTS = /* @__PURE__ */ new Set([
|
|
41
|
+
"ExportAllDeclaration",
|
|
42
|
+
"ExportDefaultDeclaration",
|
|
43
|
+
"ExportNamedDeclaration",
|
|
44
|
+
"ImportDeclaration",
|
|
45
|
+
"TSExportAssignment"
|
|
46
|
+
]);
|
|
47
|
+
function isModuleStatement(statement) {
|
|
48
|
+
if (MODULE_STATEMENTS.has(statement.type)) return true;
|
|
49
|
+
if (statement.type !== "TSImportEqualsDeclaration") return false;
|
|
50
|
+
const reference = statement["moduleReference"];
|
|
51
|
+
return isNode(reference) && reference.type === "TSExternalModuleReference";
|
|
36
52
|
}
|
|
37
53
|
/**
|
|
38
|
-
*
|
|
54
|
+
* Whether the file is a module. TypeScript decides this by its statements, not
|
|
55
|
+
* by the extension: a file without an `import` or `export` is a script, its
|
|
56
|
+
* top-level names are global, and adding an `import` would turn it into a
|
|
57
|
+
* module and take its globals away (`vite-env.d.ts` with `interface
|
|
58
|
+
* ImportMetaEnv`, `interface Window`, `declare var`).
|
|
59
|
+
*/
|
|
60
|
+
function isModule(program) {
|
|
61
|
+
return getProgramBody(program).some(isModuleStatement);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Whether the file the node is in can take an import without changing what it
|
|
65
|
+
* is: it already is a module. A script file cannot, and `ok`/`err` have no
|
|
66
|
+
* global name to fall back on, so a rule that needs them there must not offer a
|
|
67
|
+
* fix.
|
|
39
68
|
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
69
|
+
* @param {unknown} node - Any node of the file.
|
|
70
|
+
* @returns {boolean} True when an import can be added to the file.
|
|
71
|
+
*/
|
|
72
|
+
function canAddImport(node) {
|
|
73
|
+
const program = getProgram(node);
|
|
74
|
+
return program !== null && isModule(program);
|
|
75
|
+
}
|
|
76
|
+
function isScopeLike(value) {
|
|
77
|
+
return typeof value === "object" && value !== null && "set" in value && value.set instanceof Map;
|
|
78
|
+
}
|
|
79
|
+
function getUpperScope(scope) {
|
|
80
|
+
const upper = scope.upper;
|
|
81
|
+
return isScopeLike(upper) ? upper : null;
|
|
82
|
+
}
|
|
83
|
+
/** The first binding of `name` visible from `node`, innermost scope first. */
|
|
84
|
+
function findBinding(sourceCode, node, name) {
|
|
85
|
+
const start = sourceCode.getScope(node);
|
|
86
|
+
let scope = isScopeLike(start) ? start : null;
|
|
87
|
+
while (scope) {
|
|
88
|
+
const variable = scope.set.get(name);
|
|
89
|
+
if (variable !== void 0) return variable;
|
|
90
|
+
scope = getUpperScope(scope);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function getDefinitions(variable) {
|
|
94
|
+
if (typeof variable === "object" && variable !== null && "defs" in variable && Array.isArray(variable.defs)) return variable.defs;
|
|
95
|
+
return [];
|
|
96
|
+
}
|
|
97
|
+
function sourcesFor(kind) {
|
|
98
|
+
return kind === "value" ? RESULT_HELPER_SOURCES : TYPE_SOURCES;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Whether one definition is `import { name } from "<package>"`, imported under
|
|
102
|
+
* its own name. A renamed import (`import { ok as okay }`), a default import
|
|
103
|
+
* and an import from another module are different bindings that happen to share
|
|
104
|
+
* the name. For a value, a type-only import does not count either: it has no
|
|
105
|
+
* runtime binding to call.
|
|
106
|
+
*/
|
|
107
|
+
function isPackageImport(definition, name, kind) {
|
|
108
|
+
if (typeof definition !== "object" || definition === null || !("type" in definition) || definition.type !== "ImportBinding" || !("node" in definition) || !("parent" in definition)) return false;
|
|
109
|
+
const specifier = definition.node;
|
|
110
|
+
const declaration = definition.parent;
|
|
111
|
+
if (!isNode(specifier) || specifier.type !== "ImportSpecifier" || !isImportDeclaration(declaration)) return false;
|
|
112
|
+
const source = getStringLiteralValue(declaration["source"]);
|
|
113
|
+
if (source === null || !sourcesFor(kind).has(source)) return false;
|
|
114
|
+
if (getModuleExportName(specifier["imported"]) !== name) return false;
|
|
115
|
+
if (kind === "value") return declaration["importKind"] !== "type" && specifier["importKind"] !== "type";
|
|
116
|
+
return true;
|
|
117
|
+
}
|
|
118
|
+
function getSpecifiers(declaration) {
|
|
119
|
+
return Array.isArray(declaration["specifiers"]) ? declaration["specifiers"].filter(isNode) : [];
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* The import of the package that the name can join, or `null` when there is
|
|
123
|
+
* none. A value joins `import { … }`. A type joins `import type { … }`, or else
|
|
124
|
+
* an `import { … }` of the package as `type Name` (an inline type specifier),
|
|
125
|
+
* so the file does not end up with two imports from one module. An import with
|
|
126
|
+
* a namespace specifier, or with no named specifier, is left alone.
|
|
127
|
+
*/
|
|
128
|
+
function findMergeTarget(imports, kind) {
|
|
129
|
+
const sources = sourcesFor(kind);
|
|
130
|
+
let inlineTarget = null;
|
|
131
|
+
for (const declaration of imports) {
|
|
132
|
+
const source = getStringLiteralValue(declaration["source"]);
|
|
133
|
+
const isTypeImport = declaration["importKind"] === "type";
|
|
134
|
+
if (source === null || !sources.has(source)) continue;
|
|
135
|
+
if (kind === "value" && isTypeImport) continue;
|
|
136
|
+
const specifiers = getSpecifiers(declaration);
|
|
137
|
+
if (specifiers.some((specifier) => {
|
|
138
|
+
return specifier.type === "ImportNamespaceSpecifier";
|
|
139
|
+
})) continue;
|
|
140
|
+
const range = specifiers.filter((specifier) => {
|
|
141
|
+
return specifier.type === "ImportSpecifier";
|
|
142
|
+
}).at(-1)?.["range"];
|
|
143
|
+
if (!Array.isArray(range) || typeof range[1] !== "number") continue;
|
|
144
|
+
if (kind === "value" || isTypeImport) return {
|
|
145
|
+
at: range[1],
|
|
146
|
+
inlineType: false
|
|
147
|
+
};
|
|
148
|
+
inlineTarget ??= {
|
|
149
|
+
at: range[1],
|
|
150
|
+
inlineType: true
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
return inlineTarget;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Where and what to insert so `name` is imported from the package, and whether
|
|
157
|
+
* it has to be at all.
|
|
158
|
+
*
|
|
159
|
+
* The answer comes from the scope at the place the fix is about to use the
|
|
160
|
+
* name, not from the list of imports. A catch parameter called `err`, a local
|
|
161
|
+
* called `ok`, or an unrelated library's `Maybe` all make a name mean something
|
|
162
|
+
* else there, and adding an import for it would not change that.
|
|
46
163
|
*
|
|
47
|
-
*
|
|
164
|
+
* Where the import goes: appended to an existing import of the same kind from
|
|
165
|
+
* the package; otherwise a new line after the last import; with no import,
|
|
166
|
+
* after the directive prologue (`"use client"` has to stay the first statement
|
|
167
|
+
* of the file or it stops being a directive); with neither, before the first
|
|
168
|
+
* statement.
|
|
48
169
|
*
|
|
49
|
-
*
|
|
170
|
+
* A script file (no `import` or `export`) gets no import: that would turn it
|
|
171
|
+
* into a module and take its globals away. A type is then written by its global
|
|
172
|
+
* name, as it was before this rule added imports; a value, which has no global
|
|
173
|
+
* name, gets no fix. Inside a module, `declare global` and `declare module`
|
|
174
|
+
* blocks get the import like any other code: the file is a module already, and
|
|
175
|
+
* the global name would break a project that does not load the globals entry.
|
|
50
176
|
*
|
|
51
|
-
* @param {
|
|
52
|
-
* @param {
|
|
53
|
-
* @
|
|
54
|
-
*
|
|
55
|
-
*
|
|
177
|
+
* @param {ImportSourceCode} sourceCode - Source code of the file, for scopes.
|
|
178
|
+
* @param {unknown} node - The node the fix uses `name` at.
|
|
179
|
+
* @param {string} name - The named export to import, e.g. `"err"`.
|
|
180
|
+
* @param {ImportKind} kind - `"value"` for a helper that is called, `"type"`
|
|
181
|
+
* for a type that is only named.
|
|
182
|
+
* @returns {ImportPlan} Whether to insert, with the zero-width insertion to
|
|
183
|
+
* apply.
|
|
56
184
|
*/
|
|
57
|
-
function
|
|
185
|
+
function planTypeBuddyImport(sourceCode, node, name, kind) {
|
|
58
186
|
const program = getProgram(node);
|
|
59
|
-
if (!program ||
|
|
187
|
+
if (!program || !isNode(node)) return { kind: "conflict" };
|
|
188
|
+
const binding = findBinding(sourceCode, node, name);
|
|
189
|
+
if (binding !== void 0) {
|
|
190
|
+
const definitions = getDefinitions(binding);
|
|
191
|
+
return { kind: definitions.length > 0 && definitions.every((definition) => {
|
|
192
|
+
return isPackageImport(definition, name, kind);
|
|
193
|
+
}) ? "present" : "conflict" };
|
|
194
|
+
}
|
|
195
|
+
if (!isModule(program)) return { kind: kind === "type" ? "global" : "conflict" };
|
|
60
196
|
const body = getProgramBody(program);
|
|
61
197
|
const imports = body.filter(isImportDeclaration);
|
|
62
|
-
const
|
|
63
|
-
if (
|
|
64
|
-
|
|
65
|
-
|
|
198
|
+
const merge = findMergeTarget(imports, kind);
|
|
199
|
+
if (merge !== null) return {
|
|
200
|
+
kind: "insert",
|
|
201
|
+
range: [merge.at, merge.at],
|
|
202
|
+
text: `, ${merge.inlineType ? "type " : ""}${name}`
|
|
203
|
+
};
|
|
204
|
+
const statement = kind === "type" ? `import type { ${name} } from "${PACKAGE_NAME}";` : `import { ${name} } from "${PACKAGE_NAME}";`;
|
|
205
|
+
const lastImport = imports.at(-1);
|
|
206
|
+
if (lastImport) {
|
|
207
|
+
const range = lastImport["range"];
|
|
208
|
+
if (!Array.isArray(range) || range.length < 2) return { kind: "conflict" };
|
|
209
|
+
const end = range[1];
|
|
210
|
+
return {
|
|
211
|
+
kind: "insert",
|
|
212
|
+
range: [end, end],
|
|
213
|
+
text: `\n${statement}`
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
const lastDirective = body.filter(isDirective).at(-1);
|
|
217
|
+
if (lastDirective) {
|
|
218
|
+
const range = lastDirective["range"];
|
|
219
|
+
if (!Array.isArray(range) || range.length < 2) return { kind: "conflict" };
|
|
66
220
|
const end = range[1];
|
|
67
221
|
return {
|
|
222
|
+
kind: "insert",
|
|
68
223
|
range: [end, end],
|
|
69
224
|
text: `\n${statement}`
|
|
70
225
|
};
|
|
71
226
|
}
|
|
227
|
+
const range = (body[0] ?? program)["range"];
|
|
228
|
+
if (!Array.isArray(range) || range.length < 2) return { kind: "conflict" };
|
|
72
229
|
const start = range[0];
|
|
73
230
|
return {
|
|
231
|
+
kind: "insert",
|
|
74
232
|
range: [start, start],
|
|
75
233
|
text: `${statement}\n`
|
|
76
234
|
};
|
|
77
235
|
}
|
|
78
|
-
|
|
79
|
-
|
|
236
|
+
/**
|
|
237
|
+
* Where the first non-directive statement of a body starts, for a fix that
|
|
238
|
+
* wraps the body. `"use cache"` and `"use server"` only count as directives at
|
|
239
|
+
* the very top of the body; wrapping them in a `try` turns them into expression
|
|
240
|
+
* statements that do nothing.
|
|
241
|
+
*
|
|
242
|
+
* @param {unknown} body - A block statement.
|
|
243
|
+
* @returns {number | null} The offset right after the directive prologue, or
|
|
244
|
+
* the offset right after the opening brace when there is none; null when the
|
|
245
|
+
* range is unusable.
|
|
246
|
+
*/
|
|
247
|
+
function getBodyStartAfterDirectives(body) {
|
|
248
|
+
if (!isNode(body) || !Array.isArray(body["range"])) return null;
|
|
249
|
+
const opening = body["range"][0];
|
|
250
|
+
if (typeof opening !== "number") return null;
|
|
251
|
+
const lastDirective = (Array.isArray(body["body"]) ? body["body"].filter(isNode) : []).filter(isDirective).at(-1);
|
|
252
|
+
if (lastDirective) {
|
|
253
|
+
const directiveRange = lastDirective["range"];
|
|
254
|
+
if (Array.isArray(directiveRange) && typeof directiveRange[1] === "number") return directiveRange[1];
|
|
255
|
+
return null;
|
|
256
|
+
}
|
|
257
|
+
return opening + 1;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Turns import plans into the fixes a rule returns, for one file.
|
|
261
|
+
*
|
|
262
|
+
* `fixes` returns `null` when the name is something else at that spot (or a
|
|
263
|
+
* value cannot be imported there), and a rule then offers no fix at all: a fix
|
|
264
|
+
* that calls the caught `err` or a different library's `Maybe` is worse than
|
|
265
|
+
* none.
|
|
266
|
+
*
|
|
267
|
+
* Every fix that needs an import carries it itself. oxlint applies a fix as a
|
|
268
|
+
* whole or not at all, and drops a fix that overlaps one it applied earlier in
|
|
269
|
+
* the same pass; an import attached to only the first fix of a file would be
|
|
270
|
+
* lost with that fix while the later fixes, which no longer overlap, applied
|
|
271
|
+
* without it. The price is that fixes needing the same import share one
|
|
272
|
+
* insertion point, so one `--fix` pass applies one of them; the next pass finds
|
|
273
|
+
* the import present and applies the rest.
|
|
274
|
+
*
|
|
275
|
+
* @param {ImportSourceCode} sourceCode - Source code of the file, for scopes.
|
|
276
|
+
* @returns {{ fixes: Function }} The planner.
|
|
277
|
+
*/
|
|
278
|
+
function createImportPlanner(sourceCode) {
|
|
279
|
+
return { fixes(node, fixer, name, kind) {
|
|
280
|
+
const plan = planTypeBuddyImport(sourceCode, node, name, kind);
|
|
281
|
+
if (plan.kind === "conflict") return null;
|
|
282
|
+
if (plan.kind === "insert") return [fixer.insertTextBeforeRange(plan.range, plan.text)];
|
|
283
|
+
return [];
|
|
284
|
+
} };
|
|
285
|
+
}
|
|
286
|
+
export { canAddImport, createImportPlanner, getBodyStartAfterDirectives, planTypeBuddyImport };
|
package/dist/rules/use_server.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// rules/use_server.ts
|
|
2
2
|
const USE_SERVER = "use server";
|
|
3
3
|
const FUNCTION_TYPES = /* @__PURE__ */ new Set([
|
|
4
4
|
"ArrowFunctionExpression",
|
|
@@ -60,5 +60,4 @@ function createUseServerGuard() {
|
|
|
60
60
|
}
|
|
61
61
|
};
|
|
62
62
|
}
|
|
63
|
-
//#endregion
|
|
64
63
|
export { createUseServerGuard };
|
package/globals.d.ts
CHANGED
|
@@ -1,60 +1,65 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
Stringified as StringifiedImport,
|
|
2
|
+
JsonifiedValue as JsonifiedValueImport,
|
|
3
|
+
Stringified as StringifiedImport
|
|
5
4
|
} from "./src/types/json.js";
|
|
6
|
-
import type { Maybe as MaybeImport, ResolveMaybe as ResolveMaybeImport } from "./src/types/maybe.js";
|
|
7
5
|
import type {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
Maybe as MaybeImport,
|
|
7
|
+
ResolveMaybe as ResolveMaybeImport
|
|
8
|
+
} from "./src/types/maybe.js";
|
|
9
|
+
import type {
|
|
10
|
+
Failed as FailedImport,
|
|
11
|
+
MaybePromise as MaybePromiseImport,
|
|
12
|
+
Success as SuccessImport
|
|
11
13
|
} from "./src/types/maybe_promise.js";
|
|
12
14
|
import type {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
+
Nullable as NullableImport,
|
|
16
|
+
ResolveNullable as ResolveNullableImport
|
|
15
17
|
} from "./src/types/nullable.js";
|
|
16
18
|
import type {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
+
Optional as OptionalImport,
|
|
20
|
+
ResolveOptional as ResolveOptionalImport
|
|
19
21
|
} from "./src/types/optional.js";
|
|
20
22
|
|
|
21
23
|
declare global {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
24
|
+
type Failed<T extends null = null> = FailedImport<T>;
|
|
25
|
+
type JsonifiedValue<T> = JsonifiedValueImport<T>;
|
|
26
|
+
type Maybe<T> = MaybeImport<T>;
|
|
27
|
+
type MaybePromise<T> = MaybePromiseImport<T>;
|
|
28
|
+
type Nullable<T> = NullableImport<T>;
|
|
29
|
+
type Optional<T> = OptionalImport<T>;
|
|
30
|
+
type ResolveMaybe<T, R extends Maybe<T>> = ResolveMaybeImport<T, R>;
|
|
31
|
+
type ResolveNullable<T, R extends Nullable<T>> = ResolveNullableImport<
|
|
32
|
+
T,
|
|
33
|
+
R
|
|
34
|
+
>;
|
|
35
|
+
type ResolveOptional<T, R extends Optional<T>> = ResolveOptionalImport<
|
|
36
|
+
T,
|
|
37
|
+
R
|
|
38
|
+
>;
|
|
39
|
+
type Stringified<T> = StringifiedImport<T>;
|
|
40
|
+
type Success<T> = SuccessImport<T>;
|
|
33
41
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
42
|
+
interface JSON {
|
|
43
|
+
stringify<T>(
|
|
44
|
+
value: T,
|
|
45
|
+
replacer?: null,
|
|
46
|
+
space?: string | number
|
|
47
|
+
): Stringified<T>;
|
|
40
48
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
replacer?: null,
|
|
44
|
-
): JsonifiedObjectImport<T>;
|
|
45
|
-
}
|
|
49
|
+
parse<T>(str: Stringified<T>, replacer?: null): JsonifiedValueImport<T>;
|
|
50
|
+
}
|
|
46
51
|
}
|
|
47
52
|
|
|
48
53
|
export type {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
54
|
+
FailedImport as Failed,
|
|
55
|
+
JsonifiedValueImport as JsonifiedValue,
|
|
56
|
+
MaybeImport as Maybe,
|
|
57
|
+
MaybePromiseImport as MaybePromise,
|
|
58
|
+
NullableImport as Nullable,
|
|
59
|
+
OptionalImport as Optional,
|
|
60
|
+
ResolveMaybeImport as ResolveMaybe,
|
|
61
|
+
ResolveNullableImport as ResolveNullable,
|
|
62
|
+
ResolveOptionalImport as ResolveOptional,
|
|
63
|
+
StringifiedImport as Stringified,
|
|
64
|
+
SuccessImport as Success
|
|
60
65
|
};
|
package/jsr.json
CHANGED
|
@@ -1,25 +1,26 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
2
|
+
"$schema": "https://jsr.io/schema/config-file.v1.json",
|
|
3
|
+
"name": "@murky-web/typebuddy",
|
|
4
|
+
"version": "3.0.1",
|
|
5
|
+
"license": "ISC",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": "./src/public_api.ts",
|
|
8
|
+
"./oxlint": "./oxlint/index.ts"
|
|
9
|
+
},
|
|
10
|
+
"publish": {
|
|
11
|
+
"include": [
|
|
12
|
+
"README.md",
|
|
13
|
+
"src/**/*.ts",
|
|
14
|
+
"oxlint/**/*.ts",
|
|
15
|
+
"rules/**/*.ts"
|
|
16
|
+
],
|
|
17
|
+
"exclude": [
|
|
18
|
+
"tests/**",
|
|
19
|
+
"smoke/**",
|
|
20
|
+
"globals.d.ts",
|
|
21
|
+
"src/index.ts",
|
|
22
|
+
"dist/**",
|
|
23
|
+
"node_modules/**"
|
|
24
|
+
]
|
|
25
|
+
}
|
|
25
26
|
}
|
package/oxlint/index.ts
CHANGED
|
@@ -3,13 +3,15 @@ import { errorSafeAsyncRule } from "../rules/maybe_promise_rule.js";
|
|
|
3
3
|
import { maybeRule } from "../rules/maybe_rule.js";
|
|
4
4
|
import { nullableRule } from "../rules/nullable_rule.js";
|
|
5
5
|
import { optionalRule } from "../rules/optional_rule.js";
|
|
6
|
+
import { withoutTestFiles } from "../rules/test_file.js";
|
|
6
7
|
|
|
8
|
+
// typebuddy does not apply to test files: every rule is a no-op there.
|
|
7
9
|
const rules = {
|
|
8
|
-
"prefer-maybe": maybeRule,
|
|
9
|
-
"prefer-maybe-promise": errorSafeAsyncRule,
|
|
10
|
-
"prefer-nullable": nullableRule,
|
|
11
|
-
"prefer-optional": optionalRule,
|
|
12
|
-
"require-try-catch": requireTryCatchAsyncRule
|
|
10
|
+
"prefer-maybe": withoutTestFiles(maybeRule),
|
|
11
|
+
"prefer-maybe-promise": withoutTestFiles(errorSafeAsyncRule),
|
|
12
|
+
"prefer-nullable": withoutTestFiles(nullableRule),
|
|
13
|
+
"prefer-optional": withoutTestFiles(optionalRule),
|
|
14
|
+
"require-try-catch": withoutTestFiles(requireTryCatchAsyncRule)
|
|
13
15
|
} as const satisfies Record<string, unknown>;
|
|
14
16
|
|
|
15
17
|
type TypebuddyOxlintPlugin = {
|
|
@@ -21,9 +23,9 @@ type TypebuddyOxlintPlugin = {
|
|
|
21
23
|
|
|
22
24
|
const plugin: TypebuddyOxlintPlugin = {
|
|
23
25
|
meta: {
|
|
24
|
-
name: "typebuddy"
|
|
26
|
+
name: "typebuddy"
|
|
25
27
|
},
|
|
26
|
-
rules
|
|
28
|
+
rules
|
|
27
29
|
};
|
|
28
30
|
|
|
29
31
|
export default plugin;
|