@opsydyn/oxlint-effect 0.1.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -1
- package/dist/index.mjs +785 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -140,6 +140,286 @@ function getEffectGeneratorArgument(node, propertyName) {
|
|
|
140
140
|
function isEffectGeneratorCall(node, propertyName) {
|
|
141
141
|
return getEffectGeneratorArgument(node, propertyName) !== void 0;
|
|
142
142
|
}
|
|
143
|
+
function findYieldWithoutStar(node, seen = /* @__PURE__ */ new WeakSet()) {
|
|
144
|
+
if (Array.isArray(node)) {
|
|
145
|
+
for (const child of node) {
|
|
146
|
+
const match = findYieldWithoutStar(child, seen);
|
|
147
|
+
if (match) return match;
|
|
148
|
+
}
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
if (typeof node !== "object" || node === null) return;
|
|
152
|
+
if (seen.has(node)) return;
|
|
153
|
+
seen.add(node);
|
|
154
|
+
if (node.type === "YieldExpression" && node.delegate !== true) return node;
|
|
155
|
+
for (const [key, child] of Object.entries(node)) {
|
|
156
|
+
if (key === "parent") continue;
|
|
157
|
+
const match = findYieldWithoutStar(child, seen);
|
|
158
|
+
if (match) return match;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
function findYieldWithoutStarInEffectGen(node) {
|
|
162
|
+
const generator = getEffectGeneratorArgument(node, "gen");
|
|
163
|
+
return generator ? findYieldWithoutStar(generator.body) : void 0;
|
|
164
|
+
}
|
|
165
|
+
function isAsyncFunctionCallback(node) {
|
|
166
|
+
return typeof node === "object" && node !== null && (node.type === "ArrowFunctionExpression" || node.type === "FunctionExpression") && node.async === true;
|
|
167
|
+
}
|
|
168
|
+
const effectAsyncCallbackCombinators = /* @__PURE__ */ new Set([
|
|
169
|
+
"andThen",
|
|
170
|
+
"catchAll",
|
|
171
|
+
"catchTag",
|
|
172
|
+
"filterOrFail",
|
|
173
|
+
"flatMap",
|
|
174
|
+
"forEach",
|
|
175
|
+
"map",
|
|
176
|
+
"orElse",
|
|
177
|
+
"tap"
|
|
178
|
+
]);
|
|
179
|
+
function findAsyncEffectCombinatorCallback(node) {
|
|
180
|
+
if (!isEffectMemberCall(node)) return;
|
|
181
|
+
const property = node.callee.property;
|
|
182
|
+
if (!isIdentifier(property) || !effectAsyncCallbackCombinators.has(property.name)) return;
|
|
183
|
+
return node.arguments.find((argument) => isAsyncFunctionCallback(argument));
|
|
184
|
+
}
|
|
185
|
+
function findThrowStatement(node, seen = /* @__PURE__ */ new WeakSet()) {
|
|
186
|
+
if (Array.isArray(node)) {
|
|
187
|
+
for (const child of node) {
|
|
188
|
+
const match = findThrowStatement(child, seen);
|
|
189
|
+
if (match) return match;
|
|
190
|
+
}
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
if (typeof node !== "object" || node === null) return;
|
|
194
|
+
if (seen.has(node)) return;
|
|
195
|
+
seen.add(node);
|
|
196
|
+
if (node.type === "ThrowStatement") return node;
|
|
197
|
+
for (const [key, child] of Object.entries(node)) {
|
|
198
|
+
if (key === "parent") continue;
|
|
199
|
+
const match = findThrowStatement(child, seen);
|
|
200
|
+
if (match) return match;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
function findThrowInEffectLogic(node) {
|
|
204
|
+
const generator = getEffectGeneratorArgument(node, "gen");
|
|
205
|
+
if (generator) return findThrowStatement(generator.body);
|
|
206
|
+
if (!isEffectMemberCall(node)) return;
|
|
207
|
+
const property = node.callee.property;
|
|
208
|
+
if (!isIdentifier(property) || !effectAsyncCallbackCombinators.has(property.name)) return;
|
|
209
|
+
for (const argument of node.arguments) {
|
|
210
|
+
const body = callbackBody(argument);
|
|
211
|
+
const match = body ? findThrowStatement(body) : void 0;
|
|
212
|
+
if (match) return match;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
function findTryStatement(node, seen = /* @__PURE__ */ new WeakSet()) {
|
|
216
|
+
if (Array.isArray(node)) {
|
|
217
|
+
for (const child of node) {
|
|
218
|
+
const match = findTryStatement(child, seen);
|
|
219
|
+
if (match) return match;
|
|
220
|
+
}
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
if (typeof node !== "object" || node === null) return;
|
|
224
|
+
if (seen.has(node)) return;
|
|
225
|
+
seen.add(node);
|
|
226
|
+
if (node.type === "TryStatement") return node;
|
|
227
|
+
for (const [key, child] of Object.entries(node)) {
|
|
228
|
+
if (key === "parent") continue;
|
|
229
|
+
const match = findTryStatement(child, seen);
|
|
230
|
+
if (match) return match;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
function findTryCatchInEffectLogic(node) {
|
|
234
|
+
const generator = getEffectGeneratorArgument(node, "gen");
|
|
235
|
+
if (generator) return findTryStatement(generator.body);
|
|
236
|
+
if (!isEffectMemberCall(node)) return;
|
|
237
|
+
const property = node.callee.property;
|
|
238
|
+
if (!isIdentifier(property) || !effectAsyncCallbackCombinators.has(property.name)) return;
|
|
239
|
+
for (const argument of node.arguments) {
|
|
240
|
+
const body = callbackBody(argument);
|
|
241
|
+
const match = body ? findTryStatement(body) : void 0;
|
|
242
|
+
if (match) return match;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
function isPromiseStaticApiCall(node) {
|
|
246
|
+
return isMemberCall(node, "Promise", "all") || isMemberCall(node, "Promise", "allSettled") || isMemberCall(node, "Promise", "any") || isMemberCall(node, "Promise", "race") || isMemberCall(node, "Promise", "reject") || isMemberCall(node, "Promise", "resolve");
|
|
247
|
+
}
|
|
248
|
+
function isPromiseChainCall(node) {
|
|
249
|
+
if (typeof node !== "object" || node === null || node.type !== "CallExpression") return false;
|
|
250
|
+
const callee = node.callee;
|
|
251
|
+
return typeof callee === "object" && callee !== null && callee.type === "MemberExpression" && callee.computed !== true && (isIdentifier(callee.property, "then") || isIdentifier(callee.property, "catch") || isIdentifier(callee.property, "finally"));
|
|
252
|
+
}
|
|
253
|
+
function findPromiseApiCall(node, seen = /* @__PURE__ */ new WeakSet()) {
|
|
254
|
+
if (Array.isArray(node)) {
|
|
255
|
+
for (const child of node) {
|
|
256
|
+
const match = findPromiseApiCall(child, seen);
|
|
257
|
+
if (match) return match;
|
|
258
|
+
}
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
if (typeof node !== "object" || node === null) return;
|
|
262
|
+
if (seen.has(node)) return;
|
|
263
|
+
seen.add(node);
|
|
264
|
+
if (isPromiseStaticApiCall(node) || isPromiseChainCall(node)) return node;
|
|
265
|
+
for (const [key, child] of Object.entries(node)) {
|
|
266
|
+
if (key === "parent") continue;
|
|
267
|
+
const match = findPromiseApiCall(child, seen);
|
|
268
|
+
if (match) return match;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
function findPromiseApiInEffectLogic(node) {
|
|
272
|
+
const generator = getEffectGeneratorArgument(node, "gen");
|
|
273
|
+
if (generator) return findPromiseApiCall(generator.body);
|
|
274
|
+
if (!isEffectMemberCall(node)) return;
|
|
275
|
+
const property = node.callee.property;
|
|
276
|
+
if (!isIdentifier(property) || !effectAsyncCallbackCombinators.has(property.name)) return;
|
|
277
|
+
for (const argument of node.arguments) {
|
|
278
|
+
const body = callbackBody(argument);
|
|
279
|
+
const match = body ? findPromiseApiCall(body) : void 0;
|
|
280
|
+
if (match) return match;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
const promiseConcurrencyMethods = /* @__PURE__ */ new Set([
|
|
284
|
+
"all",
|
|
285
|
+
"allSettled",
|
|
286
|
+
"any",
|
|
287
|
+
"race"
|
|
288
|
+
]);
|
|
289
|
+
function isPromiseConcurrencyCall(node) {
|
|
290
|
+
if (typeof node !== "object" || node === null || node.type !== "CallExpression") return false;
|
|
291
|
+
const callee = node.callee;
|
|
292
|
+
return typeof callee === "object" && callee !== null && callee.type === "MemberExpression" && callee.computed !== true && isIdentifier(callee.object, "Promise") && isIdentifier(callee.property) && promiseConcurrencyMethods.has(callee.property.name);
|
|
293
|
+
}
|
|
294
|
+
function findPromiseConcurrencyCall(node, seen = /* @__PURE__ */ new WeakSet()) {
|
|
295
|
+
if (Array.isArray(node)) {
|
|
296
|
+
for (const child of node) {
|
|
297
|
+
const match = findPromiseConcurrencyCall(child, seen);
|
|
298
|
+
if (match) return match;
|
|
299
|
+
}
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
if (typeof node !== "object" || node === null) return;
|
|
303
|
+
if (seen.has(node)) return;
|
|
304
|
+
seen.add(node);
|
|
305
|
+
if (isPromiseConcurrencyCall(node)) return node;
|
|
306
|
+
for (const [key, child] of Object.entries(node)) {
|
|
307
|
+
if (key === "parent") continue;
|
|
308
|
+
const match = findPromiseConcurrencyCall(child, seen);
|
|
309
|
+
if (match) return match;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
function findPromiseConcurrencyInEffectLogic(node) {
|
|
313
|
+
const generator = getEffectGeneratorArgument(node, "gen");
|
|
314
|
+
if (generator) return findPromiseConcurrencyCall(generator.body);
|
|
315
|
+
if (isEffectMemberCallNamed(node, "sync")) {
|
|
316
|
+
const body = callbackBody(firstArgument(node));
|
|
317
|
+
return body ? findPromiseConcurrencyCall(body) : void 0;
|
|
318
|
+
}
|
|
319
|
+
if (!isEffectMemberCall(node)) return;
|
|
320
|
+
const property = node.callee.property;
|
|
321
|
+
if (!isIdentifier(property) || !effectAsyncCallbackCombinators.has(property.name)) return;
|
|
322
|
+
for (const argument of node.arguments) {
|
|
323
|
+
const body = callbackBody(argument);
|
|
324
|
+
const match = body ? findPromiseConcurrencyCall(body) : void 0;
|
|
325
|
+
if (match) return match;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
function callbackHasParameter(node) {
|
|
329
|
+
if (typeof node !== "object" || node === null) return false;
|
|
330
|
+
const callback = node;
|
|
331
|
+
return (callback.type === "ArrowFunctionExpression" || callback.type === "FunctionExpression") && Array.isArray(callback.params) && callback.params.length > 0;
|
|
332
|
+
}
|
|
333
|
+
function isCancellationAwareTryPromise(node) {
|
|
334
|
+
if (!isEffectMemberCallNamed(node, "tryPromise")) return false;
|
|
335
|
+
const argument = firstArgument(node);
|
|
336
|
+
if (callbackHasParameter(argument)) return true;
|
|
337
|
+
return callbackHasParameter(objectPropertyValue(argument, "try"));
|
|
338
|
+
}
|
|
339
|
+
function isNoninterruptiblePromiseEffect(node) {
|
|
340
|
+
if (isEffectMemberCallNamed(node, "promise")) return true;
|
|
341
|
+
return isEffectMemberCallNamed(node, "tryPromise") && !isCancellationAwareTryPromise(node);
|
|
342
|
+
}
|
|
343
|
+
function noninterruptiblePromiseTimeoutNode(node) {
|
|
344
|
+
if (!isEffectMemberCallNamed(node, "timeout")) return;
|
|
345
|
+
const effect = firstArgument(node);
|
|
346
|
+
return isNoninterruptiblePromiseEffect(effect) ? effect : void 0;
|
|
347
|
+
}
|
|
348
|
+
const blockingSyncObjectNames = /* @__PURE__ */ new Set([
|
|
349
|
+
"crypto",
|
|
350
|
+
"fs",
|
|
351
|
+
"zlib"
|
|
352
|
+
]);
|
|
353
|
+
function isBlockingSyncCall(node) {
|
|
354
|
+
if (typeof node !== "object" || node === null || node.type !== "CallExpression") return false;
|
|
355
|
+
const callee = node.callee;
|
|
356
|
+
if (isIdentifier(callee)) return callee.name.endsWith("Sync");
|
|
357
|
+
if (typeof callee !== "object" || callee === null || callee.type !== "MemberExpression" || callee.computed === true || !isIdentifier(callee.object) || !isIdentifier(callee.property)) return false;
|
|
358
|
+
const objectName = callee.object.name;
|
|
359
|
+
const propertyName = callee.property.name;
|
|
360
|
+
return blockingSyncObjectNames.has(objectName) && propertyName.endsWith("Sync");
|
|
361
|
+
}
|
|
362
|
+
function findBlockingSyncCall(node, seen = /* @__PURE__ */ new WeakSet()) {
|
|
363
|
+
if (Array.isArray(node)) {
|
|
364
|
+
for (const child of node) {
|
|
365
|
+
const match = findBlockingSyncCall(child, seen);
|
|
366
|
+
if (match) return match;
|
|
367
|
+
}
|
|
368
|
+
return;
|
|
369
|
+
}
|
|
370
|
+
if (typeof node !== "object" || node === null) return;
|
|
371
|
+
if (seen.has(node)) return;
|
|
372
|
+
seen.add(node);
|
|
373
|
+
if (isBlockingSyncCall(node)) return node;
|
|
374
|
+
for (const [key, child] of Object.entries(node)) {
|
|
375
|
+
if (key === "parent") continue;
|
|
376
|
+
const match = findBlockingSyncCall(child, seen);
|
|
377
|
+
if (match) return match;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
function findBlockingSyncCallInEffectLogic(node) {
|
|
381
|
+
const generator = getEffectGeneratorArgument(node, "gen");
|
|
382
|
+
if (generator) return findBlockingSyncCall(generator.body);
|
|
383
|
+
if (isEffectMemberCallNamed(node, "sync")) {
|
|
384
|
+
const body = callbackBody(firstArgument(node));
|
|
385
|
+
return body ? findBlockingSyncCall(body) : void 0;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
const effectRunMethods = /* @__PURE__ */ new Set([
|
|
389
|
+
"runCallback",
|
|
390
|
+
"runFork",
|
|
391
|
+
"runPromise",
|
|
392
|
+
"runPromiseExit",
|
|
393
|
+
"runSync",
|
|
394
|
+
"runSyncExit"
|
|
395
|
+
]);
|
|
396
|
+
function isEffectRunCall(node) {
|
|
397
|
+
if (!isEffectMemberCall(node)) return false;
|
|
398
|
+
const property = node.callee.property;
|
|
399
|
+
return isIdentifier(property) && effectRunMethods.has(property.name);
|
|
400
|
+
}
|
|
401
|
+
function isEffectOrDieReference(node) {
|
|
402
|
+
return isMemberExpression(node, "Effect", "orDie") || isMemberExpression(node, "Effect", "orDieWith") || isEffectMemberCallNamed(node, "orDie") || isEffectMemberCallNamed(node, "orDieWith");
|
|
403
|
+
}
|
|
404
|
+
function findEffectOrDieOutsideBoundary(node) {
|
|
405
|
+
if (isEffectOrDieReference(node)) return node;
|
|
406
|
+
if (isPipeCall(node)) return pipeParts(node).find((part) => isEffectOrDieReference(part));
|
|
407
|
+
}
|
|
408
|
+
function isSwallowedCatchAllBody(node) {
|
|
409
|
+
return isEffectMemberCallNamed(node, "succeed") || isEffectMemberCallNamed(node, "asVoid") || isEffectMemberCallNamed(node, "ignore") || isEffectVoidMember(node);
|
|
410
|
+
}
|
|
411
|
+
function getSwallowedCatchAllHandler(node) {
|
|
412
|
+
if (!isEffectMemberCallNamed(node, "catchAll")) return;
|
|
413
|
+
const body = callbackBody(firstArgument(node));
|
|
414
|
+
return isSwallowedCatchAllBody(body) ? body : void 0;
|
|
415
|
+
}
|
|
416
|
+
function isEffectIgnoreReference(node) {
|
|
417
|
+
return isMemberExpression(node, "Effect", "ignore") || isEffectMemberCallNamed(node, "ignore");
|
|
418
|
+
}
|
|
419
|
+
function findEffectIgnore(node) {
|
|
420
|
+
if (isEffectIgnoreReference(node)) return node;
|
|
421
|
+
if (isPipeCall(node)) return pipeParts(node).find((part) => isEffectIgnoreReference(part));
|
|
422
|
+
}
|
|
143
423
|
function isConsoleCall(node) {
|
|
144
424
|
if (typeof node !== "object" || node === null) return false;
|
|
145
425
|
const call = node;
|
|
@@ -197,6 +477,154 @@ function hasConcurrencyOne(node) {
|
|
|
197
477
|
return (isIdentifier(key, "concurrency") || typeof key === "object" && key !== null && key.value === "concurrency") && typeof value === "object" && value !== null && (value.type === "Literal" || value.type === "NumericLiteral") && value.value === 1;
|
|
198
478
|
});
|
|
199
479
|
}
|
|
480
|
+
function hasConcurrencyOption(node) {
|
|
481
|
+
if (typeof node !== "object" || node === null) return false;
|
|
482
|
+
const object = node;
|
|
483
|
+
if (object.type !== "ObjectExpression" || !Array.isArray(object.properties)) return false;
|
|
484
|
+
return object.properties.some((entry) => {
|
|
485
|
+
if (typeof entry !== "object" || entry === null) return false;
|
|
486
|
+
const key = entry.key;
|
|
487
|
+
return isIdentifier(key, "concurrency") || typeof key === "object" && key !== null && key.value === "concurrency";
|
|
488
|
+
});
|
|
489
|
+
}
|
|
490
|
+
function isCollectionMapCall(node) {
|
|
491
|
+
if (typeof node !== "object" || node === null) return false;
|
|
492
|
+
const call = node;
|
|
493
|
+
return call.type === "CallExpression" && typeof call.callee === "object" && call.callee !== null && call.callee.type === "MemberExpression" && call.callee.computed !== true && isIdentifier(call.callee.property, "map");
|
|
494
|
+
}
|
|
495
|
+
function isUnboundedMappedEffectAll(node) {
|
|
496
|
+
return isEffectMemberCallNamed(node, "all") && isCollectionMapCall(firstArgument(node)) && !hasConcurrencyOption(node.arguments[1]);
|
|
497
|
+
}
|
|
498
|
+
function containsEffectForkCall(node, seen = /* @__PURE__ */ new WeakSet()) {
|
|
499
|
+
if (isEffectMemberCallNamed(node, "fork")) return node;
|
|
500
|
+
if (Array.isArray(node)) {
|
|
501
|
+
for (const child of node) {
|
|
502
|
+
const match = containsEffectForkCall(child, seen);
|
|
503
|
+
if (match) return match;
|
|
504
|
+
}
|
|
505
|
+
return;
|
|
506
|
+
}
|
|
507
|
+
if (typeof node !== "object" || node === null) return;
|
|
508
|
+
if (seen.has(node)) return;
|
|
509
|
+
seen.add(node);
|
|
510
|
+
for (const [key, child] of Object.entries(node)) {
|
|
511
|
+
if (key === "parent") continue;
|
|
512
|
+
const match = containsEffectForkCall(child, seen);
|
|
513
|
+
if (match) return match;
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
function containsEffectMemberCallInSet(node, propertyNames, seen = /* @__PURE__ */ new WeakSet()) {
|
|
517
|
+
if (isEffectMemberCall(node)) {
|
|
518
|
+
const property = node.callee.property;
|
|
519
|
+
if (isIdentifier(property) && propertyNames.has(property.name)) return true;
|
|
520
|
+
}
|
|
521
|
+
if (Array.isArray(node)) return node.some((child) => containsEffectMemberCallInSet(child, propertyNames, seen));
|
|
522
|
+
if (typeof node !== "object" || node === null) return false;
|
|
523
|
+
if (seen.has(node)) return false;
|
|
524
|
+
seen.add(node);
|
|
525
|
+
return Object.entries(node).some(([key, child]) => key !== "parent" && containsEffectMemberCallInSet(child, propertyNames, seen));
|
|
526
|
+
}
|
|
527
|
+
const raceCleanupCalls = /* @__PURE__ */ new Set([
|
|
528
|
+
"acquireRelease",
|
|
529
|
+
"acquireUseRelease",
|
|
530
|
+
"ensuring",
|
|
531
|
+
"forkIn",
|
|
532
|
+
"forkScoped",
|
|
533
|
+
"scoped"
|
|
534
|
+
]);
|
|
535
|
+
function isEffectRaceWithoutCleanup(node) {
|
|
536
|
+
if (!isEffectMemberCallNamed(node, "race") && !isEffectMemberCallNamed(node, "raceAll")) return false;
|
|
537
|
+
return !containsEffectMemberCallInSet(node.arguments, raceCleanupCalls);
|
|
538
|
+
}
|
|
539
|
+
function isUnboundedEffectForEach(node) {
|
|
540
|
+
return isEffectMemberCallNamed(node, "forEach") && !hasConcurrencyOption(node.arguments[2]);
|
|
541
|
+
}
|
|
542
|
+
const retryCalls = /* @__PURE__ */ new Set(["retry"]);
|
|
543
|
+
function isUnboundedConcurrentRetry(node) {
|
|
544
|
+
return (isUnboundedMappedEffectAll(node) || isUnboundedEffectForEach(node)) && containsEffectMemberCallInSet(node.arguments, retryCalls);
|
|
545
|
+
}
|
|
546
|
+
function variableDeclarationIdentifierNames(node) {
|
|
547
|
+
if (typeof node !== "object" || node === null || node.type !== "VariableDeclaration") return [];
|
|
548
|
+
const declarations = node.declarations;
|
|
549
|
+
if (!Array.isArray(declarations)) return [];
|
|
550
|
+
return declarations.flatMap((declaration) => {
|
|
551
|
+
if (typeof declaration !== "object" || declaration === null) return [];
|
|
552
|
+
const id = declaration.id;
|
|
553
|
+
return isIdentifier(id) ? [id.name] : [];
|
|
554
|
+
});
|
|
555
|
+
}
|
|
556
|
+
function collectDeclaredIdentifierNames(node, names = /* @__PURE__ */ new Set(), seen = /* @__PURE__ */ new WeakSet()) {
|
|
557
|
+
if (Array.isArray(node)) {
|
|
558
|
+
for (const child of node) collectDeclaredIdentifierNames(child, names, seen);
|
|
559
|
+
return names;
|
|
560
|
+
}
|
|
561
|
+
if (typeof node !== "object" || node === null) return names;
|
|
562
|
+
if (seen.has(node)) return names;
|
|
563
|
+
seen.add(node);
|
|
564
|
+
if (node.type === "VariableDeclaration") for (const name of variableDeclarationIdentifierNames(node)) names.add(name);
|
|
565
|
+
for (const [key, child] of Object.entries(node)) if (key !== "parent") collectDeclaredIdentifierNames(child, names, seen);
|
|
566
|
+
return names;
|
|
567
|
+
}
|
|
568
|
+
const mutatingCollectionMethods = /* @__PURE__ */ new Set([
|
|
569
|
+
"add",
|
|
570
|
+
"clear",
|
|
571
|
+
"delete",
|
|
572
|
+
"pop",
|
|
573
|
+
"push",
|
|
574
|
+
"reverse",
|
|
575
|
+
"set",
|
|
576
|
+
"shift",
|
|
577
|
+
"sort",
|
|
578
|
+
"splice",
|
|
579
|
+
"unshift"
|
|
580
|
+
]);
|
|
581
|
+
function mutatedIdentifierName(node) {
|
|
582
|
+
if (typeof node !== "object" || node === null) return;
|
|
583
|
+
const candidate = node;
|
|
584
|
+
if (candidate.type === "AssignmentExpression" && isIdentifier(candidate.left)) return candidate.left.name;
|
|
585
|
+
if (candidate.type === "UpdateExpression" && isIdentifier(candidate.argument)) return candidate.argument.name;
|
|
586
|
+
if (candidate.type === "CallExpression" && typeof candidate.callee === "object" && candidate.callee !== null && candidate.callee.type === "MemberExpression" && candidate.callee.computed !== true && isIdentifier(candidate.callee.object) && isIdentifier(candidate.callee.property) && mutatingCollectionMethods.has(candidate.callee.property.name)) return candidate.callee.object.name;
|
|
587
|
+
}
|
|
588
|
+
function findSharedMutableStateMutation(node, mutableNames, localNames = collectDeclaredIdentifierNames(node), seen = /* @__PURE__ */ new WeakSet()) {
|
|
589
|
+
if (Array.isArray(node)) {
|
|
590
|
+
for (const child of node) {
|
|
591
|
+
const match = findSharedMutableStateMutation(child, mutableNames, localNames, seen);
|
|
592
|
+
if (match) return match;
|
|
593
|
+
}
|
|
594
|
+
return;
|
|
595
|
+
}
|
|
596
|
+
if (typeof node !== "object" || node === null) return;
|
|
597
|
+
if (seen.has(node)) return;
|
|
598
|
+
seen.add(node);
|
|
599
|
+
const mutatedName = mutatedIdentifierName(node);
|
|
600
|
+
if (mutatedName && mutableNames.has(mutatedName) && !localNames.has(mutatedName)) return node;
|
|
601
|
+
for (const [key, child] of Object.entries(node)) {
|
|
602
|
+
if (key === "parent") continue;
|
|
603
|
+
const match = findSharedMutableStateMutation(child, mutableNames, localNames, seen);
|
|
604
|
+
if (match) return match;
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
function concurrentEffectWorkNode(node) {
|
|
608
|
+
if (isEffectMemberCallNamed(node, "fork") || isEffectMemberCallNamed(node, "all") || isEffectMemberCallNamed(node, "forEach")) return node.arguments;
|
|
609
|
+
}
|
|
610
|
+
function forkedFiberVariableName(node) {
|
|
611
|
+
if (typeof node !== "object" || node === null || node.type !== "VariableDeclarator") return;
|
|
612
|
+
const declarator = node;
|
|
613
|
+
return isIdentifier(declarator.id) && isEffectMemberCallNamed(declarator.init, "fork") ? declarator.id.name : void 0;
|
|
614
|
+
}
|
|
615
|
+
const fiberObservationCalls = /* @__PURE__ */ new Set([
|
|
616
|
+
"await",
|
|
617
|
+
"interrupt",
|
|
618
|
+
"join"
|
|
619
|
+
]);
|
|
620
|
+
function observedFiberVariableName(node) {
|
|
621
|
+
if (typeof node !== "object" || node === null || node.type !== "CallExpression") return;
|
|
622
|
+
const call = node;
|
|
623
|
+
const callee = call.callee;
|
|
624
|
+
if (typeof callee !== "object" || callee === null || callee.type !== "MemberExpression" || callee.computed === true || !isIdentifier(callee.object, "Fiber") || !isIdentifier(callee.property) || !fiberObservationCalls.has(callee.property.name) || !Array.isArray(call.arguments)) return;
|
|
625
|
+
const [fiber] = call.arguments;
|
|
626
|
+
return isIdentifier(fiber) ? fiber.name : void 0;
|
|
627
|
+
}
|
|
200
628
|
function isEffectAsVoidPipeArgument(node) {
|
|
201
629
|
return isMemberExpression(node, "Effect", "asVoid") || isMemberCall(node, "Effect", "asVoid");
|
|
202
630
|
}
|
|
@@ -232,6 +660,48 @@ function isQualifiedTypeReference(node, leftName, rightName) {
|
|
|
232
660
|
const typeName = node.typeName;
|
|
233
661
|
return typeof typeName === "object" && typeName !== null && typeName.type === "TSQualifiedName" && isIdentifier(typeName.left, leftName) && isIdentifier(typeName.right, rightName);
|
|
234
662
|
}
|
|
663
|
+
function isIdentifierTypeReference(node, name) {
|
|
664
|
+
return typeof node === "object" && node !== null && node.type === "TSTypeReference" && isIdentifier(node.typeName, name);
|
|
665
|
+
}
|
|
666
|
+
function typeArguments(node) {
|
|
667
|
+
if (typeof node !== "object" || node === null) return [];
|
|
668
|
+
const container = node.typeParameters ?? node.typeArguments;
|
|
669
|
+
if (typeof container !== "object" || container === null) return [];
|
|
670
|
+
const params = container.params ?? container.arguments;
|
|
671
|
+
return Array.isArray(params) ? params : [];
|
|
672
|
+
}
|
|
673
|
+
function isGenericErrorType(node) {
|
|
674
|
+
return isIdentifier(node, "Error") || isIdentifierTypeReference(node, "Error");
|
|
675
|
+
}
|
|
676
|
+
function returnTypeAnnotation(node) {
|
|
677
|
+
if (typeof node !== "object" || node === null) return;
|
|
678
|
+
const returnType = node.returnType;
|
|
679
|
+
if (typeof returnType !== "object" || returnType === null) return;
|
|
680
|
+
return returnType.typeAnnotation ?? returnType;
|
|
681
|
+
}
|
|
682
|
+
function genericEffectErrorReturnType(node) {
|
|
683
|
+
const annotation = returnTypeAnnotation(node);
|
|
684
|
+
if (!isQualifiedTypeReference(annotation, "Effect", "Effect")) return;
|
|
685
|
+
const [, error] = typeArguments(annotation);
|
|
686
|
+
return isGenericErrorType(error) ? annotation : void 0;
|
|
687
|
+
}
|
|
688
|
+
function exportedGenericEffectErrorTarget(node) {
|
|
689
|
+
if (typeof node !== "object" || node === null) return;
|
|
690
|
+
const exportNode = node;
|
|
691
|
+
if (exportNode.type !== "ExportNamedDeclaration" && exportNode.type !== "ExportDefaultDeclaration") return;
|
|
692
|
+
const declaration = exportNode.declaration;
|
|
693
|
+
if (typeof declaration !== "object" || declaration === null) return;
|
|
694
|
+
if (declaration.type === "FunctionDeclaration") return genericEffectErrorReturnType(declaration);
|
|
695
|
+
if (declaration.type !== "VariableDeclaration") return;
|
|
696
|
+
for (const declarator of declaration.declarations ?? []) {
|
|
697
|
+
if (typeof declarator !== "object" || declarator === null) continue;
|
|
698
|
+
const init = declarator.init;
|
|
699
|
+
if (typeof init === "object" && init !== null && (init.type === "ArrowFunctionExpression" || init.type === "FunctionExpression")) {
|
|
700
|
+
const target = genericEffectErrorReturnType(init);
|
|
701
|
+
if (target) return target;
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
}
|
|
235
705
|
function containsQualifiedTypeReference(node, leftName, rightName, seen = /* @__PURE__ */ new WeakSet()) {
|
|
236
706
|
if (isQualifiedTypeReference(node, leftName, rightName)) return true;
|
|
237
707
|
if (Array.isArray(node)) return node.some((child) => containsQualifiedTypeReference(child, leftName, rightName, seen));
|
|
@@ -909,6 +1379,20 @@ const noNestedEffectGen = defineRule({ create(context) {
|
|
|
909
1379
|
}
|
|
910
1380
|
};
|
|
911
1381
|
} });
|
|
1382
|
+
const noYieldWithoutStarInEffectGen = defineRule({ create(context) {
|
|
1383
|
+
let hasEffectEcosystemImport = false;
|
|
1384
|
+
return {
|
|
1385
|
+
ImportDeclaration(node) {
|
|
1386
|
+
const source = getImportSource(node);
|
|
1387
|
+
if (source && isEffectEcosystemImport(source)) hasEffectEcosystemImport = true;
|
|
1388
|
+
},
|
|
1389
|
+
CallExpression(node) {
|
|
1390
|
+
if (!hasEffectEcosystemImport) return;
|
|
1391
|
+
const yieldNode = findYieldWithoutStarInEffectGen(node);
|
|
1392
|
+
if (yieldNode) report(context, yieldNode, "Rule: use yield* inside Effect.gen. Why: plain yield returns an Effect value without delegating to the Effect interpreter. Fix: replace `yield Effect.x` with `yield* Effect.x`.");
|
|
1393
|
+
}
|
|
1394
|
+
};
|
|
1395
|
+
} });
|
|
912
1396
|
const noMatchVoidBranch = defineRule({ create(context) {
|
|
913
1397
|
let hasEffectEcosystemImport = false;
|
|
914
1398
|
return {
|
|
@@ -953,6 +1437,104 @@ const noEffectAllStepSequencing = defineRule({ create(context) {
|
|
|
953
1437
|
if (isEffectAllAsVoidPipe(node) && containsAllStepSideEffect(firstArgument(node.callee.object))) report(context, node, "Rule: avoid Effect.all for sequential side-effect steps. Why: it hides imperative sequencing in an array. Fix: use one explicit linear pipeline with Effect.andThen/flatMap and reserve Effect.all for real value aggregation.");
|
|
954
1438
|
} };
|
|
955
1439
|
} });
|
|
1440
|
+
const noAsyncEffectCombinatorCallback = defineRule({ create(context) {
|
|
1441
|
+
let hasEffectEcosystemImport = false;
|
|
1442
|
+
return {
|
|
1443
|
+
ImportDeclaration(node) {
|
|
1444
|
+
const source = getImportSource(node);
|
|
1445
|
+
if (source && isEffectEcosystemImport(source)) hasEffectEcosystemImport = true;
|
|
1446
|
+
},
|
|
1447
|
+
CallExpression(node) {
|
|
1448
|
+
if (!hasEffectEcosystemImport) return;
|
|
1449
|
+
const callback = findAsyncEffectCombinatorCallback(node);
|
|
1450
|
+
if (callback) report(context, callback, "Rule: avoid async callbacks in Effect combinators. Why: async callbacks return Promises and bypass Effect failure, interruption, and tracing semantics. Fix: return an Effect and compose with Effect.flatMap/fromPromise at the boundary.");
|
|
1451
|
+
}
|
|
1452
|
+
};
|
|
1453
|
+
} });
|
|
1454
|
+
const noThrowInEffectLogic = defineRule({ create(context) {
|
|
1455
|
+
let hasEffectEcosystemImport = false;
|
|
1456
|
+
return {
|
|
1457
|
+
ImportDeclaration(node) {
|
|
1458
|
+
const source = getImportSource(node);
|
|
1459
|
+
if (source && isEffectEcosystemImport(source)) hasEffectEcosystemImport = true;
|
|
1460
|
+
},
|
|
1461
|
+
CallExpression(node) {
|
|
1462
|
+
if (!hasEffectEcosystemImport) return;
|
|
1463
|
+
const throwNode = findThrowInEffectLogic(node);
|
|
1464
|
+
if (throwNode) report(context, throwNode, "Rule: avoid throw inside Effect logic. Why: thrown exceptions bypass typed Effect error channels and interruption semantics. Fix: return Effect.fail with a structured tagged error.");
|
|
1465
|
+
}
|
|
1466
|
+
};
|
|
1467
|
+
} });
|
|
1468
|
+
const noOrDieOutsideBoundary = defineRule({ create(context) {
|
|
1469
|
+
let hasEffectEcosystemImport = false;
|
|
1470
|
+
return {
|
|
1471
|
+
ImportDeclaration(node) {
|
|
1472
|
+
const source = getImportSource(node);
|
|
1473
|
+
if (source && isEffectEcosystemImport(source)) hasEffectEcosystemImport = true;
|
|
1474
|
+
},
|
|
1475
|
+
CallExpression(node) {
|
|
1476
|
+
if (!hasEffectEcosystemImport) return;
|
|
1477
|
+
const target = findEffectOrDieOutsideBoundary(node);
|
|
1478
|
+
if (target) report(context, target, "Rule: avoid Effect.orDie outside runtime boundaries. Why: converting typed failures into defects hides recoverable domain errors. Fix: keep typed errors in domain logic and reserve orDie/orDieWith for explicit application boundaries.");
|
|
1479
|
+
}
|
|
1480
|
+
};
|
|
1481
|
+
} });
|
|
1482
|
+
const noSwallowedCatchAll = defineRule({ create(context) {
|
|
1483
|
+
let hasEffectEcosystemImport = false;
|
|
1484
|
+
return {
|
|
1485
|
+
ImportDeclaration(node) {
|
|
1486
|
+
const source = getImportSource(node);
|
|
1487
|
+
if (source && isEffectEcosystemImport(source)) hasEffectEcosystemImport = true;
|
|
1488
|
+
},
|
|
1489
|
+
CallExpression(node) {
|
|
1490
|
+
if (!hasEffectEcosystemImport) return;
|
|
1491
|
+
const handlerBody = getSwallowedCatchAllHandler(node);
|
|
1492
|
+
if (handlerBody) report(context, handlerBody, "Rule: avoid swallowing errors in catchAll. Why: succeed/void recovery can hide failures without telemetry or typed recovery. Fix: log, re-fail with a structured error, or recover through an explicit domain branch.");
|
|
1493
|
+
}
|
|
1494
|
+
};
|
|
1495
|
+
} });
|
|
1496
|
+
const noEffectIgnore = defineRule({ create(context) {
|
|
1497
|
+
let hasEffectEcosystemImport = false;
|
|
1498
|
+
return {
|
|
1499
|
+
ImportDeclaration(node) {
|
|
1500
|
+
const source = getImportSource(node);
|
|
1501
|
+
if (source && isEffectEcosystemImport(source)) hasEffectEcosystemImport = true;
|
|
1502
|
+
},
|
|
1503
|
+
CallExpression(node) {
|
|
1504
|
+
if (!hasEffectEcosystemImport) return;
|
|
1505
|
+
const target = findEffectIgnore(node);
|
|
1506
|
+
if (target) report(context, target, "Rule: avoid Effect.ignore. Why: ignoring failable effects hides failure ownership. Fix: handle the error with typed recovery, log and re-fail, or isolate the ignore at an explicit boundary with a documented reason.");
|
|
1507
|
+
}
|
|
1508
|
+
};
|
|
1509
|
+
} });
|
|
1510
|
+
const noTryCatchInEffectLogic = defineRule({ create(context) {
|
|
1511
|
+
let hasEffectEcosystemImport = false;
|
|
1512
|
+
return {
|
|
1513
|
+
ImportDeclaration(node) {
|
|
1514
|
+
const source = getImportSource(node);
|
|
1515
|
+
if (source && isEffectEcosystemImport(source)) hasEffectEcosystemImport = true;
|
|
1516
|
+
},
|
|
1517
|
+
CallExpression(node) {
|
|
1518
|
+
if (!hasEffectEcosystemImport) return;
|
|
1519
|
+
const tryNode = findTryCatchInEffectLogic(node);
|
|
1520
|
+
if (tryNode) report(context, tryNode, "Rule: avoid try/catch inside Effect logic. Why: it bypasses typed error channels and can miss interruption/cause semantics. Fix: use Effect.try, Effect.catchAll, Effect.catchTag, or typed error combinators.");
|
|
1521
|
+
}
|
|
1522
|
+
};
|
|
1523
|
+
} });
|
|
1524
|
+
const noPromiseApiInEffectLogic = defineRule({ create(context) {
|
|
1525
|
+
let hasEffectEcosystemImport = false;
|
|
1526
|
+
return {
|
|
1527
|
+
ImportDeclaration(node) {
|
|
1528
|
+
const source = getImportSource(node);
|
|
1529
|
+
if (source && isEffectEcosystemImport(source)) hasEffectEcosystemImport = true;
|
|
1530
|
+
},
|
|
1531
|
+
CallExpression(node) {
|
|
1532
|
+
if (!hasEffectEcosystemImport) return;
|
|
1533
|
+
const promiseNode = findPromiseApiInEffectLogic(node);
|
|
1534
|
+
if (promiseNode) report(context, promiseNode, "Rule: avoid Promise APIs inside Effect logic. Why: Promise APIs bypass Effect scheduling, typed errors, cancellation, and tracing. Fix: use Effect.all, Effect.tryPromise, or move Promise interop to a boundary adapter.");
|
|
1535
|
+
}
|
|
1536
|
+
};
|
|
1537
|
+
} });
|
|
956
1538
|
const noTryCatch = defineRule({ create(context) {
|
|
957
1539
|
return { TryStatement(node) {
|
|
958
1540
|
report(context, node, "Rule: avoid try/catch in Effect files. Why: it bypasses Effect error channels and reintroduces imperative control flow. Fix: model failures in Effect and handle them with typed errors and Effect combinators.");
|
|
@@ -1060,6 +1642,23 @@ const noEffectTypeAlias = defineRule({ create(context) {
|
|
|
1060
1642
|
}
|
|
1061
1643
|
};
|
|
1062
1644
|
} });
|
|
1645
|
+
const noPublicGenericEffectError = defineRule({ create(context) {
|
|
1646
|
+
let hasEffectEcosystemImport = false;
|
|
1647
|
+
return {
|
|
1648
|
+
ImportDeclaration(node) {
|
|
1649
|
+
const source = getImportSource(node);
|
|
1650
|
+
if (source && isEffectEcosystemImport(source)) hasEffectEcosystemImport = true;
|
|
1651
|
+
},
|
|
1652
|
+
ExportNamedDeclaration(node) {
|
|
1653
|
+
const target = hasEffectEcosystemImport ? exportedGenericEffectErrorTarget(node) : void 0;
|
|
1654
|
+
if (target) report(context, target, "Rule: avoid public Effect APIs with generic Error. Why: public services need recoverable, typed error contracts. Fix: expose tagged domain errors instead of Error.");
|
|
1655
|
+
},
|
|
1656
|
+
ExportDefaultDeclaration(node) {
|
|
1657
|
+
const target = hasEffectEcosystemImport ? exportedGenericEffectErrorTarget(node) : void 0;
|
|
1658
|
+
if (target) report(context, target, "Rule: avoid public Effect APIs with generic Error. Why: public services need recoverable, typed error contracts. Fix: expose tagged domain errors instead of Error.");
|
|
1659
|
+
}
|
|
1660
|
+
};
|
|
1661
|
+
} });
|
|
1063
1662
|
const noModelOverlayCast = defineRule({ create(context) {
|
|
1064
1663
|
let hasEffectEcosystemImport = false;
|
|
1065
1664
|
return {
|
|
@@ -1289,6 +1888,18 @@ function createForbiddenMemberCallRule(objectName, propertyName, message) {
|
|
|
1289
1888
|
}
|
|
1290
1889
|
const noEffectBind = createForbiddenMemberCallRule("Effect", "bind", "Rule: avoid Effect.bind. Why: it obscures linear data flow behind builder-style binding. Fix: use Effect.gen or a direct pipe with flatMap/map.");
|
|
1291
1890
|
const noRuntimeRunFork = createForbiddenMemberCallRule("Runtime", "runFork", "Rule: avoid Runtime.runFork. Why: detached fibers hide lifetime and interruption ownership. Fix: run effects through the application runtime boundary.");
|
|
1891
|
+
const noRunEffectOutsideBoundary = defineRule({ create(context) {
|
|
1892
|
+
let hasEffectEcosystemImport = false;
|
|
1893
|
+
return {
|
|
1894
|
+
ImportDeclaration(node) {
|
|
1895
|
+
const source = getImportSource(node);
|
|
1896
|
+
if (source && isEffectEcosystemImport(source)) hasEffectEcosystemImport = true;
|
|
1897
|
+
},
|
|
1898
|
+
CallExpression(node) {
|
|
1899
|
+
if (hasEffectEcosystemImport && isEffectRunCall(node)) report(context, node.callee, "Rule: avoid running Effects outside runtime boundaries. Why: direct Effect.run* calls scatter execution ownership. Fix: return Effects from domain logic and run them at the app, CLI, worker, route, or test boundary.");
|
|
1900
|
+
}
|
|
1901
|
+
};
|
|
1902
|
+
} });
|
|
1292
1903
|
const noEffectAsync = createForbiddenMemberCallRule("Effect", "async", "Rule: avoid Effect.async. Why: manual callback bridges are easy to leak or resume incorrectly. Fix: use scoped Effect APIs or a dedicated platform adapter.");
|
|
1293
1904
|
const noNestedEffectCall = defineRule({ create(context) {
|
|
1294
1905
|
return { CallExpression(node) {
|
|
@@ -1334,6 +1945,159 @@ const noEffectOrElseLadder = defineRule({ create(context) {
|
|
|
1334
1945
|
if (hasOrElseSequencingFirstArgument(node)) report(context, node, "Rule: avoid Effect.orElse around sequencing chains. Why: it hides error handling and splits the flow. Fix: move error handling to a single terminal decision after the pipeline.");
|
|
1335
1946
|
} };
|
|
1336
1947
|
} });
|
|
1948
|
+
const noUnboundedEffectAll = defineRule({ create(context) {
|
|
1949
|
+
let hasEffectEcosystemImport = false;
|
|
1950
|
+
return {
|
|
1951
|
+
ImportDeclaration(node) {
|
|
1952
|
+
const source = getImportSource(node);
|
|
1953
|
+
if (source && isEffectEcosystemImport(source)) hasEffectEcosystemImport = true;
|
|
1954
|
+
},
|
|
1955
|
+
CallExpression(node) {
|
|
1956
|
+
if (hasEffectEcosystemImport && isUnboundedMappedEffectAll(node)) report(context, node, "Rule: avoid unbounded Effect.all over mapped collections. Why: it can launch work for every item at once and fail under load. Fix: pass an explicit `{ concurrency: n }` option or use a bounded batching strategy.");
|
|
1957
|
+
}
|
|
1958
|
+
};
|
|
1959
|
+
} });
|
|
1960
|
+
const noFireAndForgetFork = defineRule({ create(context) {
|
|
1961
|
+
let hasEffectEcosystemImport = false;
|
|
1962
|
+
return {
|
|
1963
|
+
ImportDeclaration(node) {
|
|
1964
|
+
const source = getImportSource(node);
|
|
1965
|
+
if (source && isEffectEcosystemImport(source)) hasEffectEcosystemImport = true;
|
|
1966
|
+
},
|
|
1967
|
+
ExpressionStatement(node) {
|
|
1968
|
+
if (hasEffectEcosystemImport && isEffectMemberCallNamed(node.expression, "fork")) report(context, node.expression, "Rule: avoid fire-and-forget Effect.fork. Why: detached fibers hide failure, interruption, and ownership. Fix: bind the fiber and join/await/interrupt it, or use Effect.forkScoped / Effect.forkIn with an explicit scope.");
|
|
1969
|
+
}
|
|
1970
|
+
};
|
|
1971
|
+
} });
|
|
1972
|
+
const noForkInLoop = defineRule({ create(context) {
|
|
1973
|
+
let hasEffectEcosystemImport = false;
|
|
1974
|
+
const checkLoop = (node) => {
|
|
1975
|
+
if (!hasEffectEcosystemImport) return;
|
|
1976
|
+
const fork = containsEffectForkCall(node.body);
|
|
1977
|
+
if (fork) report(context, fork, "Rule: avoid Effect.fork inside loops. Why: loop-spawned fibers create unbounded concurrency and unclear ownership. Fix: use Effect.forEach / Effect.all with an explicit concurrency limit or a scoped supervisor.");
|
|
1978
|
+
};
|
|
1979
|
+
return {
|
|
1980
|
+
ImportDeclaration(node) {
|
|
1981
|
+
const source = getImportSource(node);
|
|
1982
|
+
if (source && isEffectEcosystemImport(source)) hasEffectEcosystemImport = true;
|
|
1983
|
+
},
|
|
1984
|
+
ForStatement: checkLoop,
|
|
1985
|
+
ForInStatement: checkLoop,
|
|
1986
|
+
ForOfStatement: checkLoop,
|
|
1987
|
+
WhileStatement: checkLoop,
|
|
1988
|
+
DoWhileStatement: checkLoop
|
|
1989
|
+
};
|
|
1990
|
+
} });
|
|
1991
|
+
const noRaceWithoutCleanup = defineRule({ create(context) {
|
|
1992
|
+
let hasEffectEcosystemImport = false;
|
|
1993
|
+
return {
|
|
1994
|
+
ImportDeclaration(node) {
|
|
1995
|
+
const source = getImportSource(node);
|
|
1996
|
+
if (source && isEffectEcosystemImport(source)) hasEffectEcosystemImport = true;
|
|
1997
|
+
},
|
|
1998
|
+
CallExpression(node) {
|
|
1999
|
+
if (hasEffectEcosystemImport && isEffectRaceWithoutCleanup(node)) report(context, node, "Rule: avoid Effect.race without loser cleanup. Why: racing effects without ensuring/scoped cleanup can leak losing work or resources. Fix: wrap raced effects with Effect.ensuring/acquireRelease or use a scoped race boundary.");
|
|
2000
|
+
}
|
|
2001
|
+
};
|
|
2002
|
+
} });
|
|
2003
|
+
const noUnobservedFiber = defineRule({ create(context) {
|
|
2004
|
+
let hasEffectEcosystemImport = false;
|
|
2005
|
+
const forkedFibers = /* @__PURE__ */ new Map();
|
|
2006
|
+
const observedFibers = /* @__PURE__ */ new Set();
|
|
2007
|
+
return {
|
|
2008
|
+
ImportDeclaration(node) {
|
|
2009
|
+
const source = getImportSource(node);
|
|
2010
|
+
if (source && isEffectEcosystemImport(source)) hasEffectEcosystemImport = true;
|
|
2011
|
+
},
|
|
2012
|
+
VariableDeclarator(node) {
|
|
2013
|
+
const name = forkedFiberVariableName(node);
|
|
2014
|
+
if (name) forkedFibers.set(name, node);
|
|
2015
|
+
},
|
|
2016
|
+
CallExpression(node) {
|
|
2017
|
+
const name = observedFiberVariableName(node);
|
|
2018
|
+
if (name) observedFibers.add(name);
|
|
2019
|
+
},
|
|
2020
|
+
"Program:exit"() {
|
|
2021
|
+
if (!hasEffectEcosystemImport) return;
|
|
2022
|
+
for (const [name, node] of forkedFibers) if (!observedFibers.has(name)) report(context, node, "Rule: avoid unobserved forked fibers. Why: forked fiber failures and interruption should be observed. Fix: pass the fiber to Fiber.join, Fiber.await, Fiber.interrupt, or use scoped fork APIs.");
|
|
2023
|
+
}
|
|
2024
|
+
};
|
|
2025
|
+
} });
|
|
2026
|
+
const noUnboundedConcurrentRetry = defineRule({ create(context) {
|
|
2027
|
+
let hasEffectEcosystemImport = false;
|
|
2028
|
+
return {
|
|
2029
|
+
ImportDeclaration(node) {
|
|
2030
|
+
const source = getImportSource(node);
|
|
2031
|
+
if (source && isEffectEcosystemImport(source)) hasEffectEcosystemImport = true;
|
|
2032
|
+
},
|
|
2033
|
+
CallExpression(node) {
|
|
2034
|
+
if (hasEffectEcosystemImport && isUnboundedConcurrentRetry(node)) report(context, node, "Rule: avoid unbounded concurrent retry. Why: retry inside unbounded parallel collection effects can amplify load and create retry storms. Fix: add an explicit concurrency limit or move retry behind a bounded queue/backoff policy.");
|
|
2035
|
+
}
|
|
2036
|
+
};
|
|
2037
|
+
} });
|
|
2038
|
+
const noBlockingCallInEffect = defineRule({ create(context) {
|
|
2039
|
+
let hasEffectEcosystemImport = false;
|
|
2040
|
+
return {
|
|
2041
|
+
ImportDeclaration(node) {
|
|
2042
|
+
const source = getImportSource(node);
|
|
2043
|
+
if (source && isEffectEcosystemImport(source)) hasEffectEcosystemImport = true;
|
|
2044
|
+
},
|
|
2045
|
+
CallExpression(node) {
|
|
2046
|
+
if (!hasEffectEcosystemImport) return;
|
|
2047
|
+
const blockingNode = findBlockingSyncCallInEffectLogic(node);
|
|
2048
|
+
if (blockingNode) report(context, blockingNode, "Rule: avoid blocking sync calls inside Effect logic. Why: sync fs/crypto/zlib calls block the runtime worker and hide throughput costs. Fix: use Effect.async/tryPromise at a platform boundary, stream APIs, or a dedicated blocking executor.");
|
|
2049
|
+
}
|
|
2050
|
+
};
|
|
2051
|
+
} });
|
|
2052
|
+
const noPromiseConcurrencyInEffect = defineRule({ create(context) {
|
|
2053
|
+
let hasEffectEcosystemImport = false;
|
|
2054
|
+
return {
|
|
2055
|
+
ImportDeclaration(node) {
|
|
2056
|
+
const source = getImportSource(node);
|
|
2057
|
+
if (source && isEffectEcosystemImport(source)) hasEffectEcosystemImport = true;
|
|
2058
|
+
},
|
|
2059
|
+
CallExpression(node) {
|
|
2060
|
+
if (!hasEffectEcosystemImport) return;
|
|
2061
|
+
const promiseNode = findPromiseConcurrencyInEffectLogic(node);
|
|
2062
|
+
if (promiseNode) report(context, promiseNode, "Rule: avoid Promise concurrency APIs inside Effect logic. Why: Promise.all/allSettled/race/any bypass Effect concurrency, interruption, tracing, and error channels. Fix: use Effect.all, Effect.forEach, Effect.race, or a boundary adapter with explicit cancellation ownership.");
|
|
2063
|
+
}
|
|
2064
|
+
};
|
|
2065
|
+
} });
|
|
2066
|
+
const noSharedMutableStateAcrossFibers = defineRule({ create(context) {
|
|
2067
|
+
let hasEffectEcosystemImport = false;
|
|
2068
|
+
const mutableNames = /* @__PURE__ */ new Set();
|
|
2069
|
+
return {
|
|
2070
|
+
ImportDeclaration(node) {
|
|
2071
|
+
const source = getImportSource(node);
|
|
2072
|
+
if (source && isEffectEcosystemImport(source)) hasEffectEcosystemImport = true;
|
|
2073
|
+
},
|
|
2074
|
+
VariableDeclaration(node) {
|
|
2075
|
+
if (node.kind !== "let" && node.kind !== "var") return;
|
|
2076
|
+
for (const name of variableDeclarationIdentifierNames(node)) mutableNames.add(name);
|
|
2077
|
+
},
|
|
2078
|
+
CallExpression(node) {
|
|
2079
|
+
if (!hasEffectEcosystemImport) return;
|
|
2080
|
+
const workNode = concurrentEffectWorkNode(node);
|
|
2081
|
+
if (!workNode) return;
|
|
2082
|
+
const mutationNode = findSharedMutableStateMutation(workNode, mutableNames);
|
|
2083
|
+
if (mutationNode) report(context, mutationNode, "Rule: avoid mutating shared state across fibers. Why: outer let/var state mutated from forked or parallel work creates nondeterministic races. Fix: model shared state with Ref/SynchronizedRef/Queue or aggregate immutable results with bounded Effect.all/forEach.");
|
|
2084
|
+
}
|
|
2085
|
+
};
|
|
2086
|
+
} });
|
|
2087
|
+
const noTimeoutWithNoninterruptiblePromise = defineRule({ create(context) {
|
|
2088
|
+
let hasEffectEcosystemImport = false;
|
|
2089
|
+
return {
|
|
2090
|
+
ImportDeclaration(node) {
|
|
2091
|
+
const source = getImportSource(node);
|
|
2092
|
+
if (source && isEffectEcosystemImport(source)) hasEffectEcosystemImport = true;
|
|
2093
|
+
},
|
|
2094
|
+
CallExpression(node) {
|
|
2095
|
+
if (!hasEffectEcosystemImport) return;
|
|
2096
|
+
const promiseNode = noninterruptiblePromiseTimeoutNode(node);
|
|
2097
|
+
if (promiseNode) report(context, promiseNode, "Rule: avoid timeout around noninterruptible Promise effects. Why: timing out Effect.promise or tryPromise without a signal leaves the underlying Promise running after interruption. Fix: use Effect.tryPromise with an AbortSignal parameter and pass it to the async API.");
|
|
2098
|
+
}
|
|
2099
|
+
};
|
|
2100
|
+
} });
|
|
1337
2101
|
const rules = {
|
|
1338
2102
|
"no-react-state": noReactState,
|
|
1339
2103
|
"no-if-statement": noIfStatement,
|
|
@@ -1350,11 +2114,19 @@ const rules = {
|
|
|
1350
2114
|
"no-effect-fn-generator": noEffectFnGenerator,
|
|
1351
2115
|
"no-effect-sync-console": noEffectSyncConsole,
|
|
1352
2116
|
"no-nested-effect-gen": noNestedEffectGen,
|
|
2117
|
+
"no-yield-without-star-in-effect-gen": noYieldWithoutStarInEffectGen,
|
|
1353
2118
|
"no-match-void-branch": noMatchVoidBranch,
|
|
1354
2119
|
"no-match-effect-branch": noMatchEffectBranch,
|
|
1355
2120
|
"warn-effect-sync-wrapper": warnEffectSyncWrapper,
|
|
1356
2121
|
"no-effect-side-effect-wrapper": noEffectSideEffectWrapper,
|
|
1357
2122
|
"no-effect-all-step-sequencing": noEffectAllStepSequencing,
|
|
2123
|
+
"no-async-effect-combinator-callback": noAsyncEffectCombinatorCallback,
|
|
2124
|
+
"no-throw-in-effect-logic": noThrowInEffectLogic,
|
|
2125
|
+
"no-or-die-outside-boundary": noOrDieOutsideBoundary,
|
|
2126
|
+
"no-swallowed-catch-all": noSwallowedCatchAll,
|
|
2127
|
+
"no-effect-ignore": noEffectIgnore,
|
|
2128
|
+
"no-try-catch-in-effect-logic": noTryCatchInEffectLogic,
|
|
2129
|
+
"no-promise-api-in-effect-logic": noPromiseApiInEffectLogic,
|
|
1358
2130
|
"no-try-catch": noTryCatch,
|
|
1359
2131
|
"no-effect-wrapper-alias": noEffectWrapperAlias,
|
|
1360
2132
|
"no-manual-effect-channels": noManualEffectChannels,
|
|
@@ -1366,6 +2138,7 @@ const rules = {
|
|
|
1366
2138
|
"no-naked-object-state-update": noNakedObjectStateUpdate,
|
|
1367
2139
|
"no-effect-succeed-variable": noEffectSucceedVariable,
|
|
1368
2140
|
"no-effect-type-alias": noEffectTypeAlias,
|
|
2141
|
+
"no-public-generic-effect-error": noPublicGenericEffectError,
|
|
1369
2142
|
"no-model-overlay-cast": noModelOverlayCast,
|
|
1370
2143
|
"no-unknown-boolean-coercion-helper": noUnknownBooleanCoercionHelper,
|
|
1371
2144
|
"no-fromnullable-nullish-coalesce": noFromnullableNullishCoalesce,
|
|
@@ -1386,6 +2159,7 @@ const rules = {
|
|
|
1386
2159
|
"no-effect-do": noEffectDo,
|
|
1387
2160
|
"no-effect-bind": noEffectBind,
|
|
1388
2161
|
"no-runtime-runfork": noRuntimeRunFork,
|
|
2162
|
+
"no-run-effect-outside-boundary": noRunEffectOutsideBoundary,
|
|
1389
2163
|
"no-effect-async": noEffectAsync,
|
|
1390
2164
|
"prevent-dynamic-imports": defineRule({ create(context) {
|
|
1391
2165
|
return { ImportExpression(node) {
|
|
@@ -1397,7 +2171,17 @@ const rules = {
|
|
|
1397
2171
|
"no-flatmap-ladder": noFlatMapLadder,
|
|
1398
2172
|
"no-pipe-ladder": noPipeLadder,
|
|
1399
2173
|
"no-call-tower": noCallTower,
|
|
1400
|
-
"no-effect-orElse-ladder": noEffectOrElseLadder
|
|
2174
|
+
"no-effect-orElse-ladder": noEffectOrElseLadder,
|
|
2175
|
+
"no-unbounded-effect-all": noUnboundedEffectAll,
|
|
2176
|
+
"no-fire-and-forget-fork": noFireAndForgetFork,
|
|
2177
|
+
"no-fork-in-loop": noForkInLoop,
|
|
2178
|
+
"no-race-without-cleanup": noRaceWithoutCleanup,
|
|
2179
|
+
"no-unobserved-fiber": noUnobservedFiber,
|
|
2180
|
+
"no-unbounded-concurrent-retry": noUnboundedConcurrentRetry,
|
|
2181
|
+
"no-blocking-call-in-effect": noBlockingCallInEffect,
|
|
2182
|
+
"no-promise-concurrency-in-effect": noPromiseConcurrencyInEffect,
|
|
2183
|
+
"no-shared-mutable-state-across-fibers": noSharedMutableStateAcrossFibers,
|
|
2184
|
+
"no-timeout-with-noninterruptible-promise": noTimeoutWithNoninterruptiblePromise
|
|
1401
2185
|
};
|
|
1402
2186
|
const allRules = Object.fromEntries(Object.keys(rules).map((ruleName) => [`linteffect/${ruleName}`, "error"]));
|
|
1403
2187
|
const recommended = {
|