@opsydyn/oxlint-effect 0.2.0 → 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 +20 -1
- package/dist/index.mjs +417 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -16,11 +16,15 @@ import { recommended } from "@opsydyn/oxlint-effect";
|
|
|
16
16
|
|
|
17
17
|
export default defineConfig({
|
|
18
18
|
plugins: ["typescript"],
|
|
19
|
-
jsPlugins: recommended.jsPlugins,
|
|
19
|
+
jsPlugins: [...recommended.jsPlugins],
|
|
20
20
|
rules: recommended.rules,
|
|
21
21
|
});
|
|
22
22
|
```
|
|
23
23
|
|
|
24
|
+
`recommended.jsPlugins` is exported as a readonly tuple. Spreading it creates
|
|
25
|
+
the mutable array shape expected by Oxlint's `ExternalPluginEntry[]` config
|
|
26
|
+
type.
|
|
27
|
+
|
|
24
28
|
For local development inside this repository, point `jsPlugins` at the TypeScript source:
|
|
25
29
|
|
|
26
30
|
```ts
|
|
@@ -74,6 +78,21 @@ boundaries.
|
|
|
74
78
|
| `linteffect/no-effect-type-alias` | Type aliases around `Effect.Effect<...>`. | Keeps service surfaces concrete and discoverable. |
|
|
75
79
|
| `linteffect/no-public-generic-effect-error` | Exported APIs returning `Effect.Effect<_, Error, _>`. | Public Effect APIs should expose tagged, recoverable domain errors instead of generic `Error`. |
|
|
76
80
|
|
|
81
|
+
### Concurrency Safety
|
|
82
|
+
|
|
83
|
+
| Rule | Catches | Why |
|
|
84
|
+
| --- | --- | --- |
|
|
85
|
+
| `linteffect/no-unbounded-effect-all` | `Effect.all(items.map(...))` without an explicit `concurrency` option. | Prevents load-dependent runaway parallelism and makes throughput ownership explicit. |
|
|
86
|
+
| `linteffect/no-fire-and-forget-fork` | Bare `Effect.fork(...)` expression statements. | Detached fibers hide failure, interruption, and lifecycle ownership. |
|
|
87
|
+
| `linteffect/no-fork-in-loop` | `Effect.fork(...)` inside `for`, `for...of`, `for...in`, `while`, or `do...while` loops. | Avoids loop-spawned unbounded fibers; use bounded `Effect.all` / `Effect.forEach` or scoped supervision. |
|
|
88
|
+
| `linteffect/no-race-without-cleanup` | `Effect.race(...)` / `Effect.raceAll(...)` without `Effect.ensuring`, scoped, or acquire/release cleanup. | Racing effects need explicit loser cleanup so losing work and resources do not leak. |
|
|
89
|
+
| `linteffect/no-unobserved-fiber` | `const fiber = Effect.fork(...)` when the fiber is never passed to `Fiber.join`, `Fiber.await`, or `Fiber.interrupt`. | Forked fibers should have observed failure and interruption ownership. |
|
|
90
|
+
| `linteffect/no-unbounded-concurrent-retry` | `Effect.retry(...)` nested inside unbounded mapped `Effect.all(...)` or unbounded `Effect.forEach(...)`. | Prevents retry storms by requiring bounded concurrency or a queue/backoff policy. |
|
|
91
|
+
| `linteffect/no-blocking-call-in-effect` | Sync `fs` / `crypto` / `zlib` calls inside `Effect.sync` or `Effect.gen`. | Blocking calls stall the runtime worker and should live behind async/platform boundaries. |
|
|
92
|
+
| `linteffect/no-promise-concurrency-in-effect` | `Promise.all`, `Promise.allSettled`, `Promise.race`, or `Promise.any` inside Effect logic. | Keeps concurrency, interruption, tracing, and typed failures inside Effect. |
|
|
93
|
+
| `linteffect/no-shared-mutable-state-across-fibers` | Outer `let` / `var` state mutated from `Effect.fork`, `Effect.all`, or `Effect.forEach` work. | Shared mutable state across fibers creates nondeterministic races; use Effect concurrency primitives. |
|
|
94
|
+
| `linteffect/no-timeout-with-noninterruptible-promise` | `Effect.timeout(Effect.promise(...))` or `Effect.timeout(Effect.tryPromise(...))` without a signal-aware callback. | Timeout should interrupt the underlying async operation, not only the Effect wrapper. |
|
|
95
|
+
|
|
77
96
|
### Pipeline Shape and Sequencing
|
|
78
97
|
|
|
79
98
|
| Rule | Catches | Why |
|
package/dist/index.mjs
CHANGED
|
@@ -280,6 +280,111 @@ function findPromiseApiInEffectLogic(node) {
|
|
|
280
280
|
if (match) return match;
|
|
281
281
|
}
|
|
282
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
|
+
}
|
|
283
388
|
const effectRunMethods = /* @__PURE__ */ new Set([
|
|
284
389
|
"runCallback",
|
|
285
390
|
"runFork",
|
|
@@ -372,6 +477,154 @@ function hasConcurrencyOne(node) {
|
|
|
372
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;
|
|
373
478
|
});
|
|
374
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
|
+
}
|
|
375
628
|
function isEffectAsVoidPipeArgument(node) {
|
|
376
629
|
return isMemberExpression(node, "Effect", "asVoid") || isMemberCall(node, "Effect", "asVoid");
|
|
377
630
|
}
|
|
@@ -1692,6 +1945,159 @@ const noEffectOrElseLadder = defineRule({ create(context) {
|
|
|
1692
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.");
|
|
1693
1946
|
} };
|
|
1694
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
|
+
} });
|
|
1695
2101
|
const rules = {
|
|
1696
2102
|
"no-react-state": noReactState,
|
|
1697
2103
|
"no-if-statement": noIfStatement,
|
|
@@ -1765,7 +2171,17 @@ const rules = {
|
|
|
1765
2171
|
"no-flatmap-ladder": noFlatMapLadder,
|
|
1766
2172
|
"no-pipe-ladder": noPipeLadder,
|
|
1767
2173
|
"no-call-tower": noCallTower,
|
|
1768
|
-
"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
|
|
1769
2185
|
};
|
|
1770
2186
|
const allRules = Object.fromEntries(Object.keys(rules).map((ruleName) => [`linteffect/${ruleName}`, "error"]));
|
|
1771
2187
|
const recommended = {
|