@systemfsoftware/oxlint-plugin-effect-platform 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +203 -0
- package/README.md +114 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.mjs +1061 -0
- package/dist/oxlint-plugin-effect-entrypoint-untrimmed.d.ts +24 -0
- package/dist/oxlint-plugin-effect-entrypoint.d.ts +24 -0
- package/dist/oxlint-plugin-effect-platform-untrimmed.d.ts +32 -0
- package/dist/oxlint-plugin-effect-platform.d.ts +32 -0
- package/package.json +87 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,1061 @@
|
|
|
1
|
+
import { defineRule } from "@oxlint/plugins";
|
|
2
|
+
import { Effect, Schema } from "effect";
|
|
3
|
+
//#region src/rules/entrypoint-interprets-once.config.ts
|
|
4
|
+
const Options$6 = Schema.Struct({});
|
|
5
|
+
const ENTRYPOINT_FILE$2 = /(?:^|[\\/])main\.ts$/u;
|
|
6
|
+
const RUN_MAIN$1 = "runMain";
|
|
7
|
+
const QUALIFIED_EDGE_CALLEES = /* @__PURE__ */ new Set([
|
|
8
|
+
"Effect.runPromise",
|
|
9
|
+
"Effect.runPromiseExit",
|
|
10
|
+
"Effect.runSync",
|
|
11
|
+
"Effect.runSyncExit",
|
|
12
|
+
"Effect.runFork",
|
|
13
|
+
"Effect.runCallback",
|
|
14
|
+
"ManagedRuntime.make",
|
|
15
|
+
"Layer.toRuntime"
|
|
16
|
+
]);
|
|
17
|
+
const MISSING_EDGE_NAME = "an entrypoint that interprets nothing";
|
|
18
|
+
const MISSING_EDGE_EXPECTED = "exactly one interpretation edge - runMain, ManagedRuntime.make, Layer.toRuntime, or a top-level Effect.run*";
|
|
19
|
+
const MISSING_EDGE_ACTUAL = "a main.ts containing no interpretation edge";
|
|
20
|
+
const MISSING_EDGE_FIX = "interpret the program here - runMain for a terminating process, Layer.launch inside runMain for one that never returns, ManagedRuntime.make for a promise-native host; a main.ts that interprets nothing is a module wearing the entrypoint name";
|
|
21
|
+
const MULTIPLE_EDGES_EXPECTED = "exactly one interpretation edge in the entrypoint";
|
|
22
|
+
const MULTIPLE_EDGES_ACTUAL = "a second interpretation edge in the same entrypoint";
|
|
23
|
+
const MULTIPLE_EDGES_FIX = "collapse the program into one Effect and interpret it once; a second edge starts fibers the outer edge cannot interrupt and whose finalizers it never runs";
|
|
24
|
+
const INTERPRETS_ONCE_MESSAGE = "{{name}} is forbidden. Expected: {{expected}}. Actual: {{actual}}. Fix: {{fix}}.";
|
|
25
|
+
const meta$8 = {
|
|
26
|
+
type: "problem",
|
|
27
|
+
docs: { description: "Require exactly one interpretation edge in main.ts. An Effect value is a description; the entrypoint is the single place it is interpreted. Zero edges means the file is a module wearing the entrypoint name; two means the outer edge cannot interrupt or finalize the fibers the inner one started." },
|
|
28
|
+
schema: [Options$6],
|
|
29
|
+
messages: {
|
|
30
|
+
missingEdge: INTERPRETS_ONCE_MESSAGE,
|
|
31
|
+
multipleEdges: INTERPRETS_ONCE_MESSAGE
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
//#endregion
|
|
35
|
+
//#region src/rules/entrypoint-interprets-once.ts
|
|
36
|
+
const isEntrypointFile$2 = (filename) => ENTRYPOINT_FILE$2.test(filename);
|
|
37
|
+
const edgeName = (callee) => {
|
|
38
|
+
if (callee.type === "Identifier") return callee.name === "runMain" ? RUN_MAIN$1 : null;
|
|
39
|
+
if (callee.type !== "MemberExpression") return null;
|
|
40
|
+
if (callee.computed) return null;
|
|
41
|
+
const property = callee.property;
|
|
42
|
+
if (property.type !== "Identifier") return null;
|
|
43
|
+
const object = callee.object;
|
|
44
|
+
if (object.type !== "Identifier") return property.name === "runMain" ? property.name : null;
|
|
45
|
+
const qualified = `${object.name}.${property.name}`;
|
|
46
|
+
if (property.name === "runMain") return qualified;
|
|
47
|
+
return QUALIFIED_EDGE_CALLEES.has(qualified) ? qualified : null;
|
|
48
|
+
};
|
|
49
|
+
const entrypointInterpretsOnce = defineRule({
|
|
50
|
+
meta: meta$8,
|
|
51
|
+
create(context) {
|
|
52
|
+
if (!isEntrypointFile$2(context.filename)) return {};
|
|
53
|
+
const edges = [];
|
|
54
|
+
return {
|
|
55
|
+
CallExpression(node) {
|
|
56
|
+
const name = edgeName(node.callee);
|
|
57
|
+
if (name !== null) edges.push({
|
|
58
|
+
node,
|
|
59
|
+
name
|
|
60
|
+
});
|
|
61
|
+
},
|
|
62
|
+
"Program:exit"(node) {
|
|
63
|
+
if (edges.length === 0) {
|
|
64
|
+
context.report({
|
|
65
|
+
node,
|
|
66
|
+
messageId: "missingEdge",
|
|
67
|
+
data: {
|
|
68
|
+
name: MISSING_EDGE_NAME,
|
|
69
|
+
expected: MISSING_EDGE_EXPECTED,
|
|
70
|
+
actual: MISSING_EDGE_ACTUAL,
|
|
71
|
+
fix: MISSING_EDGE_FIX
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
if (edges.length === 1) return;
|
|
77
|
+
for (const edge of edges) context.report({
|
|
78
|
+
node: edge.node,
|
|
79
|
+
messageId: "multipleEdges",
|
|
80
|
+
data: {
|
|
81
|
+
name: edge.name,
|
|
82
|
+
expected: MULTIPLE_EDGES_EXPECTED,
|
|
83
|
+
actual: MULTIPLE_EDGES_ACTUAL,
|
|
84
|
+
fix: MULTIPLE_EDGES_FIX
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
//#endregion
|
|
92
|
+
//#region src/rules/entrypoint-no-exports.config.ts
|
|
93
|
+
const Options$5 = Schema.Struct({});
|
|
94
|
+
const ENTRYPOINT_FILE$1 = /(?:^|[\\/])main\.ts$/u;
|
|
95
|
+
const NAMED_EXPORT = "a named export from main.ts";
|
|
96
|
+
const DEFAULT_EXPORT = "a default export from main.ts";
|
|
97
|
+
const STAR_EXPORT = "a re-export from main.ts";
|
|
98
|
+
const ENTRYPOINT_EXPORT_EXPECTED = "an entrypoint with no public surface at all";
|
|
99
|
+
const ENTRYPOINT_EXPORT_ACTUAL = "an entrypoint exporting a binding for another module to import";
|
|
100
|
+
const ENTRYPOINT_EXPORT_FIX = "nothing may import main.ts, so an export here is dead weight - move the binding to the cell that owns it (executor, adapter, layer) and leave main.ts holding only the interpretation edge";
|
|
101
|
+
const meta$7 = {
|
|
102
|
+
type: "problem",
|
|
103
|
+
docs: { description: "Ban every export from main.ts. An entrypoint is interpreted, never imported, so an exported binding proves the file is a library wearing the entrypoint name - the exemption that lets a junk drawer grow behind a sanctioned filename." },
|
|
104
|
+
schema: [Options$5],
|
|
105
|
+
messages: { entrypointExport: "{{name}} is forbidden. Expected: {{expected}}. Actual: {{actual}}. Fix: {{fix}}." }
|
|
106
|
+
};
|
|
107
|
+
//#endregion
|
|
108
|
+
//#region src/rules/entrypoint-no-exports.ts
|
|
109
|
+
const isEntrypointFile$1 = (filename) => ENTRYPOINT_FILE$1.test(filename);
|
|
110
|
+
const entrypointNoExports = defineRule({
|
|
111
|
+
meta: meta$7,
|
|
112
|
+
create(context) {
|
|
113
|
+
if (!isEntrypointFile$1(context.filename)) return {};
|
|
114
|
+
const reportExport = (node, name) => {
|
|
115
|
+
context.report({
|
|
116
|
+
node,
|
|
117
|
+
messageId: "entrypointExport",
|
|
118
|
+
data: {
|
|
119
|
+
name,
|
|
120
|
+
expected: ENTRYPOINT_EXPORT_EXPECTED,
|
|
121
|
+
actual: ENTRYPOINT_EXPORT_ACTUAL,
|
|
122
|
+
fix: ENTRYPOINT_EXPORT_FIX
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
};
|
|
126
|
+
return {
|
|
127
|
+
ExportNamedDeclaration(node) {
|
|
128
|
+
reportExport(node, NAMED_EXPORT);
|
|
129
|
+
},
|
|
130
|
+
ExportDefaultDeclaration(node) {
|
|
131
|
+
reportExport(node, DEFAULT_EXPORT);
|
|
132
|
+
},
|
|
133
|
+
ExportAllDeclaration(node) {
|
|
134
|
+
reportExport(node, STAR_EXPORT);
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
//#endregion
|
|
140
|
+
//#region src/rules/entrypoint-no-promise-wrapper.config.ts
|
|
141
|
+
const Options$4 = Schema.Struct({});
|
|
142
|
+
const ENTRYPOINT_FILE = /(?:^|[\\/])main\.ts$/u;
|
|
143
|
+
const RUN_MAIN = "runMain";
|
|
144
|
+
const PROMISE_CONSTRUCTORS = /* @__PURE__ */ new Set(["Effect.promise", "Effect.tryPromise"]);
|
|
145
|
+
const PROMISE_WRAPPER_EXPECTED = "the program itself handed to runMain";
|
|
146
|
+
const PROMISE_WRAPPER_ACTUAL = "a foreign promise wrapped in an Effect and handed to runMain";
|
|
147
|
+
const PROMISE_WRAPPER_FIX = "the awaited framework starts its own fibers, so runMain interrupts nothing and runs none of their finalizers - either let the framework own the loop and drop runMain, or build the program as one Effect and interpret that";
|
|
148
|
+
const meta$6 = {
|
|
149
|
+
type: "problem",
|
|
150
|
+
docs: { description: "Ban runMain wrapping a bare Effect.promise or Effect.tryPromise in main.ts. The outer edge only awaits a promise: the fibers doing the work belong to a runtime inside it, beyond reach of the interrupt handling and teardown runMain exists to provide." },
|
|
151
|
+
schema: [Options$4],
|
|
152
|
+
messages: { promiseWrapper: "{{name}} is forbidden. Expected: {{expected}}. Actual: {{actual}}. Fix: {{fix}}." }
|
|
153
|
+
};
|
|
154
|
+
//#endregion
|
|
155
|
+
//#region src/rules/entrypoint-no-promise-wrapper.ts
|
|
156
|
+
const isEntrypointFile = (filename) => ENTRYPOINT_FILE.test(filename);
|
|
157
|
+
const isRunMainCallee = (callee) => {
|
|
158
|
+
if (callee.type === "Identifier") return callee.name === RUN_MAIN;
|
|
159
|
+
if (callee.type !== "MemberExpression") return false;
|
|
160
|
+
if (callee.computed) return false;
|
|
161
|
+
const property = callee.property;
|
|
162
|
+
return property.type === "Identifier" && property.name === "runMain";
|
|
163
|
+
};
|
|
164
|
+
const promiseConstructorName = (node) => {
|
|
165
|
+
if (node.type !== "CallExpression") return null;
|
|
166
|
+
const callee = node.callee;
|
|
167
|
+
if (callee.type !== "MemberExpression") return null;
|
|
168
|
+
if (callee.computed) return null;
|
|
169
|
+
const object = callee.object;
|
|
170
|
+
const property = callee.property;
|
|
171
|
+
if (object.type !== "Identifier") return null;
|
|
172
|
+
if (property.type !== "Identifier") return null;
|
|
173
|
+
const qualified = `${object.name}.${property.name}`;
|
|
174
|
+
return PROMISE_CONSTRUCTORS.has(qualified) ? qualified : null;
|
|
175
|
+
};
|
|
176
|
+
const entrypointNoPromiseWrapper = defineRule({
|
|
177
|
+
meta: meta$6,
|
|
178
|
+
create(context) {
|
|
179
|
+
if (!isEntrypointFile(context.filename)) return {};
|
|
180
|
+
return { CallExpression(node) {
|
|
181
|
+
if (!isRunMainCallee(node.callee)) return;
|
|
182
|
+
const [first] = node.arguments;
|
|
183
|
+
if (first === void 0) return;
|
|
184
|
+
const name = promiseConstructorName(first);
|
|
185
|
+
if (name === null) return;
|
|
186
|
+
context.report({
|
|
187
|
+
node: first,
|
|
188
|
+
messageId: "promiseWrapper",
|
|
189
|
+
data: {
|
|
190
|
+
name,
|
|
191
|
+
expected: PROMISE_WRAPPER_EXPECTED,
|
|
192
|
+
actual: PROMISE_WRAPPER_ACTUAL,
|
|
193
|
+
fix: PROMISE_WRAPPER_FIX
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
} };
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
//#endregion
|
|
200
|
+
//#region src/rules/entrypoint-not-imported.config.ts
|
|
201
|
+
const Options$3 = Schema.Struct({});
|
|
202
|
+
const MAIN_MODULE_SOURCE = /(?:^|\/)main(?:\.[cm]?[jt]sx?)?$/u;
|
|
203
|
+
const ENTRYPOINT_IMPORT_EXPECTED = "the entrypoint imported by nothing - the process interprets it, no module consumes it";
|
|
204
|
+
const ENTRYPOINT_IMPORT_ACTUAL = "an import of main.ts";
|
|
205
|
+
const ENTRYPOINT_IMPORT_FIX = "import the cell that owns the binding instead; if main.ts is the only place it exists, it was never an entrypoint - move the behavior into an executor, adapter, or layer and leave main.ts holding only the interpretation edge";
|
|
206
|
+
//#endregion
|
|
207
|
+
//#region src/rules/entrypoint-not-imported.ts
|
|
208
|
+
const entrypointNotImported = defineRule({
|
|
209
|
+
meta: {
|
|
210
|
+
type: "problem",
|
|
211
|
+
docs: { description: "Ban every import of a main module. An entrypoint is a process edge, not a module surface; an importer proves main.ts is carrying behavior that belongs in a cell, and turns the entrypoint into a second, unreachable interpretation site." },
|
|
212
|
+
schema: [Options$3],
|
|
213
|
+
messages: { entrypointImport: "{{name}} is forbidden. Expected: {{expected}}. Actual: {{actual}}. Fix: {{fix}}." }
|
|
214
|
+
},
|
|
215
|
+
create(context) {
|
|
216
|
+
const reportSource = (node, source) => {
|
|
217
|
+
if (!MAIN_MODULE_SOURCE.test(source)) return;
|
|
218
|
+
context.report({
|
|
219
|
+
node,
|
|
220
|
+
messageId: "entrypointImport",
|
|
221
|
+
data: {
|
|
222
|
+
name: source,
|
|
223
|
+
expected: ENTRYPOINT_IMPORT_EXPECTED,
|
|
224
|
+
actual: ENTRYPOINT_IMPORT_ACTUAL,
|
|
225
|
+
fix: ENTRYPOINT_IMPORT_FIX
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
};
|
|
229
|
+
return {
|
|
230
|
+
ImportDeclaration(node) {
|
|
231
|
+
reportSource(node, node.source.value);
|
|
232
|
+
},
|
|
233
|
+
ExportNamedDeclaration(node) {
|
|
234
|
+
if (node.source === null) return;
|
|
235
|
+
reportSource(node, node.source.value);
|
|
236
|
+
},
|
|
237
|
+
ExportAllDeclaration(node) {
|
|
238
|
+
reportSource(node, node.source.value);
|
|
239
|
+
},
|
|
240
|
+
ImportExpression(node) {
|
|
241
|
+
if (node.source.type !== "Literal") return;
|
|
242
|
+
if (typeof node.source.value !== "string") return;
|
|
243
|
+
reportSource(node, node.source.value);
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
const CATCH_METHODS = /* @__PURE__ */ new Set([
|
|
249
|
+
"catch",
|
|
250
|
+
"catchCause",
|
|
251
|
+
"catchCauseFilter",
|
|
252
|
+
"catchCauseIf",
|
|
253
|
+
"catchDefect",
|
|
254
|
+
"catchEager",
|
|
255
|
+
"catchFilter",
|
|
256
|
+
"catchIf",
|
|
257
|
+
"catchNoSuchElement",
|
|
258
|
+
"catchReason",
|
|
259
|
+
"catchReasons",
|
|
260
|
+
"catchTag",
|
|
261
|
+
"catchTags",
|
|
262
|
+
"orElseSucceed"
|
|
263
|
+
]);
|
|
264
|
+
const EFFECT_LOG_METHODS = /* @__PURE__ */ new Set([
|
|
265
|
+
"log",
|
|
266
|
+
"logDebug",
|
|
267
|
+
"logError",
|
|
268
|
+
"logFatal",
|
|
269
|
+
"logWarning",
|
|
270
|
+
"logInfo",
|
|
271
|
+
"logTrace",
|
|
272
|
+
"logWithLevel"
|
|
273
|
+
]);
|
|
274
|
+
const CONSOLE_LOG_METHODS = /* @__PURE__ */ new Set([
|
|
275
|
+
"log",
|
|
276
|
+
"error",
|
|
277
|
+
"warn",
|
|
278
|
+
"info",
|
|
279
|
+
"debug"
|
|
280
|
+
]);
|
|
281
|
+
//#endregion
|
|
282
|
+
//#region src/rules/no-logging-in-catch.ts
|
|
283
|
+
const noLoggingInCatch = defineRule({
|
|
284
|
+
meta: {
|
|
285
|
+
type: "suggestion",
|
|
286
|
+
docs: { description: "Prevents logging inside Effect catch blocks. Use Effect.tapError or logging outside catch instead." },
|
|
287
|
+
schema: [],
|
|
288
|
+
messages: { noLoggingInCatch: "{{name}} is forbidden inside {{catchMethod}}. Expected: {{expected}}. Actual: {{actual}}. Fix: {{fix}}." }
|
|
289
|
+
},
|
|
290
|
+
create(context) {
|
|
291
|
+
const trackedEffectImports = /* @__PURE__ */ new Set();
|
|
292
|
+
const catchMethodStack = [];
|
|
293
|
+
const activeCatchCallbacks = /* @__PURE__ */ new WeakSet();
|
|
294
|
+
const getCatchMethodName = (node) => {
|
|
295
|
+
const { callee } = node;
|
|
296
|
+
if (callee.type === "MemberExpression" && callee.property.type === "Identifier" && CATCH_METHODS.has(callee.property.name)) return callee.property.name;
|
|
297
|
+
return null;
|
|
298
|
+
};
|
|
299
|
+
const reportViolation = (node, loggingMethod, catchMethod) => {
|
|
300
|
+
context.report({
|
|
301
|
+
node,
|
|
302
|
+
messageId: "noLoggingInCatch",
|
|
303
|
+
data: {
|
|
304
|
+
name: loggingMethod,
|
|
305
|
+
catchMethod,
|
|
306
|
+
expected: "Use Effect.tapError, Effect.tap, or logging outside the catch block",
|
|
307
|
+
actual: `${loggingMethod} inside ${catchMethod}`,
|
|
308
|
+
fix: "Move logging to Effect.tapError before the catch, or handle error recovery without side effects in catch"
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
};
|
|
312
|
+
const enterCatchCallback = (node) => {
|
|
313
|
+
if (trackedEffectImports.size === 0) return;
|
|
314
|
+
if (node.parent.type !== "CallExpression") return;
|
|
315
|
+
const callExpr = node.parent;
|
|
316
|
+
const method = getCatchMethodName(callExpr);
|
|
317
|
+
if (method !== null && node === callExpr.arguments[callExpr.arguments.length - 1]) {
|
|
318
|
+
catchMethodStack.push(method);
|
|
319
|
+
activeCatchCallbacks.add(node);
|
|
320
|
+
}
|
|
321
|
+
};
|
|
322
|
+
const exitCatchCallback = (node) => {
|
|
323
|
+
if (activeCatchCallbacks.has(node)) {
|
|
324
|
+
catchMethodStack.pop();
|
|
325
|
+
activeCatchCallbacks.delete(node);
|
|
326
|
+
}
|
|
327
|
+
};
|
|
328
|
+
return {
|
|
329
|
+
ImportDeclaration(node) {
|
|
330
|
+
const source = node.source.value;
|
|
331
|
+
for (const spec of node.specifiers) {
|
|
332
|
+
if (source === "effect") {
|
|
333
|
+
if (spec.type === "ImportSpecifier" && spec.imported.type === "Identifier" && spec.imported.name === "Effect") trackedEffectImports.add(spec.local.name);
|
|
334
|
+
continue;
|
|
335
|
+
}
|
|
336
|
+
if (source === "effect/Effect") {
|
|
337
|
+
if (spec.type === "ImportNamespaceSpecifier" || spec.type === "ImportDefaultSpecifier") trackedEffectImports.add(spec.local.name);
|
|
338
|
+
if (spec.type === "ImportSpecifier" && spec.imported.type === "Identifier" && spec.imported.name === "Effect") trackedEffectImports.add(spec.local.name);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
},
|
|
342
|
+
VariableDeclaration(node) {
|
|
343
|
+
for (const decl of node.declarations) {
|
|
344
|
+
if (decl.id.type !== "Identifier") continue;
|
|
345
|
+
trackedEffectImports.delete(decl.id.name);
|
|
346
|
+
}
|
|
347
|
+
},
|
|
348
|
+
ArrowFunctionExpression: enterCatchCallback,
|
|
349
|
+
"ArrowFunctionExpression:exit": exitCatchCallback,
|
|
350
|
+
FunctionExpression: enterCatchCallback,
|
|
351
|
+
"FunctionExpression:exit": exitCatchCallback,
|
|
352
|
+
CallExpression(node) {
|
|
353
|
+
const catchMethod = catchMethodStack[catchMethodStack.length - 1];
|
|
354
|
+
if (catchMethod === void 0) return;
|
|
355
|
+
const { callee } = node;
|
|
356
|
+
if (callee.type !== "MemberExpression") return;
|
|
357
|
+
if (callee.property.type !== "Identifier") return;
|
|
358
|
+
if (callee.object.type !== "Identifier") return;
|
|
359
|
+
const objectName = callee.object.name;
|
|
360
|
+
const methodName = callee.property.name;
|
|
361
|
+
if (trackedEffectImports.has(objectName) && EFFECT_LOG_METHODS.has(methodName)) {
|
|
362
|
+
reportViolation(node, `${objectName}.${methodName}`, catchMethod);
|
|
363
|
+
return;
|
|
364
|
+
}
|
|
365
|
+
if (objectName === "console" && CONSOLE_LOG_METHODS.has(methodName)) reportViolation(node, `console.${methodName}`, catchMethod);
|
|
366
|
+
},
|
|
367
|
+
MemberExpression(node) {
|
|
368
|
+
const catchMethod = catchMethodStack[catchMethodStack.length - 1];
|
|
369
|
+
if (catchMethod === void 0) return;
|
|
370
|
+
if (node.parent.type !== "CallExpression") return;
|
|
371
|
+
const pipeCallee = node.parent.callee;
|
|
372
|
+
if (pipeCallee.type !== "MemberExpression") return;
|
|
373
|
+
if (pipeCallee.property.type !== "Identifier") return;
|
|
374
|
+
if (pipeCallee.property.name !== "pipe") return;
|
|
375
|
+
if (node.object.type === "Identifier" && trackedEffectImports.has(node.object.name) && node.property.type === "Identifier" && EFFECT_LOG_METHODS.has(node.property.name)) reportViolation(node.parent, `${node.object.name}.${node.property.name}`, catchMethod);
|
|
376
|
+
}
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
});
|
|
380
|
+
//#endregion
|
|
381
|
+
//#region src/rules/no-native-map-in-effect.config.ts
|
|
382
|
+
const Options$2 = Schema.Struct({
|
|
383
|
+
allow: Schema.Array(Schema.String).pipe(Schema.withDecodingDefaultType(Effect.succeed([]))),
|
|
384
|
+
expected: Schema.String.pipe(Schema.withDecodingDefaultType(Effect.succeed("HashMap from effect (HashMap.empty() or HashMap.fromIterable())"))),
|
|
385
|
+
fix: Schema.String.pipe(Schema.withDecodingDefaultType(Effect.succeed("Replace with HashMap.empty() for empty maps, or HashMap.fromIterable(iterable) for maps with initial data")))
|
|
386
|
+
});
|
|
387
|
+
const meta$3 = {
|
|
388
|
+
type: "problem",
|
|
389
|
+
docs: { description: "When Effect is imported, ban native Map (new Map). Use HashMap from effect instead." },
|
|
390
|
+
schema: [Schema.toJsonSchemaDocument(Options$2).schema],
|
|
391
|
+
messages: { forbiddenMap: "{{actual}} is forbidden when Effect is imported. Expected: {{expected}}. Actual: {{actual}}. Fix: {{fix}}." }
|
|
392
|
+
};
|
|
393
|
+
//#endregion
|
|
394
|
+
//#region src/rules/no-native-map-in-effect.ts
|
|
395
|
+
const isEffectImport$1 = (sourceValue) => sourceValue === "effect" || sourceValue.startsWith("effect/") || sourceValue.startsWith("@effect/");
|
|
396
|
+
const isInsideEffectGen$1 = (node) => {
|
|
397
|
+
if (node == null) return false;
|
|
398
|
+
const parent = node.parent;
|
|
399
|
+
if (parent !== null && parent.type === "CallExpression" && parent.callee.type === "MemberExpression" && parent.callee.property.type === "Identifier" && parent.callee.property.name === "gen") return true;
|
|
400
|
+
return isInsideEffectGen$1(parent);
|
|
401
|
+
};
|
|
402
|
+
const isMapCallee = (callee) => {
|
|
403
|
+
if (callee.type === "Identifier") return callee.name === "Map";
|
|
404
|
+
if (callee.type === "MemberExpression" && callee.property.type === "Identifier") return callee.property.name === "Map";
|
|
405
|
+
return false;
|
|
406
|
+
};
|
|
407
|
+
const noNativeMapInEffect = defineRule({
|
|
408
|
+
meta: meta$3,
|
|
409
|
+
create(context) {
|
|
410
|
+
const options = Schema.decodeUnknownSync(Options$2)(context.options[0] ?? {});
|
|
411
|
+
const allow = new Set(options.allow);
|
|
412
|
+
let hasEffectImport = false;
|
|
413
|
+
return {
|
|
414
|
+
ImportDeclaration(node) {
|
|
415
|
+
if (isEffectImport$1(node.source.value)) hasEffectImport = true;
|
|
416
|
+
},
|
|
417
|
+
NewExpression(node) {
|
|
418
|
+
if (!hasEffectImport) return;
|
|
419
|
+
if (allow.has("Map")) return;
|
|
420
|
+
if (!isMapCallee(node.callee)) return;
|
|
421
|
+
if (!isInsideEffectGen$1(node)) return;
|
|
422
|
+
const actual = node.arguments.length === 0 ? "new Map()" : "new Map(iterable)";
|
|
423
|
+
context.report({
|
|
424
|
+
node: node.callee,
|
|
425
|
+
messageId: "forbiddenMap",
|
|
426
|
+
data: {
|
|
427
|
+
expected: options.expected,
|
|
428
|
+
actual,
|
|
429
|
+
fix: options.fix
|
|
430
|
+
}
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
});
|
|
436
|
+
//#endregion
|
|
437
|
+
//#region src/rules/no-native-set-in-effect.config.ts
|
|
438
|
+
const Options$1 = Schema.Struct({
|
|
439
|
+
allow: Schema.Array(Schema.String).pipe(Schema.withDecodingDefaultType(Effect.succeed([]))),
|
|
440
|
+
expected: Schema.String.pipe(Schema.withDecodingDefaultType(Effect.succeed("HashSet from effect (HashSet.empty() or HashSet.fromIterable())"))),
|
|
441
|
+
fix: Schema.String.pipe(Schema.withDecodingDefaultType(Effect.succeed("Replace with HashSet.empty() for empty sets, or HashSet.fromIterable(iterable) for sets with initial data")))
|
|
442
|
+
});
|
|
443
|
+
const meta$2 = {
|
|
444
|
+
type: "problem",
|
|
445
|
+
docs: { description: "When Effect is imported, ban native Set (new Set). Use HashSet from effect instead." },
|
|
446
|
+
schema: [Schema.toJsonSchemaDocument(Options$1).schema],
|
|
447
|
+
messages: { forbiddenSet: "{{actual}} is forbidden when Effect is imported. Expected: {{expected}}. Actual: {{actual}}. Fix: {{fix}}." }
|
|
448
|
+
};
|
|
449
|
+
//#endregion
|
|
450
|
+
//#region src/rules/no-native-set-in-effect.ts
|
|
451
|
+
const isSetCallee = (callee) => callee.type === "Identifier" && callee.name === "Set";
|
|
452
|
+
const isEffectImport = (sourceValue) => sourceValue === "effect" || sourceValue.startsWith("effect/") || sourceValue.startsWith("@effect/");
|
|
453
|
+
const isInsideEffectGen = (node) => {
|
|
454
|
+
if (node == null) return false;
|
|
455
|
+
const parent = node.parent;
|
|
456
|
+
if (parent !== null && parent.type === "CallExpression" && parent.callee.type === "MemberExpression" && parent.callee.property.type === "Identifier" && parent.callee.property.name === "gen") return true;
|
|
457
|
+
return isInsideEffectGen(parent);
|
|
458
|
+
};
|
|
459
|
+
const noNativeSetInEffect = defineRule({
|
|
460
|
+
meta: meta$2,
|
|
461
|
+
create(context) {
|
|
462
|
+
const options = Schema.decodeUnknownSync(Options$1)(context.options[0] ?? {});
|
|
463
|
+
const allow = new Set(options.allow);
|
|
464
|
+
let hasEffectImport = false;
|
|
465
|
+
return {
|
|
466
|
+
ImportDeclaration(node) {
|
|
467
|
+
if (isEffectImport(node.source.value)) hasEffectImport = true;
|
|
468
|
+
},
|
|
469
|
+
NewExpression(node) {
|
|
470
|
+
if (!hasEffectImport) return;
|
|
471
|
+
if (allow.has("Set")) return;
|
|
472
|
+
if (!isSetCallee(node.callee)) return;
|
|
473
|
+
if (!isInsideEffectGen(node)) return;
|
|
474
|
+
const actual = node.arguments.length === 0 ? "new Set()" : "new Set(iterable)";
|
|
475
|
+
context.report({
|
|
476
|
+
node: node.callee,
|
|
477
|
+
messageId: "forbiddenSet",
|
|
478
|
+
data: {
|
|
479
|
+
expected: options.expected,
|
|
480
|
+
actual,
|
|
481
|
+
fix: options.fix
|
|
482
|
+
}
|
|
483
|
+
});
|
|
484
|
+
}
|
|
485
|
+
};
|
|
486
|
+
}
|
|
487
|
+
});
|
|
488
|
+
//#endregion
|
|
489
|
+
//#region src/rules/no-new-worker-with-wasm-import.config.ts
|
|
490
|
+
const Options = Schema.Struct({
|
|
491
|
+
wasmImportPatterns: Schema.Array(Schema.String).pipe(Schema.withDecodingDefaultType(Effect.succeed([/^(@[^/]+\/)?[^/]+-wasm(\/.*)?$/].map((re) => re.source)))),
|
|
492
|
+
expected: Schema.String.pipe(Schema.withDecodingDefaultType(Effect.succeed("Bun.spawn subprocess pool"))),
|
|
493
|
+
fix: Schema.String.pipe(Schema.withDecodingDefaultType(Effect.succeed("Run each worker in its own OS process (not in a thread of the parent) so each one has its own WASM heap and concurrent init cannot race. A subprocess-per-worker pool with a per-child crash handler (re-dispatch the in-flight work and spawn a replacement) is the standard shape.")))
|
|
494
|
+
});
|
|
495
|
+
const meta$1 = {
|
|
496
|
+
type: "problem",
|
|
497
|
+
docs: { description: "When a file imports a WASM module (e.g. `*-wasm`), ban new Worker(filePath). Use Bun.spawn for process isolation — WASM global state races on concurrent init across threads of the same OS process and segfaults bun." },
|
|
498
|
+
schema: [Schema.toJsonSchemaDocument(Options).schema],
|
|
499
|
+
messages: { forbiddenNewWorkerWithWasm: "{{actual}} is forbidden when a WASM module is imported. Expected: {{expected}}. Actual: {{actual}}. Fix: {{fix}}." }
|
|
500
|
+
};
|
|
501
|
+
//#endregion
|
|
502
|
+
//#region src/rules/no-new-worker-with-wasm-import.ts
|
|
503
|
+
const isWasmImport = (sourceValue, patterns) => patterns.some((re) => re.test(sourceValue));
|
|
504
|
+
const isNewWorkerCall = (node) => {
|
|
505
|
+
if (node.callee.type !== "Identifier" || node.callee.name !== "Worker") return false;
|
|
506
|
+
if (node.arguments[0] === void 0) return false;
|
|
507
|
+
return true;
|
|
508
|
+
};
|
|
509
|
+
const noNewWorkerWithWasmImport = defineRule({
|
|
510
|
+
meta: meta$1,
|
|
511
|
+
create(context) {
|
|
512
|
+
const options = Schema.decodeUnknownSync(Options)(context.options[0] ?? {});
|
|
513
|
+
const patterns = options.wasmImportPatterns.map((src) => new RegExp(src));
|
|
514
|
+
let hasWasmImport = false;
|
|
515
|
+
return {
|
|
516
|
+
ImportDeclaration(node) {
|
|
517
|
+
if (isWasmImport(node.source.value, patterns)) hasWasmImport = true;
|
|
518
|
+
},
|
|
519
|
+
NewExpression(node) {
|
|
520
|
+
if (!hasWasmImport) return;
|
|
521
|
+
if (!isNewWorkerCall(node)) return;
|
|
522
|
+
context.report({
|
|
523
|
+
node: node.callee,
|
|
524
|
+
messageId: "forbiddenNewWorkerWithWasm",
|
|
525
|
+
data: {
|
|
526
|
+
expected: options.expected,
|
|
527
|
+
actual: "new Worker(filePath)",
|
|
528
|
+
fix: options.fix
|
|
529
|
+
}
|
|
530
|
+
});
|
|
531
|
+
}
|
|
532
|
+
};
|
|
533
|
+
}
|
|
534
|
+
});
|
|
535
|
+
//#endregion
|
|
536
|
+
//#region ../import-origin/dist/index.mjs
|
|
537
|
+
const isScopeLike = (value) => typeof value === "object" && value !== null && "references" in value && "upper" in value;
|
|
538
|
+
const isIdentifier = (node) => node.type === "Identifier";
|
|
539
|
+
const isMemberExpression = (node) => node.type === "MemberExpression";
|
|
540
|
+
const isVariableDeclarator = (node) => node.type === "VariableDeclarator";
|
|
541
|
+
/**
|
|
542
|
+
* The variable a reference identifier resolves to: the reference's own
|
|
543
|
+
* `resolved` binding, found by identity in the scope tree. Name-based scope
|
|
544
|
+
* lookups merge same-scope re-declarations (an import plus a shadowing const
|
|
545
|
+
* collapse into one variable), so only the reference knows the shadow.
|
|
546
|
+
*/
|
|
547
|
+
const variableOfIdentifier = (identifier, getScope) => {
|
|
548
|
+
const scopeValue = getScope(identifier);
|
|
549
|
+
let scope = isScopeLike(scopeValue) ? scopeValue : null;
|
|
550
|
+
while (scope !== null) {
|
|
551
|
+
const found = scope.references.find((reference) => reference.identifier === identifier);
|
|
552
|
+
if (found !== void 0 && found.resolved !== null) return { defs: found.resolved.defs };
|
|
553
|
+
if (found !== void 0) return null;
|
|
554
|
+
scope = scope.upper;
|
|
555
|
+
}
|
|
556
|
+
return null;
|
|
557
|
+
};
|
|
558
|
+
/** The member names that forward, rather than extend, an origin. */
|
|
559
|
+
const FORWARDING_MEMBERS = {
|
|
560
|
+
bind: true,
|
|
561
|
+
call: true,
|
|
562
|
+
apply: true
|
|
563
|
+
};
|
|
564
|
+
/** TS wrappers that carry an expression without changing what it denotes. */
|
|
565
|
+
const TS_EXPRESSION_WRAPPERS = {
|
|
566
|
+
TSAsExpression: true,
|
|
567
|
+
TSSatisfiesExpression: true,
|
|
568
|
+
TSNonNullExpression: true,
|
|
569
|
+
TSTypeAssertion: true,
|
|
570
|
+
TSInstantiationExpression: true
|
|
571
|
+
};
|
|
572
|
+
const isExpressionWrapper = (node) => TS_EXPRESSION_WRAPPERS[node.type] === true;
|
|
573
|
+
const unwrapExpression = (node) => {
|
|
574
|
+
let current = node;
|
|
575
|
+
while (isExpressionWrapper(current)) current = current.expression;
|
|
576
|
+
return current;
|
|
577
|
+
};
|
|
578
|
+
/**
|
|
579
|
+
* The statically known string value of an expression that evaluates to a
|
|
580
|
+
* string: a string literal, a template with no substitutions, a `+`
|
|
581
|
+
* concatenation of two such, or `Symbol.for('name')`. Anything not foldable
|
|
582
|
+
* from syntax alone is `null` — never a guessed name. The `Symbol.for` fold is
|
|
583
|
+
* the well-known-symbol member addressing: `S[Symbol.for('Struct')]` names the
|
|
584
|
+
* same member as `S.Struct`. A shadowed `Symbol` binding would break the fold —
|
|
585
|
+
* the same permissiveness the resolver already extends to local aliases.
|
|
586
|
+
*/
|
|
587
|
+
const staticStringValue = (node, depth = 0) => {
|
|
588
|
+
if (node === null || depth > 64) return null;
|
|
589
|
+
if (node.type === "Literal" && typeof node.value === "string") return node.value;
|
|
590
|
+
if (node.type === "TemplateLiteral" && node.expressions.length === 0) return node.quasis[0]?.value.cooked ?? null;
|
|
591
|
+
if (node.type === "BinaryExpression" && node.operator === "+") {
|
|
592
|
+
const left = staticStringValue(node.left, depth + 1);
|
|
593
|
+
if (left === null) return null;
|
|
594
|
+
const right = staticStringValue(node.right, depth + 1);
|
|
595
|
+
return right === null ? null : left + right;
|
|
596
|
+
}
|
|
597
|
+
if (node.type === "CallExpression" && node.arguments.length === 1) {
|
|
598
|
+
const argument = node.arguments[0];
|
|
599
|
+
if (argument !== void 0 && argument.type === "Literal" && typeof argument.value === "string" && node.callee.type === "MemberExpression" && !node.callee.computed && node.callee.object.type === "Identifier" && node.callee.object.name === "Symbol" && node.callee.property.type === "Identifier" && node.callee.property.name === "for") return argument.value;
|
|
600
|
+
}
|
|
601
|
+
return null;
|
|
602
|
+
};
|
|
603
|
+
/**
|
|
604
|
+
* The declared member name of a member expression: an identifier property in a
|
|
605
|
+
* non-computed position, or a computed property whose key folds to a static
|
|
606
|
+
* string (`S['Union']`, `S['Stru' + 'ct']`, `S[Symbol.for('Struct')]`).
|
|
607
|
+
* Everything else — a variable subscript `S[key]` — is `null`: the member is
|
|
608
|
+
* not statically known. Never fall back to the subscript variable's name; that
|
|
609
|
+
* would read `S[decoder]` as the member `decoder` and misclassify a codec use
|
|
610
|
+
* as a schema construction.
|
|
611
|
+
*/
|
|
612
|
+
const memberNameOf = (node) => {
|
|
613
|
+
const property = node.property;
|
|
614
|
+
if (!node.computed && property.type === "Identifier") return property.name;
|
|
615
|
+
return staticStringValue(property);
|
|
616
|
+
};
|
|
617
|
+
/**
|
|
618
|
+
* The alias-chain ladder guard. 64 levels of alias/member indirection is
|
|
619
|
+
* beyond any real chain; a chain that exhausts it resolves to `null` — the
|
|
620
|
+
* "undetermined" value, not "definitely not an import". Callers that must
|
|
621
|
+
* fail closed treat that exhausted-`null` the same as any other unresolved
|
|
622
|
+
* module-local chain (schema-declaration-location reports it), so a deep
|
|
623
|
+
* ladder can no longer park a schema silently. Tune the cap, never the
|
|
624
|
+
* semantics: a depth overflow is a report, not a pass.
|
|
625
|
+
*/
|
|
626
|
+
const MAX_DEPTH = 64;
|
|
627
|
+
/**
|
|
628
|
+
* What this expression ultimately denotes: `{ source, importedName, path }`
|
|
629
|
+
* for an identifier or member chain that reaches an import binding, `null`
|
|
630
|
+
* for everything the resolver cannot prove — my "undetermined", not "this is
|
|
631
|
+
* not an import".
|
|
632
|
+
*/
|
|
633
|
+
const resolveImportOrigin = (node, getScope, depth = 0) => {
|
|
634
|
+
if (depth > MAX_DEPTH) return null;
|
|
635
|
+
node = unwrapExpression(node);
|
|
636
|
+
if (isIdentifier(node)) return resolveIdentifierOrigin(node, getScope, depth);
|
|
637
|
+
if (node.type === "SequenceExpression") {
|
|
638
|
+
const last = node.expressions[node.expressions.length - 1];
|
|
639
|
+
return last === void 0 ? null : resolveImportOrigin(last, getScope, depth + 1);
|
|
640
|
+
}
|
|
641
|
+
if (isMemberExpression(node)) {
|
|
642
|
+
const object = resolveImportOrigin(node.object, getScope, depth + 1);
|
|
643
|
+
if (object === null) return null;
|
|
644
|
+
const member = memberNameOf(node);
|
|
645
|
+
if (member === null || FORWARDING_MEMBERS[member] === true) return object;
|
|
646
|
+
return object.importedName === null ? {
|
|
647
|
+
...object,
|
|
648
|
+
importedName: member
|
|
649
|
+
} : {
|
|
650
|
+
...object,
|
|
651
|
+
path: [...object.path, member]
|
|
652
|
+
};
|
|
653
|
+
}
|
|
654
|
+
if (node.type === "CallExpression" && isMemberExpression(node.callee)) {
|
|
655
|
+
const member = memberNameOf(node.callee);
|
|
656
|
+
if (member !== null && FORWARDING_MEMBERS[member] === true) return resolveImportOrigin(node.callee.object, getScope, depth + 1);
|
|
657
|
+
}
|
|
658
|
+
return null;
|
|
659
|
+
};
|
|
660
|
+
const resolveIdentifierOrigin = (identifier, getScope, depth) => {
|
|
661
|
+
const variable = variableOfIdentifier(identifier, getScope);
|
|
662
|
+
if (variable === null) return null;
|
|
663
|
+
const def = variable.defs[variable.defs.length - 1];
|
|
664
|
+
if (def === void 0) return null;
|
|
665
|
+
if (def.type === "ImportBinding") {
|
|
666
|
+
const declaration = def.parent;
|
|
667
|
+
if (declaration === null || declaration.type !== "ImportDeclaration") return null;
|
|
668
|
+
const source = declaration.source.value;
|
|
669
|
+
if (typeof source !== "string") return null;
|
|
670
|
+
const specifier = def.node;
|
|
671
|
+
if (specifier.type === "ImportSpecifier") {
|
|
672
|
+
const imported = specifier.imported;
|
|
673
|
+
if (imported.type === "Identifier") return {
|
|
674
|
+
source,
|
|
675
|
+
importedName: imported.name,
|
|
676
|
+
path: []
|
|
677
|
+
};
|
|
678
|
+
return imported.type === "Literal" && typeof imported.value === "string" ? {
|
|
679
|
+
source,
|
|
680
|
+
importedName: imported.value,
|
|
681
|
+
path: []
|
|
682
|
+
} : null;
|
|
683
|
+
}
|
|
684
|
+
if (specifier.type === "ImportDefaultSpecifier") return {
|
|
685
|
+
source,
|
|
686
|
+
importedName: "default",
|
|
687
|
+
path: []
|
|
688
|
+
};
|
|
689
|
+
return {
|
|
690
|
+
source,
|
|
691
|
+
importedName: null,
|
|
692
|
+
path: []
|
|
693
|
+
};
|
|
694
|
+
}
|
|
695
|
+
if (def.type !== "Variable") return null;
|
|
696
|
+
const declarator = isVariableDeclarator(def.node) ? def.node : def.parent !== null && isVariableDeclarator(def.parent) ? def.parent : null;
|
|
697
|
+
if (declarator === null) return null;
|
|
698
|
+
const declaration = declarator.parent;
|
|
699
|
+
if (declaration === null || declaration.type !== "VariableDeclaration") return null;
|
|
700
|
+
const init = declarator.init;
|
|
701
|
+
if (init === null) return null;
|
|
702
|
+
const base = resolveImportOrigin(init, getScope, depth + 1);
|
|
703
|
+
if (base === null) return null;
|
|
704
|
+
if (declarator.id.type === "ObjectPattern") {
|
|
705
|
+
const bound = def.name;
|
|
706
|
+
if (bound === null) return null;
|
|
707
|
+
for (const property of declarator.id.properties) {
|
|
708
|
+
if (property.type !== "Property") continue;
|
|
709
|
+
const key = property.key;
|
|
710
|
+
const keyName = !property.computed && key.type === "Identifier" ? key.name : staticStringValue(key);
|
|
711
|
+
if (keyName === null) continue;
|
|
712
|
+
let binding = property.value;
|
|
713
|
+
if (binding.type === "AssignmentPattern") {
|
|
714
|
+
if (binding.left.type !== "Identifier") continue;
|
|
715
|
+
binding = binding.left;
|
|
716
|
+
}
|
|
717
|
+
if (binding !== bound) continue;
|
|
718
|
+
return base.importedName === null ? {
|
|
719
|
+
...base,
|
|
720
|
+
importedName: keyName
|
|
721
|
+
} : {
|
|
722
|
+
...base,
|
|
723
|
+
path: [...base.path, keyName]
|
|
724
|
+
};
|
|
725
|
+
}
|
|
726
|
+
return null;
|
|
727
|
+
}
|
|
728
|
+
return base;
|
|
729
|
+
};
|
|
730
|
+
//#endregion
|
|
731
|
+
//#region src/rules/runtime-construction-placement.config.ts
|
|
732
|
+
const isRuntimeCodeFile = (filename) => /(?:^|[\\/])src[\\/]/u.test(filename) || filename.endsWith(".test.ts");
|
|
733
|
+
const isInterpretationEdge = (filename) => /(?:^|[\\/])main\.ts$/u.test(filename);
|
|
734
|
+
const EFFECT_MODULE = "effect";
|
|
735
|
+
const CELL_MODULE = "@systemfsoftware/effect-cell-types";
|
|
736
|
+
const MANAGED_RUNTIME_NAMESPACE = "ManagedRuntime";
|
|
737
|
+
const LAYER_NAMESPACE = "Layer";
|
|
738
|
+
const CELL_NAMESPACE = "Cell";
|
|
739
|
+
const MAKE_MEMBER = "make";
|
|
740
|
+
const PROVIDE_MEMBER = "provide";
|
|
741
|
+
const TRACKED_WIRING_CALLS = [
|
|
742
|
+
{
|
|
743
|
+
source: EFFECT_MODULE,
|
|
744
|
+
namespace: MANAGED_RUNTIME_NAMESPACE,
|
|
745
|
+
member: MAKE_MEMBER
|
|
746
|
+
},
|
|
747
|
+
{
|
|
748
|
+
source: EFFECT_MODULE,
|
|
749
|
+
namespace: LAYER_NAMESPACE,
|
|
750
|
+
member: PROVIDE_MEMBER
|
|
751
|
+
},
|
|
752
|
+
{
|
|
753
|
+
source: CELL_MODULE,
|
|
754
|
+
namespace: CELL_NAMESPACE,
|
|
755
|
+
member: PROVIDE_MEMBER
|
|
756
|
+
}
|
|
757
|
+
];
|
|
758
|
+
const MEMOIZING_ASSIGNMENT_OPERATORS = [
|
|
759
|
+
"=",
|
|
760
|
+
"||=",
|
|
761
|
+
"??="
|
|
762
|
+
];
|
|
763
|
+
const WIRING_PER_CALL_EXPECTED = "wiring built once per process and deferred to first use in a module-scope lazy memoized closure";
|
|
764
|
+
const WIRING_PER_CALL_ACTUAL = "the wiring is constructed inside a function body, so every call builds its own runtime";
|
|
765
|
+
const WIRING_PER_CALL_FIX = "build the wiring in one module-scope lazy memoized closure and read that runtime where it is needed; a runtime constructed per call is never finalized and the fibers it starts outlive the caller - delete the construction if this module already reads a process-scope runtime";
|
|
766
|
+
const EAGER_CONSTRUCTION_EXPECTED = "runtime construction deferred to first use, inside a module-scope memoizing closure";
|
|
767
|
+
const EAGER_CONSTRUCTION_ACTUAL = "the runtime is constructed while the module is imported";
|
|
768
|
+
const EAGER_CONSTRUCTION_FIX = "wrap the construction in a module-scope memoizing closure and call it where the runtime is needed, so importing the module starts nothing; delete the runtime if this module already reads a process-scope one";
|
|
769
|
+
const PLACEMENT_MESSAGE = "{{name}} is forbidden. Expected: {{expected}}. Actual: {{actual}}. Fix: {{fix}}.";
|
|
770
|
+
const meta = {
|
|
771
|
+
type: "problem",
|
|
772
|
+
docs: { description: "`ManagedRuntime.make`, `Layer.provide`, or `Cell.provide` inside a function body rebuilds wiring per call; `ManagedRuntime.make` evaluated at module scope constructs the runtime at import time. The rule judges runtime code: files under a `src/` directory segment and `*.test.ts` files; a package-root hook, config, or setup file is outside its subject, `.tst.ts` type-test files run nowhere, and `main.ts` is exempt from the module-scope verdict as the interpretation edge. Lawful and silent in scope: a memoized module-scope closure, module-scope graph composition, `cell.run(input)` at any depth. Shapes, bounds, and examples: the README." },
|
|
773
|
+
schema: [],
|
|
774
|
+
messages: {
|
|
775
|
+
wiringPerCall: PLACEMENT_MESSAGE,
|
|
776
|
+
eagerConstruction: PLACEMENT_MESSAGE
|
|
777
|
+
}
|
|
778
|
+
};
|
|
779
|
+
//#endregion
|
|
780
|
+
//#region src/rules/runtime-construction-placement.ts
|
|
781
|
+
const isFunctionNode = (node) => node.type === "FunctionDeclaration" || node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression";
|
|
782
|
+
const staticMemberNameOf = (member) => {
|
|
783
|
+
if (member.computed === true) {
|
|
784
|
+
const property = member.property;
|
|
785
|
+
return property.type === "Literal" && typeof property.value === "string" ? property.value : null;
|
|
786
|
+
}
|
|
787
|
+
return member.property.type === "Identifier" ? member.property.name : null;
|
|
788
|
+
};
|
|
789
|
+
const dynamicImportSourceOf = (node) => {
|
|
790
|
+
if (node.type !== "AwaitExpression") return null;
|
|
791
|
+
const argument = node.argument;
|
|
792
|
+
if (argument.type !== "ImportExpression") return null;
|
|
793
|
+
const source = argument.source;
|
|
794
|
+
return source.type === "Literal" && typeof source.value === "string" ? source.value : null;
|
|
795
|
+
};
|
|
796
|
+
/**
|
|
797
|
+
* `const { ManagedRuntime } = await import('effect')` binds like the static form: the
|
|
798
|
+
* destructured name carries its property, and a plain identifier id is the namespace
|
|
799
|
+
* binding `import * as ns` produces. A dynamic import declares no import binding, so the
|
|
800
|
+
* shared resolver cannot reach it; these are the bindings the rule tracks for itself.
|
|
801
|
+
*/
|
|
802
|
+
const dynamicImportBindingsOf = (declarator) => {
|
|
803
|
+
if (declarator.init === null) return [];
|
|
804
|
+
const source = dynamicImportSourceOf(declarator.init);
|
|
805
|
+
if (source === null) return [];
|
|
806
|
+
const id = declarator.id;
|
|
807
|
+
if (id.type === "Identifier") return [[id.name, {
|
|
808
|
+
source,
|
|
809
|
+
importedName: null,
|
|
810
|
+
path: []
|
|
811
|
+
}]];
|
|
812
|
+
if (id.type !== "ObjectPattern") return [];
|
|
813
|
+
return id.properties.flatMap((property) => {
|
|
814
|
+
if (property.type !== "Property" || property.value.type !== "Identifier") return [];
|
|
815
|
+
const key = property.key;
|
|
816
|
+
const importedName = key.type === "Identifier" ? key.name : key.type === "Literal" && typeof key.value === "string" ? key.value : null;
|
|
817
|
+
return importedName === null ? [] : [[property.value.name, {
|
|
818
|
+
source,
|
|
819
|
+
importedName,
|
|
820
|
+
path: []
|
|
821
|
+
}]];
|
|
822
|
+
});
|
|
823
|
+
};
|
|
824
|
+
const seedDynamicImportBindings = (bindings, declarator) => {
|
|
825
|
+
for (const [name, binding] of dynamicImportBindingsOf(declarator)) if (!bindings.has(name)) bindings.set(name, binding);
|
|
826
|
+
};
|
|
827
|
+
const closeOverAliases = (bindings, program) => {
|
|
828
|
+
for (let hop = 0; hop < 8; hop += 1) {
|
|
829
|
+
const before = bindings.size;
|
|
830
|
+
for (const statement of program.body) {
|
|
831
|
+
if (statement.type !== "VariableDeclaration") continue;
|
|
832
|
+
for (const declarator of statement.declarations) {
|
|
833
|
+
if (declarator.id.type !== "Identifier" || declarator.init === null) continue;
|
|
834
|
+
const init = declarator.init;
|
|
835
|
+
if (init.type !== "Identifier") continue;
|
|
836
|
+
const base = bindings.get(init.name);
|
|
837
|
+
if (base === void 0 || bindings.has(declarator.id.name)) continue;
|
|
838
|
+
bindings.set(declarator.id.name, base);
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
if (bindings.size === before) break;
|
|
842
|
+
}
|
|
843
|
+
};
|
|
844
|
+
const dynamicOriginOf = (node, bindings) => {
|
|
845
|
+
if (node.type === "Identifier") return bindings.get(node.name) ?? null;
|
|
846
|
+
if (node.type !== "MemberExpression") return null;
|
|
847
|
+
const member = staticMemberNameOf(node);
|
|
848
|
+
if (member === null) return null;
|
|
849
|
+
const receiver = dynamicOriginOf(node.object, bindings);
|
|
850
|
+
if (receiver === null) return null;
|
|
851
|
+
return receiver.importedName === null ? {
|
|
852
|
+
...receiver,
|
|
853
|
+
importedName: member
|
|
854
|
+
} : {
|
|
855
|
+
...receiver,
|
|
856
|
+
path: [...receiver.path, member]
|
|
857
|
+
};
|
|
858
|
+
};
|
|
859
|
+
const trackedWiringCallOf = (origin, member) => origin.path.length > 0 ? null : TRACKED_WIRING_CALLS.find((candidate) => candidate.source === origin.source && candidate.member === member && (candidate.namespace === origin.importedName || origin.importedName === null)) ?? null;
|
|
860
|
+
const enclosingFunctionOf = (node) => {
|
|
861
|
+
let current = node.parent;
|
|
862
|
+
while (current !== null) {
|
|
863
|
+
if (isFunctionNode(current)) return current;
|
|
864
|
+
current = current.parent;
|
|
865
|
+
}
|
|
866
|
+
return null;
|
|
867
|
+
};
|
|
868
|
+
const isModuleScopeBinding = (declarator) => {
|
|
869
|
+
const declaration = declarator.parent;
|
|
870
|
+
if (declaration === null || declaration.type !== "VariableDeclaration") return false;
|
|
871
|
+
const holder = declaration.parent;
|
|
872
|
+
if (holder === null) return false;
|
|
873
|
+
if (holder.type === "Program") return true;
|
|
874
|
+
return holder.type === "ExportNamedDeclaration" && holder.parent !== null && holder.parent.type === "Program";
|
|
875
|
+
};
|
|
876
|
+
const isDeferredModuleClosure = (fn) => {
|
|
877
|
+
if (fn.type === "FunctionDeclaration" || fn.generator === true) return false;
|
|
878
|
+
let current = fn.parent;
|
|
879
|
+
while (current !== null) {
|
|
880
|
+
if (isFunctionNode(current)) {
|
|
881
|
+
if (current.type === "FunctionDeclaration" || current.generator === true) return false;
|
|
882
|
+
current = current.parent;
|
|
883
|
+
continue;
|
|
884
|
+
}
|
|
885
|
+
if (current.type === "VariableDeclarator") return isModuleScopeBinding(current);
|
|
886
|
+
const parent = current.parent;
|
|
887
|
+
if (parent === null || parent.type === "Program") return false;
|
|
888
|
+
current = parent;
|
|
889
|
+
}
|
|
890
|
+
return false;
|
|
891
|
+
};
|
|
892
|
+
const isCacheWrite = (node) => node.type === "AssignmentExpression" && MEMOIZING_ASSIGNMENT_OPERATORS.includes(node.operator);
|
|
893
|
+
const isBoundByAModuleScopeBinding = (node) => {
|
|
894
|
+
let current = node;
|
|
895
|
+
while (current !== null) {
|
|
896
|
+
if (isFunctionNode(current) || current.type === "Program") return false;
|
|
897
|
+
if (isCacheWrite(current)) return true;
|
|
898
|
+
if (current.type === "VariableDeclarator") return current.init !== null && isModuleScopeBinding(current);
|
|
899
|
+
current = current.parent;
|
|
900
|
+
}
|
|
901
|
+
return false;
|
|
902
|
+
};
|
|
903
|
+
const MAX_WALK_DEPTH = 32;
|
|
904
|
+
const isNode = (value) => value !== null && typeof value === "object" && "type" in value;
|
|
905
|
+
const mentionsName = (value, name, depth) => {
|
|
906
|
+
if (depth > MAX_WALK_DEPTH) return false;
|
|
907
|
+
if (Array.isArray(value)) return value.some((item) => mentionsName(item, name, depth + 1));
|
|
908
|
+
if (!isNode(value)) return false;
|
|
909
|
+
if (value.type === "Identifier") return value.name === name;
|
|
910
|
+
for (const [key, child] of Object.entries(value)) {
|
|
911
|
+
if (key === "parent") continue;
|
|
912
|
+
if (mentionsName(child, name, depth + 1)) return true;
|
|
913
|
+
}
|
|
914
|
+
return false;
|
|
915
|
+
};
|
|
916
|
+
const isReadInsideANestedFunction = (value, enclosing, name, depth) => {
|
|
917
|
+
if (depth > MAX_WALK_DEPTH) return false;
|
|
918
|
+
if (Array.isArray(value)) return value.some((item) => isReadInsideANestedFunction(item, enclosing, name, depth + 1));
|
|
919
|
+
if (!isNode(value)) return false;
|
|
920
|
+
if (value !== enclosing && isFunctionNode(value)) return mentionsName(value, name, depth + 1);
|
|
921
|
+
for (const [key, child] of Object.entries(value)) {
|
|
922
|
+
if (key === "parent") continue;
|
|
923
|
+
if (isReadInsideANestedFunction(child, enclosing, name, depth + 1)) return true;
|
|
924
|
+
}
|
|
925
|
+
return false;
|
|
926
|
+
};
|
|
927
|
+
const isCapturedDeclaratorBinding = (declarator, enclosing) => {
|
|
928
|
+
if (declarator.id.type !== "Identifier") return false;
|
|
929
|
+
return isReadInsideANestedFunction(enclosing, enclosing, declarator.id.name, 0);
|
|
930
|
+
};
|
|
931
|
+
const isMemoizedConstruction = (call, enclosing) => {
|
|
932
|
+
let current = call.parent;
|
|
933
|
+
while (current !== null && current !== enclosing) {
|
|
934
|
+
if (isCacheWrite(current)) return true;
|
|
935
|
+
if (current.type === "VariableDeclarator" && isCapturedDeclaratorBinding(current, enclosing)) return true;
|
|
936
|
+
current = current.parent;
|
|
937
|
+
}
|
|
938
|
+
const consumer = enclosing.parent;
|
|
939
|
+
if (consumer === null || consumer.type !== "CallExpression") return false;
|
|
940
|
+
return isBoundByAModuleScopeBinding(consumer);
|
|
941
|
+
};
|
|
942
|
+
const runtimeConstructionPlacement = defineRule({
|
|
943
|
+
meta,
|
|
944
|
+
create(context) {
|
|
945
|
+
if (context.filename.endsWith(".tst.ts")) return {};
|
|
946
|
+
if (!isRuntimeCodeFile(context.filename)) return {};
|
|
947
|
+
const getScope = context.sourceCode.getScope;
|
|
948
|
+
let dynamicBindings = /* @__PURE__ */ new Map();
|
|
949
|
+
return {
|
|
950
|
+
Program(node) {
|
|
951
|
+
const bindings = /* @__PURE__ */ new Map();
|
|
952
|
+
for (const statement of node.body) {
|
|
953
|
+
if (statement.type !== "VariableDeclaration") continue;
|
|
954
|
+
for (const declarator of statement.declarations) seedDynamicImportBindings(bindings, declarator);
|
|
955
|
+
}
|
|
956
|
+
closeOverAliases(bindings, node);
|
|
957
|
+
dynamicBindings = bindings;
|
|
958
|
+
},
|
|
959
|
+
VariableDeclaration(node) {
|
|
960
|
+
for (const declarator of node.declarations) seedDynamicImportBindings(dynamicBindings, declarator);
|
|
961
|
+
},
|
|
962
|
+
CallExpression(node) {
|
|
963
|
+
const callee = node.callee;
|
|
964
|
+
if (callee.type !== "MemberExpression") return;
|
|
965
|
+
const member = staticMemberNameOf(callee);
|
|
966
|
+
if (member === null) return;
|
|
967
|
+
const receiver = resolveImportOrigin(callee.object, getScope) ?? dynamicOriginOf(callee.object, dynamicBindings);
|
|
968
|
+
if (receiver === null) return;
|
|
969
|
+
const tracked = trackedWiringCallOf(receiver, member);
|
|
970
|
+
if (tracked === null) return;
|
|
971
|
+
const name = `${tracked.namespace}.${tracked.member}`;
|
|
972
|
+
const enclosing = enclosingFunctionOf(node);
|
|
973
|
+
if (enclosing !== null && isDeferredModuleClosure(enclosing) && isMemoizedConstruction(node, enclosing)) return;
|
|
974
|
+
if (enclosing !== null) {
|
|
975
|
+
context.report({
|
|
976
|
+
node: callee,
|
|
977
|
+
messageId: "wiringPerCall",
|
|
978
|
+
data: {
|
|
979
|
+
name,
|
|
980
|
+
expected: WIRING_PER_CALL_EXPECTED,
|
|
981
|
+
actual: WIRING_PER_CALL_ACTUAL,
|
|
982
|
+
fix: WIRING_PER_CALL_FIX
|
|
983
|
+
}
|
|
984
|
+
});
|
|
985
|
+
return;
|
|
986
|
+
}
|
|
987
|
+
if (tracked.namespace !== "ManagedRuntime") return;
|
|
988
|
+
if (isInterpretationEdge(context.filename)) return;
|
|
989
|
+
context.report({
|
|
990
|
+
node: callee,
|
|
991
|
+
messageId: "eagerConstruction",
|
|
992
|
+
data: {
|
|
993
|
+
name,
|
|
994
|
+
expected: EAGER_CONSTRUCTION_EXPECTED,
|
|
995
|
+
actual: EAGER_CONSTRUCTION_ACTUAL,
|
|
996
|
+
fix: EAGER_CONSTRUCTION_FIX
|
|
997
|
+
}
|
|
998
|
+
});
|
|
999
|
+
}
|
|
1000
|
+
};
|
|
1001
|
+
}
|
|
1002
|
+
});
|
|
1003
|
+
//#endregion
|
|
1004
|
+
//#region src/index.ts
|
|
1005
|
+
const PLUGIN_NAME = "@systemfsoftware/oxlint-plugin-effect-platform";
|
|
1006
|
+
const rule = (name) => `${PLUGIN_NAME}/${name}`;
|
|
1007
|
+
const recommendedRules = {
|
|
1008
|
+
[rule("entrypoint-interprets-once")]: "error",
|
|
1009
|
+
[rule("entrypoint-no-exports")]: "error",
|
|
1010
|
+
[rule("entrypoint-not-imported")]: "error",
|
|
1011
|
+
[rule("entrypoint-no-promise-wrapper")]: "error",
|
|
1012
|
+
[rule("runtime-construction-placement")]: "error",
|
|
1013
|
+
[rule("no-logging-in-catch")]: "error",
|
|
1014
|
+
[rule("no-native-map-in-effect")]: "error",
|
|
1015
|
+
[rule("no-native-set-in-effect")]: "error",
|
|
1016
|
+
[rule("no-new-worker-with-wasm-import")]: "error"
|
|
1017
|
+
};
|
|
1018
|
+
const noNodeBuiltinImports = ["error", { patterns: [
|
|
1019
|
+
{
|
|
1020
|
+
regex: "^node:.*",
|
|
1021
|
+
message: "Importing Node.js builtins via \"node:\" is forbidden — use \"@effect/platform\" or a Web Standard API (e.g. global URL, fetch, Web Crypto, Web Streams) instead."
|
|
1022
|
+
},
|
|
1023
|
+
{
|
|
1024
|
+
regex: "^(?:assert|async_hooks|buffer|child_process|cluster|console|constants|crypto|dgram|diagnostics_channel|dns|domain|events|fs|http|http2|https|inspector|module|net|os|path|perf_hooks|process|punycode|querystring|readline|repl|stream|string_decoder|sys|timers|tls|trace_events|tty|url|util|v8|vm|wasi|worker_threads|zlib)(?:/.*)?$",
|
|
1025
|
+
message: "Importing Node.js builtins without the \"node:\" prefix is forbidden (e.g. \"fs\") — use \"@effect/platform\" or a Web Standard API instead. Even \"node:fs\" is forbidden."
|
|
1026
|
+
},
|
|
1027
|
+
{
|
|
1028
|
+
regex: "^@std/(?:encoding|fs|path|streams)(?:/.*)?$",
|
|
1029
|
+
message: "Importing @std modules that mirror Effect services (encoding → Encoding, fs → FileSystem, path → Path, streams → Stream) is forbidden — use the corresponding Effect module instead."
|
|
1030
|
+
}
|
|
1031
|
+
] }];
|
|
1032
|
+
var src_default = {
|
|
1033
|
+
meta: { name: PLUGIN_NAME },
|
|
1034
|
+
rules: {
|
|
1035
|
+
"entrypoint-interprets-once": entrypointInterpretsOnce,
|
|
1036
|
+
"entrypoint-no-exports": entrypointNoExports,
|
|
1037
|
+
"entrypoint-not-imported": entrypointNotImported,
|
|
1038
|
+
"entrypoint-no-promise-wrapper": entrypointNoPromiseWrapper,
|
|
1039
|
+
"runtime-construction-placement": runtimeConstructionPlacement,
|
|
1040
|
+
"no-logging-in-catch": noLoggingInCatch,
|
|
1041
|
+
"no-native-map-in-effect": noNativeMapInEffect,
|
|
1042
|
+
"no-native-set-in-effect": noNativeSetInEffect,
|
|
1043
|
+
"no-new-worker-with-wasm-import": noNewWorkerWithWasmImport
|
|
1044
|
+
},
|
|
1045
|
+
configs: { recommended: {
|
|
1046
|
+
rules: recommendedRules,
|
|
1047
|
+
overrides: [{
|
|
1048
|
+
files: ["**/src/**", "**/*.test.ts"],
|
|
1049
|
+
rules: { "no-restricted-imports": noNodeBuiltinImports }
|
|
1050
|
+
}, {
|
|
1051
|
+
files: [
|
|
1052
|
+
"**/__fixtures__/**",
|
|
1053
|
+
"**/fixtures/**",
|
|
1054
|
+
"**/testResources/**"
|
|
1055
|
+
],
|
|
1056
|
+
rules: { "no-restricted-imports": "off" }
|
|
1057
|
+
}]
|
|
1058
|
+
} }
|
|
1059
|
+
};
|
|
1060
|
+
//#endregion
|
|
1061
|
+
export { src_default as default, noNodeBuiltinImports };
|