@systemfsoftware/oxlint-plugin-effect-platform 1.3.0 → 1.4.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/CHANGELOG.md +16 -0
- package/README.md +18 -3
- package/dist/index.d.ts +2 -3
- package/dist/index.mjs +189 -31
- package/dist/oxlint-plugin-effect-platform-untrimmed.d.ts +3 -3
- package/dist/oxlint-plugin-effect-platform.d.ts +3 -3
- package/package.json +10 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @systemfsoftware/oxlint-plugin-effect-platform
|
|
2
2
|
|
|
3
|
+
## 1.4.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- `no-unported-time-source` accepts the virtual clock shipped by `@systemfsoftware/vitest` as a registered port, so that clock's host-timer call is not reported as an unported time source.
|
|
8
|
+
|
|
9
|
+
- Adds `no-unported-time-source`, enabled at `error` in the recommended config. Production source can no longer call `Date.now`, `performance.now`, `process.hrtime`, `Math.random`, `crypto.getRandomValues`, `crypto.randomUUID`, `setTimeout`, `setInterval`, or `setImmediate`, construct an argument-less `new Date()`, or import `node:timers` or `node:timers/promises`.
|
|
10
|
+
|
|
11
|
+
Route those reads through the module that owns the source, and register that module as a port by naming its path, or a path suffix, in the rule's `ports` option. A source injected as a parameter, a local, or an import is not reported, `queueMicrotask` and `new Date(arg)` are not reported, and test and fixture files are outside the rule.
|
|
12
|
+
|
|
13
|
+
## 1.3.1
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- Update peer and runtime dependency on `effect` and companion packages to `4.0.0-rc.117`.
|
|
18
|
+
|
|
3
19
|
## 1.3.0
|
|
4
20
|
|
|
5
21
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -30,7 +30,7 @@ let runtime: ManagedRuntime.ManagedRuntime<AppLive, never> | undefined
|
|
|
30
30
|
export const getRuntime = () => (runtime ??= ManagedRuntime.make(AppLive))
|
|
31
31
|
```
|
|
32
32
|
|
|
33
|
-
And `cell.run(input)` is work, not wiring: an arrow application any module may perform at any depth. The
|
|
33
|
+
And `cell.run(input)` is work, not wiring: an arrow application any module may perform at any depth. The six rules below keep those three facts mechanical, so a file that violates them fails lint instead of review.
|
|
34
34
|
|
|
35
35
|
## Install
|
|
36
36
|
|
|
@@ -55,7 +55,7 @@ export default defineConfig({
|
|
|
55
55
|
pnpm oxlint src
|
|
56
56
|
```
|
|
57
57
|
|
|
58
|
-
All
|
|
58
|
+
All six rules are in the recommended set, so the spread enables them at `error`. To adopt gradually, drop the spread and name rules individually as `'@systemfsoftware/oxlint-plugin-effect-entrypoint/<rule>': 'warn'`; entries placed after the spread override it.
|
|
59
59
|
|
|
60
60
|
## Rules
|
|
61
61
|
|
|
@@ -66,6 +66,7 @@ All five rules are in the recommended set, so the spread enables them at `error`
|
|
|
66
66
|
| `entrypoint-not-imported` | Any static import, re-export, or dynamic `import()` of a `main` module, reported in the importing file — production, barrel, or test |
|
|
67
67
|
| `entrypoint-no-promise-wrapper` | `runMain(Effect.tryPromise(...))` or `runMain(Effect.promise(...))`: the outer edge awaits a promise while the real fibers run in a runtime it cannot interrupt |
|
|
68
68
|
| `runtime-construction-placement` | `ManagedRuntime.make` or `Layer.provide` inside a function body — wiring rebuilt per call — and `ManagedRuntime.make` at module scope, where importing the module starts fibers nothing can interrupt. It judges runtime code: a file under a `src/` directory segment, or a `*.test.ts` file; a package-root hook, config, or setup file is outside its subject |
|
|
69
|
+
| `no-unported-time-source` | A direct `Date.now`, `performance.now`, `process.hrtime`, `Math.random`, `crypto.getRandomValues`, `crypto.randomUUID`, `setTimeout`, `setInterval`, or `setImmediate` call, an argument-less `new Date()`, or a static or dynamic import of `node:timers` in production source outside a file listed in the rule's `ports` option |
|
|
69
70
|
|
|
70
71
|
What the placement rule leaves alone, each a shape the rule's own fixtures pin:
|
|
71
72
|
|
|
@@ -78,10 +79,18 @@ What the placement rule leaves alone, each a shape the rule's own fixtures pin:
|
|
|
78
79
|
|
|
79
80
|
Callers resolve through their import specifier — aliased, namespaced, or destructured from `await import('effect')`. A call reached through a re-export chain is not seen: the receiver must resolve to a direct import in the same file.
|
|
80
81
|
|
|
82
|
+
What the time-source rule leaves alone, each a shape the rule's own fixtures pin:
|
|
83
|
+
|
|
84
|
+
- `queueMicrotask(...)`: it yields to the microtask queue and reads no clock, so it is not a time source.
|
|
85
|
+
- `new Date(0)` and any `new Date(arg)`: the argument fixes the instant, so there is nothing for a clock port to own.
|
|
86
|
+
- A source injected as a parameter, shadowed by a local declaration, or imported from another module: the call crosses the boundary instead of reading the process, so the port — not the call site — owns the verdict.
|
|
87
|
+
- A file listed in the rule's `ports` option, matched by repo-relative path or path suffix: the recommended config registers `packages/atom/effect-atom/src/internal/HostTimer.ts` and `packages/effect-schema-law/src/recursion-laws.ts`.
|
|
88
|
+
- Test and fixture files (`.test.ts`, `.spec.ts`, `__tests__/`, `__fixtures__/`, `tests/`, `testResources/`): the regime binds production code.
|
|
89
|
+
|
|
81
90
|
## FAQ
|
|
82
91
|
|
|
83
92
|
**Q: Installed, but nothing is reported.**
|
|
84
|
-
A: Three of the
|
|
93
|
+
A: Three of the entrypoint rules are filename-gated to the exact basename `main.ts`. The rest judge production code, and a clean file reports nothing: `cell.run(input)` at any depth, module-scope layer composition, module-scope composition in a package-root hook, a memoized bootstrap, a timer reached through a port, and `queueMicrotask` are all outside the rules' verdicts.
|
|
85
94
|
|
|
86
95
|
**Q: Does `runtime-construction-placement` report my module-scope lazy thunk?**
|
|
87
96
|
A: No, when the thunk memoizes: `const getRuntime = () => (runtime ??= ManagedRuntime.make(AppLive))` writes the construction into a cache binding, so every call reads the one runtime. A closure that merely wraps the call — `const getRuntime = () => ManagedRuntime.make(AppLive)` — caches nothing and reports as wiring built per call, as does a runtime built inside any other function body or evaluated at import time.
|
|
@@ -101,6 +110,12 @@ A: A test importing `main.ts` proves what a production import proves: behavior l
|
|
|
101
110
|
**Q: A construction reached through a re-export chain is not reported. Why?**
|
|
102
111
|
A: The rule reads syntax only, so a receiver must resolve to a direct import in the same file. Import the constructing module directly, or the construction stays invisible to this rule.
|
|
103
112
|
|
|
113
|
+
**Q: Why does `no-unported-time-source` report `setTimeout` but not `queueMicrotask`?**
|
|
114
|
+
A: `queueMicrotask` only yields to the microtask queue — it reads no clock, so no kernel port can or must own it. `setTimeout` reads the process schedule, so it reports unless the file is a registered port.
|
|
115
|
+
|
|
116
|
+
**Q: My function takes `setTimeout` as a parameter. Is that still unported?**
|
|
117
|
+
A: No. A timer injected as a parameter crosses the port boundary at the call site; the rule stays silent wherever the name resolves to a parameter, a local declaration, or an import. Only a reference that resolves to nothing — the process global — reports.
|
|
118
|
+
|
|
104
119
|
## Requirements
|
|
105
120
|
|
|
106
121
|
`effect` and TypeScript 5.0+ as peers. The rules read syntax only; no type information or `tsconfig` wiring is needed.
|
package/dist/index.d.ts
CHANGED
|
@@ -15,12 +15,11 @@ declare const _default: {
|
|
|
15
15
|
'no-native-map-in-effect': import("@oxlint/plugins").Rule;
|
|
16
16
|
'no-native-set-in-effect': import("@oxlint/plugins").Rule;
|
|
17
17
|
'no-new-worker-with-wasm-import': import("@oxlint/plugins").Rule;
|
|
18
|
+
'no-unported-time-source': import("@oxlint/plugins").Rule;
|
|
18
19
|
};
|
|
19
20
|
configs: {
|
|
20
21
|
recommended: {
|
|
21
|
-
rules:
|
|
22
|
-
readonly [x: string]: "error";
|
|
23
|
-
};
|
|
22
|
+
rules: import("oxlint").DummyRuleMap;
|
|
24
23
|
overrides: OxlintOverride[];
|
|
25
24
|
};
|
|
26
25
|
};
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { defineRule } from "@oxlint/plugins";
|
|
2
2
|
import { Effect, Schema } from "effect";
|
|
3
3
|
//#region src/rules/entrypoint-interprets-once.config.ts
|
|
4
|
-
const Options$
|
|
4
|
+
const Options$7 = Schema.Struct({});
|
|
5
5
|
const ENTRYPOINT_FILE$2 = /(?:^|[\\/])main\.ts$/u;
|
|
6
6
|
const RUN_MAIN$1 = "runMain";
|
|
7
7
|
const QUALIFIED_EDGE_CALLEES = /* @__PURE__ */ new Set([
|
|
@@ -22,10 +22,10 @@ const MULTIPLE_EDGES_EXPECTED = "exactly one interpretation edge in the entrypoi
|
|
|
22
22
|
const MULTIPLE_EDGES_ACTUAL = "a second interpretation edge in the same entrypoint";
|
|
23
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
24
|
const INTERPRETS_ONCE_MESSAGE = "{{name}} is forbidden. Expected: {{expected}}. Actual: {{actual}}. Fix: {{fix}}.";
|
|
25
|
-
const meta$
|
|
25
|
+
const meta$9 = {
|
|
26
26
|
type: "problem",
|
|
27
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$
|
|
28
|
+
schema: [Options$7],
|
|
29
29
|
messages: {
|
|
30
30
|
missingEdge: INTERPRETS_ONCE_MESSAGE,
|
|
31
31
|
multipleEdges: INTERPRETS_ONCE_MESSAGE
|
|
@@ -47,7 +47,7 @@ const edgeName = (callee) => {
|
|
|
47
47
|
return QUALIFIED_EDGE_CALLEES.has(qualified) ? qualified : null;
|
|
48
48
|
};
|
|
49
49
|
const entrypointInterpretsOnce = defineRule({
|
|
50
|
-
meta: meta$
|
|
50
|
+
meta: meta$9,
|
|
51
51
|
create(context) {
|
|
52
52
|
if (!isEntrypointFile$2(context.filename)) return {};
|
|
53
53
|
const edges = [];
|
|
@@ -90,7 +90,7 @@ const entrypointInterpretsOnce = defineRule({
|
|
|
90
90
|
});
|
|
91
91
|
//#endregion
|
|
92
92
|
//#region src/rules/entrypoint-no-exports.config.ts
|
|
93
|
-
const Options$
|
|
93
|
+
const Options$6 = Schema.Struct({});
|
|
94
94
|
const ENTRYPOINT_FILE$1 = /(?:^|[\\/])main\.ts$/u;
|
|
95
95
|
const NAMED_EXPORT = "a named export from main.ts";
|
|
96
96
|
const DEFAULT_EXPORT = "a default export from main.ts";
|
|
@@ -98,17 +98,17 @@ const STAR_EXPORT = "a re-export from main.ts";
|
|
|
98
98
|
const ENTRYPOINT_EXPORT_EXPECTED = "an entrypoint with no public surface at all";
|
|
99
99
|
const ENTRYPOINT_EXPORT_ACTUAL = "an entrypoint exporting a binding for another module to import";
|
|
100
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$
|
|
101
|
+
const meta$8 = {
|
|
102
102
|
type: "problem",
|
|
103
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$
|
|
104
|
+
schema: [Options$6],
|
|
105
105
|
messages: { entrypointExport: "{{name}} is forbidden. Expected: {{expected}}. Actual: {{actual}}. Fix: {{fix}}." }
|
|
106
106
|
};
|
|
107
107
|
//#endregion
|
|
108
108
|
//#region src/rules/entrypoint-no-exports.ts
|
|
109
109
|
const isEntrypointFile$1 = (filename) => ENTRYPOINT_FILE$1.test(filename);
|
|
110
110
|
const entrypointNoExports = defineRule({
|
|
111
|
-
meta: meta$
|
|
111
|
+
meta: meta$8,
|
|
112
112
|
create(context) {
|
|
113
113
|
if (!isEntrypointFile$1(context.filename)) return {};
|
|
114
114
|
const reportExport = (node, name) => {
|
|
@@ -138,17 +138,17 @@ const entrypointNoExports = defineRule({
|
|
|
138
138
|
});
|
|
139
139
|
//#endregion
|
|
140
140
|
//#region src/rules/entrypoint-no-promise-wrapper.config.ts
|
|
141
|
-
const Options$
|
|
141
|
+
const Options$5 = Schema.Struct({});
|
|
142
142
|
const ENTRYPOINT_FILE = /(?:^|[\\/])main\.ts$/u;
|
|
143
143
|
const RUN_MAIN = "runMain";
|
|
144
144
|
const PROMISE_CONSTRUCTORS = /* @__PURE__ */ new Set(["Effect.promise", "Effect.tryPromise"]);
|
|
145
145
|
const PROMISE_WRAPPER_EXPECTED = "the program itself handed to runMain";
|
|
146
146
|
const PROMISE_WRAPPER_ACTUAL = "a foreign promise wrapped in an Effect and handed to runMain";
|
|
147
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$
|
|
148
|
+
const meta$7 = {
|
|
149
149
|
type: "problem",
|
|
150
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$
|
|
151
|
+
schema: [Options$5],
|
|
152
152
|
messages: { promiseWrapper: "{{name}} is forbidden. Expected: {{expected}}. Actual: {{actual}}. Fix: {{fix}}." }
|
|
153
153
|
};
|
|
154
154
|
//#endregion
|
|
@@ -174,7 +174,7 @@ const promiseConstructorName = (node) => {
|
|
|
174
174
|
return PROMISE_CONSTRUCTORS.has(qualified) ? qualified : null;
|
|
175
175
|
};
|
|
176
176
|
const entrypointNoPromiseWrapper = defineRule({
|
|
177
|
-
meta: meta$
|
|
177
|
+
meta: meta$7,
|
|
178
178
|
create(context) {
|
|
179
179
|
if (!isEntrypointFile(context.filename)) return {};
|
|
180
180
|
return { CallExpression(node) {
|
|
@@ -198,7 +198,7 @@ const entrypointNoPromiseWrapper = defineRule({
|
|
|
198
198
|
});
|
|
199
199
|
//#endregion
|
|
200
200
|
//#region src/rules/entrypoint-not-imported.config.ts
|
|
201
|
-
const Options$
|
|
201
|
+
const Options$4 = Schema.Struct({});
|
|
202
202
|
const MAIN_MODULE_SOURCE = /(?:^|\/)main(?:\.[cm]?[jt]sx?)?$/u;
|
|
203
203
|
const ENTRYPOINT_IMPORT_EXPECTED = "the entrypoint imported by nothing - the process interprets it, no module consumes it";
|
|
204
204
|
const ENTRYPOINT_IMPORT_ACTUAL = "an import of main.ts";
|
|
@@ -209,7 +209,7 @@ const entrypointNotImported = defineRule({
|
|
|
209
209
|
meta: {
|
|
210
210
|
type: "problem",
|
|
211
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$
|
|
212
|
+
schema: [Options$4],
|
|
213
213
|
messages: { entrypointImport: "{{name}} is forbidden. Expected: {{expected}}. Actual: {{actual}}. Fix: {{fix}}." }
|
|
214
214
|
},
|
|
215
215
|
create(context) {
|
|
@@ -379,15 +379,15 @@ const noLoggingInCatch = defineRule({
|
|
|
379
379
|
});
|
|
380
380
|
//#endregion
|
|
381
381
|
//#region src/rules/no-native-map-in-effect.config.ts
|
|
382
|
-
const Options$
|
|
382
|
+
const Options$3 = Schema.Struct({
|
|
383
383
|
allow: Schema.Array(Schema.String).pipe(Schema.withDecodingDefaultType(Effect.succeed([]))),
|
|
384
384
|
expected: Schema.String.pipe(Schema.withDecodingDefaultType(Effect.succeed("HashMap from effect (HashMap.empty() or HashMap.fromIterable())"))),
|
|
385
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
386
|
});
|
|
387
|
-
const meta$
|
|
387
|
+
const meta$4 = {
|
|
388
388
|
type: "problem",
|
|
389
389
|
docs: { description: "When Effect is imported, ban native Map (new Map). Use HashMap from effect instead." },
|
|
390
|
-
schema: [Schema.toJsonSchemaDocument(Options$
|
|
390
|
+
schema: [Schema.toJsonSchemaDocument(Options$3).schema],
|
|
391
391
|
messages: { forbiddenMap: "{{actual}} is forbidden when Effect is imported. Expected: {{expected}}. Actual: {{actual}}. Fix: {{fix}}." }
|
|
392
392
|
};
|
|
393
393
|
//#endregion
|
|
@@ -405,9 +405,9 @@ const isMapCallee = (callee) => {
|
|
|
405
405
|
return false;
|
|
406
406
|
};
|
|
407
407
|
const noNativeMapInEffect = defineRule({
|
|
408
|
-
meta: meta$
|
|
408
|
+
meta: meta$4,
|
|
409
409
|
create(context) {
|
|
410
|
-
const options = Schema.decodeUnknownSync(Options$
|
|
410
|
+
const options = Schema.decodeUnknownSync(Options$3)(context.options[0] ?? {});
|
|
411
411
|
const allow = new Set(options.allow);
|
|
412
412
|
let hasEffectImport = false;
|
|
413
413
|
return {
|
|
@@ -435,15 +435,15 @@ const noNativeMapInEffect = defineRule({
|
|
|
435
435
|
});
|
|
436
436
|
//#endregion
|
|
437
437
|
//#region src/rules/no-native-set-in-effect.config.ts
|
|
438
|
-
const Options$
|
|
438
|
+
const Options$2 = Schema.Struct({
|
|
439
439
|
allow: Schema.Array(Schema.String).pipe(Schema.withDecodingDefaultType(Effect.succeed([]))),
|
|
440
440
|
expected: Schema.String.pipe(Schema.withDecodingDefaultType(Effect.succeed("HashSet from effect (HashSet.empty() or HashSet.fromIterable())"))),
|
|
441
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
442
|
});
|
|
443
|
-
const meta$
|
|
443
|
+
const meta$3 = {
|
|
444
444
|
type: "problem",
|
|
445
445
|
docs: { description: "When Effect is imported, ban native Set (new Set). Use HashSet from effect instead." },
|
|
446
|
-
schema: [Schema.toJsonSchemaDocument(Options$
|
|
446
|
+
schema: [Schema.toJsonSchemaDocument(Options$2).schema],
|
|
447
447
|
messages: { forbiddenSet: "{{actual}} is forbidden when Effect is imported. Expected: {{expected}}. Actual: {{actual}}. Fix: {{fix}}." }
|
|
448
448
|
};
|
|
449
449
|
//#endregion
|
|
@@ -457,9 +457,9 @@ const isInsideEffectGen = (node) => {
|
|
|
457
457
|
return isInsideEffectGen(parent);
|
|
458
458
|
};
|
|
459
459
|
const noNativeSetInEffect = defineRule({
|
|
460
|
-
meta: meta$
|
|
460
|
+
meta: meta$3,
|
|
461
461
|
create(context) {
|
|
462
|
-
const options = Schema.decodeUnknownSync(Options$
|
|
462
|
+
const options = Schema.decodeUnknownSync(Options$2)(context.options[0] ?? {});
|
|
463
463
|
const allow = new Set(options.allow);
|
|
464
464
|
let hasEffectImport = false;
|
|
465
465
|
return {
|
|
@@ -487,15 +487,15 @@ const noNativeSetInEffect = defineRule({
|
|
|
487
487
|
});
|
|
488
488
|
//#endregion
|
|
489
489
|
//#region src/rules/no-new-worker-with-wasm-import.config.ts
|
|
490
|
-
const Options = Schema.Struct({
|
|
490
|
+
const Options$1 = Schema.Struct({
|
|
491
491
|
wasmImportPatterns: Schema.Array(Schema.String).pipe(Schema.withDecodingDefaultType(Effect.succeed([/^(@[^/]+\/)?[^/]+-wasm(\/.*)?$/].map((re) => re.source)))),
|
|
492
492
|
expected: Schema.String.pipe(Schema.withDecodingDefaultType(Effect.succeed("Bun.spawn subprocess pool"))),
|
|
493
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
494
|
});
|
|
495
|
-
const meta$
|
|
495
|
+
const meta$2 = {
|
|
496
496
|
type: "problem",
|
|
497
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],
|
|
498
|
+
schema: [Schema.toJsonSchemaDocument(Options$1).schema],
|
|
499
499
|
messages: { forbiddenNewWorkerWithWasm: "{{actual}} is forbidden when a WASM module is imported. Expected: {{expected}}. Actual: {{actual}}. Fix: {{fix}}." }
|
|
500
500
|
};
|
|
501
501
|
//#endregion
|
|
@@ -507,9 +507,9 @@ const isNewWorkerCall = (node) => {
|
|
|
507
507
|
return true;
|
|
508
508
|
};
|
|
509
509
|
const noNewWorkerWithWasmImport = defineRule({
|
|
510
|
-
meta: meta$
|
|
510
|
+
meta: meta$2,
|
|
511
511
|
create(context) {
|
|
512
|
-
const options = Schema.decodeUnknownSync(Options)(context.options[0] ?? {});
|
|
512
|
+
const options = Schema.decodeUnknownSync(Options$1)(context.options[0] ?? {});
|
|
513
513
|
const patterns = options.wasmImportPatterns.map((src) => new RegExp(src));
|
|
514
514
|
let hasWasmImport = false;
|
|
515
515
|
return {
|
|
@@ -533,6 +533,155 @@ const noNewWorkerWithWasmImport = defineRule({
|
|
|
533
533
|
}
|
|
534
534
|
});
|
|
535
535
|
//#endregion
|
|
536
|
+
//#region src/rules/no-unported-time-source.config.ts
|
|
537
|
+
const Options = Schema.Struct({ ports: Schema.Array(Schema.String).pipe(Schema.withDecodingDefaultType(Effect.succeed([]))) });
|
|
538
|
+
const TIME_SOURCE_MESSAGE = "{{name}} is forbidden. Expected: {{expected}}. Actual: {{actual}}. Fix: {{fix}}.";
|
|
539
|
+
const TIME_SOURCE_EXPECTED = "time, scheduling, and randomness reached through a named, replaceable port — a file listed in this rule's `ports` option, or a source injected as a parameter";
|
|
540
|
+
const TIME_SOURCE_FIX = "call the port module that owns this source instead of the process, and register a port file by adding its repo-relative path to this rule's `ports` option, e.g. { ports: ['packages/atom/effect-atom/src/internal/HostTimer.ts'] }";
|
|
541
|
+
const TIME_SOURCE_APIS = [
|
|
542
|
+
"Date.now",
|
|
543
|
+
"Math.random",
|
|
544
|
+
"crypto.getRandomValues",
|
|
545
|
+
"crypto.randomUUID",
|
|
546
|
+
"performance.now",
|
|
547
|
+
"process.hrtime"
|
|
548
|
+
];
|
|
549
|
+
const GLOBAL_CALL_APIS = [
|
|
550
|
+
"setInterval",
|
|
551
|
+
"setImmediate",
|
|
552
|
+
"setTimeout"
|
|
553
|
+
];
|
|
554
|
+
const TIMERS_MODULES = ["node:timers", "node:timers/promises"];
|
|
555
|
+
const globalCallVerdict = (api) => ({
|
|
556
|
+
name: `a direct ${api} call`,
|
|
557
|
+
actual: `a call reached through the global ${api}`
|
|
558
|
+
});
|
|
559
|
+
const newDateVerdict = () => ({
|
|
560
|
+
name: "an argument-less new Date()",
|
|
561
|
+
actual: "a `new Date()` whose argument list is empty"
|
|
562
|
+
});
|
|
563
|
+
const timersImportVerdict = (source) => ({
|
|
564
|
+
name: `a direct ${source} import`,
|
|
565
|
+
actual: `an import of the module ${source}`
|
|
566
|
+
});
|
|
567
|
+
const normalizePath = (filename) => filename.replaceAll("\\", "/");
|
|
568
|
+
const TEST_OR_FIXTURE_PATH = /(^|\/)(__tests__|__fixtures__|tests|testResources)\/|\.(test|spec)\.[cm]?[jt]sx?$/u;
|
|
569
|
+
const isTestOrFixtureFile = (filename) => TEST_OR_FIXTURE_PATH.test(normalizePath(filename));
|
|
570
|
+
const isRegisteredPort = (filename, ports) => {
|
|
571
|
+
const candidate = normalizePath(filename);
|
|
572
|
+
return ports.some((port) => {
|
|
573
|
+
const normalized = normalizePath(port);
|
|
574
|
+
return candidate === normalized || candidate.endsWith(`/${normalized}`);
|
|
575
|
+
});
|
|
576
|
+
};
|
|
577
|
+
const meta$1 = {
|
|
578
|
+
type: "problem",
|
|
579
|
+
docs: { description: "Production source takes timers, clocks, randomness, and task scheduling only through a named, replaceable port: a direct Date.now, argument-less new Date(), performance.now, process.hrtime, Math.random, crypto.getRandomValues, crypto.randomUUID, setTimeout, setInterval, or setImmediate call, or an import of node:timers, fails at that call unless the file is listed in the rule's `ports` option. queueMicrotask reads no clock and is not flagged. A source injected as a parameter is a port crossing the boundary, not a direct read. Test and fixture files are outside the rule." },
|
|
580
|
+
schema: [Schema.toJsonSchemaDocument(Options).schema],
|
|
581
|
+
messages: { unportedTimeSource: TIME_SOURCE_MESSAGE }
|
|
582
|
+
};
|
|
583
|
+
//#endregion
|
|
584
|
+
//#region src/rules/no-unported-time-source.ts
|
|
585
|
+
const isScopeLike$1 = (value) => typeof value === "object" && value !== null && "references" in value && "upper" in value;
|
|
586
|
+
const isIdentifierNode = (node) => node.type === "Identifier";
|
|
587
|
+
const decodeOptions = (input) => Effect.runSync(Effect.orDie(Schema.decodeUnknownEffect(Options)(input)));
|
|
588
|
+
const timersModuleOf = (source) => {
|
|
589
|
+
if (source.type !== "Literal") return null;
|
|
590
|
+
const value = source.value;
|
|
591
|
+
return typeof value === "string" && TIMERS_MODULES.includes(value) ? value : null;
|
|
592
|
+
};
|
|
593
|
+
const rootIdentifierOf = (node) => {
|
|
594
|
+
let current = node;
|
|
595
|
+
while (current.type === "MemberExpression") current = current.object;
|
|
596
|
+
return isIdentifierNode(current) ? current : null;
|
|
597
|
+
};
|
|
598
|
+
const memberPathOf = (node) => {
|
|
599
|
+
if (isIdentifierNode(node)) return [node.name];
|
|
600
|
+
if (node.type !== "MemberExpression" || node.computed === true) return null;
|
|
601
|
+
if (!isIdentifierNode(node.property)) return null;
|
|
602
|
+
const object = memberPathOf(node.object);
|
|
603
|
+
return object === null ? null : [...object, node.property.name];
|
|
604
|
+
};
|
|
605
|
+
const timeSourceApiOf = (path) => TIME_SOURCE_APIS.find((api) => {
|
|
606
|
+
const segments = api.split(".");
|
|
607
|
+
return segments.length <= path.length && segments.every((segment, index) => path[index] === segment);
|
|
608
|
+
}) ?? null;
|
|
609
|
+
/**
|
|
610
|
+
* A reference the scope chain cannot resolve declares no binding in this module:
|
|
611
|
+
* it is the global the process owns. A resolved reference — a parameter, a local
|
|
612
|
+
* declaration, an import — is a port crossing the boundary and stays silent.
|
|
613
|
+
*/
|
|
614
|
+
const isGlobalReference = (identifier, getScope) => {
|
|
615
|
+
const scopeValue = getScope(identifier);
|
|
616
|
+
if (!isScopeLike$1(scopeValue)) return true;
|
|
617
|
+
for (let scope = scopeValue; scope !== null; scope = scope.upper) {
|
|
618
|
+
const found = scope.references.find((reference) => reference.identifier === identifier);
|
|
619
|
+
if (found !== void 0) return found.resolved === null;
|
|
620
|
+
}
|
|
621
|
+
return true;
|
|
622
|
+
};
|
|
623
|
+
const noUnportedTimeSource = defineRule({
|
|
624
|
+
meta: meta$1,
|
|
625
|
+
create(context) {
|
|
626
|
+
if (isTestOrFixtureFile(context.filename)) return {};
|
|
627
|
+
const options = decodeOptions(context.options[0] ?? {});
|
|
628
|
+
if (isRegisteredPort(context.filename, options.ports)) return {};
|
|
629
|
+
const getScope = context.sourceCode.getScope;
|
|
630
|
+
const report = (verdict, node) => {
|
|
631
|
+
context.report({
|
|
632
|
+
node,
|
|
633
|
+
messageId: "unportedTimeSource",
|
|
634
|
+
data: {
|
|
635
|
+
...verdict,
|
|
636
|
+
expected: TIME_SOURCE_EXPECTED,
|
|
637
|
+
fix: TIME_SOURCE_FIX
|
|
638
|
+
}
|
|
639
|
+
});
|
|
640
|
+
};
|
|
641
|
+
const reportTimersImport = (node, source) => {
|
|
642
|
+
const module = timersModuleOf(source);
|
|
643
|
+
if (module !== null) report(timersImportVerdict(module), node);
|
|
644
|
+
};
|
|
645
|
+
const reportGlobalCall = (node, path) => {
|
|
646
|
+
const api = timeSourceApiOf(path);
|
|
647
|
+
if (api === null) return;
|
|
648
|
+
const root = rootIdentifierOf(node.callee);
|
|
649
|
+
if (root === null || !isGlobalReference(root, getScope)) return;
|
|
650
|
+
report(globalCallVerdict(api), node);
|
|
651
|
+
};
|
|
652
|
+
return {
|
|
653
|
+
ImportDeclaration(node) {
|
|
654
|
+
reportTimersImport(node, node.source);
|
|
655
|
+
},
|
|
656
|
+
ExportNamedDeclaration(node) {
|
|
657
|
+
if (node.source !== null) reportTimersImport(node, node.source);
|
|
658
|
+
},
|
|
659
|
+
ExportAllDeclaration(node) {
|
|
660
|
+
reportTimersImport(node, node.source);
|
|
661
|
+
},
|
|
662
|
+
ImportExpression(node) {
|
|
663
|
+
reportTimersImport(node, node.source);
|
|
664
|
+
},
|
|
665
|
+
CallExpression(node) {
|
|
666
|
+
const callee = node.callee;
|
|
667
|
+
if (isIdentifierNode(callee)) {
|
|
668
|
+
if (GLOBAL_CALL_APIS.includes(callee.name) && isGlobalReference(callee, getScope)) report(globalCallVerdict(callee.name), node);
|
|
669
|
+
return;
|
|
670
|
+
}
|
|
671
|
+
const path = memberPathOf(callee);
|
|
672
|
+
if (path !== null) reportGlobalCall(node, path);
|
|
673
|
+
},
|
|
674
|
+
NewExpression(node) {
|
|
675
|
+
if (node.arguments.length > 0) return;
|
|
676
|
+
if (!isIdentifierNode(node.callee)) return;
|
|
677
|
+
if (node.callee.name !== "Date") return;
|
|
678
|
+
if (!isGlobalReference(node.callee, getScope)) return;
|
|
679
|
+
report(newDateVerdict(), node);
|
|
680
|
+
}
|
|
681
|
+
};
|
|
682
|
+
}
|
|
683
|
+
});
|
|
684
|
+
//#endregion
|
|
536
685
|
//#region ../import-origin/dist/index.mjs
|
|
537
686
|
const isScopeLike = (value) => typeof value === "object" && value !== null && "references" in value && "upper" in value;
|
|
538
687
|
const isIdentifier = (node) => node.type === "Identifier";
|
|
@@ -990,6 +1139,13 @@ const runtimeConstructionPlacement = defineRule({
|
|
|
990
1139
|
//#region src/index.ts
|
|
991
1140
|
const PLUGIN_NAME = "@systemfsoftware/oxlint-plugin-effect-platform";
|
|
992
1141
|
const rule = (name) => `${PLUGIN_NAME}/${name}`;
|
|
1142
|
+
/** The files that own the process timers, clocks, and randomness the rest of production source must reach through them. */
|
|
1143
|
+
const PLATFORM_PORTS = [
|
|
1144
|
+
"packages/atom/effect-atom/src/internal/HostTimer.ts",
|
|
1145
|
+
"packages/effect-schema-law/src/recursion-laws.ts",
|
|
1146
|
+
"packages/trace-spec/src/Suite.ts",
|
|
1147
|
+
"packages/vitest/src/internal/virtual-time.ts"
|
|
1148
|
+
];
|
|
993
1149
|
const recommendedRules = {
|
|
994
1150
|
[rule("entrypoint-interprets-once")]: "error",
|
|
995
1151
|
[rule("entrypoint-no-exports")]: "error",
|
|
@@ -999,7 +1155,8 @@ const recommendedRules = {
|
|
|
999
1155
|
[rule("no-logging-in-catch")]: "error",
|
|
1000
1156
|
[rule("no-native-map-in-effect")]: "error",
|
|
1001
1157
|
[rule("no-native-set-in-effect")]: "error",
|
|
1002
|
-
[rule("no-new-worker-with-wasm-import")]: "error"
|
|
1158
|
+
[rule("no-new-worker-with-wasm-import")]: "error",
|
|
1159
|
+
[rule("no-unported-time-source")]: ["error", { ports: [...PLATFORM_PORTS] }]
|
|
1003
1160
|
};
|
|
1004
1161
|
const noNodeBuiltinImports = ["error", { patterns: [
|
|
1005
1162
|
{
|
|
@@ -1026,7 +1183,8 @@ var src_default = {
|
|
|
1026
1183
|
"no-logging-in-catch": noLoggingInCatch,
|
|
1027
1184
|
"no-native-map-in-effect": noNativeMapInEffect,
|
|
1028
1185
|
"no-native-set-in-effect": noNativeSetInEffect,
|
|
1029
|
-
"no-new-worker-with-wasm-import": noNewWorkerWithWasmImport
|
|
1186
|
+
"no-new-worker-with-wasm-import": noNewWorkerWithWasmImport,
|
|
1187
|
+
"no-unported-time-source": noUnportedTimeSource
|
|
1030
1188
|
},
|
|
1031
1189
|
configs: { recommended: {
|
|
1032
1190
|
rules: recommendedRules,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DummyRuleMap } from 'oxlint';
|
|
1
2
|
import { OxlintOverride } from 'oxlint';
|
|
2
3
|
import { Rule } from '@oxlint/plugins';
|
|
3
4
|
|
|
@@ -15,12 +16,11 @@ declare const _default: {
|
|
|
15
16
|
'no-native-map-in-effect': Rule;
|
|
16
17
|
'no-native-set-in-effect': Rule;
|
|
17
18
|
'no-new-worker-with-wasm-import': Rule;
|
|
19
|
+
'no-unported-time-source': Rule;
|
|
18
20
|
};
|
|
19
21
|
configs: {
|
|
20
22
|
recommended: {
|
|
21
|
-
rules:
|
|
22
|
-
readonly [x: string]: "error";
|
|
23
|
-
};
|
|
23
|
+
rules: DummyRuleMap;
|
|
24
24
|
overrides: OxlintOverride[];
|
|
25
25
|
};
|
|
26
26
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DummyRuleMap } from 'oxlint';
|
|
1
2
|
import { OxlintOverride } from 'oxlint';
|
|
2
3
|
import { Rule } from '@oxlint/plugins';
|
|
3
4
|
|
|
@@ -15,12 +16,11 @@ declare const _default: {
|
|
|
15
16
|
'no-native-map-in-effect': Rule;
|
|
16
17
|
'no-native-set-in-effect': Rule;
|
|
17
18
|
'no-new-worker-with-wasm-import': Rule;
|
|
19
|
+
'no-unported-time-source': Rule;
|
|
18
20
|
};
|
|
19
21
|
configs: {
|
|
20
22
|
recommended: {
|
|
21
|
-
rules:
|
|
22
|
-
readonly [x: string]: "error";
|
|
23
|
-
};
|
|
23
|
+
rules: DummyRuleMap;
|
|
24
24
|
overrides: OxlintOverride[];
|
|
25
25
|
};
|
|
26
26
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@systemfsoftware/oxlint-plugin-effect-platform",
|
|
3
3
|
"license": "Apache-2.0",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.4.0",
|
|
5
5
|
"author": "Ryan Lee <drdgvhbh@gmail.com>",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -44,29 +44,29 @@
|
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@microsoft/api-extractor": "^7.59.1",
|
|
46
46
|
"@systemfsoftware/arethetypeswrong-cli": "^4.2.0",
|
|
47
|
+
"@systemfsoftware/oxlint-import-origin": "^0.1.0",
|
|
48
|
+
"@systemfsoftware/stryker-config": "^0.1.0",
|
|
47
49
|
"@systemfsoftware/stryker-ignorer-effect-schema-declarations": "^0.1.1",
|
|
48
50
|
"@systemfsoftware/stryker-ignorer-in-source-vitest-block": "^0.1.1",
|
|
49
51
|
"@systemfsoftware/stryker-js": "^10.1.1",
|
|
50
52
|
"@systemfsoftware/stryker-js-typescript-checker": "^7.0.5",
|
|
51
53
|
"@systemfsoftware/stryker-js-vitest-runner": "^7.1.1",
|
|
52
54
|
"@systemfsoftware/stryker-test-contribution": "^3.0.3",
|
|
55
|
+
"@systemfsoftware/tsconfig": "^2.0.1",
|
|
56
|
+
"@systemfsoftware/tsdown-config": "^0.1.0",
|
|
57
|
+
"@systemfsoftware/vitest-config": "^0.1.0",
|
|
53
58
|
"@types/node": "^26",
|
|
54
59
|
"@vitest/coverage-v8": "^5",
|
|
55
|
-
"effect": "4.0.0-rc.
|
|
60
|
+
"effect": "4.0.0-rc.117",
|
|
56
61
|
"fast-check": "^4",
|
|
57
62
|
"oxlint": "~1.82.0",
|
|
58
63
|
"rimraf": "^6.1.3",
|
|
59
64
|
"tsdown": "^0.23.0",
|
|
60
65
|
"typescript": "^7",
|
|
61
|
-
"vitest": "^5"
|
|
62
|
-
"@systemfsoftware/oxlint-import-origin": "^0.1.0",
|
|
63
|
-
"@systemfsoftware/stryker-config": "^0.1.0",
|
|
64
|
-
"@systemfsoftware/tsconfig": "^1.3.6",
|
|
65
|
-
"@systemfsoftware/tsdown-config": "^0.1.0",
|
|
66
|
-
"@systemfsoftware/vitest-config": "^0.1.0"
|
|
66
|
+
"vitest": "^5"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
|
-
"effect": "4.0.0-rc.
|
|
69
|
+
"effect": "4.0.0-rc.117",
|
|
70
70
|
"typescript": ">=5.0.0"
|
|
71
71
|
},
|
|
72
72
|
"publishConfig": {
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
"scripts": {
|
|
76
76
|
"build": "tsdown -l warn && pnpm api:check",
|
|
77
77
|
"clean": "rimraf dist",
|
|
78
|
-
"typecheck": "tsc
|
|
78
|
+
"typecheck": "tsc -b",
|
|
79
79
|
"test": "vitest run",
|
|
80
80
|
"mutation": "stryker run",
|
|
81
81
|
"mutation:full": "stryker run --force",
|