@jandragsbaek/oxlint-plugin 0.0.0-stage → 0.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/LICENSE +22 -0
- package/README.md +113 -2
- package/dist/index.d.mts +3993 -0
- package/dist/index.mjs +3276 -0
- package/dist/presets.d.mts +31 -0
- package/dist/presets.mjs +141 -0
- package/package.json +68 -4
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,3276 @@
|
|
|
1
|
+
// node_modules/.pnpm/@oxlint+plugins@1.94.0/node_modules/@oxlint/plugins/index.js
|
|
2
|
+
/**
|
|
3
|
+
* Define a plugin.
|
|
4
|
+
*
|
|
5
|
+
* No-op function, just to provide type safety. Input is passed through unchanged.
|
|
6
|
+
*
|
|
7
|
+
* @param plugin - Plugin to define
|
|
8
|
+
* @returns Same plugin as passed in
|
|
9
|
+
*/
|
|
10
|
+
function definePlugin(plugin) {
|
|
11
|
+
return plugin;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Define a rule.
|
|
15
|
+
*
|
|
16
|
+
* No-op function, just to provide type safety. Input is passed through unchanged.
|
|
17
|
+
*
|
|
18
|
+
* @param rule - Rule to define
|
|
19
|
+
* @returns Same rule as passed in
|
|
20
|
+
*/
|
|
21
|
+
function defineRule(rule) {
|
|
22
|
+
return rule;
|
|
23
|
+
}
|
|
24
|
+
Object.freeze({
|
|
25
|
+
get filename() {
|
|
26
|
+
throw Error("Cannot access `context.filename` in `createOnce`");
|
|
27
|
+
},
|
|
28
|
+
getFilename() {
|
|
29
|
+
throw Error("Cannot call `context.getFilename` in `createOnce`");
|
|
30
|
+
},
|
|
31
|
+
get physicalFilename() {
|
|
32
|
+
throw Error("Cannot access `context.physicalFilename` in `createOnce`");
|
|
33
|
+
},
|
|
34
|
+
getPhysicalFilename() {
|
|
35
|
+
throw Error("Cannot call `context.getPhysicalFilename` in `createOnce`");
|
|
36
|
+
},
|
|
37
|
+
get cwd() {
|
|
38
|
+
throw Error("Cannot access `context.cwd` in `createOnce`");
|
|
39
|
+
},
|
|
40
|
+
getCwd() {
|
|
41
|
+
throw Error("Cannot call `context.getCwd` in `createOnce`");
|
|
42
|
+
},
|
|
43
|
+
get sourceCode() {
|
|
44
|
+
throw Error("Cannot access `context.sourceCode` in `createOnce`");
|
|
45
|
+
},
|
|
46
|
+
getSourceCode() {
|
|
47
|
+
throw Error("Cannot call `context.getSourceCode` in `createOnce`");
|
|
48
|
+
},
|
|
49
|
+
get languageOptions() {
|
|
50
|
+
throw Error("Cannot access `context.languageOptions` in `createOnce`");
|
|
51
|
+
},
|
|
52
|
+
get settings() {
|
|
53
|
+
throw Error("Cannot access `context.settings` in `createOnce`");
|
|
54
|
+
},
|
|
55
|
+
extend(extension) {
|
|
56
|
+
return Object.freeze(Object.assign(Object.create(this), extension));
|
|
57
|
+
},
|
|
58
|
+
get parserOptions() {
|
|
59
|
+
throw Error("Cannot access `context.parserOptions` in `createOnce`");
|
|
60
|
+
},
|
|
61
|
+
get parserPath() {
|
|
62
|
+
throw Error("Cannot access `context.parserPath` in `createOnce`");
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
// src/rules/namespace-node-imports.ts
|
|
66
|
+
const NODE_MODULE_ALIASES = /* @__PURE__ */ new Map([["assert/strict", "Assert"], ["fs/promises", "FSP"]]);
|
|
67
|
+
const NODE_SEGMENT_ALIASES = /* @__PURE__ */ new Map([
|
|
68
|
+
["fs", "FS"],
|
|
69
|
+
["os", "OS"],
|
|
70
|
+
["url", "URL"],
|
|
71
|
+
["vm", "VM"]
|
|
72
|
+
]);
|
|
73
|
+
const toPascalCase = (value) => value.split(/[_-]/u).filter((segment) => segment.length > 0).map((segment) => segment[0]?.toUpperCase() + segment.slice(1)).join("");
|
|
74
|
+
const expectedNamespaceAlias = (source) => {
|
|
75
|
+
const moduleName = source.slice(5);
|
|
76
|
+
const knownAlias = NODE_MODULE_ALIASES.get(moduleName);
|
|
77
|
+
if (knownAlias !== void 0) return `Node${knownAlias}`;
|
|
78
|
+
return `Node${moduleName.split("/").map((segment) => NODE_SEGMENT_ALIASES.get(segment) ?? toPascalCase(segment)).join("")}`;
|
|
79
|
+
};
|
|
80
|
+
const literalStringValue = (node) => {
|
|
81
|
+
if (typeof node !== "object" || node === null) return void 0;
|
|
82
|
+
if (!("type" in node) || node.type !== "Literal") return void 0;
|
|
83
|
+
if (!("value" in node) || typeof node.value !== "string") return void 0;
|
|
84
|
+
return node.value;
|
|
85
|
+
};
|
|
86
|
+
const identifierName = (node) => {
|
|
87
|
+
if (typeof node !== "object" || node === null) return void 0;
|
|
88
|
+
if (!("type" in node) || node.type !== "Identifier") return void 0;
|
|
89
|
+
if (!("name" in node) || typeof node.name !== "string") return void 0;
|
|
90
|
+
return node.name;
|
|
91
|
+
};
|
|
92
|
+
var namespace_node_imports_default = defineRule({
|
|
93
|
+
meta: {
|
|
94
|
+
type: "problem",
|
|
95
|
+
docs: { description: "Require canonical namespace imports for Node.js built-in modules." }
|
|
96
|
+
},
|
|
97
|
+
create(context) {
|
|
98
|
+
return { ImportDeclaration(node) {
|
|
99
|
+
const source = literalStringValue(node.source);
|
|
100
|
+
if (source === void 0 || !source.startsWith("node:")) return;
|
|
101
|
+
const expectedAlias = expectedNamespaceAlias(source);
|
|
102
|
+
const namespaceImport = node.specifiers.length === 1 && node.specifiers[0]?.type === "ImportNamespaceSpecifier" ? node.specifiers[0] : void 0;
|
|
103
|
+
if (identifierName(namespaceImport?.local) === expectedAlias) return;
|
|
104
|
+
context.report({
|
|
105
|
+
node,
|
|
106
|
+
message: `Import ${source} as a namespace named ${expectedAlias}.`
|
|
107
|
+
});
|
|
108
|
+
} };
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
// src/rules/no-dom-test-environment.ts
|
|
112
|
+
const DOM_ENVIRONMENT_PACKAGE = /^(?:jsdom|happy-dom)(?:\/|$)/u;
|
|
113
|
+
const PRAGMA = ["@vitest", "environment"].join("-");
|
|
114
|
+
const MESSAGE$5 = "Select test environments in Vitest project configuration instead of a per-file pragma or a DOM emulator import. Web DOM tests belong in *.browser.test.{ts,tsx}.";
|
|
115
|
+
var no_dom_test_environment_default = defineRule({
|
|
116
|
+
meta: {
|
|
117
|
+
type: "problem",
|
|
118
|
+
docs: { description: "Reject per-file Vitest environments and DOM emulator imports." }
|
|
119
|
+
},
|
|
120
|
+
create(context) {
|
|
121
|
+
const checkImport = (source) => {
|
|
122
|
+
if (source === null) return;
|
|
123
|
+
const value = source.type === "Literal" ? source.value : source.type === "TemplateLiteral" && source.expressions.length === 0 ? source.quasis[0]?.value.cooked : void 0;
|
|
124
|
+
if (typeof value === "string" && DOM_ENVIRONMENT_PACKAGE.test(value)) context.report({
|
|
125
|
+
node: source,
|
|
126
|
+
message: MESSAGE$5
|
|
127
|
+
});
|
|
128
|
+
};
|
|
129
|
+
return {
|
|
130
|
+
Program() {
|
|
131
|
+
const index = context.sourceCode.text.indexOf(PRAGMA);
|
|
132
|
+
if (index !== -1) context.report({
|
|
133
|
+
loc: context.sourceCode.getLocFromIndex(index),
|
|
134
|
+
message: MESSAGE$5
|
|
135
|
+
});
|
|
136
|
+
},
|
|
137
|
+
ImportDeclaration: (node) => checkImport(node.source),
|
|
138
|
+
ImportExpression: (node) => checkImport(node.source),
|
|
139
|
+
ExportNamedDeclaration: (node) => checkImport(node.source),
|
|
140
|
+
ExportAllDeclaration: (node) => checkImport(node.source),
|
|
141
|
+
TSExternalModuleReference: (node) => checkImport(node.expression),
|
|
142
|
+
CallExpression(node) {
|
|
143
|
+
if (node.callee.type === "Identifier" && node.callee.name === "require") checkImport(node.arguments[0] ?? null);
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
// src/rules/no-em-dash-copy.ts
|
|
149
|
+
const EM_DASH = "—";
|
|
150
|
+
const MESSAGE$4 = "No em dashes in product copy. Use a period, comma, colon, or parentheses instead.";
|
|
151
|
+
var no_em_dash_copy_default = defineRule({
|
|
152
|
+
meta: {
|
|
153
|
+
type: "suggestion",
|
|
154
|
+
docs: { description: "Disallow em dashes in strings and JSX text that users or agents read." }
|
|
155
|
+
},
|
|
156
|
+
create(context) {
|
|
157
|
+
const check = (node, text) => {
|
|
158
|
+
if (text?.includes(EM_DASH)) context.report({
|
|
159
|
+
node,
|
|
160
|
+
message: MESSAGE$4
|
|
161
|
+
});
|
|
162
|
+
};
|
|
163
|
+
return {
|
|
164
|
+
Literal(node) {
|
|
165
|
+
if (typeof node.value === "string") check(node, node.value);
|
|
166
|
+
},
|
|
167
|
+
TemplateElement(node) {
|
|
168
|
+
check(node, node.value.cooked);
|
|
169
|
+
},
|
|
170
|
+
JSXText(node) {
|
|
171
|
+
check(node, node.value);
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
// src/rules/no-hookless-use-function.ts
|
|
177
|
+
const HOOK_NAME = /^use[A-Z]/;
|
|
178
|
+
const HOOK_CALLEE = /^use([A-Z]|$)/;
|
|
179
|
+
function isFunctionNode(node) {
|
|
180
|
+
return node.type === "FunctionDeclaration" || node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression";
|
|
181
|
+
}
|
|
182
|
+
function isHookCallee(callee) {
|
|
183
|
+
if (callee.type === "Identifier") return HOOK_CALLEE.test(callee.name);
|
|
184
|
+
if (callee.type === "MemberExpression" && !callee.computed) return callee.property.type === "Identifier" && HOOK_CALLEE.test(callee.property.name);
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
function callsHook(node, root) {
|
|
188
|
+
if (typeof node !== "object" || node === null) return false;
|
|
189
|
+
if (Array.isArray(node)) return node.some((child) => callsHook(child, root));
|
|
190
|
+
if (!("type" in node) || typeof node.type !== "string") return false;
|
|
191
|
+
const typed = node;
|
|
192
|
+
if (typed !== root && isFunctionNode(typed)) return false;
|
|
193
|
+
if (typed.type === "CallExpression" && isHookCallee(typed.callee)) return true;
|
|
194
|
+
for (const [key, value] of Object.entries(typed)) {
|
|
195
|
+
if (key === "parent") continue;
|
|
196
|
+
if (callsHook(value, root)) return true;
|
|
197
|
+
}
|
|
198
|
+
return false;
|
|
199
|
+
}
|
|
200
|
+
var no_hookless_use_function_default = defineRule({
|
|
201
|
+
meta: {
|
|
202
|
+
type: "problem",
|
|
203
|
+
docs: { description: "Disallow use* functions that call no hooks; the React Compiler only compiles functions that do. Mirrors eslint-react's no-unnecessary-use-prefix, which oxlint does not ship." },
|
|
204
|
+
schema: []
|
|
205
|
+
},
|
|
206
|
+
create(context) {
|
|
207
|
+
const check = (name, fn, reportNode) => {
|
|
208
|
+
if (!HOOK_NAME.test(name)) return;
|
|
209
|
+
if (callsHook(fn.body, fn)) return;
|
|
210
|
+
context.report({
|
|
211
|
+
node: reportNode,
|
|
212
|
+
message: `"${name}" calls no hooks, so the React Compiler skips it and whatever it returns is rebuilt on every render. Rename it to a plain function, or read the hook it depends on inside it.`
|
|
213
|
+
});
|
|
214
|
+
};
|
|
215
|
+
return {
|
|
216
|
+
FunctionDeclaration(node) {
|
|
217
|
+
if (node.id) check(node.id.name, node, node.id);
|
|
218
|
+
},
|
|
219
|
+
VariableDeclarator(node) {
|
|
220
|
+
if (node.id.type !== "Identifier" || node.init == null) return;
|
|
221
|
+
if (node.init.type !== "ArrowFunctionExpression" && node.init.type !== "FunctionExpression") return;
|
|
222
|
+
check(node.id.name, node.init, node.id);
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
// node_modules/.pnpm/effect@4.1.2/node_modules/effect/dist/Pipeable.js
|
|
228
|
+
/**
|
|
229
|
+
* The `Pipeable` module defines the shared interface and implementation helpers
|
|
230
|
+
* for values that support Effect-style method chaining with `.pipe(...)`.
|
|
231
|
+
*
|
|
232
|
+
* A `Pipeable` value can pass itself through a sequence of unary functions from
|
|
233
|
+
* left to right, so code can be written as `value.pipe(f, g, h)` instead of
|
|
234
|
+
* deeply nesting calls. This is the method form used by many Effect data types
|
|
235
|
+
* to compose transformations, validations, and effectful operations while
|
|
236
|
+
* keeping the original value as the starting point of the pipeline.
|
|
237
|
+
*
|
|
238
|
+
* @stability stable
|
|
239
|
+
* @since 2.0.0
|
|
240
|
+
*/
|
|
241
|
+
/**
|
|
242
|
+
* Applies a `pipe` method's variadic arguments to an initial value from left
|
|
243
|
+
* to right.
|
|
244
|
+
*
|
|
245
|
+
* **When to use**
|
|
246
|
+
*
|
|
247
|
+
* Use to implement a custom `.pipe(...)` method from JavaScript's `arguments`
|
|
248
|
+
* object.
|
|
249
|
+
*
|
|
250
|
+
* **Details**
|
|
251
|
+
*
|
|
252
|
+
* This helper is intended for implementing `Pipeable.pipe` methods that
|
|
253
|
+
* receive JavaScript's `arguments` object. With no functions it returns the
|
|
254
|
+
* original value; otherwise it feeds each result into the next function.
|
|
255
|
+
*
|
|
256
|
+
* **Example** (Implementing a pipe method)
|
|
257
|
+
*
|
|
258
|
+
* ```ts import.meta.vitest
|
|
259
|
+
* import { Pipeable } from "effect"
|
|
260
|
+
*
|
|
261
|
+
* class NumberBox {
|
|
262
|
+
* constructor(readonly value: number) {}
|
|
263
|
+
*
|
|
264
|
+
* pipe(..._fns: ReadonlyArray<(value: number) => number>): number {
|
|
265
|
+
* return Pipeable.pipeArguments(this.value, arguments) as number
|
|
266
|
+
* }
|
|
267
|
+
* }
|
|
268
|
+
*
|
|
269
|
+
* const result = new NumberBox(5).pipe(
|
|
270
|
+
* (n) => n + 2,
|
|
271
|
+
* (n) => n * 3
|
|
272
|
+
* )
|
|
273
|
+
* result // => 21
|
|
274
|
+
* ```
|
|
275
|
+
*
|
|
276
|
+
* @stability stable
|
|
277
|
+
* @category combinators
|
|
278
|
+
* @since 2.0.0
|
|
279
|
+
*/
|
|
280
|
+
const pipeArguments = (self, args) => {
|
|
281
|
+
switch (args.length) {
|
|
282
|
+
case 0: return self;
|
|
283
|
+
case 1: return args[0](self);
|
|
284
|
+
case 2: return args[1](args[0](self));
|
|
285
|
+
case 3: return args[2](args[1](args[0](self)));
|
|
286
|
+
case 4: return args[3](args[2](args[1](args[0](self))));
|
|
287
|
+
case 5: return args[4](args[3](args[2](args[1](args[0](self)))));
|
|
288
|
+
case 6: return args[5](args[4](args[3](args[2](args[1](args[0](self))))));
|
|
289
|
+
case 7: return args[6](args[5](args[4](args[3](args[2](args[1](args[0](self)))))));
|
|
290
|
+
case 8: return args[7](args[6](args[5](args[4](args[3](args[2](args[1](args[0](self))))))));
|
|
291
|
+
case 9: return args[8](args[7](args[6](args[5](args[4](args[3](args[2](args[1](args[0](self)))))))));
|
|
292
|
+
default: {
|
|
293
|
+
let ret = self;
|
|
294
|
+
for (let i = 0, len = args.length; i < len; i++) ret = args[i](ret);
|
|
295
|
+
return ret;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
// node_modules/.pnpm/effect@4.1.2/node_modules/effect/dist/Function.js
|
|
300
|
+
/**
|
|
301
|
+
* Creates a function that can be called in data-first style or data-last
|
|
302
|
+
* (`pipe`-friendly) style.
|
|
303
|
+
*
|
|
304
|
+
* **When to use**
|
|
305
|
+
*
|
|
306
|
+
* Use to expose one implementation through both direct and `pipe`-friendly
|
|
307
|
+
* call styles.
|
|
308
|
+
*
|
|
309
|
+
* **Details**
|
|
310
|
+
*
|
|
311
|
+
* Pass either the arity of the uncurried function or a predicate that decides
|
|
312
|
+
* whether the current call is data-first. Arity is the common case. Use a
|
|
313
|
+
* predicate when optional arguments make arity ambiguous.
|
|
314
|
+
*
|
|
315
|
+
* **Example** (Selecting data-first or data-last style by arity)
|
|
316
|
+
*
|
|
317
|
+
* ```ts import.meta.vitest
|
|
318
|
+
* import { Function, pipe } from "effect"
|
|
319
|
+
*
|
|
320
|
+
* const sum = Function.dual<
|
|
321
|
+
* (that: number) => (self: number) => number,
|
|
322
|
+
* (self: number, that: number) => number
|
|
323
|
+
* >(2, (self, that) => self + that)
|
|
324
|
+
*
|
|
325
|
+
* sum(2, 3) // => 5
|
|
326
|
+
* pipe(2, sum(3)) // => 5
|
|
327
|
+
* ```
|
|
328
|
+
*
|
|
329
|
+
* **Example** (Defining overloads with call signatures)
|
|
330
|
+
*
|
|
331
|
+
* ```ts import.meta.vitest
|
|
332
|
+
* import { Function, pipe } from "effect"
|
|
333
|
+
*
|
|
334
|
+
* const sum: {
|
|
335
|
+
* (that: number): (self: number) => number
|
|
336
|
+
* (self: number, that: number): number
|
|
337
|
+
* } = Function.dual(2, (self: number, that: number): number => self + that)
|
|
338
|
+
*
|
|
339
|
+
* sum(2, 3) // => 5
|
|
340
|
+
* pipe(2, sum(3)) // => 5
|
|
341
|
+
* ```
|
|
342
|
+
*
|
|
343
|
+
* **Example** (Selecting data-first or data-last style with a predicate)
|
|
344
|
+
*
|
|
345
|
+
* ```ts import.meta.vitest
|
|
346
|
+
* import { Function, pipe } from "effect"
|
|
347
|
+
*
|
|
348
|
+
* const sum = Function.dual<
|
|
349
|
+
* (that: number) => (self: number) => number,
|
|
350
|
+
* (self: number, that: number) => number
|
|
351
|
+
* >(
|
|
352
|
+
* (args) => args.length === 2,
|
|
353
|
+
* (self, that) => self + that
|
|
354
|
+
* )
|
|
355
|
+
*
|
|
356
|
+
* sum(2, 3) // => 5
|
|
357
|
+
* pipe(2, sum(3)) // => 5
|
|
358
|
+
* ```
|
|
359
|
+
*
|
|
360
|
+
* @stability stable
|
|
361
|
+
* @category combinators
|
|
362
|
+
* @since 2.0.0
|
|
363
|
+
*/
|
|
364
|
+
const dual = function(arity, body) {
|
|
365
|
+
if (typeof arity === "function") return function() {
|
|
366
|
+
return arity(arguments) ? body.apply(this, arguments) : (self) => body(self, ...arguments);
|
|
367
|
+
};
|
|
368
|
+
switch (arity) {
|
|
369
|
+
case 0:
|
|
370
|
+
case 1: throw new RangeError(`Invalid arity ${arity}`);
|
|
371
|
+
case 2: return function(a, b) {
|
|
372
|
+
if (arguments.length >= 2) return body(a, b);
|
|
373
|
+
return function(self) {
|
|
374
|
+
return body(self, a);
|
|
375
|
+
};
|
|
376
|
+
};
|
|
377
|
+
case 3: return function(a, b, c) {
|
|
378
|
+
if (arguments.length >= 3) return body(a, b, c);
|
|
379
|
+
return function(self) {
|
|
380
|
+
return body(self, a, b);
|
|
381
|
+
};
|
|
382
|
+
};
|
|
383
|
+
default: return function() {
|
|
384
|
+
if (arguments.length >= arity) return body.apply(this, arguments);
|
|
385
|
+
const args = arguments;
|
|
386
|
+
return function(self) {
|
|
387
|
+
return body(self, ...args);
|
|
388
|
+
};
|
|
389
|
+
};
|
|
390
|
+
}
|
|
391
|
+
};
|
|
392
|
+
// node_modules/.pnpm/effect@4.1.2/node_modules/effect/dist/internal/equal.js
|
|
393
|
+
/** @internal */
|
|
394
|
+
const getAllObjectKeys = (obj) => {
|
|
395
|
+
const keys = new Set(Reflect.ownKeys(obj));
|
|
396
|
+
if (obj.constructor === Object) return keys;
|
|
397
|
+
if (obj instanceof Error) keys.delete("stack");
|
|
398
|
+
const proto = Object.getPrototypeOf(obj);
|
|
399
|
+
let current = proto;
|
|
400
|
+
while (current !== null && current !== Object.prototype) {
|
|
401
|
+
const ownKeys = Reflect.ownKeys(current);
|
|
402
|
+
for (let i = 0; i < ownKeys.length; i++) keys.add(ownKeys[i]);
|
|
403
|
+
current = Object.getPrototypeOf(current);
|
|
404
|
+
}
|
|
405
|
+
if (keys.has("constructor") && typeof obj.constructor === "function" && proto === obj.constructor.prototype) keys.delete("constructor");
|
|
406
|
+
return keys;
|
|
407
|
+
};
|
|
408
|
+
/** @internal */
|
|
409
|
+
const byReferenceInstances = /*#__PURE__*/ new WeakSet();
|
|
410
|
+
/** @internal */
|
|
411
|
+
const viewBytes = (view) => new Uint8Array(view.buffer, view.byteOffset, view.byteLength);
|
|
412
|
+
/** @internal */
|
|
413
|
+
const isArrayBufferLike = (u) => u instanceof ArrayBuffer || typeof SharedArrayBuffer !== "undefined" && u instanceof SharedArrayBuffer;
|
|
414
|
+
/**
|
|
415
|
+
* Returns `undefined` for detached buffers, which can no longer be read.
|
|
416
|
+
*
|
|
417
|
+
* @internal
|
|
418
|
+
*/
|
|
419
|
+
const bufferBytes = (buffer) => {
|
|
420
|
+
try {
|
|
421
|
+
return new Uint8Array(buffer);
|
|
422
|
+
} catch {
|
|
423
|
+
return;
|
|
424
|
+
}
|
|
425
|
+
};
|
|
426
|
+
// node_modules/.pnpm/effect@4.1.2/node_modules/effect/dist/internal/hash.js
|
|
427
|
+
/**
|
|
428
|
+
* Back-edge count used to avoid caching entry-point-dependent hashes.
|
|
429
|
+
*
|
|
430
|
+
* @internal
|
|
431
|
+
*/
|
|
432
|
+
let backEdges = 0;
|
|
433
|
+
/** @internal */
|
|
434
|
+
const addBackEdge = () => {
|
|
435
|
+
backEdges++;
|
|
436
|
+
};
|
|
437
|
+
// node_modules/.pnpm/effect@4.1.2/node_modules/effect/dist/Predicate.js
|
|
438
|
+
/**
|
|
439
|
+
* Defines runtime checks for values.
|
|
440
|
+
*
|
|
441
|
+
* A `Predicate<A>` returns `true` or `false` for an `A`. A
|
|
442
|
+
* `Refinement<A, B>` is a predicate that also narrows the TypeScript type when
|
|
443
|
+
* it succeeds. This module includes guards for common JavaScript values,
|
|
444
|
+
* property and tag checks, tuple and struct checks, boolean combinators, and
|
|
445
|
+
* helpers for composing predicates and refinements.
|
|
446
|
+
*
|
|
447
|
+
* @stability stable
|
|
448
|
+
* @since 2.0.0
|
|
449
|
+
*/
|
|
450
|
+
/**
|
|
451
|
+
* Checks whether a value is a `function`.
|
|
452
|
+
*
|
|
453
|
+
* **When to use**
|
|
454
|
+
*
|
|
455
|
+
* Use when you need a `Predicate` guard to narrow an `unknown` value to a
|
|
456
|
+
* callable function.
|
|
457
|
+
*
|
|
458
|
+
* **Details**
|
|
459
|
+
*
|
|
460
|
+
* Uses `typeof input === "function"`.
|
|
461
|
+
*
|
|
462
|
+
* **Example** (Guarding functions)
|
|
463
|
+
*
|
|
464
|
+
* ```ts import.meta.vitest
|
|
465
|
+
* import { Predicate } from "effect"
|
|
466
|
+
*
|
|
467
|
+
* const data: unknown = () => 1
|
|
468
|
+
*
|
|
469
|
+
* if (Predicate.isFunction(data)) {
|
|
470
|
+
* data() // => 1
|
|
471
|
+
* }
|
|
472
|
+
* ```
|
|
473
|
+
*
|
|
474
|
+
* @see {@link isObjectKeyword}
|
|
475
|
+
* @stability stable
|
|
476
|
+
* @category guards
|
|
477
|
+
* @since 2.0.0
|
|
478
|
+
*/
|
|
479
|
+
function isFunction(input) {
|
|
480
|
+
return typeof input === "function";
|
|
481
|
+
}
|
|
482
|
+
/**
|
|
483
|
+
* Checks whether a value is an `object` in the JavaScript sense (objects, arrays, functions).
|
|
484
|
+
*
|
|
485
|
+
* **When to use**
|
|
486
|
+
*
|
|
487
|
+
* Use when you need a `Predicate` guard that accepts arrays and functions as
|
|
488
|
+
* well as objects.
|
|
489
|
+
*
|
|
490
|
+
* **Details**
|
|
491
|
+
*
|
|
492
|
+
* Returns `true` for arrays and functions, and `false` for `null`.
|
|
493
|
+
*
|
|
494
|
+
* **Example** (Checking object keywords)
|
|
495
|
+
*
|
|
496
|
+
* ```ts import.meta.vitest
|
|
497
|
+
* import { Predicate } from "effect"
|
|
498
|
+
*
|
|
499
|
+
* Predicate.isObjectKeyword(() => 1) // => true
|
|
500
|
+
* Predicate.isObjectKeyword(null) // => false
|
|
501
|
+
* ```
|
|
502
|
+
*
|
|
503
|
+
* @see {@link isObject}
|
|
504
|
+
* @see {@link isObjectOrArray}
|
|
505
|
+
* @stability stable
|
|
506
|
+
* @category guards
|
|
507
|
+
* @since 4.0.0
|
|
508
|
+
*/
|
|
509
|
+
function isObjectKeyword(input) {
|
|
510
|
+
return typeof input === "object" && input !== null || isFunction(input);
|
|
511
|
+
}
|
|
512
|
+
/**
|
|
513
|
+
* Checks whether a value has a given property key.
|
|
514
|
+
*
|
|
515
|
+
* **When to use**
|
|
516
|
+
*
|
|
517
|
+
* Use when you need a `Predicate` guard for property access on `unknown`
|
|
518
|
+
* values with a simple structural object check.
|
|
519
|
+
*
|
|
520
|
+
* **Details**
|
|
521
|
+
*
|
|
522
|
+
* Uses the `in` operator and `isObjectKeyword`. This does not check property
|
|
523
|
+
* value types.
|
|
524
|
+
*
|
|
525
|
+
* **Example** (Guarding object properties)
|
|
526
|
+
*
|
|
527
|
+
* ```ts import.meta.vitest
|
|
528
|
+
* import { Predicate } from "effect"
|
|
529
|
+
*
|
|
530
|
+
* const hasName = Predicate.hasProperty("name")
|
|
531
|
+
* const data: unknown = { name: "Ada" }
|
|
532
|
+
*
|
|
533
|
+
* if (hasName(data)) {
|
|
534
|
+
* data.name // => "Ada"
|
|
535
|
+
* }
|
|
536
|
+
* ```
|
|
537
|
+
*
|
|
538
|
+
* @see {@link isTagged}
|
|
539
|
+
* @see {@link isObjectKeyword}
|
|
540
|
+
* @stability stable
|
|
541
|
+
* @category guards
|
|
542
|
+
* @since 2.0.0
|
|
543
|
+
*/
|
|
544
|
+
const hasProperty = /*#__PURE__*/ dual(2, (self, property) => isObjectKeyword(self) && property in self);
|
|
545
|
+
// node_modules/.pnpm/effect@4.1.2/node_modules/effect/dist/Hash.js
|
|
546
|
+
/**
|
|
547
|
+
* Computes Effect hash values and defines the interface for objects that want
|
|
548
|
+
* to provide their own hash implementation. Hashes are small numeric
|
|
549
|
+
* fingerprints used by Effect data structures to bucket values quickly; they
|
|
550
|
+
* are not cryptographic digests and they are not proof that two values are
|
|
551
|
+
* equal. The module also includes helpers for primitive, structure, array, and
|
|
552
|
+
* reference-based hashes, plus functions for combining and optimizing numeric
|
|
553
|
+
* hash values.
|
|
554
|
+
*
|
|
555
|
+
* @stability stable
|
|
556
|
+
* @since 2.0.0
|
|
557
|
+
*/
|
|
558
|
+
/**
|
|
559
|
+
* Defines the unique identifier used to identify objects that implement the Hash interface.
|
|
560
|
+
*
|
|
561
|
+
* **When to use**
|
|
562
|
+
*
|
|
563
|
+
* Use as the computed property key for the method that supplies a custom hash
|
|
564
|
+
* value on a `Hash` implementor.
|
|
565
|
+
*
|
|
566
|
+
* @see {@link Hash} for the interface implemented with this symbol
|
|
567
|
+
* @see {@link isHash} for checking whether a value implements `Hash`
|
|
568
|
+
* @see {@link hash} for computing hash values
|
|
569
|
+
*
|
|
570
|
+
* @stability stable
|
|
571
|
+
* @category symbols
|
|
572
|
+
* @since 2.0.0
|
|
573
|
+
*/
|
|
574
|
+
const symbol$1 = "~effect/Hash";
|
|
575
|
+
/**
|
|
576
|
+
* Computes a hash value for any given value.
|
|
577
|
+
*
|
|
578
|
+
* **When to use**
|
|
579
|
+
*
|
|
580
|
+
* Use to compute an Effect hash for primitives, collections, and hashable
|
|
581
|
+
* objects.
|
|
582
|
+
*
|
|
583
|
+
* **Details**
|
|
584
|
+
*
|
|
585
|
+
* This function can hash primitives (numbers, strings, booleans, etc.) as well as
|
|
586
|
+
* objects, arrays, and other complex data structures. It automatically handles
|
|
587
|
+
* different types and provides a consistent hash value for equivalent inputs.
|
|
588
|
+
*
|
|
589
|
+
* **Gotchas**
|
|
590
|
+
*
|
|
591
|
+
* Objects being hashed must be treated as immutable after their first hash
|
|
592
|
+
* computation. Hash results are cached, so mutating an object after hashing will
|
|
593
|
+
* lead to stale cached values and broken hash-based operations. For mutable
|
|
594
|
+
* objects, implement a custom `Hash` interface that hashes the object reference
|
|
595
|
+
* rather than its content.
|
|
596
|
+
*
|
|
597
|
+
* **Example** (Hashing different values)
|
|
598
|
+
*
|
|
599
|
+
* ```ts import.meta.vitest
|
|
600
|
+
* import { Hash } from "effect"
|
|
601
|
+
*
|
|
602
|
+
* Hash.hash(42) === Hash.hash(42) // => true
|
|
603
|
+
* Hash.hash("hello") === Hash.hash("hello") // => true
|
|
604
|
+
* Hash.hash([1, 2, 3]) === Hash.hash([1, 2, 3]) // => true
|
|
605
|
+
* ```
|
|
606
|
+
*
|
|
607
|
+
* @stability stable
|
|
608
|
+
* @category hashing
|
|
609
|
+
* @since 2.0.0
|
|
610
|
+
*/
|
|
611
|
+
const hash = (self) => {
|
|
612
|
+
switch (typeof self) {
|
|
613
|
+
case "number": return number(self);
|
|
614
|
+
case "bigint": return string(self.toString(10));
|
|
615
|
+
case "string": return string(self);
|
|
616
|
+
case "function":
|
|
617
|
+
case "object": if (self === null) break;
|
|
618
|
+
else if (self instanceof Date) {
|
|
619
|
+
if (Number.isNaN(self.getTime())) return string("Invalid Date");
|
|
620
|
+
return string(self.toISOString());
|
|
621
|
+
} else if (self instanceof RegExp) return string(self.toString());
|
|
622
|
+
else {
|
|
623
|
+
if (byReferenceInstances.has(self)) return random(self);
|
|
624
|
+
const cached = hashCache.get(self);
|
|
625
|
+
if (cached !== void 0) return cached;
|
|
626
|
+
if (visitedObjects.has(self)) {
|
|
627
|
+
addBackEdge();
|
|
628
|
+
return string("[Circular]");
|
|
629
|
+
}
|
|
630
|
+
visitedObjects.add(self);
|
|
631
|
+
const seen = backEdges;
|
|
632
|
+
let h;
|
|
633
|
+
try {
|
|
634
|
+
if (isHash(self)) h = self[symbol$1]();
|
|
635
|
+
else if (typeof self === "function") h = random(self);
|
|
636
|
+
else if (isArrayBufferLike(self)) {
|
|
637
|
+
const bytes = bufferBytes(self);
|
|
638
|
+
h = bytes === void 0 ? random(self) : array(bytes);
|
|
639
|
+
} else if (self instanceof DataView) h = array(viewBytes(self));
|
|
640
|
+
else if (Array.isArray(self) || ArrayBuffer.isView(self)) h = array(self);
|
|
641
|
+
else if (self instanceof Map) h = hashMap(self);
|
|
642
|
+
else if (self instanceof Set) h = hashSet(self);
|
|
643
|
+
else h = structure(self);
|
|
644
|
+
} finally {
|
|
645
|
+
visitedObjects.delete(self);
|
|
646
|
+
}
|
|
647
|
+
if (seen === backEdges) hashCache.set(self, h);
|
|
648
|
+
return h;
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
return optimize(mix(string(String(self))));
|
|
652
|
+
};
|
|
653
|
+
/**
|
|
654
|
+
* Generates a random hash value for an object and caches it.
|
|
655
|
+
*
|
|
656
|
+
* **When to use**
|
|
657
|
+
*
|
|
658
|
+
* Use to hash an object by reference identity instead of structural content.
|
|
659
|
+
*
|
|
660
|
+
* **Details**
|
|
661
|
+
*
|
|
662
|
+
* This function creates a random hash value for objects that don't have their own
|
|
663
|
+
* hash implementation. The hash value is cached using a WeakMap, so the same object
|
|
664
|
+
* will always return the same hash value during its lifetime.
|
|
665
|
+
*
|
|
666
|
+
* **Example** (Hashing objects by reference)
|
|
667
|
+
*
|
|
668
|
+
* ```ts import.meta.vitest
|
|
669
|
+
* import { Hash } from "effect"
|
|
670
|
+
*
|
|
671
|
+
* const obj1 = { a: 1 }
|
|
672
|
+
* const obj2 = { a: 1 }
|
|
673
|
+
*
|
|
674
|
+
* Hash.random(obj1) === Hash.random(obj1) // => true
|
|
675
|
+
*
|
|
676
|
+
* typeof Hash.random(obj2) // => "number"
|
|
677
|
+
* ```
|
|
678
|
+
*
|
|
679
|
+
* @stability stable
|
|
680
|
+
* @category hashing
|
|
681
|
+
* @since 2.0.0
|
|
682
|
+
*/
|
|
683
|
+
const random = (self) => {
|
|
684
|
+
if (!randomHashCache.has(self)) randomHashCache.set(self, optimize(Math.random() * 4294967296 | 0));
|
|
685
|
+
return randomHashCache.get(self);
|
|
686
|
+
};
|
|
687
|
+
const mix = (h) => {
|
|
688
|
+
h ^= h >>> 16;
|
|
689
|
+
h = Math.imul(h, 2246822507);
|
|
690
|
+
h ^= h >>> 13;
|
|
691
|
+
h = Math.imul(h, 3266489909);
|
|
692
|
+
return h ^ h >>> 16;
|
|
693
|
+
};
|
|
694
|
+
/**
|
|
695
|
+
* Combines two hash values into a single hash value.
|
|
696
|
+
*
|
|
697
|
+
* **When to use**
|
|
698
|
+
*
|
|
699
|
+
* Use to build a hash for a composite value by folding together hash values for
|
|
700
|
+
* its parts.
|
|
701
|
+
*
|
|
702
|
+
* **Details**
|
|
703
|
+
*
|
|
704
|
+
* Supports direct and pipeable usage. Argument order affects the result.
|
|
705
|
+
*
|
|
706
|
+
* **Example** (Combining hash values)
|
|
707
|
+
*
|
|
708
|
+
* ```ts import.meta.vitest
|
|
709
|
+
* import { Hash, pipe } from "effect"
|
|
710
|
+
*
|
|
711
|
+
* const hash1 = Hash.hash("hello")
|
|
712
|
+
* const hash2 = Hash.hash("world")
|
|
713
|
+
*
|
|
714
|
+
* const combined = Hash.combine(hash2)(hash1)
|
|
715
|
+
* combined === pipe(hash1, Hash.combine(hash2)) // => true
|
|
716
|
+
* ```
|
|
717
|
+
*
|
|
718
|
+
* @see {@link hash} for computing hash values from arbitrary inputs
|
|
719
|
+
* @see {@link structureKeys} for hashing selected object fields without manual combination
|
|
720
|
+
*
|
|
721
|
+
* @stability stable
|
|
722
|
+
* @category hashing
|
|
723
|
+
* @since 2.0.0
|
|
724
|
+
*/
|
|
725
|
+
const combine = /*#__PURE__*/ dual(2, (self, b) => mix(Math.imul(self, 2654435761) + Math.imul(b, 2246822507)));
|
|
726
|
+
/**
|
|
727
|
+
* Applies bit manipulation techniques to optimize a hash value.
|
|
728
|
+
*
|
|
729
|
+
* **When to use**
|
|
730
|
+
*
|
|
731
|
+
* Use to improve the bit distribution of a raw numeric hash value.
|
|
732
|
+
*
|
|
733
|
+
* **Details**
|
|
734
|
+
*
|
|
735
|
+
* This function takes a hash value and applies bitwise operations to improve
|
|
736
|
+
* the distribution of hash values, reducing the likelihood of collisions.
|
|
737
|
+
*
|
|
738
|
+
* **Example** (Optimizing a hash value)
|
|
739
|
+
*
|
|
740
|
+
* ```ts import.meta.vitest
|
|
741
|
+
* import { Hash } from "effect"
|
|
742
|
+
*
|
|
743
|
+
* Hash.optimize(1234567890) // => 160826066
|
|
744
|
+
* ```
|
|
745
|
+
*
|
|
746
|
+
* @stability stable
|
|
747
|
+
* @category hashing
|
|
748
|
+
* @since 2.0.0
|
|
749
|
+
*/
|
|
750
|
+
const optimize = (n) => n & 3221225471 | n >>> 1 & 1073741824;
|
|
751
|
+
/**
|
|
752
|
+
* Checks whether a value implements the Hash interface.
|
|
753
|
+
*
|
|
754
|
+
* **When to use**
|
|
755
|
+
*
|
|
756
|
+
* Use to detect whether an unknown value provides a custom hash implementation.
|
|
757
|
+
*
|
|
758
|
+
* **Details**
|
|
759
|
+
*
|
|
760
|
+
* This function determines whether a given value has a function under the Hash
|
|
761
|
+
* symbol, indicating that it can provide its own hash value implementation.
|
|
762
|
+
* Data that merely carries the key, such as parsed JSON, is hashed as data.
|
|
763
|
+
*
|
|
764
|
+
* **Example** (Checking for Hash support)
|
|
765
|
+
*
|
|
766
|
+
* ```ts import.meta.vitest
|
|
767
|
+
* import { Hash } from "effect"
|
|
768
|
+
*
|
|
769
|
+
* class MyHashable implements Hash.Hash {
|
|
770
|
+
* [Hash.symbol]() {
|
|
771
|
+
* return 42
|
|
772
|
+
* }
|
|
773
|
+
* }
|
|
774
|
+
*
|
|
775
|
+
* Hash.isHash(new MyHashable()) // => true
|
|
776
|
+
* Hash.isHash({}) // => false
|
|
777
|
+
* Hash.isHash("string") // => false
|
|
778
|
+
* ```
|
|
779
|
+
*
|
|
780
|
+
* @stability stable
|
|
781
|
+
* @category guards
|
|
782
|
+
* @since 2.0.0
|
|
783
|
+
*/
|
|
784
|
+
const isHash = (u) => hasProperty(u, "~effect/Hash") && typeof u["~effect/Hash"] === "function";
|
|
785
|
+
const float64 = /*#__PURE__*/ new DataView(/*#__PURE__*/ new ArrayBuffer(8));
|
|
786
|
+
/**
|
|
787
|
+
* Computes a hash value for a number.
|
|
788
|
+
*
|
|
789
|
+
* **When to use**
|
|
790
|
+
*
|
|
791
|
+
* Use to hash a JavaScript number with Effect's numeric hash semantics.
|
|
792
|
+
*
|
|
793
|
+
* **Details**
|
|
794
|
+
*
|
|
795
|
+
* Int32 values hash to themselves. Other numbers hash from their IEEE-754 bits,
|
|
796
|
+
* with a canonical representation for `NaN`.
|
|
797
|
+
*
|
|
798
|
+
* **Example** (Hashing numbers)
|
|
799
|
+
*
|
|
800
|
+
* ```ts import.meta.vitest
|
|
801
|
+
* import { Hash } from "effect"
|
|
802
|
+
*
|
|
803
|
+
* Number.isInteger(Hash.number(42)) // => true
|
|
804
|
+
* Number.isInteger(Hash.number(3.14)) // => true
|
|
805
|
+
* Hash.number(NaN) === Hash.number(NaN) // => true
|
|
806
|
+
* Hash.number(Infinity) === Hash.number(Infinity) // => true
|
|
807
|
+
* Hash.number(100) === Hash.number(100) // => true
|
|
808
|
+
* ```
|
|
809
|
+
*
|
|
810
|
+
* @stability stable
|
|
811
|
+
* @category hashing
|
|
812
|
+
* @since 2.0.0
|
|
813
|
+
*/
|
|
814
|
+
const number = (n) => {
|
|
815
|
+
const h = n | 0;
|
|
816
|
+
if (h === n) return optimize(h);
|
|
817
|
+
float64.setFloat64(0, n !== n ? NaN : n);
|
|
818
|
+
return optimize(combine(float64.getInt32(0), float64.getInt32(4)));
|
|
819
|
+
};
|
|
820
|
+
/**
|
|
821
|
+
* Computes a hash value for a string using the djb2 algorithm.
|
|
822
|
+
*
|
|
823
|
+
* **When to use**
|
|
824
|
+
*
|
|
825
|
+
* Use when you need a string field to contribute to a custom structural hash
|
|
826
|
+
* implementation.
|
|
827
|
+
*
|
|
828
|
+
* **Details**
|
|
829
|
+
*
|
|
830
|
+
* This function implements a variation of the djb2 hash algorithm, which is
|
|
831
|
+
* known for its good distribution properties and speed. It processes each
|
|
832
|
+
* character of the string to produce a consistent hash value.
|
|
833
|
+
*
|
|
834
|
+
* **Example** (Hashing strings)
|
|
835
|
+
*
|
|
836
|
+
* ```ts import.meta.vitest
|
|
837
|
+
* import { Hash } from "effect"
|
|
838
|
+
*
|
|
839
|
+
* Hash.string("hello") // => 181380007
|
|
840
|
+
* Hash.string("world") // => 164394279
|
|
841
|
+
* Hash.string("") // => 5381
|
|
842
|
+
* Hash.string("test") === Hash.string("test") // => true
|
|
843
|
+
* ```
|
|
844
|
+
*
|
|
845
|
+
* @stability stable
|
|
846
|
+
* @category hashing
|
|
847
|
+
* @since 2.0.0
|
|
848
|
+
*/
|
|
849
|
+
const string = (str) => {
|
|
850
|
+
let h = 5381, i = str.length;
|
|
851
|
+
while (i) h = h * 33 ^ str.charCodeAt(--i);
|
|
852
|
+
return optimize(h);
|
|
853
|
+
};
|
|
854
|
+
/**
|
|
855
|
+
* Computes a hash value for an object using only the specified keys.
|
|
856
|
+
*
|
|
857
|
+
* **When to use**
|
|
858
|
+
*
|
|
859
|
+
* Use to hash an object by a selected set of property keys.
|
|
860
|
+
*
|
|
861
|
+
* **Details**
|
|
862
|
+
*
|
|
863
|
+
* This function allows you to hash an object by considering only specific keys,
|
|
864
|
+
* which is useful when you want to create a hash based on a subset of an object's
|
|
865
|
+
* properties.
|
|
866
|
+
*
|
|
867
|
+
* **Example** (Hashing selected object keys)
|
|
868
|
+
*
|
|
869
|
+
* ```ts import.meta.vitest
|
|
870
|
+
* import { Hash } from "effect"
|
|
871
|
+
*
|
|
872
|
+
* const person = { name: "John", age: 30, city: "New York" }
|
|
873
|
+
*
|
|
874
|
+
* const hash1 = Hash.structureKeys(person, ["name", "age"])
|
|
875
|
+
* const hash2 = Hash.structureKeys(person, ["name", "city"])
|
|
876
|
+
*
|
|
877
|
+
* hash1 // => -731887653
|
|
878
|
+
* hash2 // => 148523102
|
|
879
|
+
*
|
|
880
|
+
* const person2 = { name: "John", age: 30, city: "Boston" }
|
|
881
|
+
* const hash3 = Hash.structureKeys(person2, ["name", "age"])
|
|
882
|
+
* hash1 === hash3 // => true
|
|
883
|
+
* ```
|
|
884
|
+
*
|
|
885
|
+
* @stability stable
|
|
886
|
+
* @category hashing
|
|
887
|
+
* @since 2.0.0
|
|
888
|
+
*/
|
|
889
|
+
const structureKeys = (o, keys) => {
|
|
890
|
+
let h = 12289;
|
|
891
|
+
for (const key of keys) h ^= combine(hash(key), hash(o[key]));
|
|
892
|
+
return optimize(h);
|
|
893
|
+
};
|
|
894
|
+
/**
|
|
895
|
+
* Computes a structural hash for an object using Effect's object key collection.
|
|
896
|
+
*
|
|
897
|
+
* **When to use**
|
|
898
|
+
*
|
|
899
|
+
* Use to hash an object from all structural keys collected by Effect.
|
|
900
|
+
*
|
|
901
|
+
* **Details**
|
|
902
|
+
*
|
|
903
|
+
* The hash is based on the object's structural keys and their values, including
|
|
904
|
+
* symbol keys and relevant prototype keys for non-plain objects.
|
|
905
|
+
*
|
|
906
|
+
* **Example** (Hashing object structures)
|
|
907
|
+
*
|
|
908
|
+
* ```ts import.meta.vitest
|
|
909
|
+
* import { Hash } from "effect"
|
|
910
|
+
*
|
|
911
|
+
* const obj1 = { name: "John", age: 30 }
|
|
912
|
+
* const obj2 = { name: "Jane", age: 25 }
|
|
913
|
+
* const obj3 = { name: "John", age: 30 }
|
|
914
|
+
*
|
|
915
|
+
* Hash.structure(obj1) // => -731887653
|
|
916
|
+
* Hash.structure(obj2) // => -222100417
|
|
917
|
+
* Hash.structure(obj3) // => -731887653
|
|
918
|
+
* Hash.structure(obj1) === Hash.structure(obj3) // => true
|
|
919
|
+
* ```
|
|
920
|
+
*
|
|
921
|
+
* @stability stable
|
|
922
|
+
* @category hashing
|
|
923
|
+
* @since 2.0.0
|
|
924
|
+
*/
|
|
925
|
+
const structure = (o) => structureKeys(o, getAllObjectKeys(o));
|
|
926
|
+
const unordered = (seed, f) => (iter) => {
|
|
927
|
+
let h = seed;
|
|
928
|
+
for (const element of iter) h ^= f(element);
|
|
929
|
+
return optimize(h);
|
|
930
|
+
};
|
|
931
|
+
/**
|
|
932
|
+
* Computes a hash value for an iterable by hashing all of its elements.
|
|
933
|
+
*
|
|
934
|
+
* **When to use**
|
|
935
|
+
*
|
|
936
|
+
* Use to hash the values yielded by an iterable with Effect hash semantics.
|
|
937
|
+
*
|
|
938
|
+
* **Details**
|
|
939
|
+
*
|
|
940
|
+
* Folds element hashes with {@link combine}, so order and length affect the
|
|
941
|
+
* result.
|
|
942
|
+
*
|
|
943
|
+
* **Gotchas**
|
|
944
|
+
*
|
|
945
|
+
* A hash is not an equality proof. Distinct inputs can still share a hash.
|
|
946
|
+
*
|
|
947
|
+
* **Example** (Hashing arrays)
|
|
948
|
+
*
|
|
949
|
+
* ```ts import.meta.vitest
|
|
950
|
+
* import { Hash } from "effect"
|
|
951
|
+
*
|
|
952
|
+
* const arr1 = [1, 2, 3]
|
|
953
|
+
* const arr2 = [1, 2, 3]
|
|
954
|
+
* const arr3 = [3, 2, 1]
|
|
955
|
+
*
|
|
956
|
+
* Hash.array(arr1) === Hash.array(arr2) // => true
|
|
957
|
+
* Hash.array(arr1) === Hash.array(arr3) // => false
|
|
958
|
+
* ```
|
|
959
|
+
*
|
|
960
|
+
* @see {@link hash} for the general-purpose hash dispatcher
|
|
961
|
+
*
|
|
962
|
+
* @stability stable
|
|
963
|
+
* @category hashing
|
|
964
|
+
* @since 2.0.0
|
|
965
|
+
*/
|
|
966
|
+
const array = (arr) => {
|
|
967
|
+
let h = 6151;
|
|
968
|
+
for (const element of arr) h = combine(h, hash(element));
|
|
969
|
+
return optimize(h);
|
|
970
|
+
};
|
|
971
|
+
const hashMap = /*#__PURE__*/ unordered(/*#__PURE__*/ string("Map"), ([k, v]) => combine(hash(k), hash(v)));
|
|
972
|
+
const setSeed = /*#__PURE__*/ string("Set");
|
|
973
|
+
const hashSet = /*#__PURE__*/ unordered(setSeed, (element) => combine(setSeed, hash(element)));
|
|
974
|
+
const randomHashCache = /*#__PURE__*/ new WeakMap();
|
|
975
|
+
const hashCache = /*#__PURE__*/ new WeakMap();
|
|
976
|
+
const visitedObjects = /*#__PURE__*/ new WeakSet();
|
|
977
|
+
// node_modules/.pnpm/effect@4.1.2/node_modules/effect/dist/Equal.js
|
|
978
|
+
/**
|
|
979
|
+
* Defines the unique string identifier for the `Equal` interface.
|
|
980
|
+
*
|
|
981
|
+
* **When to use**
|
|
982
|
+
*
|
|
983
|
+
* Use when you implement custom equality and need the computed property key for
|
|
984
|
+
* the equality method.
|
|
985
|
+
*
|
|
986
|
+
* **Details**
|
|
987
|
+
*
|
|
988
|
+
* This is a pure constant with no allocation or side effects.
|
|
989
|
+
*
|
|
990
|
+
* **Example** (Implementing Equal on a class)
|
|
991
|
+
*
|
|
992
|
+
* ```ts import.meta.vitest
|
|
993
|
+
* import { Equal, Hash } from "effect"
|
|
994
|
+
*
|
|
995
|
+
* class UserId implements Equal.Equal {
|
|
996
|
+
* constructor(readonly id: string) {}
|
|
997
|
+
*
|
|
998
|
+
* [Equal.symbol](that: Equal.Equal): boolean {
|
|
999
|
+
* return that instanceof UserId && this.id === that.id
|
|
1000
|
+
* }
|
|
1001
|
+
*
|
|
1002
|
+
* [Hash.symbol](): number {
|
|
1003
|
+
* return Hash.string(this.id)
|
|
1004
|
+
* }
|
|
1005
|
+
* }
|
|
1006
|
+
*
|
|
1007
|
+
* Equal.equals(new UserId("1"), new UserId("1")) // => true
|
|
1008
|
+
* Equal.equals(new UserId("1"), new UserId("2")) // => false
|
|
1009
|
+
* ```
|
|
1010
|
+
*
|
|
1011
|
+
* @see {@link Equal} — the interface that uses this symbol
|
|
1012
|
+
* @see {@link isEqual} — type guard for `Equal` implementors
|
|
1013
|
+
* @stability stable
|
|
1014
|
+
* @category symbols
|
|
1015
|
+
* @since 2.0.0
|
|
1016
|
+
*/
|
|
1017
|
+
const symbol = "~effect/Equal";
|
|
1018
|
+
function equals() {
|
|
1019
|
+
if (arguments.length === 1) return (self) => compareBoth(self, arguments[0]);
|
|
1020
|
+
return compareBoth(arguments[0], arguments[1]);
|
|
1021
|
+
}
|
|
1022
|
+
function compareBoth(self, that) {
|
|
1023
|
+
if (self === that) return true;
|
|
1024
|
+
if (self == null || that == null) return false;
|
|
1025
|
+
const selfType = typeof self;
|
|
1026
|
+
if (selfType !== typeof that) return false;
|
|
1027
|
+
if (selfType === "number" && self !== self && that !== that) return true;
|
|
1028
|
+
if (selfType !== "object" && selfType !== "function") return false;
|
|
1029
|
+
if (byReferenceInstances.has(self) || byReferenceInstances.has(that)) return false;
|
|
1030
|
+
return compareObjects(self, that);
|
|
1031
|
+
}
|
|
1032
|
+
function compareObjects(self, that) {
|
|
1033
|
+
const depth = pathLeft.length;
|
|
1034
|
+
for (let i = depth; i-- > 0;) if (pathLeft[i] === self && pathRight[i] === that) return true;
|
|
1035
|
+
if (depth) return compareOnPath(self, that);
|
|
1036
|
+
let known = results.get(self);
|
|
1037
|
+
if (!known) results.set(self, known = /* @__PURE__ */ new WeakMap());
|
|
1038
|
+
let result = known.get(that);
|
|
1039
|
+
if (result === void 0) known.set(that, result = compareOnPath(self, that));
|
|
1040
|
+
return result;
|
|
1041
|
+
}
|
|
1042
|
+
function compareOnPath(self, that) {
|
|
1043
|
+
pathLeft.push(self);
|
|
1044
|
+
pathRight.push(that);
|
|
1045
|
+
try {
|
|
1046
|
+
return compareStructure(self, that);
|
|
1047
|
+
} finally {
|
|
1048
|
+
pathLeft.pop();
|
|
1049
|
+
pathRight.pop();
|
|
1050
|
+
}
|
|
1051
|
+
}
|
|
1052
|
+
const pathLeft = [];
|
|
1053
|
+
const pathRight = [];
|
|
1054
|
+
const results = /*#__PURE__*/ new WeakMap();
|
|
1055
|
+
function compareStructure(self, that) {
|
|
1056
|
+
if (hash(self) !== hash(that)) return false;
|
|
1057
|
+
else if (self instanceof Date) {
|
|
1058
|
+
if (!(that instanceof Date)) return false;
|
|
1059
|
+
const selfTime = self.getTime();
|
|
1060
|
+
const thatTime = that.getTime();
|
|
1061
|
+
return selfTime === thatTime || Number.isNaN(selfTime) && Number.isNaN(thatTime);
|
|
1062
|
+
} else if (self instanceof RegExp) return that instanceof RegExp && self.toString() === that.toString();
|
|
1063
|
+
const bothEquals = isEqual(self);
|
|
1064
|
+
if (bothEquals !== isEqual(that) || typeof self === "function" && !bothEquals) return false;
|
|
1065
|
+
else if (bothEquals) return self[symbol](that);
|
|
1066
|
+
else if (Array.isArray(self)) {
|
|
1067
|
+
if (!Array.isArray(that) || self.length !== that.length) return false;
|
|
1068
|
+
return compareArrays(self, that);
|
|
1069
|
+
} else if (isArrayBufferLike(self)) {
|
|
1070
|
+
if (!isArrayBufferLike(that) || self instanceof ArrayBuffer !== that instanceof ArrayBuffer) return false;
|
|
1071
|
+
const selfBytes = bufferBytes(self);
|
|
1072
|
+
const thatBytes = bufferBytes(that);
|
|
1073
|
+
return selfBytes !== void 0 && thatBytes !== void 0 && compareTypedArrays(selfBytes, thatBytes);
|
|
1074
|
+
} else if (ArrayBuffer.isView(self)) {
|
|
1075
|
+
const selfIsDataView = self instanceof DataView;
|
|
1076
|
+
if (!ArrayBuffer.isView(that) || self.byteLength !== that.byteLength || selfIsDataView !== that instanceof DataView) return false;
|
|
1077
|
+
if (selfIsDataView) return compareTypedArrays(viewBytes(self), viewBytes(that));
|
|
1078
|
+
return compareTypedArrays(self, that);
|
|
1079
|
+
} else if (self instanceof Map) {
|
|
1080
|
+
if (!(that instanceof Map) || self.size !== that.size) return false;
|
|
1081
|
+
return compareHashed(self, that, entryHash, equalEntries);
|
|
1082
|
+
} else if (self instanceof Set) {
|
|
1083
|
+
if (!(that instanceof Set) || self.size !== that.size) return false;
|
|
1084
|
+
return compareHashed(self, that, hash, compareBoth);
|
|
1085
|
+
}
|
|
1086
|
+
return compareRecords(self, that);
|
|
1087
|
+
}
|
|
1088
|
+
function compareArrays(self, that) {
|
|
1089
|
+
for (let i = 0; i < self.length; i++) if (!compareBoth(self[i], that[i])) return false;
|
|
1090
|
+
return true;
|
|
1091
|
+
}
|
|
1092
|
+
function compareTypedArrays(self, that) {
|
|
1093
|
+
if (self.length !== that.length) return false;
|
|
1094
|
+
for (let i = 0; i < self.length; i++) if (self[i] !== that[i]) return false;
|
|
1095
|
+
return true;
|
|
1096
|
+
}
|
|
1097
|
+
function compareRecords(self, that) {
|
|
1098
|
+
const selfKeys = getAllObjectKeys(self);
|
|
1099
|
+
const thatKeys = getAllObjectKeys(that);
|
|
1100
|
+
if (selfKeys.size !== thatKeys.size) return false;
|
|
1101
|
+
for (const key of selfKeys) if (!thatKeys.has(key) || !compareBoth(self[key], that[key])) return false;
|
|
1102
|
+
return true;
|
|
1103
|
+
}
|
|
1104
|
+
function compareHashed(self, that, hashOf, equivalent) {
|
|
1105
|
+
const groups = /* @__PURE__ */ new Map();
|
|
1106
|
+
let remaining = 0;
|
|
1107
|
+
for (const item of that) {
|
|
1108
|
+
const h = hashOf(item);
|
|
1109
|
+
const group = groups.get(h);
|
|
1110
|
+
if (group) group.push(item);
|
|
1111
|
+
else groups.set(h, [item]);
|
|
1112
|
+
remaining++;
|
|
1113
|
+
}
|
|
1114
|
+
outer: for (const item of self) {
|
|
1115
|
+
const group = groups.get(hashOf(item));
|
|
1116
|
+
if (group) {
|
|
1117
|
+
for (let i = 0; i < group.length; i++) if (equivalent(item, group[i])) {
|
|
1118
|
+
group[i] = group[group.length - 1];
|
|
1119
|
+
group.pop();
|
|
1120
|
+
remaining--;
|
|
1121
|
+
continue outer;
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
return false;
|
|
1125
|
+
}
|
|
1126
|
+
return remaining === 0;
|
|
1127
|
+
}
|
|
1128
|
+
const entryHash = (entry) => hash(entry[0]);
|
|
1129
|
+
const equalEntries = (self, that) => compareBoth(self[0], that[0]) && compareBoth(self[1], that[1]);
|
|
1130
|
+
/**
|
|
1131
|
+
* Checks whether a value implements the {@link Equal} interface.
|
|
1132
|
+
*
|
|
1133
|
+
* **When to use**
|
|
1134
|
+
*
|
|
1135
|
+
* Use when you need generic utility code to distinguish `Equal` implementors
|
|
1136
|
+
* from plain values before calling `[Equal.symbol]` directly.
|
|
1137
|
+
*
|
|
1138
|
+
* **Details**
|
|
1139
|
+
*
|
|
1140
|
+
* - Pure function, no side effects.
|
|
1141
|
+
* - Returns `true` if and only if `u` has a function keyed by {@link symbol}.
|
|
1142
|
+
* Data that merely carries the key, such as parsed JSON, is not `Equal`.
|
|
1143
|
+
* - Acts as a TypeScript type guard, narrowing the input to {@link Equal}.
|
|
1144
|
+
*
|
|
1145
|
+
* **Example** (Checking Equal values)
|
|
1146
|
+
*
|
|
1147
|
+
* ```ts import.meta.vitest
|
|
1148
|
+
* import { Equal, Hash } from "effect"
|
|
1149
|
+
*
|
|
1150
|
+
* class Token implements Equal.Equal {
|
|
1151
|
+
* constructor(readonly value: string) {}
|
|
1152
|
+
* [Equal.symbol](that: Equal.Equal): boolean {
|
|
1153
|
+
* return that instanceof Token && this.value === that.value
|
|
1154
|
+
* }
|
|
1155
|
+
* [Hash.symbol](): number {
|
|
1156
|
+
* return Hash.string(this.value)
|
|
1157
|
+
* }
|
|
1158
|
+
* }
|
|
1159
|
+
*
|
|
1160
|
+
* Equal.isEqual(new Token("abc")) // => true
|
|
1161
|
+
* Equal.isEqual({ x: 1 }) // => false
|
|
1162
|
+
* Equal.isEqual(42) // => false
|
|
1163
|
+
* ```
|
|
1164
|
+
*
|
|
1165
|
+
* @see {@link Equal} — the interface being checked
|
|
1166
|
+
* @see {@link symbol} — the property key that signals `Equal` support
|
|
1167
|
+
* @stability stable
|
|
1168
|
+
* @category guards
|
|
1169
|
+
* @since 2.0.0
|
|
1170
|
+
*/
|
|
1171
|
+
const isEqual = (u) => hasProperty(u, "~effect/Equal") && typeof u["~effect/Equal"] === "function";
|
|
1172
|
+
// node_modules/.pnpm/effect@4.1.2/node_modules/effect/dist/Redactable.js
|
|
1173
|
+
/**
|
|
1174
|
+
* Defines the symbol used to identify objects that implement the {@link Redactable}
|
|
1175
|
+
* protocol.
|
|
1176
|
+
*
|
|
1177
|
+
* **When to use**
|
|
1178
|
+
*
|
|
1179
|
+
* Use as the property key when implementing the `Redactable` protocol.
|
|
1180
|
+
*
|
|
1181
|
+
* **Details**
|
|
1182
|
+
*
|
|
1183
|
+
* Add a method under this key to make an object redactable. The method receives
|
|
1184
|
+
* the current `Context` and must return the replacement value. The symbol is
|
|
1185
|
+
* registered globally via `Symbol.for("~effect/Redactable")`, so it is
|
|
1186
|
+
* identical across multiple copies of the library at runtime.
|
|
1187
|
+
*
|
|
1188
|
+
* **Example** (Masking an API key)
|
|
1189
|
+
*
|
|
1190
|
+
* ```ts import.meta.vitest
|
|
1191
|
+
* import { Context, Redactable } from "effect"
|
|
1192
|
+
*
|
|
1193
|
+
* class ApiKey {
|
|
1194
|
+
* constructor(readonly raw: string) {}
|
|
1195
|
+
*
|
|
1196
|
+
* [Redactable.symbolRedactable](_ctx: Context.Context<never>) {
|
|
1197
|
+
* return this.raw.slice(0, 4) + "..."
|
|
1198
|
+
* }
|
|
1199
|
+
* }
|
|
1200
|
+
*
|
|
1201
|
+
* Redactable.redact(new ApiKey("secret-key")) // => "secr..."
|
|
1202
|
+
* ```
|
|
1203
|
+
*
|
|
1204
|
+
* @see {@link Redactable} for the interface this symbol belongs to
|
|
1205
|
+
* @see {@link isRedactable} to check whether a value has this symbol
|
|
1206
|
+
* @stability stable
|
|
1207
|
+
* @category symbols
|
|
1208
|
+
* @since 3.10.0
|
|
1209
|
+
*/
|
|
1210
|
+
const symbolRedactable = /*#__PURE__*/ Symbol.for("~effect/Redactable");
|
|
1211
|
+
/**
|
|
1212
|
+
* Type guard that checks whether a value implements the {@link Redactable}
|
|
1213
|
+
* interface.
|
|
1214
|
+
*
|
|
1215
|
+
* **When to use**
|
|
1216
|
+
*
|
|
1217
|
+
* Use to narrow an unknown value before calling redaction-specific helpers.
|
|
1218
|
+
*
|
|
1219
|
+
* @see {@link Redactable} for the interface being checked
|
|
1220
|
+
* @see {@link redact} to apply redaction if the value is redactable
|
|
1221
|
+
* @stability stable
|
|
1222
|
+
* @category guards
|
|
1223
|
+
* @since 3.10.0
|
|
1224
|
+
*/
|
|
1225
|
+
const isRedactable = (u) => hasProperty(u, symbolRedactable);
|
|
1226
|
+
/**
|
|
1227
|
+
* Returns a redacted value if it implements {@link Redactable}, otherwise returns it
|
|
1228
|
+
* unchanged.
|
|
1229
|
+
*
|
|
1230
|
+
* **When to use**
|
|
1231
|
+
*
|
|
1232
|
+
* Use as the general-purpose entry point for redaction when the input may
|
|
1233
|
+
* or may not implement the redaction protocol.
|
|
1234
|
+
*
|
|
1235
|
+
* **Details**
|
|
1236
|
+
*
|
|
1237
|
+
* This function calls {@link isRedactable} and, when it returns `true`,
|
|
1238
|
+
* delegates to {@link getRedacted}.
|
|
1239
|
+
*
|
|
1240
|
+
* **Gotchas**
|
|
1241
|
+
*
|
|
1242
|
+
* Redaction is not recursive. Nested redactable values inside the returned
|
|
1243
|
+
* object are not automatically redacted.
|
|
1244
|
+
*
|
|
1245
|
+
* @see {@link isRedactable} to check before redacting
|
|
1246
|
+
* @see {@link getRedacted} for the lower-level variant for known redactables
|
|
1247
|
+
* @stability stable
|
|
1248
|
+
* @category destructors
|
|
1249
|
+
* @since 3.10.0
|
|
1250
|
+
*/
|
|
1251
|
+
function redact(u) {
|
|
1252
|
+
if (isRedactable(u)) return getRedacted(u);
|
|
1253
|
+
return u;
|
|
1254
|
+
}
|
|
1255
|
+
/**
|
|
1256
|
+
* Returns the result of calling `[symbolRedactable]` on a value that is
|
|
1257
|
+
* already known to be {@link Redactable}.
|
|
1258
|
+
*
|
|
1259
|
+
* **When to use**
|
|
1260
|
+
*
|
|
1261
|
+
* Use when you need to read the redacted representation from a value already
|
|
1262
|
+
* verified as `Redactable`.
|
|
1263
|
+
*
|
|
1264
|
+
* **Details**
|
|
1265
|
+
*
|
|
1266
|
+
* This function reads the current fiber's `Context` from the global fiber
|
|
1267
|
+
* reference and passes it to the redaction method.
|
|
1268
|
+
*
|
|
1269
|
+
* **Gotchas**
|
|
1270
|
+
*
|
|
1271
|
+
* If no fiber is active, an empty `Context` is passed to the redaction method.
|
|
1272
|
+
*
|
|
1273
|
+
* @see {@link redact} for the higher-level variant that handles non-redactable values
|
|
1274
|
+
* @see {@link isRedactable} for the type guard to verify before calling this
|
|
1275
|
+
* @stability stable
|
|
1276
|
+
* @category destructors
|
|
1277
|
+
* @since 4.0.0
|
|
1278
|
+
*/
|
|
1279
|
+
function getRedacted(redactable) {
|
|
1280
|
+
return redactable[symbolRedactable](globalThis["~effect/Fiber/currentFiber"]?.context ?? emptyContext);
|
|
1281
|
+
}
|
|
1282
|
+
const emptyMap = /*#__PURE__*/ new Map();
|
|
1283
|
+
const emptyContext = {
|
|
1284
|
+
"~effect/Context": {},
|
|
1285
|
+
base: emptyMap,
|
|
1286
|
+
depth: 0,
|
|
1287
|
+
mapUnsafe: emptyMap,
|
|
1288
|
+
pipe() {
|
|
1289
|
+
return pipeArguments(this, arguments);
|
|
1290
|
+
}
|
|
1291
|
+
};
|
|
1292
|
+
// node_modules/.pnpm/effect@4.1.2/node_modules/effect/dist/Formatter.js
|
|
1293
|
+
/**
|
|
1294
|
+
* Formats JavaScript values into readable strings.
|
|
1295
|
+
*
|
|
1296
|
+
* `format` is intended for logs, diagnostics, and error messages. It handles
|
|
1297
|
+
* primitives, objects, arrays, dates, regular expressions, maps, sets, class
|
|
1298
|
+
* instances, errors, circular references, and redactable values. `formatJson`
|
|
1299
|
+
* wraps JSON formatting with redaction and circular-reference handling, and the
|
|
1300
|
+
* module also includes helpers for property keys, paths, and dates.
|
|
1301
|
+
*
|
|
1302
|
+
* @stability stable
|
|
1303
|
+
* @since 4.0.0
|
|
1304
|
+
*/
|
|
1305
|
+
/**
|
|
1306
|
+
* Converts any JavaScript value into a human-readable string.
|
|
1307
|
+
*
|
|
1308
|
+
* **When to use**
|
|
1309
|
+
*
|
|
1310
|
+
* Use when you need to format arbitrary JavaScript values for debugging,
|
|
1311
|
+
* logging, or error messages.
|
|
1312
|
+
*
|
|
1313
|
+
* **Details**
|
|
1314
|
+
*
|
|
1315
|
+
* - Output is **not** valid JSON; use {@link formatJson} when you need
|
|
1316
|
+
* parseable JSON.
|
|
1317
|
+
* - Handles `BigInt`, `Symbol`, `Set`, `Map`, `Date`, `RegExp`, and class
|
|
1318
|
+
* instances that `JSON.stringify` cannot represent.
|
|
1319
|
+
* - Circular references are shown as `"[Circular]"` instead of throwing.
|
|
1320
|
+
* - Failures while inspecting a value are rendered as diagnostic placeholders instead of throwing.
|
|
1321
|
+
* - Primitives: stringified naturally (`null`, `undefined`, `123`, `true`).
|
|
1322
|
+
* Strings are JSON-quoted.
|
|
1323
|
+
* - Objects with a custom `toString` (not `Object.prototype.toString`):
|
|
1324
|
+
* `toString()` is called unless `ignoreToString` is `true`.
|
|
1325
|
+
* - Errors with a `cause`: formatted as `"<message> (cause: <cause>)"`.
|
|
1326
|
+
* - Iterables (`Set`, `Map`, etc.): formatted as
|
|
1327
|
+
* `ClassName([...elements])`.
|
|
1328
|
+
* - Class instances: wrapped as `ClassName({...})`.
|
|
1329
|
+
* - `Redactable` values are automatically redacted.
|
|
1330
|
+
* - Arrays/objects with 0–1 entries are inline; larger ones are
|
|
1331
|
+
* pretty-printed when `space` is set.
|
|
1332
|
+
* - `space` — indentation unit (number of spaces, or a string like
|
|
1333
|
+
* `"\t"`). Defaults to `0` (compact).
|
|
1334
|
+
* - `ignoreToString` — skip calling `toString()`. Defaults to `false`.
|
|
1335
|
+
*
|
|
1336
|
+
* **Example** (Formatting compact output)
|
|
1337
|
+
*
|
|
1338
|
+
* ```ts import.meta.vitest
|
|
1339
|
+
* import { Formatter } from "effect"
|
|
1340
|
+
*
|
|
1341
|
+
* Formatter.format({ a: 1, b: [2, 3] }) // => "{\"a\":1,\"b\":[2,3]}"
|
|
1342
|
+
* ```
|
|
1343
|
+
*
|
|
1344
|
+
* **Example** (Pretty-printed output)
|
|
1345
|
+
*
|
|
1346
|
+
* ```ts import.meta.vitest
|
|
1347
|
+
* import { Formatter } from "effect"
|
|
1348
|
+
*
|
|
1349
|
+
* const output = Formatter.format({ a: 1, b: [2, 3] }, { space: 2 })
|
|
1350
|
+
* output // => "{\n \"a\": 1,\n \"b\": [\n 2,\n 3\n ]\n}"
|
|
1351
|
+
* ```
|
|
1352
|
+
*
|
|
1353
|
+
* **Example** (Handling circular references)
|
|
1354
|
+
*
|
|
1355
|
+
* ```ts import.meta.vitest
|
|
1356
|
+
* import { Formatter } from "effect"
|
|
1357
|
+
*
|
|
1358
|
+
* const obj: any = { name: "loop" }
|
|
1359
|
+
* obj.self = obj
|
|
1360
|
+
* Formatter.format(obj) // => "{\"name\":\"loop\",\"self\":[Circular]}"
|
|
1361
|
+
* ```
|
|
1362
|
+
*
|
|
1363
|
+
* @see {@link formatJson}
|
|
1364
|
+
* @see {@link Formatter}
|
|
1365
|
+
* @stability stable
|
|
1366
|
+
* @category formatting
|
|
1367
|
+
* @since 2.0.0
|
|
1368
|
+
*/
|
|
1369
|
+
function format(input, options) {
|
|
1370
|
+
const space = options?.space ?? 0;
|
|
1371
|
+
const ancestors = /* @__PURE__ */ new WeakSet();
|
|
1372
|
+
const gap = !space ? "" : typeof space === "number" ? " ".repeat(space) : space;
|
|
1373
|
+
const ind = (d) => gap.repeat(d);
|
|
1374
|
+
const wrap = (v, body) => {
|
|
1375
|
+
const ctor = v?.constructor;
|
|
1376
|
+
return ctor && ctor !== Object.prototype.constructor && ctor.name ? `${ctor.name}(${body})` : body;
|
|
1377
|
+
};
|
|
1378
|
+
const ownKeys = (o) => {
|
|
1379
|
+
try {
|
|
1380
|
+
return Reflect.ownKeys(o);
|
|
1381
|
+
} catch {
|
|
1382
|
+
return ["[ownKeys threw]"];
|
|
1383
|
+
}
|
|
1384
|
+
};
|
|
1385
|
+
function recur(v, d = 0) {
|
|
1386
|
+
try {
|
|
1387
|
+
return recurUnsafe(v, d);
|
|
1388
|
+
} catch {
|
|
1389
|
+
if (typeof v === "object" && v !== null || typeof v === "function") ancestors.delete(v);
|
|
1390
|
+
return "[inspection threw]";
|
|
1391
|
+
}
|
|
1392
|
+
}
|
|
1393
|
+
function recurUnsafe(v, d = 0) {
|
|
1394
|
+
if (typeof v === "string") return JSON.stringify(v);
|
|
1395
|
+
if (typeof v === "number" || v == null || typeof v === "boolean" || typeof v === "symbol") return String(v);
|
|
1396
|
+
if (typeof v === "bigint") return String(v) + "n";
|
|
1397
|
+
if (typeof v === "object" || typeof v === "function") {
|
|
1398
|
+
if (ancestors.has(v)) return CIRCULAR;
|
|
1399
|
+
ancestors.add(v);
|
|
1400
|
+
let output;
|
|
1401
|
+
if (symbolRedactable in v) output = recur(getRedacted(v), d);
|
|
1402
|
+
else if (Array.isArray(v)) output = !gap || v.length <= 1 ? `[${v.map((x) => recur(x, d)).join(",")}]` : `[\n${ind(d + 1)}${v.map((x) => recur(x, d + 1)).join(",\n" + ind(d + 1))}\n${ind(d)}]`;
|
|
1403
|
+
else if (v instanceof Date) output = formatDate(v);
|
|
1404
|
+
else if (!options?.ignoreToString && hasProperty(v, "toString") && typeof v["toString"] === "function" && v["toString"] !== Object.prototype.toString && v["toString"] !== Array.prototype.toString) {
|
|
1405
|
+
const s = safeToString(v);
|
|
1406
|
+
output = v instanceof Error && v.cause !== void 0 ? `${s} (cause: ${recur(v.cause, d)})` : s;
|
|
1407
|
+
} else if (Symbol.iterator in v) output = `${v.constructor.name}(${recur(Array.from(v), d)})`;
|
|
1408
|
+
else {
|
|
1409
|
+
const keys = ownKeys(v);
|
|
1410
|
+
if (!gap || keys.length <= 1) {
|
|
1411
|
+
const body = `{${keys.map((k) => `${formatPropertyKey(k)}:${recur(safeGet(v, k), d)}`).join(",")}}`;
|
|
1412
|
+
output = wrap(v, body);
|
|
1413
|
+
} else {
|
|
1414
|
+
const body = `{\n${keys.map((k) => `${ind(d + 1)}${formatPropertyKey(k)}: ${recur(safeGet(v, k), d + 1)}`).join(",\n")}\n${ind(d)}}`;
|
|
1415
|
+
output = wrap(v, body);
|
|
1416
|
+
}
|
|
1417
|
+
}
|
|
1418
|
+
ancestors.delete(v);
|
|
1419
|
+
return output;
|
|
1420
|
+
}
|
|
1421
|
+
return String(v);
|
|
1422
|
+
}
|
|
1423
|
+
return recur(input, 0);
|
|
1424
|
+
}
|
|
1425
|
+
const CIRCULAR = "[Circular]";
|
|
1426
|
+
/**
|
|
1427
|
+
* @internal
|
|
1428
|
+
*/
|
|
1429
|
+
function formatPropertyKey(name) {
|
|
1430
|
+
return typeof name === "string" ? JSON.stringify(name) : String(name);
|
|
1431
|
+
}
|
|
1432
|
+
/**
|
|
1433
|
+
* Formats a `Date` as an ISO 8601 string, returning `"Invalid Date"` for
|
|
1434
|
+
* invalid dates instead of throwing.
|
|
1435
|
+
*
|
|
1436
|
+
* @internal
|
|
1437
|
+
*/
|
|
1438
|
+
function formatDate(date) {
|
|
1439
|
+
try {
|
|
1440
|
+
return date.toISOString();
|
|
1441
|
+
} catch {
|
|
1442
|
+
return "Invalid Date";
|
|
1443
|
+
}
|
|
1444
|
+
}
|
|
1445
|
+
function safeToString(input) {
|
|
1446
|
+
try {
|
|
1447
|
+
const s = input.toString();
|
|
1448
|
+
return typeof s === "string" ? s : String(s);
|
|
1449
|
+
} catch {
|
|
1450
|
+
return "[toString threw]";
|
|
1451
|
+
}
|
|
1452
|
+
}
|
|
1453
|
+
function safeGet(input, key) {
|
|
1454
|
+
try {
|
|
1455
|
+
return input[key];
|
|
1456
|
+
} catch {
|
|
1457
|
+
return "[property access threw]";
|
|
1458
|
+
}
|
|
1459
|
+
}
|
|
1460
|
+
// node_modules/.pnpm/effect@4.1.2/node_modules/effect/dist/Inspectable.js
|
|
1461
|
+
/**
|
|
1462
|
+
* Defines the symbol used by Node.js for custom object inspection.
|
|
1463
|
+
*
|
|
1464
|
+
* **When to use**
|
|
1465
|
+
*
|
|
1466
|
+
* Use to implement Node.js custom inspection for a value.
|
|
1467
|
+
*
|
|
1468
|
+
* **Details**
|
|
1469
|
+
*
|
|
1470
|
+
* This symbol is recognized by Node.js's `util.inspect()` function and the REPL
|
|
1471
|
+
* for custom object representation. When an object has a method with this symbol,
|
|
1472
|
+
* it will be called to determine how the object should be displayed.
|
|
1473
|
+
*
|
|
1474
|
+
* **Example** (Defining custom Node inspection)
|
|
1475
|
+
*
|
|
1476
|
+
* ```ts import.meta.vitest
|
|
1477
|
+
* import { Inspectable } from "effect"
|
|
1478
|
+
*
|
|
1479
|
+
* class CustomObject {
|
|
1480
|
+
* constructor(private value: string) {}
|
|
1481
|
+
*
|
|
1482
|
+
* [Inspectable.NodeInspectSymbol]() {
|
|
1483
|
+
* return `CustomObject(${this.value})`
|
|
1484
|
+
* }
|
|
1485
|
+
* }
|
|
1486
|
+
*
|
|
1487
|
+
* const obj = new CustomObject("hello")
|
|
1488
|
+
* obj[Inspectable.NodeInspectSymbol]() // => "CustomObject(hello)"
|
|
1489
|
+
* ```
|
|
1490
|
+
*
|
|
1491
|
+
* @stability stable
|
|
1492
|
+
* @category symbols
|
|
1493
|
+
* @since 2.0.0
|
|
1494
|
+
*/
|
|
1495
|
+
const NodeInspectSymbol = /*#__PURE__*/ Symbol.for("nodejs.util.inspect.custom");
|
|
1496
|
+
/**
|
|
1497
|
+
* Converts a value to its structured inspection representation.
|
|
1498
|
+
*
|
|
1499
|
+
* **When to use**
|
|
1500
|
+
*
|
|
1501
|
+
* Use when you need the structured representation of an inspectable value
|
|
1502
|
+
* without risking unhandled errors.
|
|
1503
|
+
*
|
|
1504
|
+
* **Details**
|
|
1505
|
+
*
|
|
1506
|
+
* This function applies redaction before extracting data from objects that
|
|
1507
|
+
* implement `toJSON`, recursively processes arrays, and handles errors
|
|
1508
|
+
* gracefully. Plain objects are returned unchanged, so the result is not
|
|
1509
|
+
* guaranteed to be accepted by `JSON.stringify`; it may still contain values
|
|
1510
|
+
* such as `BigInt`, functions, or circular references.
|
|
1511
|
+
*
|
|
1512
|
+
* @see {@link toStringUnknown} for converting unknown values to strings
|
|
1513
|
+
*
|
|
1514
|
+
* @stability stable
|
|
1515
|
+
* @category converting
|
|
1516
|
+
* @since 4.0.0
|
|
1517
|
+
*/
|
|
1518
|
+
const toJson = (input) => {
|
|
1519
|
+
try {
|
|
1520
|
+
input = redact(input);
|
|
1521
|
+
if (hasProperty(input, "toJSON") && isFunction(input["toJSON"]) && input["toJSON"].length === 0) return input.toJSON();
|
|
1522
|
+
else if (Array.isArray(input)) return input.map(toJson);
|
|
1523
|
+
return input;
|
|
1524
|
+
} catch {
|
|
1525
|
+
return "[toJSON threw]";
|
|
1526
|
+
}
|
|
1527
|
+
};
|
|
1528
|
+
// node_modules/.pnpm/effect@4.1.2/node_modules/effect/dist/Utils.js
|
|
1529
|
+
/**
|
|
1530
|
+
* Yields its wrapped value exactly once, then completes with the value sent
|
|
1531
|
+
* back in.
|
|
1532
|
+
*
|
|
1533
|
+
* **When to use**
|
|
1534
|
+
*
|
|
1535
|
+
* Use to implement `[Symbol.iterator]()` on Effect-like types so they can be
|
|
1536
|
+
* `yield*`-ed inside generator functions, such as `Effect.gen` and
|
|
1537
|
+
* `Option.gen`.
|
|
1538
|
+
*
|
|
1539
|
+
* **Details**
|
|
1540
|
+
*
|
|
1541
|
+
* The first call to `next()` returns a fresh `{ value: self, done: false }`.
|
|
1542
|
+
* Every subsequent call returns `{ value: a, done: true }` where `a` is the
|
|
1543
|
+
* argument passed to `next()`. To keep `yield*` cheap, the completion result
|
|
1544
|
+
* is the iterator itself rather than a new object, so only the iterator and
|
|
1545
|
+
* the single yielded result are allocated per `yield*`.
|
|
1546
|
+
*
|
|
1547
|
+
* **Example** (Yielding a wrapped value in a generator)
|
|
1548
|
+
*
|
|
1549
|
+
* ```ts import.meta.vitest
|
|
1550
|
+
* import { Utils } from "effect"
|
|
1551
|
+
*
|
|
1552
|
+
* const gen = new Utils.SingleShotGen<string, number>("hello")
|
|
1553
|
+
*
|
|
1554
|
+
* gen.next(0).value // => "hello"
|
|
1555
|
+
*
|
|
1556
|
+
* gen.next(42).value // => 42
|
|
1557
|
+
* ```
|
|
1558
|
+
*
|
|
1559
|
+
* @see {@link Gen} for the type-level signature that relies on `SingleShotGen`
|
|
1560
|
+
* @stability stable
|
|
1561
|
+
* @category constructors
|
|
1562
|
+
* @since 2.0.0
|
|
1563
|
+
*/
|
|
1564
|
+
var SingleShotGen = class {
|
|
1565
|
+
constructor(self) {
|
|
1566
|
+
this.value = self;
|
|
1567
|
+
this.done = false;
|
|
1568
|
+
}
|
|
1569
|
+
/**
|
|
1570
|
+
* Yields the stored value once, then completes with the value sent back in.
|
|
1571
|
+
*
|
|
1572
|
+
* **When to use**
|
|
1573
|
+
*
|
|
1574
|
+
* Use to advance a `SingleShotGen` through its single yield and completion
|
|
1575
|
+
* step.
|
|
1576
|
+
*
|
|
1577
|
+
* @since 2.0.0
|
|
1578
|
+
*/
|
|
1579
|
+
next(a) {
|
|
1580
|
+
if (this.done) {
|
|
1581
|
+
this.value = a;
|
|
1582
|
+
return this;
|
|
1583
|
+
}
|
|
1584
|
+
this.done = true;
|
|
1585
|
+
return {
|
|
1586
|
+
value: this.value,
|
|
1587
|
+
done: false
|
|
1588
|
+
};
|
|
1589
|
+
}
|
|
1590
|
+
};
|
|
1591
|
+
// node_modules/.pnpm/effect@4.1.2/node_modules/effect/dist/internal/core.js
|
|
1592
|
+
/** @internal */
|
|
1593
|
+
const EffectTypeId = `~effect/Effect`;
|
|
1594
|
+
`${EffectTypeId}`;
|
|
1595
|
+
`${EffectTypeId}`;
|
|
1596
|
+
/** @internal */
|
|
1597
|
+
const PipeInspectableProto = {
|
|
1598
|
+
pipe() {
|
|
1599
|
+
return pipeArguments(this, arguments);
|
|
1600
|
+
},
|
|
1601
|
+
toJSON() {
|
|
1602
|
+
return { ...this };
|
|
1603
|
+
},
|
|
1604
|
+
toString() {
|
|
1605
|
+
return format(this.toJSON(), {
|
|
1606
|
+
ignoreToString: true,
|
|
1607
|
+
space: 2
|
|
1608
|
+
});
|
|
1609
|
+
},
|
|
1610
|
+
[NodeInspectSymbol]() {
|
|
1611
|
+
return this.toJSON();
|
|
1612
|
+
}
|
|
1613
|
+
};
|
|
1614
|
+
({ ...PipeInspectableProto });
|
|
1615
|
+
// node_modules/.pnpm/effect@4.1.2/node_modules/effect/dist/internal/option.js
|
|
1616
|
+
/**
|
|
1617
|
+
* @since 2.0.0
|
|
1618
|
+
*/
|
|
1619
|
+
const TypeId = "~effect/Option";
|
|
1620
|
+
const CommonProto = {
|
|
1621
|
+
[TypeId]: { _A: (_) => _ },
|
|
1622
|
+
...PipeInspectableProto,
|
|
1623
|
+
[Symbol.iterator]() {
|
|
1624
|
+
return new SingleShotGen(this);
|
|
1625
|
+
}
|
|
1626
|
+
};
|
|
1627
|
+
const SomeProto = /*#__PURE__*/ Object.defineProperty(/*#__PURE__*/ Object.assign(/*#__PURE__*/ Object.create(CommonProto), {
|
|
1628
|
+
_tag: "Some",
|
|
1629
|
+
_op: "Some",
|
|
1630
|
+
[symbol](that) {
|
|
1631
|
+
return isOption(that) && isSome$1(that) && equals(this.value, that.value);
|
|
1632
|
+
},
|
|
1633
|
+
[symbol$1]() {
|
|
1634
|
+
return combine(hash(this._tag))(hash(this.value));
|
|
1635
|
+
},
|
|
1636
|
+
toString() {
|
|
1637
|
+
return `some(${format(this.value)})`;
|
|
1638
|
+
},
|
|
1639
|
+
toJSON() {
|
|
1640
|
+
return {
|
|
1641
|
+
_id: "Option",
|
|
1642
|
+
_tag: this._tag,
|
|
1643
|
+
value: toJson(this.value)
|
|
1644
|
+
};
|
|
1645
|
+
}
|
|
1646
|
+
}), "valueOrUndefined", { get() {
|
|
1647
|
+
return this.value;
|
|
1648
|
+
} });
|
|
1649
|
+
const NoneHash = /*#__PURE__*/ hash("None");
|
|
1650
|
+
const NoneProto = /*#__PURE__*/ Object.assign(/*#__PURE__*/ Object.create(CommonProto), {
|
|
1651
|
+
_tag: "None",
|
|
1652
|
+
_op: "None",
|
|
1653
|
+
valueOrUndefined: void 0,
|
|
1654
|
+
[symbol](that) {
|
|
1655
|
+
return isOption(that) && isNone$1(that);
|
|
1656
|
+
},
|
|
1657
|
+
[symbol$1]() {
|
|
1658
|
+
return NoneHash;
|
|
1659
|
+
},
|
|
1660
|
+
toString() {
|
|
1661
|
+
return `none()`;
|
|
1662
|
+
},
|
|
1663
|
+
toJSON() {
|
|
1664
|
+
return {
|
|
1665
|
+
_id: "Option",
|
|
1666
|
+
_tag: this._tag
|
|
1667
|
+
};
|
|
1668
|
+
}
|
|
1669
|
+
});
|
|
1670
|
+
/** @internal */
|
|
1671
|
+
const isOption = (input) => hasProperty(input, TypeId);
|
|
1672
|
+
/** @internal */
|
|
1673
|
+
const isNone$1 = (fa) => fa._tag === "None";
|
|
1674
|
+
/** @internal */
|
|
1675
|
+
const isSome$1 = (fa) => fa._tag === "Some";
|
|
1676
|
+
/** @internal */
|
|
1677
|
+
const none$1 = /*#__PURE__*/ Object.create(NoneProto);
|
|
1678
|
+
/** @internal */
|
|
1679
|
+
const SomeImpl = function(value) {
|
|
1680
|
+
this.value = value;
|
|
1681
|
+
};
|
|
1682
|
+
SomeImpl.prototype = SomeProto;
|
|
1683
|
+
/** @internal */
|
|
1684
|
+
const some$1 = (value) => new SomeImpl(value);
|
|
1685
|
+
// node_modules/.pnpm/effect@4.1.2/node_modules/effect/dist/Option.js
|
|
1686
|
+
/**
|
|
1687
|
+
* Creates an `Option` representing the absence of a value.
|
|
1688
|
+
*
|
|
1689
|
+
* **When to use**
|
|
1690
|
+
*
|
|
1691
|
+
* Use to represent a missing or uninitialized value, such as returning "no
|
|
1692
|
+
* result" from a function.
|
|
1693
|
+
*
|
|
1694
|
+
* **Details**
|
|
1695
|
+
*
|
|
1696
|
+
* - Returns `Option<never>`, which is a subtype of `Option<A>` for any `A`
|
|
1697
|
+
* - Always returns the same singleton instance
|
|
1698
|
+
*
|
|
1699
|
+
* **Example** (Creating an empty Option)
|
|
1700
|
+
*
|
|
1701
|
+
* ```ts import.meta.vitest
|
|
1702
|
+
* import { Option } from "effect"
|
|
1703
|
+
*
|
|
1704
|
+
* // ┌─── Option<never>
|
|
1705
|
+
* // ▼
|
|
1706
|
+
* const noValue = Option.none() // => Option.none()
|
|
1707
|
+
* ```
|
|
1708
|
+
*
|
|
1709
|
+
* @see {@link some} for the opposite operation.
|
|
1710
|
+
*
|
|
1711
|
+
* @stability stable
|
|
1712
|
+
* @category constructors
|
|
1713
|
+
* @since 2.0.0
|
|
1714
|
+
*/
|
|
1715
|
+
const none = () => none$1;
|
|
1716
|
+
/**
|
|
1717
|
+
* Wraps the given value into an `Option` to represent its presence.
|
|
1718
|
+
*
|
|
1719
|
+
* **When to use**
|
|
1720
|
+
*
|
|
1721
|
+
* Use to wrap a known present value as `Option`
|
|
1722
|
+
* - Returning a successful result from a partial function
|
|
1723
|
+
*
|
|
1724
|
+
* **Details**
|
|
1725
|
+
*
|
|
1726
|
+
* - Always returns `Some<A>`
|
|
1727
|
+
* - Does not filter `null` or `undefined`; use {@link fromNullishOr} for that
|
|
1728
|
+
*
|
|
1729
|
+
* **Example** (Wrapping a value)
|
|
1730
|
+
*
|
|
1731
|
+
* ```ts import.meta.vitest
|
|
1732
|
+
* import { Option } from "effect"
|
|
1733
|
+
*
|
|
1734
|
+
* // ┌─── Option<number>
|
|
1735
|
+
* // ▼
|
|
1736
|
+
* const value = Option.some(1) // => Option.some(1)
|
|
1737
|
+
* ```
|
|
1738
|
+
*
|
|
1739
|
+
* @see {@link none} for the opposite operation.
|
|
1740
|
+
*
|
|
1741
|
+
* @stability stable
|
|
1742
|
+
* @category constructors
|
|
1743
|
+
* @since 2.0.0
|
|
1744
|
+
*/
|
|
1745
|
+
const some = some$1;
|
|
1746
|
+
/**
|
|
1747
|
+
* Checks whether an `Option` is `None` (absent).
|
|
1748
|
+
*
|
|
1749
|
+
* **When to use**
|
|
1750
|
+
*
|
|
1751
|
+
* Use when you need to branch on an absent `Option` before accessing `.value`.
|
|
1752
|
+
*
|
|
1753
|
+
* **Details**
|
|
1754
|
+
*
|
|
1755
|
+
* - Acts as a type guard, narrowing to `None<A>`
|
|
1756
|
+
*
|
|
1757
|
+
* **Example** (Checking for None)
|
|
1758
|
+
*
|
|
1759
|
+
* ```ts import.meta.vitest
|
|
1760
|
+
* import { Option } from "effect"
|
|
1761
|
+
*
|
|
1762
|
+
* Option.isNone(Option.some(1)) // => false
|
|
1763
|
+
* Option.isNone(Option.none()) // => true
|
|
1764
|
+
* ```
|
|
1765
|
+
*
|
|
1766
|
+
* @see {@link isSome} for the opposite check.
|
|
1767
|
+
*
|
|
1768
|
+
* @stability stable
|
|
1769
|
+
* @category guards
|
|
1770
|
+
* @since 2.0.0
|
|
1771
|
+
*/
|
|
1772
|
+
const isNone = isNone$1;
|
|
1773
|
+
/**
|
|
1774
|
+
* Checks whether an `Option` contains a value (`Some`).
|
|
1775
|
+
*
|
|
1776
|
+
* **When to use**
|
|
1777
|
+
*
|
|
1778
|
+
* Use when you need to branch on a present `Option` before accessing `.value`.
|
|
1779
|
+
*
|
|
1780
|
+
* **Details**
|
|
1781
|
+
*
|
|
1782
|
+
* - Acts as a type guard, narrowing to `Some<A>`
|
|
1783
|
+
*
|
|
1784
|
+
* **Example** (Checking for Some)
|
|
1785
|
+
*
|
|
1786
|
+
* ```ts import.meta.vitest
|
|
1787
|
+
* import { Option } from "effect"
|
|
1788
|
+
*
|
|
1789
|
+
* Option.isSome(Option.some(1)) // => true
|
|
1790
|
+
* Option.isSome(Option.none()) // => false
|
|
1791
|
+
* ```
|
|
1792
|
+
*
|
|
1793
|
+
* @see {@link isNone} for the opposite check.
|
|
1794
|
+
*
|
|
1795
|
+
* @stability stable
|
|
1796
|
+
* @category guards
|
|
1797
|
+
* @since 2.0.0
|
|
1798
|
+
*/
|
|
1799
|
+
const isSome = isSome$1;
|
|
1800
|
+
/**
|
|
1801
|
+
* Pattern-matches on an `Option`, handling both `None` and `Some` cases.
|
|
1802
|
+
*
|
|
1803
|
+
* **When to use**
|
|
1804
|
+
*
|
|
1805
|
+
* Use when you need to handle both `Some` and `None` in one expression and
|
|
1806
|
+
* transform an `Option` into a plain value.
|
|
1807
|
+
*
|
|
1808
|
+
* **Details**
|
|
1809
|
+
*
|
|
1810
|
+
* - If `None`, calls `onNone` and returns its result
|
|
1811
|
+
* - If `Some`, calls `onSome` with the value and returns its result
|
|
1812
|
+
* - Supports the `dual` API (data-last and data-first)
|
|
1813
|
+
*
|
|
1814
|
+
* **Example** (Matching on an Option)
|
|
1815
|
+
*
|
|
1816
|
+
* ```ts import.meta.vitest
|
|
1817
|
+
* import { Option } from "effect"
|
|
1818
|
+
*
|
|
1819
|
+
* Option.match(Option.some(1), {
|
|
1820
|
+
* onNone: () => "Option is empty",
|
|
1821
|
+
* onSome: (value) => `Option has a value: ${value}`
|
|
1822
|
+
* }) // => "Option has a value: 1"
|
|
1823
|
+
* ```
|
|
1824
|
+
*
|
|
1825
|
+
* @see {@link getOrElse} for unwrapping with a default
|
|
1826
|
+
*
|
|
1827
|
+
* @stability stable
|
|
1828
|
+
* @category pattern matching
|
|
1829
|
+
* @since 2.0.0
|
|
1830
|
+
*/
|
|
1831
|
+
const match = /*#__PURE__*/ dual(2, (self, { onNone, onSome }) => isNone(self) ? onNone() : onSome(self.value));
|
|
1832
|
+
/**
|
|
1833
|
+
* Transforms the value inside a `Some` using the provided function, leaving
|
|
1834
|
+
* `None` unchanged.
|
|
1835
|
+
*
|
|
1836
|
+
* **When to use**
|
|
1837
|
+
*
|
|
1838
|
+
* Use to apply a pure transformation to an `Option`'s present value, especially
|
|
1839
|
+
* when chaining transformations in a pipeline.
|
|
1840
|
+
*
|
|
1841
|
+
* **Details**
|
|
1842
|
+
*
|
|
1843
|
+
* - `Some` → applies `f` and wraps the result in a new `Some`
|
|
1844
|
+
* - `None` → returns `None` unchanged
|
|
1845
|
+
*
|
|
1846
|
+
* **Example** (Mapping over an Option)
|
|
1847
|
+
*
|
|
1848
|
+
* ```ts import.meta.vitest
|
|
1849
|
+
* import { Option } from "effect"
|
|
1850
|
+
*
|
|
1851
|
+
* Option.map(Option.some(2), (n) => n * 2) // => Option.some(4)
|
|
1852
|
+
* Option.map(Option.none(), (n: number) => n * 2) // => Option.none()
|
|
1853
|
+
* ```
|
|
1854
|
+
*
|
|
1855
|
+
* @see {@link flatMap} when `f` returns an `Option`
|
|
1856
|
+
* @see {@link as} to replace the value with a constant
|
|
1857
|
+
*
|
|
1858
|
+
* @stability stable
|
|
1859
|
+
* @category mapping
|
|
1860
|
+
* @since 2.0.0
|
|
1861
|
+
*/
|
|
1862
|
+
const map = /*#__PURE__*/ dual(2, (self, f) => isNone(self) ? none() : some(f(self.value)));
|
|
1863
|
+
/**
|
|
1864
|
+
* Applies a function that returns an `Option` to the value of a `Some`,
|
|
1865
|
+
* flattening the result. Returns `None` if the input is `None`.
|
|
1866
|
+
*
|
|
1867
|
+
* **When to use**
|
|
1868
|
+
*
|
|
1869
|
+
* Use when you need to chain dependent `Option` computations where each step
|
|
1870
|
+
* may return `None`.
|
|
1871
|
+
*
|
|
1872
|
+
* **Details**
|
|
1873
|
+
*
|
|
1874
|
+
* - `Some` → applies `f` to the value and returns its `Option` result
|
|
1875
|
+
* - `None` → returns `None` without calling `f`
|
|
1876
|
+
* - Equivalent to `map` followed by {@link flatten}
|
|
1877
|
+
*
|
|
1878
|
+
* **Example** (Chaining optional lookups)
|
|
1879
|
+
*
|
|
1880
|
+
* ```ts import.meta.vitest
|
|
1881
|
+
* import { Option } from "effect"
|
|
1882
|
+
*
|
|
1883
|
+
* interface User {
|
|
1884
|
+
* readonly name: string
|
|
1885
|
+
* readonly address: Option.Option<{ readonly street: Option.Option<string> }>
|
|
1886
|
+
* }
|
|
1887
|
+
*
|
|
1888
|
+
* const user: User = {
|
|
1889
|
+
* name: "John",
|
|
1890
|
+
* address: Option.some({ street: Option.some("123 Main St") })
|
|
1891
|
+
* }
|
|
1892
|
+
*
|
|
1893
|
+
* user.address.pipe(
|
|
1894
|
+
* Option.flatMap((addr) => addr.street)
|
|
1895
|
+
* ) // => Option.some("123 Main St")
|
|
1896
|
+
* ```
|
|
1897
|
+
*
|
|
1898
|
+
* @see {@link map} when `f` returns a plain value
|
|
1899
|
+
* @see {@link andThen} for a more flexible variant
|
|
1900
|
+
* @see {@link flatten} to unwrap a nested `Option<Option<A>>`
|
|
1901
|
+
*
|
|
1902
|
+
* @stability stable
|
|
1903
|
+
* @category sequencing
|
|
1904
|
+
* @since 2.0.0
|
|
1905
|
+
*/
|
|
1906
|
+
const flatMap = /*#__PURE__*/ dual(2, (self, f) => isNone(self) ? none() : f(self.value));
|
|
1907
|
+
/**
|
|
1908
|
+
* Filters an `Option` using a predicate. Returns `None` if the predicate is
|
|
1909
|
+
* not satisfied or the input is `None`.
|
|
1910
|
+
*
|
|
1911
|
+
* **When to use**
|
|
1912
|
+
*
|
|
1913
|
+
* Use when you need to discard an `Option`'s present value when it does not
|
|
1914
|
+
* meet a condition, while narrowing the type via a refinement predicate.
|
|
1915
|
+
*
|
|
1916
|
+
* **Details**
|
|
1917
|
+
*
|
|
1918
|
+
* - `None` → `None`
|
|
1919
|
+
* - `Some` where `predicate(value)` is `true` → `Some(value)`
|
|
1920
|
+
* - `Some` where `predicate(value)` is `false` → `None`
|
|
1921
|
+
* - Supports refinements for type narrowing
|
|
1922
|
+
*
|
|
1923
|
+
* **Example** (Filtering with a predicate)
|
|
1924
|
+
*
|
|
1925
|
+
* ```ts import.meta.vitest
|
|
1926
|
+
* import { Option } from "effect"
|
|
1927
|
+
*
|
|
1928
|
+
* const removeEmpty = (input: Option.Option<string>) =>
|
|
1929
|
+
* Option.filter(input, (value) => value !== "")
|
|
1930
|
+
*
|
|
1931
|
+
* removeEmpty(Option.some("hello")) // => Option.some("hello")
|
|
1932
|
+
* removeEmpty(Option.some("")) // => Option.none()
|
|
1933
|
+
* removeEmpty(Option.none()) // => Option.none()
|
|
1934
|
+
* ```
|
|
1935
|
+
*
|
|
1936
|
+
* @see {@link filterMap} to transform and filter simultaneously
|
|
1937
|
+
* @see {@link exists} to test without filtering
|
|
1938
|
+
*
|
|
1939
|
+
* @stability stable
|
|
1940
|
+
* @category filtering
|
|
1941
|
+
* @since 2.0.0
|
|
1942
|
+
*/
|
|
1943
|
+
const filter = /*#__PURE__*/ dual(2, (self, predicate) => isNone(self) ? none() : predicate(self.value) ? some(self.value) : none());
|
|
1944
|
+
/**
|
|
1945
|
+
* Checks whether the value in a `Some` satisfies a predicate or refinement.
|
|
1946
|
+
*
|
|
1947
|
+
* **When to use**
|
|
1948
|
+
*
|
|
1949
|
+
* Use to check a condition on an optional value without unwrapping
|
|
1950
|
+
*
|
|
1951
|
+
* **Details**
|
|
1952
|
+
*
|
|
1953
|
+
* - `None` → `false`
|
|
1954
|
+
* - `Some` where `predicate(value)` is `true` → `true`
|
|
1955
|
+
* - `Some` where `predicate(value)` is `false` → `false`
|
|
1956
|
+
* - With a refinement, narrows the `Option` type on `true`
|
|
1957
|
+
*
|
|
1958
|
+
* **Example** (Testing a condition)
|
|
1959
|
+
*
|
|
1960
|
+
* ```ts import.meta.vitest
|
|
1961
|
+
* import { Option } from "effect"
|
|
1962
|
+
*
|
|
1963
|
+
* const isEven = (n: number) => n % 2 === 0
|
|
1964
|
+
*
|
|
1965
|
+
* Option.some(2).pipe(Option.exists(isEven)) // => true
|
|
1966
|
+
* Option.some(1).pipe(Option.exists(isEven)) // => false
|
|
1967
|
+
* Option.none().pipe(Option.exists(isEven)) // => false
|
|
1968
|
+
* ```
|
|
1969
|
+
*
|
|
1970
|
+
* @see {@link filter} to keep or discard based on a predicate
|
|
1971
|
+
* @see {@link contains} to test for a specific value
|
|
1972
|
+
*
|
|
1973
|
+
* @stability stable
|
|
1974
|
+
* @category predicates
|
|
1975
|
+
* @since 2.0.0
|
|
1976
|
+
*/
|
|
1977
|
+
const exists = /*#__PURE__*/ dual(2, (self, refinement) => isNone(self) ? false : refinement(self.value));
|
|
1978
|
+
// src/utils.ts
|
|
1979
|
+
const asAstNode = (node) => typeof node === "object" && node !== null && "type" in node && typeof node.type === "string" ? some(node) : none();
|
|
1980
|
+
const isExpressionWrapper = (node) => node.type === "ChainExpression" || node.type === "ParenthesizedExpression" || node.type === "TSNonNullExpression" || node.type === "TSAsExpression" || node.type === "TSTypeAssertion";
|
|
1981
|
+
function unwrapExpression(node) {
|
|
1982
|
+
let current = asAstNode(node);
|
|
1983
|
+
while (isSome(current) && isExpressionWrapper(current.value)) current = asAstNode(current.value.expression);
|
|
1984
|
+
return current;
|
|
1985
|
+
}
|
|
1986
|
+
function getPropertyName(node) {
|
|
1987
|
+
return flatMap(asAstNode(node), (expression) => {
|
|
1988
|
+
if (expression.type === "Identifier" && typeof expression.name === "string") return some(expression.name);
|
|
1989
|
+
if (expression.type === "PrivateIdentifier" && typeof expression.name === "string") return some(expression.name);
|
|
1990
|
+
if (expression.type === "Literal" && typeof expression.value === "string") return some(expression.value);
|
|
1991
|
+
return none();
|
|
1992
|
+
});
|
|
1993
|
+
}
|
|
1994
|
+
function isIdentifier(node, name) {
|
|
1995
|
+
if (isNone(node)) return false;
|
|
1996
|
+
const expression = node.value;
|
|
1997
|
+
return expression.type === "Identifier" && typeof expression.name === "string" && (name === void 0 || expression.name === name);
|
|
1998
|
+
}
|
|
1999
|
+
// src/rules/no-inline-schema-compile.ts
|
|
2000
|
+
const COMPILER_METHODS = /* @__PURE__ */ new Set([
|
|
2001
|
+
"is",
|
|
2002
|
+
"asserts",
|
|
2003
|
+
"decodeEffect",
|
|
2004
|
+
"decodeExit",
|
|
2005
|
+
"decodeOption",
|
|
2006
|
+
"decodePromise",
|
|
2007
|
+
"decodeResult",
|
|
2008
|
+
"decodeSync",
|
|
2009
|
+
"decodeUnknownExit",
|
|
2010
|
+
"decodeUnknownEffect",
|
|
2011
|
+
"decodeUnknownOption",
|
|
2012
|
+
"decodeUnknownPromise",
|
|
2013
|
+
"decodeUnknownResult",
|
|
2014
|
+
"decodeUnknownSync",
|
|
2015
|
+
"encodeExit",
|
|
2016
|
+
"encodeEffect",
|
|
2017
|
+
"encodeOption",
|
|
2018
|
+
"encodePromise",
|
|
2019
|
+
"encodeResult",
|
|
2020
|
+
"encodeSync",
|
|
2021
|
+
"encodeUnknownExit",
|
|
2022
|
+
"encodeUnknownEffect",
|
|
2023
|
+
"encodeUnknownOption",
|
|
2024
|
+
"encodeUnknownPromise",
|
|
2025
|
+
"encodeUnknownResult",
|
|
2026
|
+
"encodeUnknownSync"
|
|
2027
|
+
]);
|
|
2028
|
+
const getSchemaCompilerMethod = (callee) => {
|
|
2029
|
+
const expression = unwrapExpression(callee);
|
|
2030
|
+
if (isNone(expression) || expression.value.type !== "MemberExpression") return none();
|
|
2031
|
+
if (!isIdentifier(unwrapExpression(expression.value.object), "Schema")) return none();
|
|
2032
|
+
return filter(getPropertyName(expression.value.property), (method) => COMPILER_METHODS.has(method));
|
|
2033
|
+
};
|
|
2034
|
+
const isStaticSchemaReference = (node) => {
|
|
2035
|
+
const expression = unwrapExpression(node);
|
|
2036
|
+
if (isNone(expression)) return false;
|
|
2037
|
+
if (expression.value.type === "Identifier") {
|
|
2038
|
+
const [firstChar] = expression.value.name;
|
|
2039
|
+
return firstChar !== void 0 && firstChar.toUpperCase() === firstChar;
|
|
2040
|
+
}
|
|
2041
|
+
return expression.value.type === "MemberExpression";
|
|
2042
|
+
};
|
|
2043
|
+
const isNestedStaticSchemaCall = (node) => {
|
|
2044
|
+
const expression = unwrapExpression(node);
|
|
2045
|
+
if (isNone(expression) || expression.value.type !== "CallExpression") return false;
|
|
2046
|
+
const callee = unwrapExpression(expression.value.callee);
|
|
2047
|
+
if (isNone(callee) || callee.value.type !== "MemberExpression") return false;
|
|
2048
|
+
if (!isIdentifier(unwrapExpression(callee.value.object), "Schema")) return false;
|
|
2049
|
+
const method = getPropertyName(callee.value.property);
|
|
2050
|
+
if (isSome(method) && method.value === "fromJsonString") {
|
|
2051
|
+
const firstArg = expression.value.arguments[0];
|
|
2052
|
+
return isStaticSchemaReference(firstArg) || isNestedStaticSchemaCall(firstArg);
|
|
2053
|
+
}
|
|
2054
|
+
return true;
|
|
2055
|
+
};
|
|
2056
|
+
const isImmediatelyInvoked = (node) => {
|
|
2057
|
+
const expression = unwrapExpression(node);
|
|
2058
|
+
if (isNone(expression)) return false;
|
|
2059
|
+
const parent = "parent" in expression.value ? unwrapExpression(expression.value.parent) : none();
|
|
2060
|
+
return isSome(parent) && parent.value.type === "CallExpression" && unwrapExpression(parent.value.callee).pipe(exists((callee) => callee === expression.value));
|
|
2061
|
+
};
|
|
2062
|
+
const messageHigh = (method) => `Hoist Schema.${method}(...) to module scope: both the inline schema literal and the compiled function are rebuilt on every call. Move the compiled function to a module-level const.`;
|
|
2063
|
+
const messageMedium = (method) => `Hoist Schema.${method}(...) to module scope: the compiled function is rebuilt on every call. Move it to a module-level const.`;
|
|
2064
|
+
var no_inline_schema_compile_default = defineRule({
|
|
2065
|
+
meta: {
|
|
2066
|
+
type: "problem",
|
|
2067
|
+
docs: { description: "Disallow Schema decoder/encoder compiler calls inside function bodies; hoist them to module scope." }
|
|
2068
|
+
},
|
|
2069
|
+
createOnce(context) {
|
|
2070
|
+
let functionDepth = 0;
|
|
2071
|
+
const resetFunctionDepth = () => {
|
|
2072
|
+
functionDepth = 0;
|
|
2073
|
+
};
|
|
2074
|
+
const enterFunction = () => {
|
|
2075
|
+
functionDepth++;
|
|
2076
|
+
};
|
|
2077
|
+
const exitFunction = () => {
|
|
2078
|
+
functionDepth--;
|
|
2079
|
+
};
|
|
2080
|
+
return {
|
|
2081
|
+
before: resetFunctionDepth,
|
|
2082
|
+
FunctionDeclaration: enterFunction,
|
|
2083
|
+
"FunctionDeclaration:exit": exitFunction,
|
|
2084
|
+
FunctionExpression: enterFunction,
|
|
2085
|
+
"FunctionExpression:exit": exitFunction,
|
|
2086
|
+
ArrowFunctionExpression: enterFunction,
|
|
2087
|
+
"ArrowFunctionExpression:exit": exitFunction,
|
|
2088
|
+
CallExpression(node) {
|
|
2089
|
+
if (functionDepth === 0) return;
|
|
2090
|
+
const method = getSchemaCompilerMethod(node.callee);
|
|
2091
|
+
if (isNone(method)) return;
|
|
2092
|
+
if (!isImmediatelyInvoked(node)) return;
|
|
2093
|
+
const firstArg = node.arguments[0];
|
|
2094
|
+
const high = firstArg && isNestedStaticSchemaCall(firstArg);
|
|
2095
|
+
if (!high && !isStaticSchemaReference(firstArg)) return;
|
|
2096
|
+
context.report({
|
|
2097
|
+
node: node.callee,
|
|
2098
|
+
message: high ? messageHigh(method.value) : messageMedium(method.value)
|
|
2099
|
+
});
|
|
2100
|
+
}
|
|
2101
|
+
};
|
|
2102
|
+
}
|
|
2103
|
+
});
|
|
2104
|
+
// src/rules/no-low-value-comments.ts
|
|
2105
|
+
const TS_FILE_PATTERN = /\.[cm]?tsx?$/u;
|
|
2106
|
+
const DIRECTIVE_PATTERN$1 = /^\s*(?:(?:oxlint|eslint)-|@ts-|@effect-diagnostics|prettier-ignore|biome-ignore|c8 |istanbul |#(?:end)?region)/u;
|
|
2107
|
+
const DIVIDER_LINE_PATTERN = /^(?:[-=*#~_/+]{3,}.*|.*[-=*#~_]{3,})$/u;
|
|
2108
|
+
const TEST_STEP_PATTERN = /^(?:arrange|act|assert|given|when|then)\s*[:.]?$/iu;
|
|
2109
|
+
const TASK_MARKER_PATTERN = /\b(?:TODO|FIXME|XXX|HACK)\b/u;
|
|
2110
|
+
const TEST_MARKER_PATTERN = /^\s*(?:regression|quarantine):/u;
|
|
2111
|
+
const TASK_LINK_PATTERN = /#\d+|https?:\/\//u;
|
|
2112
|
+
const BARE_ISSUE_REF_PATTERN = /(?<![\w/&#-])#[1-9]\d{2,4}(?![\w-])/u;
|
|
2113
|
+
const CODE_SPAN_PATTERN = /`[^`]*`/gu;
|
|
2114
|
+
const PUBLIC_BOILERPLATE_PATTERN = /^@public\s+Service construction is part of the canonical/u;
|
|
2115
|
+
const MAX_COMMENT_LINES = 4;
|
|
2116
|
+
const LICENSE_PATTERN = /^!|@license|\bcopyright\b|\bSPDX-License-Identifier\b/iu;
|
|
2117
|
+
const JSDOC_TYPE_PATTERN = /^@(?:param|returns?|type|typedef)\s+\{/u;
|
|
2118
|
+
const EMPTY_JSDOC_TAG_PATTERN = /^@(?:param(?:\s+\[?[\w$.]+\]?)?|returns?)$/u;
|
|
2119
|
+
const COMMENTED_CODE_PATTERN = /^(?:(?:(?:const|let|var)\s+[\w${}[\], ]+=.*|import\s.+\sfrom\s+["'].+["']|(?:await\s+|return\s+)?[\w$.]+\(.*\)|[\w$.[\]]+\s*=\s*.+);|(?:if|for|while|switch)\s*\(.*\)\s*\{|\}(?:\s*else\s*\{)?)$/u;
|
|
2120
|
+
const DECLARATION_PATTERN = /^\s*(?:export\s+)?(?:default\s+)?(?:declare\s+)?(?:async\s+)?(?:static\s+)?(?:readonly\s+)?(?:(?:const|let|var|function\*?|class|interface|type|enum)\s+)?([A-Za-z_$][\w$]*)\s*[?!]?\s*[:=(<{]/u;
|
|
2121
|
+
const FILLER_WORDS = new Set("a an the of for to in on at by with from and or is are be this that it its as get set return create new current value given whether".split(" "));
|
|
2122
|
+
const stem = (word) => word.length > 3 ? word.replace(/([^s])s$/u, "$1") : word;
|
|
2123
|
+
const words = (text) => (text.toLowerCase().match(/[a-z0-9]+/gu) ?? []).filter((word) => !FILLER_WORDS.has(word)).map(stem).filter((word) => !FILLER_WORDS.has(word));
|
|
2124
|
+
const identifierWords = (name) => words(name.replace(/([a-z0-9])([A-Z])/gu, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/gu, "$1 $2"));
|
|
2125
|
+
const commentLines = (comment) => comment.value.split("\n").map((line) => line.replace(/^\s*\*?\s?/u, "").trim()).filter((line) => line !== "");
|
|
2126
|
+
var no_low_value_comments_default = defineRule({
|
|
2127
|
+
meta: {
|
|
2128
|
+
type: "suggestion",
|
|
2129
|
+
docs: { description: "Reject comments that only repeat the code, divide sections, or narrate tests." }
|
|
2130
|
+
},
|
|
2131
|
+
create(context) {
|
|
2132
|
+
const { sourceCode } = context;
|
|
2133
|
+
const isTypeScript = TS_FILE_PATTERN.test(context.filename);
|
|
2134
|
+
const groups = [];
|
|
2135
|
+
for (const comment of sourceCode.getAllComments()) {
|
|
2136
|
+
const previous = groups.at(-1)?.comments.at(-1);
|
|
2137
|
+
if (comment.type === "Line" && previous?.type === "Line" && previous.loc.end.line === comment.loc.start.line - 1 && previous.loc.start.column === comment.loc.start.column) {
|
|
2138
|
+
groups.at(-1).comments.push(comment);
|
|
2139
|
+
groups.at(-1).lines.push(...commentLines(comment));
|
|
2140
|
+
} else groups.push({
|
|
2141
|
+
comments: [comment],
|
|
2142
|
+
lines: commentLines(comment)
|
|
2143
|
+
});
|
|
2144
|
+
}
|
|
2145
|
+
const restatesNextName = (lastLine, lines) => {
|
|
2146
|
+
if (lines.some((line) => line.startsWith("@"))) return false;
|
|
2147
|
+
const name = DECLARATION_PATTERN.exec(sourceCode.lines[lastLine] ?? "")?.[1];
|
|
2148
|
+
if (name === void 0) return false;
|
|
2149
|
+
const content = words(lines.join(" "));
|
|
2150
|
+
if (content.length === 0 || content.length > 6) return false;
|
|
2151
|
+
const nameWords = new Set(identifierWords(name));
|
|
2152
|
+
return content.every((word) => nameWords.has(word));
|
|
2153
|
+
};
|
|
2154
|
+
const problem = (comments, lines) => {
|
|
2155
|
+
const text = comments.map((comment) => comment.value).join("\n");
|
|
2156
|
+
if (lines.length === 0 || comments.some((comment) => DIRECTIVE_PATTERN$1.test(comment.value))) return;
|
|
2157
|
+
const isLine = comments[0].type === "Line";
|
|
2158
|
+
if (lines.some((line) => DIVIDER_LINE_PATTERN.test(line))) return "Drop the section divider; split the file or let the code's structure show the grouping.";
|
|
2159
|
+
if (isLine && lines.length === 1 && TEST_STEP_PATTERN.test(lines[0])) return "Drop the test step label.";
|
|
2160
|
+
if (TASK_MARKER_PATTERN.test(text) && !TASK_LINK_PATTERN.test(text)) return "Link the issue that tracks this, or drop the marker.";
|
|
2161
|
+
if (!TASK_MARKER_PATTERN.test(text) && !TEST_MARKER_PATTERN.test(text) && BARE_ISSUE_REF_PATTERN.test(text.replace(CODE_SPAN_PATTERN, ""))) return "Drop the PR or issue number; git history records it. Keep the reason.";
|
|
2162
|
+
if (isTypeScript && lines.some((line) => JSDOC_TYPE_PATTERN.test(line))) return "Drop the JSDoc type; TypeScript already has it.";
|
|
2163
|
+
if (lines.some((line) => PUBLIC_BOILERPLATE_PATTERN.test(line))) return "Keep `@public` alone; the boilerplate after it says nothing about this export.";
|
|
2164
|
+
if (lines.some((line) => EMPTY_JSDOC_TAG_PATTERN.test(line))) return "Drop the JSDoc tag that has no description.";
|
|
2165
|
+
if (isLine && lines.every((line) => COMMENTED_CODE_PATTERN.test(line))) return "Delete commented-out code; git keeps the history.";
|
|
2166
|
+
if (restatesNextName(comments.at(-1).loc.end.line, lines)) return "Drop the comment; it only repeats the name below it. Say why, or say nothing.";
|
|
2167
|
+
if (lines.length > MAX_COMMENT_LINES && !LICENSE_PATTERN.test(text)) return `Cut this to ${MAX_COMMENT_LINES} lines or fewer: keep the constraint, drop the background.`;
|
|
2168
|
+
};
|
|
2169
|
+
return { Program() {
|
|
2170
|
+
for (const { comments, lines } of groups) {
|
|
2171
|
+
const message = problem(comments, lines);
|
|
2172
|
+
if (message === void 0) continue;
|
|
2173
|
+
context.report({
|
|
2174
|
+
loc: {
|
|
2175
|
+
start: comments[0].loc.start,
|
|
2176
|
+
end: comments.at(-1).loc.end
|
|
2177
|
+
},
|
|
2178
|
+
message
|
|
2179
|
+
});
|
|
2180
|
+
}
|
|
2181
|
+
} };
|
|
2182
|
+
}
|
|
2183
|
+
});
|
|
2184
|
+
// src/rules/no-manual-effect-runtime-in-tests.ts
|
|
2185
|
+
const TEST_FILE_PATTERN$5 = /\.(?:test|spec)\.[cm]?[jt]sx?$/u;
|
|
2186
|
+
const EFFECT_RUNTIME_METHODS = /* @__PURE__ */ new Set([
|
|
2187
|
+
"runCallback",
|
|
2188
|
+
"runCallbackWith",
|
|
2189
|
+
"runFork",
|
|
2190
|
+
"runForkWith",
|
|
2191
|
+
"runPromise",
|
|
2192
|
+
"runPromiseExit",
|
|
2193
|
+
"runPromiseExitWith",
|
|
2194
|
+
"runPromiseWith",
|
|
2195
|
+
"runSync",
|
|
2196
|
+
"runSyncExit",
|
|
2197
|
+
"runSyncExitWith",
|
|
2198
|
+
"runSyncWith"
|
|
2199
|
+
]);
|
|
2200
|
+
const readMaxOccurrences = (options) => {
|
|
2201
|
+
const [first] = options;
|
|
2202
|
+
return typeof first === "object" && first !== null && "maxOccurrences" in first && typeof first.maxOccurrences === "number" ? first.maxOccurrences : 0;
|
|
2203
|
+
};
|
|
2204
|
+
const manualRunnerName = (callee) => {
|
|
2205
|
+
const expression = unwrapExpression(callee);
|
|
2206
|
+
if (isNone(expression) || expression.value.type !== "MemberExpression") return none();
|
|
2207
|
+
const object = unwrapExpression(expression.value.object);
|
|
2208
|
+
const property = getPropertyName(expression.value.property);
|
|
2209
|
+
if (isNone(property)) return none();
|
|
2210
|
+
if (isIdentifier(object, "Effect") && EFFECT_RUNTIME_METHODS.has(property.value)) return some(`Effect.${property.value}`);
|
|
2211
|
+
if (isIdentifier(object, "ManagedRuntime") && property.value === "make") return some("ManagedRuntime.make");
|
|
2212
|
+
return none();
|
|
2213
|
+
};
|
|
2214
|
+
var no_manual_effect_runtime_in_tests_default = defineRule({
|
|
2215
|
+
meta: {
|
|
2216
|
+
type: "problem",
|
|
2217
|
+
docs: { description: "Disallow manually creating or running Effect runtimes in tests; use @effect/vitest." },
|
|
2218
|
+
schema: [{
|
|
2219
|
+
type: "object",
|
|
2220
|
+
properties: { maxOccurrences: {
|
|
2221
|
+
type: "integer",
|
|
2222
|
+
minimum: 0,
|
|
2223
|
+
description: "Legacy debt ceiling for this file: occurrences beyond this count are reported."
|
|
2224
|
+
} },
|
|
2225
|
+
additionalProperties: false
|
|
2226
|
+
}],
|
|
2227
|
+
defaultOptions: [{ maxOccurrences: 0 }]
|
|
2228
|
+
},
|
|
2229
|
+
create(context) {
|
|
2230
|
+
if (!TEST_FILE_PATTERN$5.test(context.filename)) return {};
|
|
2231
|
+
const allowedCount = readMaxOccurrences(context.options);
|
|
2232
|
+
let occurrenceCount = 0;
|
|
2233
|
+
return { CallExpression(node) {
|
|
2234
|
+
const runner = manualRunnerName(node.callee);
|
|
2235
|
+
if (isNone(runner)) return;
|
|
2236
|
+
occurrenceCount++;
|
|
2237
|
+
if (occurrenceCount <= allowedCount) return;
|
|
2238
|
+
context.report({
|
|
2239
|
+
node: node.callee,
|
|
2240
|
+
message: `Do not use ${runner.value} in tests. Use @effect/vitest with it.effect(...) and test layers instead.`
|
|
2241
|
+
});
|
|
2242
|
+
} };
|
|
2243
|
+
}
|
|
2244
|
+
});
|
|
2245
|
+
// src/rules/no-manual-memo.ts
|
|
2246
|
+
const MANUAL_MEMO_HOOKS = /* @__PURE__ */ new Set(["useCallback", "useMemo"]);
|
|
2247
|
+
const MEMO_DIRECTIVES = /* @__PURE__ */ new Set([
|
|
2248
|
+
"use memo",
|
|
2249
|
+
"use no memo",
|
|
2250
|
+
"use no forget"
|
|
2251
|
+
]);
|
|
2252
|
+
const readAllowMemoHooks = (options) => {
|
|
2253
|
+
const [first] = options;
|
|
2254
|
+
return typeof first === "object" && first !== null && "allowMemoHooks" in first && first.allowMemoHooks === true;
|
|
2255
|
+
};
|
|
2256
|
+
function manualMemoHookName(callee) {
|
|
2257
|
+
if (callee.type === "Identifier") return MANUAL_MEMO_HOOKS.has(callee.name) ? callee.name : null;
|
|
2258
|
+
if (callee.type === "MemberExpression" && !callee.computed && callee.object.type === "Identifier" && callee.object.name === "React" && callee.property.type === "Identifier" && MANUAL_MEMO_HOOKS.has(callee.property.name)) return callee.property.name;
|
|
2259
|
+
return null;
|
|
2260
|
+
}
|
|
2261
|
+
var no_manual_memo_default = defineRule({
|
|
2262
|
+
meta: {
|
|
2263
|
+
type: "suggestion",
|
|
2264
|
+
docs: { description: "Disallow useCallback, useMemo and memo directives in files the React Compiler must compile; it memoizes them." },
|
|
2265
|
+
schema: [{
|
|
2266
|
+
type: "object",
|
|
2267
|
+
properties: { allowMemoHooks: {
|
|
2268
|
+
type: "boolean",
|
|
2269
|
+
description: "Still permit useMemo and useCallback while a codebase ratchets toward full compiler coverage; directives stay banned."
|
|
2270
|
+
} },
|
|
2271
|
+
additionalProperties: false
|
|
2272
|
+
}],
|
|
2273
|
+
defaultOptions: [{ allowMemoHooks: false }]
|
|
2274
|
+
},
|
|
2275
|
+
create(context) {
|
|
2276
|
+
const allowMemoHooks = readAllowMemoHooks(context.options);
|
|
2277
|
+
return {
|
|
2278
|
+
ExpressionStatement(node) {
|
|
2279
|
+
if (typeof node.directive !== "string" || !MEMO_DIRECTIVES.has(node.directive)) return;
|
|
2280
|
+
context.report({
|
|
2281
|
+
node,
|
|
2282
|
+
message: node.directive === "use memo" ? "Drop \"use memo\": restructure so the compiler caches this on its own, e.g. move plain uses of a value before the hook call that splits its scope, or inline the helper." : `Drop "${node.directive}": fix the code the compiler cannot prove safe instead of skipping it.`
|
|
2283
|
+
});
|
|
2284
|
+
},
|
|
2285
|
+
CallExpression(node) {
|
|
2286
|
+
if (allowMemoHooks) return;
|
|
2287
|
+
const name = manualMemoHookName(node.callee);
|
|
2288
|
+
if (name === null) return;
|
|
2289
|
+
context.report({
|
|
2290
|
+
node: node.callee,
|
|
2291
|
+
message: `Drop ${name}: the React Compiler memoizes this file. Write the plain value or function.`
|
|
2292
|
+
});
|
|
2293
|
+
}
|
|
2294
|
+
};
|
|
2295
|
+
}
|
|
2296
|
+
});
|
|
2297
|
+
// src/rules/no-polling-loop-in-tests.ts
|
|
2298
|
+
const TEST_FILE_PATTERN$4 = /\.(?:test|spec)\.[cm]?[jt]sx?$/u;
|
|
2299
|
+
const FUNCTIONS$2 = /* @__PURE__ */ new Set([
|
|
2300
|
+
"ArrowFunctionExpression",
|
|
2301
|
+
"FunctionExpression",
|
|
2302
|
+
"FunctionDeclaration"
|
|
2303
|
+
]);
|
|
2304
|
+
const COUNTER_OPERATORS = /* @__PURE__ */ new Set([
|
|
2305
|
+
"<",
|
|
2306
|
+
"<=",
|
|
2307
|
+
">",
|
|
2308
|
+
">="
|
|
2309
|
+
]);
|
|
2310
|
+
const TIMERS = /* @__PURE__ */ new Set(["setImmediate", "setTimeout"]);
|
|
2311
|
+
const MESSAGE$3 = "Polling loop in a test. Spinning on `yieldNow`/`sleep` is scheduler- and load-dependent. Await the `Deferred`, `Queue.take`, `Stream` element, `drain()`, or `expect.poll` that marks the milestone.";
|
|
2312
|
+
const isNode = (value) => typeof value === "object" && value !== null && "type" in value && typeof value.type === "string";
|
|
2313
|
+
const someDescendant = (node, match) => {
|
|
2314
|
+
if (Array.isArray(node)) return node.some((child) => someDescendant(child, match));
|
|
2315
|
+
if (!isNode(node)) return false;
|
|
2316
|
+
if (match(node)) return true;
|
|
2317
|
+
if (FUNCTIONS$2.has(node.type)) return false;
|
|
2318
|
+
for (const [key, value] of Object.entries(node)) {
|
|
2319
|
+
if (key === "parent") continue;
|
|
2320
|
+
if (someDescendant(value, match)) return true;
|
|
2321
|
+
}
|
|
2322
|
+
return false;
|
|
2323
|
+
};
|
|
2324
|
+
const memberName = (node) => {
|
|
2325
|
+
const expression = unwrapExpression(node);
|
|
2326
|
+
if (isNone(expression) || expression.value.type !== "MemberExpression") return none();
|
|
2327
|
+
const object = unwrapExpression(expression.value.object);
|
|
2328
|
+
const property = getPropertyName(expression.value.property);
|
|
2329
|
+
if (isNone(object) || object.value.type !== "Identifier" || isNone(property)) return none();
|
|
2330
|
+
return some([object.value.name, property.value]);
|
|
2331
|
+
};
|
|
2332
|
+
const isMember = (node, object, property) => match(memberName(node), {
|
|
2333
|
+
onNone: () => false,
|
|
2334
|
+
onSome: ([name, key]) => name === object && key === property
|
|
2335
|
+
});
|
|
2336
|
+
const isTimerReference = (node) => {
|
|
2337
|
+
const expression = unwrapExpression(node);
|
|
2338
|
+
return isSome(expression) && expression.value.type === "Identifier" && TIMERS.has(expression.value.name);
|
|
2339
|
+
};
|
|
2340
|
+
const isTickPromise = (node) => {
|
|
2341
|
+
const expression = unwrapExpression(node);
|
|
2342
|
+
if (isNone(expression)) return false;
|
|
2343
|
+
const value = expression.value;
|
|
2344
|
+
if (value.type === "CallExpression") return isMember(value.callee, "Promise", "resolve");
|
|
2345
|
+
if (value.type !== "NewExpression" || !isIdentifier(some(value.callee), "Promise")) return false;
|
|
2346
|
+
const [executor] = value.arguments;
|
|
2347
|
+
if (isTimerReference(executor)) return true;
|
|
2348
|
+
if (!isNode(executor) || !FUNCTIONS$2.has(executor.type)) return false;
|
|
2349
|
+
return someDescendant(executor.body, (child) => child.type === "CallExpression" && isTimerReference(child.callee));
|
|
2350
|
+
};
|
|
2351
|
+
const thunkReturnsTick = (node) => {
|
|
2352
|
+
if (!isNode(node) || node.type !== "ArrowFunctionExpression") return false;
|
|
2353
|
+
const body = node.body;
|
|
2354
|
+
if (body.type !== "BlockStatement") return isTickPromise(body);
|
|
2355
|
+
const last = body.body.at(-1);
|
|
2356
|
+
return last?.type === "ReturnStatement" && isTickPromise(last.argument);
|
|
2357
|
+
};
|
|
2358
|
+
const isWait = (node) => {
|
|
2359
|
+
if (node.type === "MemberExpression") return isMember(node, "Effect", "yieldNow");
|
|
2360
|
+
if (node.type === "AwaitExpression") return isTickPromise(node.argument);
|
|
2361
|
+
if (node.type === "NewExpression") return isTickPromise(node);
|
|
2362
|
+
if (node.type !== "CallExpression") return false;
|
|
2363
|
+
if (isMember(node.callee, "Effect", "sleep")) return true;
|
|
2364
|
+
if (isIdentifier(unwrapExpression(node.callee), "setImmediate")) return true;
|
|
2365
|
+
if (isMember(node.callee, "Effect", "promise")) return thunkReturnsTick(node.arguments[0]);
|
|
2366
|
+
return false;
|
|
2367
|
+
};
|
|
2368
|
+
const hasConditionalExit = (body) => someDescendant(body, (node) => node.type === "IfStatement" && someDescendant([node.consequent, node.alternate], (child) => child.type === "ReturnStatement" || child.type === "BreakStatement" || child.type === "ThrowStatement"));
|
|
2369
|
+
const isNumericBound = (node) => {
|
|
2370
|
+
const expression = unwrapExpression(node);
|
|
2371
|
+
if (isNone(expression)) return false;
|
|
2372
|
+
const value = expression.value;
|
|
2373
|
+
return value.type === "Identifier" || value.type === "Literal" && typeof value.value === "number";
|
|
2374
|
+
};
|
|
2375
|
+
const updatesCounter = (node, name) => someDescendant(node, (child) => child.type === "UpdateExpression" && isIdentifier(unwrapExpression(child.argument), name) || child.type === "AssignmentExpression" && (child.operator === "+=" || child.operator === "-=") && isIdentifier(unwrapExpression(child.left), name));
|
|
2376
|
+
const isCounterTest = (loop) => {
|
|
2377
|
+
if (loop.test == null) return false;
|
|
2378
|
+
const expression = unwrapExpression(loop.test);
|
|
2379
|
+
if (isNone(expression) || expression.value.type !== "BinaryExpression") return false;
|
|
2380
|
+
if (!COUNTER_OPERATORS.has(expression.value.operator)) return false;
|
|
2381
|
+
const { left, right } = expression.value;
|
|
2382
|
+
const advances = [loop.body, loop.type === "ForStatement" ? loop.update : null];
|
|
2383
|
+
return [[left, right], [right, left]].some(([counter, bound]) => {
|
|
2384
|
+
const name = unwrapExpression(counter);
|
|
2385
|
+
return isSome(name) && name.value.type === "Identifier" && isNumericBound(bound) && updatesCounter(advances, name.value.name);
|
|
2386
|
+
});
|
|
2387
|
+
};
|
|
2388
|
+
const isTrueLiteral = (test) => {
|
|
2389
|
+
const expression = unwrapExpression(test);
|
|
2390
|
+
return isSome(expression) && expression.value.type === "Literal" && expression.value.value === true;
|
|
2391
|
+
};
|
|
2392
|
+
const hasPredicateExit = (loop) => hasConditionalExit(loop.body) || loop.test != null && !isTrueLiteral(loop.test) && !isCounterTest(loop);
|
|
2393
|
+
var no_polling_loop_in_tests_default = defineRule({
|
|
2394
|
+
meta: {
|
|
2395
|
+
type: "problem",
|
|
2396
|
+
docs: { description: "Disallow loops in tests that spin on yieldNow/sleep/timer ticks until a predicate holds; await the milestone instead." },
|
|
2397
|
+
schema: []
|
|
2398
|
+
},
|
|
2399
|
+
create(context) {
|
|
2400
|
+
if (!TEST_FILE_PATTERN$4.test(context.filename)) return {};
|
|
2401
|
+
const check = (loop) => {
|
|
2402
|
+
if (!someDescendant(loop.body, isWait)) return;
|
|
2403
|
+
if (!hasPredicateExit(loop)) return;
|
|
2404
|
+
context.report({
|
|
2405
|
+
node: loop,
|
|
2406
|
+
message: MESSAGE$3
|
|
2407
|
+
});
|
|
2408
|
+
};
|
|
2409
|
+
return {
|
|
2410
|
+
ForStatement: check,
|
|
2411
|
+
WhileStatement: check,
|
|
2412
|
+
DoWhileStatement: check
|
|
2413
|
+
};
|
|
2414
|
+
}
|
|
2415
|
+
});
|
|
2416
|
+
// src/rules/no-real-time-wait-in-tests.ts
|
|
2417
|
+
const TEST_FILE_PATTERN$3 = /\.(?:test|spec)\.[cm]?[jt]sx?$/u;
|
|
2418
|
+
const TEST_CLOCK_DRIVERS = /* @__PURE__ */ new Set(["adjust", "setTime"]);
|
|
2419
|
+
const TIMER_PROMISES_MODULES = /* @__PURE__ */ new Set(["node:timers/promises", "timers/promises"]);
|
|
2420
|
+
const TIMER_FUNCTIONS = /* @__PURE__ */ new Set([
|
|
2421
|
+
"setTimeout",
|
|
2422
|
+
"setInterval",
|
|
2423
|
+
"setImmediate"
|
|
2424
|
+
]);
|
|
2425
|
+
const SCHEDULE_WAITS = /* @__PURE__ */ new Set([
|
|
2426
|
+
"spaced",
|
|
2427
|
+
"fixed",
|
|
2428
|
+
"exponential"
|
|
2429
|
+
]);
|
|
2430
|
+
const TESTER_ROOTS = /* @__PURE__ */ new Set(["it", "test"]);
|
|
2431
|
+
const FUNCTIONS$1 = /* @__PURE__ */ new Set([
|
|
2432
|
+
"ArrowFunctionExpression",
|
|
2433
|
+
"FunctionExpression",
|
|
2434
|
+
"FunctionDeclaration"
|
|
2435
|
+
]);
|
|
2436
|
+
const REAL_CLOCK_MESSAGE = "Real-clock wait in a test. Await the `Deferred`/`Queue`/event that marks the milestone, or run under `it.effect` and `TestClock.adjust`. `it.live` is for subprocess/network fixtures, not for sleeping.";
|
|
2437
|
+
const UNDRIVEN_TEST_CLOCK_MESSAGE = "Sleeps on the TestClock never fire without `TestClock.adjust`; this test can only time out.";
|
|
2438
|
+
const MIXED_CLOCK_MESSAGE = "`setTimeout` is wall-clock while `Effect.sleep` here is TestClock; they never meet.";
|
|
2439
|
+
const calleeChain = (callee) => {
|
|
2440
|
+
const members = [];
|
|
2441
|
+
const calls = [];
|
|
2442
|
+
let current = unwrapExpression(callee);
|
|
2443
|
+
while (isSome(current)) {
|
|
2444
|
+
const node = current.value;
|
|
2445
|
+
if (node.type === "Identifier") return some({
|
|
2446
|
+
root: node.name,
|
|
2447
|
+
members: members.toReversed(),
|
|
2448
|
+
calls
|
|
2449
|
+
});
|
|
2450
|
+
if (node.type === "CallExpression") {
|
|
2451
|
+
calls.push(node);
|
|
2452
|
+
current = unwrapExpression(node.callee);
|
|
2453
|
+
continue;
|
|
2454
|
+
}
|
|
2455
|
+
if (node.type === "MemberExpression") {
|
|
2456
|
+
const name = getPropertyName(node.property);
|
|
2457
|
+
if (isNone(name)) return none();
|
|
2458
|
+
members.push(name.value);
|
|
2459
|
+
current = unwrapExpression(node.object);
|
|
2460
|
+
continue;
|
|
2461
|
+
}
|
|
2462
|
+
return none();
|
|
2463
|
+
}
|
|
2464
|
+
return none();
|
|
2465
|
+
};
|
|
2466
|
+
const isLayerBlock = (chain) => chain.root === "layer" || TESTER_ROOTS.has(chain.root) && chain.members.includes("layer");
|
|
2467
|
+
const testerKind = (chain) => {
|
|
2468
|
+
if (!TESTER_ROOTS.has(chain.root) || chain.members.includes("layer")) return none();
|
|
2469
|
+
if (chain.members.includes("live") || chain.members.includes("scopedLive")) return some("live");
|
|
2470
|
+
if (chain.members.includes("effect") || chain.members.includes("scoped")) return some("effect");
|
|
2471
|
+
return some("plain");
|
|
2472
|
+
};
|
|
2473
|
+
const excludesTestServices = (chain) => chain.calls.some((call) => call.arguments.some((argument) => {
|
|
2474
|
+
const expression = unwrapExpression(argument);
|
|
2475
|
+
if (isNone(expression) || expression.value.type !== "ObjectExpression") return false;
|
|
2476
|
+
return expression.value.properties.some((property) => {
|
|
2477
|
+
if (property.type !== "Property") return false;
|
|
2478
|
+
const key = getPropertyName(property.key);
|
|
2479
|
+
const value = unwrapExpression(property.value);
|
|
2480
|
+
return isSome(key) && key.value === "excludeTestServices" && isSome(value) && value.value.type === "Literal" && value.value.value === true;
|
|
2481
|
+
});
|
|
2482
|
+
}));
|
|
2483
|
+
const enclosingTester = (node) => {
|
|
2484
|
+
let child = node;
|
|
2485
|
+
let current = node.parent;
|
|
2486
|
+
let tester = none();
|
|
2487
|
+
while (current) {
|
|
2488
|
+
if (current.type === "CallExpression" && current.arguments.some((argument) => argument === child)) {
|
|
2489
|
+
const chain = calleeChain(current.callee);
|
|
2490
|
+
if (isSome(chain)) {
|
|
2491
|
+
if (isNone(tester)) {
|
|
2492
|
+
tester = testerKind(chain.value);
|
|
2493
|
+
if (isSome(tester) && tester.value !== "effect") return tester;
|
|
2494
|
+
} else if (isLayerBlock(chain.value) && excludesTestServices(chain.value)) return some("live");
|
|
2495
|
+
}
|
|
2496
|
+
}
|
|
2497
|
+
child = current;
|
|
2498
|
+
current = current.parent;
|
|
2499
|
+
}
|
|
2500
|
+
return tester;
|
|
2501
|
+
};
|
|
2502
|
+
const memberCallName = (callee) => {
|
|
2503
|
+
const expression = unwrapExpression(callee);
|
|
2504
|
+
if (isNone(expression) || expression.value.type !== "MemberExpression") return none();
|
|
2505
|
+
const object = unwrapExpression(expression.value.object);
|
|
2506
|
+
const property = getPropertyName(expression.value.property);
|
|
2507
|
+
if (isNone(property) || isNone(object) || object.value.type !== "Identifier") return none();
|
|
2508
|
+
return some([object.value.name, property.value]);
|
|
2509
|
+
};
|
|
2510
|
+
const LOOPS$1 = /* @__PURE__ */ new Set([
|
|
2511
|
+
"DoWhileStatement",
|
|
2512
|
+
"ForInStatement",
|
|
2513
|
+
"ForOfStatement",
|
|
2514
|
+
"ForStatement",
|
|
2515
|
+
"WhileStatement"
|
|
2516
|
+
]);
|
|
2517
|
+
const isPollingLoopStep = (node) => {
|
|
2518
|
+
let statement = node.parent;
|
|
2519
|
+
while (statement && statement.type !== "ExpressionStatement") {
|
|
2520
|
+
if (FUNCTIONS$1.has(statement.type)) return false;
|
|
2521
|
+
statement = statement.parent;
|
|
2522
|
+
}
|
|
2523
|
+
const block = statement?.parent;
|
|
2524
|
+
if (!block) return false;
|
|
2525
|
+
if (LOOPS$1.has(block.type)) return true;
|
|
2526
|
+
return block.type === "BlockStatement" && block.parent !== null && LOOPS$1.has(block.parent.type);
|
|
2527
|
+
};
|
|
2528
|
+
const isPromiseExecutor = (fn) => {
|
|
2529
|
+
const parent = fn.parent;
|
|
2530
|
+
return parent?.type === "NewExpression" && parent.arguments[0] === fn && isIdentifier(unwrapExpression(parent.callee), "Promise");
|
|
2531
|
+
};
|
|
2532
|
+
const isInsidePromiseExecutor = (node) => {
|
|
2533
|
+
let current = node.parent;
|
|
2534
|
+
while (current) {
|
|
2535
|
+
if (FUNCTIONS$1.has(current.type)) return isPromiseExecutor(current);
|
|
2536
|
+
current = current.parent;
|
|
2537
|
+
}
|
|
2538
|
+
return false;
|
|
2539
|
+
};
|
|
2540
|
+
var no_real_time_wait_in_tests_default = defineRule({
|
|
2541
|
+
meta: {
|
|
2542
|
+
type: "problem",
|
|
2543
|
+
docs: { description: "Disallow real-clock waits in tests; await the milestone or drive the TestClock instead." }
|
|
2544
|
+
},
|
|
2545
|
+
create(context) {
|
|
2546
|
+
if (!TEST_FILE_PATTERN$3.test(context.filename)) return {};
|
|
2547
|
+
let drivesTestClock = false;
|
|
2548
|
+
const untilDrivenReports = [];
|
|
2549
|
+
const timerPromiseLocals = /* @__PURE__ */ new Set();
|
|
2550
|
+
const timerPromiseNamespaces = /* @__PURE__ */ new Set();
|
|
2551
|
+
const isTimerPromiseCall = (callee) => {
|
|
2552
|
+
const expression = unwrapExpression(callee);
|
|
2553
|
+
if (isNone(expression)) return false;
|
|
2554
|
+
if (expression.value.type === "Identifier") return timerPromiseLocals.has(expression.value.name);
|
|
2555
|
+
return match(memberCallName(callee), {
|
|
2556
|
+
onNone: () => false,
|
|
2557
|
+
onSome: ([object, property]) => timerPromiseNamespaces.has(object) && TIMER_FUNCTIONS.has(property)
|
|
2558
|
+
});
|
|
2559
|
+
};
|
|
2560
|
+
const isCallbackTimer = (callee) => {
|
|
2561
|
+
const expression = unwrapExpression(callee);
|
|
2562
|
+
return isSome(expression) && expression.value.type === "Identifier" && TIMER_FUNCTIONS.has(expression.value.name) && !timerPromiseLocals.has(expression.value.name);
|
|
2563
|
+
};
|
|
2564
|
+
return {
|
|
2565
|
+
ImportDeclaration(node) {
|
|
2566
|
+
if (!TIMER_PROMISES_MODULES.has(node.source.value)) return;
|
|
2567
|
+
for (const specifier of node.specifiers) if (specifier.type === "ImportNamespaceSpecifier") timerPromiseNamespaces.add(specifier.local.name);
|
|
2568
|
+
else if (specifier.type === "ImportSpecifier") {
|
|
2569
|
+
const imported = getPropertyName(specifier.imported);
|
|
2570
|
+
if (isSome(imported) && TIMER_FUNCTIONS.has(imported.value)) timerPromiseLocals.add(specifier.local.name);
|
|
2571
|
+
}
|
|
2572
|
+
},
|
|
2573
|
+
CallExpression(node) {
|
|
2574
|
+
const reportFor = (message) => context.report({
|
|
2575
|
+
node: node.callee,
|
|
2576
|
+
message
|
|
2577
|
+
});
|
|
2578
|
+
if (isTimerPromiseCall(node.callee) || isCallbackTimer(node.callee) && isInsidePromiseExecutor(node)) {
|
|
2579
|
+
const tester = enclosingTester(node);
|
|
2580
|
+
reportFor(isSome(tester) && tester.value === "effect" ? `${REAL_CLOCK_MESSAGE} ${MIXED_CLOCK_MESSAGE}` : REAL_CLOCK_MESSAGE);
|
|
2581
|
+
return;
|
|
2582
|
+
}
|
|
2583
|
+
const name = memberCallName(node.callee);
|
|
2584
|
+
if (isNone(name)) return;
|
|
2585
|
+
const [object, property] = name.value;
|
|
2586
|
+
if (object === "TestClock" && TEST_CLOCK_DRIVERS.has(property)) {
|
|
2587
|
+
drivesTestClock = true;
|
|
2588
|
+
return;
|
|
2589
|
+
}
|
|
2590
|
+
const isSleep = object === "Effect" && property === "sleep";
|
|
2591
|
+
if (!(isSleep || object === "Effect" && property === "delay" || object === "Schedule" && SCHEDULE_WAITS.has(property))) return;
|
|
2592
|
+
const tester = enclosingTester(node);
|
|
2593
|
+
if (isNone(tester)) {
|
|
2594
|
+
if (isPollingLoopStep(node)) reportFor(REAL_CLOCK_MESSAGE);
|
|
2595
|
+
else untilDrivenReports.push({
|
|
2596
|
+
node: node.callee,
|
|
2597
|
+
message: REAL_CLOCK_MESSAGE
|
|
2598
|
+
});
|
|
2599
|
+
return;
|
|
2600
|
+
}
|
|
2601
|
+
if (tester.value !== "effect") reportFor(REAL_CLOCK_MESSAGE);
|
|
2602
|
+
else if (isSleep) untilDrivenReports.push({
|
|
2603
|
+
node: node.callee,
|
|
2604
|
+
message: UNDRIVEN_TEST_CLOCK_MESSAGE
|
|
2605
|
+
});
|
|
2606
|
+
},
|
|
2607
|
+
"Program:exit"() {
|
|
2608
|
+
if (drivesTestClock) return;
|
|
2609
|
+
for (const report of untilDrivenReports) context.report(report);
|
|
2610
|
+
}
|
|
2611
|
+
};
|
|
2612
|
+
}
|
|
2613
|
+
});
|
|
2614
|
+
// src/rules/no-test-in-loop.ts
|
|
2615
|
+
const TEST_FILE_PATTERN$2 = /\.(?:test|spec)\.[cm]?[jt]sx?$/u;
|
|
2616
|
+
const NODE_TEST_IMPORT_PATTERN = /["']node:test["']/u;
|
|
2617
|
+
const TEST_FUNCTIONS$1 = /* @__PURE__ */ new Set([
|
|
2618
|
+
"describe",
|
|
2619
|
+
"it",
|
|
2620
|
+
"suite",
|
|
2621
|
+
"test"
|
|
2622
|
+
]);
|
|
2623
|
+
const EACH_CAPABLE_MODIFIERS = /* @__PURE__ */ new Set(["effect", "live"]);
|
|
2624
|
+
const LOOPS = /* @__PURE__ */ new Set([
|
|
2625
|
+
"ForStatement",
|
|
2626
|
+
"ForInStatement",
|
|
2627
|
+
"ForOfStatement"
|
|
2628
|
+
]);
|
|
2629
|
+
const FUNCTIONS = /* @__PURE__ */ new Set([
|
|
2630
|
+
"ArrowFunctionExpression",
|
|
2631
|
+
"FunctionExpression",
|
|
2632
|
+
"FunctionDeclaration"
|
|
2633
|
+
]);
|
|
2634
|
+
const testCallName = (callee) => {
|
|
2635
|
+
const expression = unwrapExpression(callee);
|
|
2636
|
+
if (isNone(expression)) return none();
|
|
2637
|
+
if (expression.value.type === "Identifier") return TEST_FUNCTIONS$1.has(expression.value.name) ? some(expression.value.name) : none();
|
|
2638
|
+
if (expression.value.type !== "MemberExpression") return none();
|
|
2639
|
+
const object = unwrapExpression(expression.value.object);
|
|
2640
|
+
const property = getPropertyName(expression.value.property);
|
|
2641
|
+
if (isNone(object) || isNone(property)) return none();
|
|
2642
|
+
if (!EACH_CAPABLE_MODIFIERS.has(property.value)) return none();
|
|
2643
|
+
if (object.value.type !== "Identifier" || !TEST_FUNCTIONS$1.has(object.value.name)) return none();
|
|
2644
|
+
return some(`${object.value.name}.${property.value}`);
|
|
2645
|
+
};
|
|
2646
|
+
const isInsideLoop = (node) => {
|
|
2647
|
+
let current = node.parent;
|
|
2648
|
+
while (current) {
|
|
2649
|
+
if (LOOPS.has(current.type)) return true;
|
|
2650
|
+
if (FUNCTIONS.has(current.type)) return false;
|
|
2651
|
+
current = current.parent;
|
|
2652
|
+
}
|
|
2653
|
+
return false;
|
|
2654
|
+
};
|
|
2655
|
+
var no_test_in_loop_default = defineRule({
|
|
2656
|
+
meta: {
|
|
2657
|
+
type: "suggestion",
|
|
2658
|
+
docs: { description: "Disallow declaring tests inside a for loop; use it.each / it.effect.each / describe.each instead." }
|
|
2659
|
+
},
|
|
2660
|
+
create(context) {
|
|
2661
|
+
if (!TEST_FILE_PATTERN$2.test(context.filename)) return {};
|
|
2662
|
+
if (NODE_TEST_IMPORT_PATTERN.test(context.sourceCode.text)) return {};
|
|
2663
|
+
return { CallExpression(node) {
|
|
2664
|
+
const name = testCallName(node.callee);
|
|
2665
|
+
if (isNone(name)) return;
|
|
2666
|
+
if (!isInsideLoop(node)) return;
|
|
2667
|
+
context.report({
|
|
2668
|
+
node: node.callee,
|
|
2669
|
+
message: `Do not call ${name.value}(…) inside a for loop. Use ${name.value}.each(cases)(name, …) instead.`
|
|
2670
|
+
});
|
|
2671
|
+
} };
|
|
2672
|
+
}
|
|
2673
|
+
});
|
|
2674
|
+
// src/rules/no-test-timeout-or-unreasoned-skip.ts
|
|
2675
|
+
const TEST_FILE_PATTERN$1 = /\.(?:test|spec)\.[cm]?[jt]sx?$/u;
|
|
2676
|
+
const LIVE_TEST_FILE_PATTERN = /\.live\.(?:test|spec)\.[cm]?[jt]sx?$/u;
|
|
2677
|
+
const TEST_FUNCTIONS = /* @__PURE__ */ new Set([
|
|
2678
|
+
"describe",
|
|
2679
|
+
"it",
|
|
2680
|
+
"suite",
|
|
2681
|
+
"test"
|
|
2682
|
+
]);
|
|
2683
|
+
const HOOK_FUNCTIONS = /* @__PURE__ */ new Set([
|
|
2684
|
+
"afterAll",
|
|
2685
|
+
"afterEach",
|
|
2686
|
+
"beforeAll",
|
|
2687
|
+
"beforeEach"
|
|
2688
|
+
]);
|
|
2689
|
+
const FOCUS_OR_SKIP_MODIFIERS = /* @__PURE__ */ new Set([
|
|
2690
|
+
"only",
|
|
2691
|
+
"skip",
|
|
2692
|
+
"todo"
|
|
2693
|
+
]);
|
|
2694
|
+
const FOCUS_OR_SKIP_FUNCTIONS = /* @__PURE__ */ new Set([
|
|
2695
|
+
"fdescribe",
|
|
2696
|
+
"fit",
|
|
2697
|
+
"xdescribe",
|
|
2698
|
+
"xit",
|
|
2699
|
+
"xtest"
|
|
2700
|
+
]);
|
|
2701
|
+
const TIMEOUT_OPTIONS = /* @__PURE__ */ new Set(["retry", "timeout"]);
|
|
2702
|
+
const SET_CONFIG_OPTIONS = /* @__PURE__ */ new Set([
|
|
2703
|
+
"hookTimeout",
|
|
2704
|
+
"retry",
|
|
2705
|
+
"testTimeout"
|
|
2706
|
+
]);
|
|
2707
|
+
const QUARANTINE_PATTERN = /quarantine:\s*#\d+|https:\/\/github\.com\/[^\s/]+\/[^\s/]+\/issues\/\d+/u;
|
|
2708
|
+
const TIMEOUT_MESSAGE = "Per-test timeouts and retries hide waits that should be event-driven; the project timeout is the ceiling. Remove the override and await the milestone.";
|
|
2709
|
+
const SKIP_MESSAGE = "A skipped test needs a tracking issue in the comment above it: `// quarantine: #1234 <why>`.";
|
|
2710
|
+
const chainRoot = (node) => {
|
|
2711
|
+
const expression = unwrapExpression(node);
|
|
2712
|
+
if (isNone(expression)) return none();
|
|
2713
|
+
const value = expression.value;
|
|
2714
|
+
if (value.type === "Identifier") return some(value.name);
|
|
2715
|
+
if (value.type === "MemberExpression") return chainRoot(value.object);
|
|
2716
|
+
if (value.type === "CallExpression") return chainRoot(value.callee);
|
|
2717
|
+
return none();
|
|
2718
|
+
};
|
|
2719
|
+
const isTestChain = (node) => exists(chainRoot(node), (name) => TEST_FUNCTIONS.has(name));
|
|
2720
|
+
const hasEnabledOption = (node, names) => {
|
|
2721
|
+
const expression = unwrapExpression(node);
|
|
2722
|
+
if (isNone(expression) || expression.value.type !== "ObjectExpression") return false;
|
|
2723
|
+
return expression.value.properties.some((property) => property.type === "Property" && exists(getPropertyName(property.key), (name) => names.has(name)) && exists(unwrapExpression(property.value), (value) => value.type === "Literal" && value.value === true));
|
|
2724
|
+
};
|
|
2725
|
+
const hasOption = (node, names) => {
|
|
2726
|
+
const expression = unwrapExpression(node);
|
|
2727
|
+
if (isNone(expression) || expression.value.type !== "ObjectExpression") return false;
|
|
2728
|
+
return expression.value.properties.some((property) => property.type === "Property" && exists(getPropertyName(property.key), (name) => names.has(name)));
|
|
2729
|
+
};
|
|
2730
|
+
const isNumericLiteral = (node) => exists(unwrapExpression(node), (expression) => expression.type === "Literal" && typeof expression.value === "number");
|
|
2731
|
+
const isStringLiteral$1 = (node) => exists(unwrapExpression(node), (expression) => expression.type === "Literal" && typeof expression.value === "string");
|
|
2732
|
+
const enclosingStatement = (node) => {
|
|
2733
|
+
let current = node;
|
|
2734
|
+
while (current.parent && !/(?:Statement|Declaration)$/u.test(current.type)) current = current.parent;
|
|
2735
|
+
return current;
|
|
2736
|
+
};
|
|
2737
|
+
var no_test_timeout_or_unreasoned_skip_default = defineRule({
|
|
2738
|
+
meta: {
|
|
2739
|
+
type: "problem",
|
|
2740
|
+
docs: { description: "Disallow per-test timeouts and retries, and require a tracking issue for skipped or focused tests." }
|
|
2741
|
+
},
|
|
2742
|
+
create(context) {
|
|
2743
|
+
if (!TEST_FILE_PATTERN$1.test(context.filename)) return {};
|
|
2744
|
+
const checkTimeouts = !LIVE_TEST_FILE_PATTERN.test(context.filename);
|
|
2745
|
+
const reportUnlessQuarantined = (node) => {
|
|
2746
|
+
if (context.sourceCode.getCommentsBefore(enclosingStatement(node)).some((comment) => QUARANTINE_PATTERN.test(comment.value))) return;
|
|
2747
|
+
context.report({
|
|
2748
|
+
node,
|
|
2749
|
+
message: SKIP_MESSAGE
|
|
2750
|
+
});
|
|
2751
|
+
};
|
|
2752
|
+
return {
|
|
2753
|
+
CallExpression(node) {
|
|
2754
|
+
const callee = unwrapExpression(node.callee);
|
|
2755
|
+
if (isNone(callee)) return;
|
|
2756
|
+
if (callee.value.type === "MemberExpression" && exists(chainRoot(callee.value.object), (name) => name === "vi") && exists(getPropertyName(callee.value.property), (name) => name === "setConfig")) {
|
|
2757
|
+
if (checkTimeouts && hasOption(node.arguments[0], SET_CONFIG_OPTIONS)) context.report({
|
|
2758
|
+
node,
|
|
2759
|
+
message: TIMEOUT_MESSAGE
|
|
2760
|
+
});
|
|
2761
|
+
return;
|
|
2762
|
+
}
|
|
2763
|
+
if (callee.value.type === "Identifier" && HOOK_FUNCTIONS.has(callee.value.name)) {
|
|
2764
|
+
if (checkTimeouts && isNumericLiteral(node.arguments[1])) context.report({
|
|
2765
|
+
node,
|
|
2766
|
+
message: TIMEOUT_MESSAGE
|
|
2767
|
+
});
|
|
2768
|
+
return;
|
|
2769
|
+
}
|
|
2770
|
+
if (!isTestChain(callee.value)) return;
|
|
2771
|
+
const [, second, third] = node.arguments;
|
|
2772
|
+
if (checkTimeouts && (isNumericLiteral(third) || hasOption(third, TIMEOUT_OPTIONS) || hasOption(second, TIMEOUT_OPTIONS))) context.report({
|
|
2773
|
+
node,
|
|
2774
|
+
message: TIMEOUT_MESSAGE
|
|
2775
|
+
});
|
|
2776
|
+
if (hasEnabledOption(second, FOCUS_OR_SKIP_MODIFIERS) || hasEnabledOption(third, FOCUS_OR_SKIP_MODIFIERS)) reportUnlessQuarantined(node);
|
|
2777
|
+
},
|
|
2778
|
+
Identifier(node) {
|
|
2779
|
+
if (!FOCUS_OR_SKIP_FUNCTIONS.has(node.name)) return;
|
|
2780
|
+
const parent = node.parent;
|
|
2781
|
+
if (parent?.type !== "CallExpression" || parent.callee !== node) return;
|
|
2782
|
+
reportUnlessQuarantined(node);
|
|
2783
|
+
},
|
|
2784
|
+
MemberExpression(node) {
|
|
2785
|
+
if (!exists(getPropertyName(node.property), (n) => FOCUS_OR_SKIP_MODIFIERS.has(n))) return;
|
|
2786
|
+
if (node.computed && !isStringLiteral$1(node.property)) return;
|
|
2787
|
+
if (!isTestChain(node.object)) return;
|
|
2788
|
+
reportUnlessQuarantined(node);
|
|
2789
|
+
}
|
|
2790
|
+
};
|
|
2791
|
+
}
|
|
2792
|
+
});
|
|
2793
|
+
// src/rules/no-unreasoned-state-sync.ts
|
|
2794
|
+
const EFFECT_HOOKS = /* @__PURE__ */ new Set([
|
|
2795
|
+
"useEffect",
|
|
2796
|
+
"useLayoutEffect",
|
|
2797
|
+
"useInsertionEffect"
|
|
2798
|
+
]);
|
|
2799
|
+
const EFFECT_HOOK_TEXT = /use(?:Layout|Insertion)?Effect/;
|
|
2800
|
+
const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$|[\\/](?:tests?|__tests__)[\\/]/;
|
|
2801
|
+
const isEffectHookCall = (node) => {
|
|
2802
|
+
const callee = unwrapExpression(node.callee);
|
|
2803
|
+
if (isNone(callee)) return false;
|
|
2804
|
+
const expression = callee.value;
|
|
2805
|
+
if (expression.type === "Identifier") return EFFECT_HOOKS.has(expression.name);
|
|
2806
|
+
if (expression.type === "MemberExpression" && !expression.computed) return exists(getPropertyName(expression.property), (name) => EFFECT_HOOKS.has(name));
|
|
2807
|
+
return false;
|
|
2808
|
+
};
|
|
2809
|
+
const MESSAGE$2 = "Stop and reconsider before keeping this effect. Is it computable from props or state? Compute it during render; the compiler memoizes it. Does it respond to a user action? Do it in that handler. Does it reset state when a prop changes? Key the component on that prop. Does it tell a parent or store that a value changed? Do it where the change happens. Does it load app data? Read it from the data layer (an atom, query or loader). Does it read a value from outside React? Use a store subscription or useSyncExternalStore. An effect that sets state another effect reads is one handler or one derivation. An effect is right only when it keeps something outside React in step with this component while mounted: a DOM node, listener, timer, native module, connection, router, imperative toast, or a registry entry or resource held until unmount. Moving the same logic into a ref or store to dodge this rule is not a fix. If the effect does that, name what it keeps in step on the line above: `// oxlint-disable-next-line jandragsbaek/no-unreasoned-state-sync -- <what it syncs with and why>`.";
|
|
2810
|
+
var no_unreasoned_state_sync_default = defineRule({
|
|
2811
|
+
meta: {
|
|
2812
|
+
type: "suggestion",
|
|
2813
|
+
docs: { description: "Report every React effect hook, the usual way state gets synchronized; one that stays says why." }
|
|
2814
|
+
},
|
|
2815
|
+
create(context) {
|
|
2816
|
+
if (TEST_FILE.test(context.filename) || !EFFECT_HOOK_TEXT.test(context.sourceCode.text)) return {};
|
|
2817
|
+
return { CallExpression(node) {
|
|
2818
|
+
if (!isEffectHookCall(node)) return;
|
|
2819
|
+
context.report({
|
|
2820
|
+
node,
|
|
2821
|
+
message: MESSAGE$2
|
|
2822
|
+
});
|
|
2823
|
+
} };
|
|
2824
|
+
}
|
|
2825
|
+
});
|
|
2826
|
+
// src/rules/no-unscoped-has.ts
|
|
2827
|
+
const COMBINATOR_PATTERN = /[\s>+~]/u;
|
|
2828
|
+
const NARROWING_PATTERN = /[.#[]|^[a-z]/iu;
|
|
2829
|
+
const ROOT_COMPOUND_PATTERN = /^(?:html|body|:root)(?![\w-])/iu;
|
|
2830
|
+
const GROUP_PREFIX_PATTERN = /(?:^|:)(?:group|peer)-$/u;
|
|
2831
|
+
const ANCESTOR_PREFIX_PATTERN = /(?:^|:)in-$/u;
|
|
2832
|
+
const ATTRIBUTE_PREFIX_PATTERN = /(?:^|:)(?:data|aria)-$/u;
|
|
2833
|
+
const QUOTED_PATTERN = /(["'])(?:\\.|(?!\1).)*\1/gu;
|
|
2834
|
+
const VARIANT_END_PATTERN = /^(?:\/[\w-]+)?:/u;
|
|
2835
|
+
function variantGroups(token) {
|
|
2836
|
+
const groups = [];
|
|
2837
|
+
let depth = 0;
|
|
2838
|
+
let start = -1;
|
|
2839
|
+
for (let index = 0; index < token.length; index++) {
|
|
2840
|
+
const char = token[index];
|
|
2841
|
+
if (char === "[") {
|
|
2842
|
+
if (depth === 0) start = index + 1;
|
|
2843
|
+
depth++;
|
|
2844
|
+
} else if (char === "]" && depth > 0) {
|
|
2845
|
+
depth--;
|
|
2846
|
+
if (depth === 0 && VARIANT_END_PATTERN.test(token.slice(index + 1))) groups.push({
|
|
2847
|
+
prefix: token.slice(0, start - 1),
|
|
2848
|
+
group: token.slice(start, index)
|
|
2849
|
+
});
|
|
2850
|
+
}
|
|
2851
|
+
}
|
|
2852
|
+
return groups;
|
|
2853
|
+
}
|
|
2854
|
+
function closingParen(selector, open) {
|
|
2855
|
+
let depth = 0;
|
|
2856
|
+
for (let index = open; index < selector.length; index++) if (selector[index] === "(") depth++;
|
|
2857
|
+
else if (selector[index] === ")" && --depth === 0) return index;
|
|
2858
|
+
return selector.length;
|
|
2859
|
+
}
|
|
2860
|
+
function isWrapperSubject(selector, from) {
|
|
2861
|
+
let depth = 0;
|
|
2862
|
+
for (let index = from; index < selector.length; index++) {
|
|
2863
|
+
const char = selector[index] ?? "";
|
|
2864
|
+
if (char === "(") depth++;
|
|
2865
|
+
else if (char === ")") {
|
|
2866
|
+
if (depth === 0) return true;
|
|
2867
|
+
depth--;
|
|
2868
|
+
} else if (depth > 0) continue;
|
|
2869
|
+
else if (char === ",") return true;
|
|
2870
|
+
else if (COMBINATOR_PATTERN.test(char)) {
|
|
2871
|
+
const next = selector.slice(index).trimStart()[0];
|
|
2872
|
+
if (/\s/u.test(char) && (next === void 0 || next === ")" || next === ",")) continue;
|
|
2873
|
+
return false;
|
|
2874
|
+
}
|
|
2875
|
+
}
|
|
2876
|
+
return true;
|
|
2877
|
+
}
|
|
2878
|
+
function hasCompounds(selector) {
|
|
2879
|
+
const compounds = [];
|
|
2880
|
+
let index = selector.indexOf(":has(");
|
|
2881
|
+
while (index !== -1) {
|
|
2882
|
+
let compound = "";
|
|
2883
|
+
let depth = 0;
|
|
2884
|
+
let subjectEnd = closingParen(selector, index + 4) + 1;
|
|
2885
|
+
let skippingBranch = false;
|
|
2886
|
+
for (let position = index - 1; position >= 0; position--) {
|
|
2887
|
+
const char = selector[position] ?? "";
|
|
2888
|
+
if (char === ")") depth++;
|
|
2889
|
+
else if (char === "(") {
|
|
2890
|
+
if (depth > 0) depth--;
|
|
2891
|
+
else {
|
|
2892
|
+
if (!isWrapperSubject(selector, subjectEnd)) break;
|
|
2893
|
+
skippingBranch = false;
|
|
2894
|
+
subjectEnd = closingParen(selector, position) + 1;
|
|
2895
|
+
}
|
|
2896
|
+
} else if (depth === 0 && char === ",") {
|
|
2897
|
+
skippingBranch = true;
|
|
2898
|
+
continue;
|
|
2899
|
+
} else if (depth === 0 && !skippingBranch && COMBINATOR_PATTERN.test(char)) break;
|
|
2900
|
+
if (!skippingBranch) compound = char + compound;
|
|
2901
|
+
}
|
|
2902
|
+
compounds.push(compound);
|
|
2903
|
+
index = selector.indexOf(":has(", index + 1);
|
|
2904
|
+
}
|
|
2905
|
+
return compounds;
|
|
2906
|
+
}
|
|
2907
|
+
function withoutNegations(compound) {
|
|
2908
|
+
let result = "";
|
|
2909
|
+
let index = 0;
|
|
2910
|
+
while (index < compound.length) {
|
|
2911
|
+
if (!compound.startsWith(":not(", index)) {
|
|
2912
|
+
result += compound[index];
|
|
2913
|
+
index++;
|
|
2914
|
+
continue;
|
|
2915
|
+
}
|
|
2916
|
+
let depth = 0;
|
|
2917
|
+
for (index += 4; index < compound.length; index++) if (compound[index] === "(") depth++;
|
|
2918
|
+
else if (compound[index] === ")" && --depth === 0) break;
|
|
2919
|
+
index++;
|
|
2920
|
+
}
|
|
2921
|
+
return result;
|
|
2922
|
+
}
|
|
2923
|
+
function findUnscopedHasVariants(text) {
|
|
2924
|
+
if (!text.toLowerCase().includes(":has(")) return [];
|
|
2925
|
+
const offenders = [];
|
|
2926
|
+
for (const token of text.split(/\s+/u)) for (const { prefix, group } of variantGroups(token)) {
|
|
2927
|
+
if (ATTRIBUTE_PREFIX_PATTERN.test(prefix)) continue;
|
|
2928
|
+
const relative = group.toLowerCase().replace(QUOTED_PATTERN, "\"\"").replaceAll("_", " ");
|
|
2929
|
+
const owner = GROUP_PREFIX_PATTERN.test(prefix) ? ".group" : ".self";
|
|
2930
|
+
if (hasCompounds(ANCESTOR_PREFIX_PATTERN.test(prefix) ? `:is(${relative.replaceAll("&", "*")}) .self` : relative.includes("&") ? relative.replaceAll("&", owner) : `${owner}:is(${relative})`).some((compound) => {
|
|
2931
|
+
const anchor = withoutNegations(compound);
|
|
2932
|
+
return !NARROWING_PATTERN.test(anchor) || ROOT_COMPOUND_PATTERN.test(anchor);
|
|
2933
|
+
})) offenders.push(`[${group}]`);
|
|
2934
|
+
}
|
|
2935
|
+
return offenders;
|
|
2936
|
+
}
|
|
2937
|
+
var no_unscoped_has_default = defineRule({
|
|
2938
|
+
meta: {
|
|
2939
|
+
type: "problem",
|
|
2940
|
+
docs: { description: "Disallow Tailwind arbitrary variants with a :has() that is not anchored to a class, attribute, id, or tag." }
|
|
2941
|
+
},
|
|
2942
|
+
create(context) {
|
|
2943
|
+
const message = (variant) => `Anchor the :has() in ${variant} to a class, attribute, or tag below the document root, e.g. [&+[data-x]_…] or a has-* variant. Chrome evaluates an unanchored :has() on every ancestor, so any DOM change then restyles the whole page.`;
|
|
2944
|
+
return {
|
|
2945
|
+
Literal(node) {
|
|
2946
|
+
if (typeof node.value !== "string") return;
|
|
2947
|
+
for (const variant of findUnscopedHasVariants(node.value)) context.report({
|
|
2948
|
+
node,
|
|
2949
|
+
message: message(variant)
|
|
2950
|
+
});
|
|
2951
|
+
},
|
|
2952
|
+
TemplateElement(node) {
|
|
2953
|
+
for (const variant of findUnscopedHasVariants(node.value.cooked ?? node.value.raw)) context.report({
|
|
2954
|
+
node,
|
|
2955
|
+
message: message(variant)
|
|
2956
|
+
});
|
|
2957
|
+
}
|
|
2958
|
+
};
|
|
2959
|
+
}
|
|
2960
|
+
});
|
|
2961
|
+
// src/rules/no-untranslated-ui-text.ts
|
|
2962
|
+
const DEFAULT_MESSAGE = "Every user-facing string goes through the message catalogs. Move this text to a catalog and read it from there.";
|
|
2963
|
+
const readMessage = (options) => {
|
|
2964
|
+
const [first] = options;
|
|
2965
|
+
return typeof first === "object" && first !== null && "message" in first && typeof first.message === "string" ? first.message : DEFAULT_MESSAGE;
|
|
2966
|
+
};
|
|
2967
|
+
/** Attributes that users read or hear. */
|
|
2968
|
+
const USER_FACING_ATTRIBUTES = /* @__PURE__ */ new Set([
|
|
2969
|
+
"alt",
|
|
2970
|
+
"aria-description",
|
|
2971
|
+
"aria-label",
|
|
2972
|
+
"aria-placeholder",
|
|
2973
|
+
"aria-roledescription",
|
|
2974
|
+
"aria-valuetext",
|
|
2975
|
+
"label",
|
|
2976
|
+
"placeholder",
|
|
2977
|
+
"title"
|
|
2978
|
+
]);
|
|
2979
|
+
const HAS_LETTER = /\p{L}/u;
|
|
2980
|
+
var no_untranslated_ui_text_default = defineRule({
|
|
2981
|
+
meta: {
|
|
2982
|
+
type: "problem",
|
|
2983
|
+
docs: { description: "Disallow JSX text and user-facing attributes that bypass the i18n catalogs." },
|
|
2984
|
+
schema: [{
|
|
2985
|
+
type: "object",
|
|
2986
|
+
properties: { message: {
|
|
2987
|
+
type: "string",
|
|
2988
|
+
description: "Names the project's catalogs and how to read them, in place of the default."
|
|
2989
|
+
} },
|
|
2990
|
+
additionalProperties: false
|
|
2991
|
+
}]
|
|
2992
|
+
},
|
|
2993
|
+
create(context) {
|
|
2994
|
+
const message = readMessage(context.options);
|
|
2995
|
+
const check = (node, text) => {
|
|
2996
|
+
if (HAS_LETTER.test(text)) context.report({
|
|
2997
|
+
node,
|
|
2998
|
+
message
|
|
2999
|
+
});
|
|
3000
|
+
};
|
|
3001
|
+
return {
|
|
3002
|
+
JSXText(node) {
|
|
3003
|
+
check(node, node.value);
|
|
3004
|
+
},
|
|
3005
|
+
JSXAttribute(node) {
|
|
3006
|
+
if (node.name.type !== "JSXIdentifier" || !USER_FACING_ATTRIBUTES.has(node.name.name)) return;
|
|
3007
|
+
const value = node.value;
|
|
3008
|
+
if (value?.type === "Literal" && typeof value.value === "string") check(value, value.value);
|
|
3009
|
+
if (value?.type === "JSXExpressionContainer" && value.expression.type === "Literal" && typeof value.expression.value === "string") check(value.expression, value.expression.value);
|
|
3010
|
+
}
|
|
3011
|
+
};
|
|
3012
|
+
}
|
|
3013
|
+
});
|
|
3014
|
+
// src/rules/no-wall-clock-in-tests.ts
|
|
3015
|
+
const TEST_FILE_PATTERN = /\.(?:test|spec)\.[cm]?[jt]sx?$/u;
|
|
3016
|
+
const WALL_CLOCK_CALLS = /* @__PURE__ */ new Set([
|
|
3017
|
+
"Date.now",
|
|
3018
|
+
"performance.now",
|
|
3019
|
+
"process.hrtime",
|
|
3020
|
+
"process.hrtime.bigint"
|
|
3021
|
+
]);
|
|
3022
|
+
const VI_MOCKING_FUNCTIONS = /* @__PURE__ */ new Set([
|
|
3023
|
+
"fn",
|
|
3024
|
+
"mock",
|
|
3025
|
+
"setSystemTime",
|
|
3026
|
+
"spyOn"
|
|
3027
|
+
]);
|
|
3028
|
+
const MOCK_METHODS = /* @__PURE__ */ new Set([
|
|
3029
|
+
"mockImplementation",
|
|
3030
|
+
"mockImplementationOnce",
|
|
3031
|
+
"mockResolvedValue",
|
|
3032
|
+
"mockResolvedValueOnce",
|
|
3033
|
+
"mockReturnValue",
|
|
3034
|
+
"mockReturnValueOnce"
|
|
3035
|
+
]);
|
|
3036
|
+
const MESSAGE$1 = "Wall-clock reading in a test; elapsed-time assertions pass or fail with runner load. Use TestClock/`Clock` under `it.effect`, `vi.setSystemTime`, or a fixed epoch. Benchmarks live behind an env gate.";
|
|
3037
|
+
const isStringLiteral = (node) => exists(unwrapExpression(node), (expression) => expression.type === "Literal" && typeof expression.value === "string");
|
|
3038
|
+
const memberPath = (node) => {
|
|
3039
|
+
const expression = unwrapExpression(node);
|
|
3040
|
+
if (isNone(expression)) return none();
|
|
3041
|
+
if (expression.value.type === "Identifier") return some([expression.value.name]);
|
|
3042
|
+
if (expression.value.type !== "MemberExpression") return none();
|
|
3043
|
+
if (expression.value.computed && !isStringLiteral(expression.value.property)) return none();
|
|
3044
|
+
const property = getPropertyName(expression.value.property);
|
|
3045
|
+
if (isNone(property)) return none();
|
|
3046
|
+
return map(memberPath(expression.value.object), (path) => [...path, property.value]);
|
|
3047
|
+
};
|
|
3048
|
+
const isWallClockCall = (callee) => match(memberPath(callee), {
|
|
3049
|
+
onNone: () => false,
|
|
3050
|
+
onSome: (path) => WALL_CLOCK_CALLS.has(path.join("."))
|
|
3051
|
+
});
|
|
3052
|
+
const isMockingCall = (callee) => {
|
|
3053
|
+
const expression = unwrapExpression(callee);
|
|
3054
|
+
if (isNone(expression) || expression.value.type !== "MemberExpression") return false;
|
|
3055
|
+
const property = getPropertyName(expression.value.property);
|
|
3056
|
+
if (isNone(property)) return false;
|
|
3057
|
+
if (MOCK_METHODS.has(property.value)) return true;
|
|
3058
|
+
return VI_MOCKING_FUNCTIONS.has(property.value) && isIdentifier(unwrapExpression(expression.value.object), "vi");
|
|
3059
|
+
};
|
|
3060
|
+
const isMockArgument = (node) => {
|
|
3061
|
+
let child = node;
|
|
3062
|
+
let current = node.parent;
|
|
3063
|
+
while (current) {
|
|
3064
|
+
if (current.type === "CallExpression" && current.callee !== child && isMockingCall(current.callee)) return true;
|
|
3065
|
+
child = current;
|
|
3066
|
+
current = current.parent;
|
|
3067
|
+
}
|
|
3068
|
+
return false;
|
|
3069
|
+
};
|
|
3070
|
+
var no_wall_clock_in_tests_default = defineRule({
|
|
3071
|
+
meta: {
|
|
3072
|
+
type: "problem",
|
|
3073
|
+
docs: { description: "Disallow wall-clock readings (Date.now, new Date(), performance.now, process.hrtime) in tests." }
|
|
3074
|
+
},
|
|
3075
|
+
create(context) {
|
|
3076
|
+
if (!TEST_FILE_PATTERN.test(context.filename)) return {};
|
|
3077
|
+
return {
|
|
3078
|
+
CallExpression(node) {
|
|
3079
|
+
if (!isWallClockCall(node.callee)) return;
|
|
3080
|
+
if (isMockArgument(node)) return;
|
|
3081
|
+
context.report({
|
|
3082
|
+
node,
|
|
3083
|
+
message: MESSAGE$1
|
|
3084
|
+
});
|
|
3085
|
+
},
|
|
3086
|
+
NewExpression(node) {
|
|
3087
|
+
if (node.arguments.length > 0) return;
|
|
3088
|
+
if (!isIdentifier(unwrapExpression(node.callee), "Date")) return;
|
|
3089
|
+
if (isMockArgument(node)) return;
|
|
3090
|
+
context.report({
|
|
3091
|
+
node,
|
|
3092
|
+
message: MESSAGE$1
|
|
3093
|
+
});
|
|
3094
|
+
}
|
|
3095
|
+
};
|
|
3096
|
+
}
|
|
3097
|
+
});
|
|
3098
|
+
// src/rules/prefer-catch-tags.ts
|
|
3099
|
+
const MESSAGE = "Catch known tags with `Effect.catchTags({ Tag: handler })`, even for one tag.";
|
|
3100
|
+
var prefer_catch_tags_default = defineRule({
|
|
3101
|
+
meta: {
|
|
3102
|
+
type: "suggestion",
|
|
3103
|
+
docs: { description: "Require `Effect.catchTags` over `Effect.catchTag`." }
|
|
3104
|
+
},
|
|
3105
|
+
create(context) {
|
|
3106
|
+
const isEffectNamespace = (identifier) => {
|
|
3107
|
+
let scope = context.sourceCode.getScope(identifier);
|
|
3108
|
+
while (true) {
|
|
3109
|
+
const variable = scope.set.get(identifier.name);
|
|
3110
|
+
if (variable !== void 0) return variable.defs.some((def) => def.type === "ImportBinding" && def.node.type === "ImportNamespaceSpecifier" && def.parent?.type === "ImportDeclaration" && def.parent.source.value === "effect/Effect");
|
|
3111
|
+
if (scope.upper === null) return false;
|
|
3112
|
+
scope = scope.upper;
|
|
3113
|
+
}
|
|
3114
|
+
};
|
|
3115
|
+
return {
|
|
3116
|
+
ImportDeclaration(node) {
|
|
3117
|
+
if (node.source.value !== "effect/Effect") return;
|
|
3118
|
+
for (const specifier of node.specifiers) if (specifier.type === "ImportSpecifier" && (specifier.imported.type === "Identifier" ? specifier.imported.name : specifier.imported.value) === "catchTag") context.report({
|
|
3119
|
+
node: specifier,
|
|
3120
|
+
message: MESSAGE
|
|
3121
|
+
});
|
|
3122
|
+
},
|
|
3123
|
+
MemberExpression(node) {
|
|
3124
|
+
if (!node.computed && node.object.type === "Identifier" && node.property.type === "Identifier" && node.property.name === "catchTag" && isEffectNamespace(node.object)) context.report({
|
|
3125
|
+
node,
|
|
3126
|
+
message: MESSAGE
|
|
3127
|
+
});
|
|
3128
|
+
}
|
|
3129
|
+
};
|
|
3130
|
+
}
|
|
3131
|
+
});
|
|
3132
|
+
// src/rules/prefer-effect-fn.ts
|
|
3133
|
+
var prefer_effect_fn_default = defineRule({
|
|
3134
|
+
meta: {
|
|
3135
|
+
type: "suggestion",
|
|
3136
|
+
docs: { description: "Use Effect.fn for reusable generator-based Effect functions." }
|
|
3137
|
+
},
|
|
3138
|
+
create(context) {
|
|
3139
|
+
const isEffectImport = (identifier, member) => {
|
|
3140
|
+
let scope = context.sourceCode.getScope(identifier);
|
|
3141
|
+
while (true) {
|
|
3142
|
+
const variable = scope.set.get(identifier.name);
|
|
3143
|
+
if (variable !== void 0) return variable.defs.some((def) => {
|
|
3144
|
+
if (def.type !== "ImportBinding" || def.parent?.type !== "ImportDeclaration") return false;
|
|
3145
|
+
const source = def.parent.source.value;
|
|
3146
|
+
if (source === "effect/Effect") {
|
|
3147
|
+
if (member === "") return def.node.type === "ImportSpecifier" && (def.node.imported.type === "Identifier" ? def.node.imported.name : def.node.imported.value) === "gen";
|
|
3148
|
+
return def.node.type === "ImportNamespaceSpecifier";
|
|
3149
|
+
}
|
|
3150
|
+
return source === "effect" && def.node.type === "ImportSpecifier" && (def.node.imported.type === "Identifier" ? def.node.imported.name : def.node.imported.value) === "Effect";
|
|
3151
|
+
});
|
|
3152
|
+
if (scope.upper === null) return false;
|
|
3153
|
+
scope = scope.upper;
|
|
3154
|
+
}
|
|
3155
|
+
};
|
|
3156
|
+
const isGeneratorCall = (expression) => {
|
|
3157
|
+
if (expression.type !== "CallExpression") return false;
|
|
3158
|
+
const callee = expression.callee;
|
|
3159
|
+
if (callee.type === "Identifier") return isEffectImport(callee, "");
|
|
3160
|
+
if (callee.type !== "MemberExpression" || callee.computed) return false;
|
|
3161
|
+
if (callee.property.type !== "Identifier") return false;
|
|
3162
|
+
if (callee.property.name === "pipe") return isGeneratorCall(callee.object);
|
|
3163
|
+
return callee.property.name === "gen" && callee.object.type === "Identifier" && isEffectImport(callee.object, "gen");
|
|
3164
|
+
};
|
|
3165
|
+
const check = (node) => {
|
|
3166
|
+
if (node.async || node.generator) return;
|
|
3167
|
+
const parent = node.parent;
|
|
3168
|
+
if (node.type !== "FunctionDeclaration") {
|
|
3169
|
+
if (parent.type === "MethodDefinition") {
|
|
3170
|
+
if (parent.kind !== "method") return;
|
|
3171
|
+
} else if (parent.type === "Property") {
|
|
3172
|
+
if (parent.kind !== "init") return;
|
|
3173
|
+
const name = parent.key.type === "Identifier" ? parent.key.name : parent.key.type === "Literal" ? parent.key.value : void 0;
|
|
3174
|
+
const call = parent.parent.parent;
|
|
3175
|
+
if (call?.type === "CallExpression") {
|
|
3176
|
+
let callee = call.callee;
|
|
3177
|
+
while (callee.type === "CallExpression") callee = callee.callee;
|
|
3178
|
+
if (callee.type === "MemberExpression" && callee.property.type === "Identifier") {
|
|
3179
|
+
if ([
|
|
3180
|
+
"catchTags",
|
|
3181
|
+
"match",
|
|
3182
|
+
"matchEffect",
|
|
3183
|
+
"matchCauseEffect"
|
|
3184
|
+
].includes(callee.property.name) || name === "defaultValue" && callee.property.name === "Reference") return;
|
|
3185
|
+
}
|
|
3186
|
+
}
|
|
3187
|
+
} else if (parent.type !== "VariableDeclarator" && parent.type !== "PropertyDefinition") return;
|
|
3188
|
+
}
|
|
3189
|
+
const body = node.body;
|
|
3190
|
+
if (body === null) return;
|
|
3191
|
+
let expression;
|
|
3192
|
+
if (body.type === "BlockStatement") {
|
|
3193
|
+
if (body.body.length !== 1 || body.body[0]?.type !== "ReturnStatement") return;
|
|
3194
|
+
expression = body.body[0].argument;
|
|
3195
|
+
} else expression = body;
|
|
3196
|
+
if (expression === null || !isGeneratorCall(expression)) return;
|
|
3197
|
+
context.report({
|
|
3198
|
+
node,
|
|
3199
|
+
message: "Use Effect.fn(\"Service.operation\") for reusable Effect functions. Reserve Effect.fnUntraced for documented hot paths or an existing span; keep Effect.gen for inline programs."
|
|
3200
|
+
});
|
|
3201
|
+
};
|
|
3202
|
+
return {
|
|
3203
|
+
ArrowFunctionExpression: check,
|
|
3204
|
+
FunctionExpression: check,
|
|
3205
|
+
FunctionDeclaration: check
|
|
3206
|
+
};
|
|
3207
|
+
}
|
|
3208
|
+
});
|
|
3209
|
+
// src/rules/require-suppression-reason.ts
|
|
3210
|
+
const DIRECTIVE_PATTERN = /^\s*\*?\s*(?:(?:oxlint|eslint)-(?:disable|enable)|@ts-(?:expect-error|ignore|nocheck)|@effect-diagnostics)/u;
|
|
3211
|
+
const TS_DIRECTIVE_PATTERN = /^\s*\*?\s*@ts-(?:expect-error|ignore|nocheck)(?![\w-])(.*)$/su;
|
|
3212
|
+
const EMPTY_COMMENT_PATTERN = /^[\s*]*$/u;
|
|
3213
|
+
// src/index.ts
|
|
3214
|
+
var src_default = definePlugin({
|
|
3215
|
+
meta: { name: "jandragsbaek" },
|
|
3216
|
+
rules: {
|
|
3217
|
+
"namespace-node-imports": namespace_node_imports_default,
|
|
3218
|
+
"no-dom-test-environment": no_dom_test_environment_default,
|
|
3219
|
+
"no-em-dash-copy": no_em_dash_copy_default,
|
|
3220
|
+
"no-hookless-use-function": no_hookless_use_function_default,
|
|
3221
|
+
"no-inline-schema-compile": no_inline_schema_compile_default,
|
|
3222
|
+
"no-low-value-comments": no_low_value_comments_default,
|
|
3223
|
+
"no-manual-effect-runtime-in-tests": no_manual_effect_runtime_in_tests_default,
|
|
3224
|
+
"no-manual-memo": no_manual_memo_default,
|
|
3225
|
+
"no-polling-loop-in-tests": no_polling_loop_in_tests_default,
|
|
3226
|
+
"no-real-time-wait-in-tests": no_real_time_wait_in_tests_default,
|
|
3227
|
+
"no-test-in-loop": no_test_in_loop_default,
|
|
3228
|
+
"no-test-timeout-or-unreasoned-skip": no_test_timeout_or_unreasoned_skip_default,
|
|
3229
|
+
"no-unreasoned-state-sync": no_unreasoned_state_sync_default,
|
|
3230
|
+
"no-unscoped-has": no_unscoped_has_default,
|
|
3231
|
+
"no-untranslated-ui-text": no_untranslated_ui_text_default,
|
|
3232
|
+
"no-wall-clock-in-tests": no_wall_clock_in_tests_default,
|
|
3233
|
+
"prefer-catch-tags": prefer_catch_tags_default,
|
|
3234
|
+
"prefer-effect-fn": prefer_effect_fn_default,
|
|
3235
|
+
"require-suppression-reason": defineRule({
|
|
3236
|
+
meta: {
|
|
3237
|
+
type: "suggestion",
|
|
3238
|
+
docs: { description: "Require every lint or type-checker suppression to say why." }
|
|
3239
|
+
},
|
|
3240
|
+
create(context) {
|
|
3241
|
+
const { sourceCode } = context;
|
|
3242
|
+
return { Program() {
|
|
3243
|
+
const comments = sourceCode.getAllComments();
|
|
3244
|
+
const ownLineCommentsByEndLine = /* @__PURE__ */ new Map();
|
|
3245
|
+
for (const comment of comments) {
|
|
3246
|
+
const { line, column } = comment.loc.start;
|
|
3247
|
+
if ((sourceCode.lines[line - 1] ?? "").slice(0, column).trim() === "") ownLineCommentsByEndLine.set(comment.loc.end.line, comment);
|
|
3248
|
+
}
|
|
3249
|
+
const explainedAbove = (directive) => {
|
|
3250
|
+
let above = ownLineCommentsByEndLine.get(directive.loc.start.line - 1);
|
|
3251
|
+
while (above && (DIRECTIVE_PATTERN.test(above.value) || EMPTY_COMMENT_PATTERN.test(above.value))) above = ownLineCommentsByEndLine.get(above.loc.start.line - 1);
|
|
3252
|
+
return above !== void 0;
|
|
3253
|
+
};
|
|
3254
|
+
for (const directive of sourceCode.getDisableDirectives().directives) {
|
|
3255
|
+
if (directive.type === "enable" || directive.justification?.trim()) continue;
|
|
3256
|
+
if (explainedAbove(directive.node)) continue;
|
|
3257
|
+
context.report({
|
|
3258
|
+
loc: directive.node.loc,
|
|
3259
|
+
message: "Say why: end the directive with `-- reason` or put a comment on the line above."
|
|
3260
|
+
});
|
|
3261
|
+
}
|
|
3262
|
+
for (const comment of comments) {
|
|
3263
|
+
const after = TS_DIRECTIVE_PATTERN.exec(comment.value)?.[1];
|
|
3264
|
+
if (after === void 0 || after.replace(/^[\s:-]+/u, "").trim()) continue;
|
|
3265
|
+
if (explainedAbove(comment)) continue;
|
|
3266
|
+
context.report({
|
|
3267
|
+
loc: comment.loc,
|
|
3268
|
+
message: "Say why: write the reason after the directive or in a comment on the line above."
|
|
3269
|
+
});
|
|
3270
|
+
}
|
|
3271
|
+
} };
|
|
3272
|
+
}
|
|
3273
|
+
})
|
|
3274
|
+
}
|
|
3275
|
+
});
|
|
3276
|
+
export { src_default as default };
|