@typeonce/oxlint-plugin-ritmo 0.15.0 → 0.16.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 CHANGED
@@ -1,5 +1,37 @@
1
1
  # @typeonce/oxlint-plugin-ritmo
2
2
 
3
+ ## 0.16.0
4
+
5
+ ### Minor Changes
6
+
7
+ - be9af72: **Breaking: `ritmo/handle-tick-result` is `ritmo/handle-runtime-result`, and it also catches a `Result` passed on unchecked.** Besides a dropped `tick`, `tryTick`, `restore`, or `rewind`, it reports `runtime.snapshot()` and `runtime.checksum()`, and any of them handed to a function, printed in a template string, put in an object or array, or used as an operand without a check: a save function that takes `unknown` otherwise stores the `{ ok, value }` wrapper instead of the world. A variable, a field, a `return`, `.ok`, and `void` keep the `Result` for the code to check; a helper that takes the `Result` gets it once it is named.
8
+
9
+ Fix: rename the rule in `.oxlintrc.json`, then check each new report.
10
+
11
+ ```diff
12
+ -"ritmo/handle-tick-result": "error",
13
+ +"ritmo/handle-runtime-result": "error",
14
+ ```
15
+
16
+ ```diff
17
+ -persist(runtime.snapshot())
18
+ +const saved = runtime.snapshot()
19
+ +if (saved.ok) persist(saved.value)
20
+ ```
21
+
22
+ ### Patch Changes
23
+
24
+ - be9af72: `ritmo/no-float-timers` says what to do with a timer that must stop while the world clock runs (hit-stop, a menu over gameplay): measure it against a second clock that holds, `Clock.resource` advanced by `Clock.system(Game, { name, resource, hold })`, so its deadlines wait with it. Only time scaled by a fraction is a real float, kept with a disable comment that gives the reason. The README and the `Clock.system` JSDoc show the pattern.
25
+ - 9290521: Docs from upgrading two games across several versions:
26
+
27
+ - The skill's state-and-upgrades playbook lists the breaks that still compile, per version, and `SETUP.md` says a new lint rule is off until `.oxlintrc.json` lists it.
28
+ - The 0.13 `Decode` entry has a table from each `Decode` codec to Zod and Effect; handle schemas use `z.unknown().refine(Entity.isHandle(...))`, not `z.custom`.
29
+ - The `Snapshot.version` JSDoc says how to rewrite a format 2 save; `WorldSnapshot.relations` says targets are sorted by id while each target's sources keep their order.
30
+ - `ritmo-devtools lint`'s `uncovered-simulation-module` message names the usual cause: a host module imported at the top of the lint entry instead of inside `lintTarget`. The README shows a debug script reusing `lintTarget`.
31
+ - The `Replay` docs and the 0.15 changelog say how to keep a playtester's save button without the monitor: `recorder.save(reason)` from a key handler.
32
+ - `Touch.Layout` shows how to draw a layout with no `null` zones, and `Pointer.Actions` says to build test doubles with `Pointer.scripted`.
33
+ - The `use-ops-for-math` example uses `Angle.wrap` for a signed turn, and the spatial-grid reference defines its `made` helper.
34
+
3
35
  ## 0.15.0
4
36
 
5
37
  ### Minor Changes
package/README.md CHANGED
@@ -27,7 +27,7 @@ Register the plugin and turn the rules on in `.oxlintrc.json`. The simulation ru
27
27
  {
28
28
  "jsPlugins": ["@typeonce/oxlint-plugin-ritmo"],
29
29
  "rules": {
30
- "ritmo/handle-tick-result": "error",
30
+ "ritmo/handle-runtime-result": "error",
31
31
  "ritmo/prefix-descriptor-and-system-names": "error",
32
32
  "ritmo/use-cell-value": "error",
33
33
  "ritmo/no-state-spread": "error"
@@ -68,7 +68,7 @@ const started = performance.now()
68
68
  | [`no-infinity-in-simulation-data`](#ritmono-infinity-in-simulation-data) | simulation | `Infinity` / `NaN` in object literals | `null` |
69
69
  | [`no-float-timers`](#ritmono-float-timers) | simulation | `timer -= dt`, `cooldown - time.dt` | `Clock.deadline` / `Clock.reached` |
70
70
  | [`no-brand-cast`](#ritmono-brand-cast) | simulation | `raw as UserId`, `1 as Random.State` | the schema or constructor that brands it |
71
- | [`handle-tick-result`](#ritmohandle-tick-result) | everywhere | a dropped `runtime.tick(...)` / `restore(...)` / `rewind(...)` result | check `.ok` |
71
+ | [`handle-runtime-result`](#ritmohandle-runtime-result) | everywhere | a dropped or unchecked `runtime.tick(...)` / `restore(...)` / `rewind(...)` / `snapshot()` / `checksum()` result | check `.ok` |
72
72
  | [`prefix-descriptor-and-system-names`](#ritmoprefix-descriptor-and-system-names) | everywhere | `"Position"`, `Game.System("Move", ...)` | `"Game/Position"` |
73
73
  | [`use-cell-value`](#ritmouse-cell-value) | everywhere | `cell.present ? cell.get() : undefined` | `cell.value()` |
74
74
  | [`no-state-spread`](#ritmono-state-spread) | everywhere | `{ ...ground, _tag: "air", vy }` | `cell.transition({ from, to, data })`, `nextMachines.x.set({ _tag, ...fields })`, or the new state's fields written out |
@@ -117,10 +117,13 @@ const beauty = base * repeat ** n // reported
117
117
 
118
118
  // instead
119
119
  import { Ops } from "@typeonce/ritmo"
120
- const turn = Ops.atan2(Ops.sin(b - a), Ops.cos(b - a))
120
+ import { Angle } from "@typeonce/ritmo-math"
121
+ const turn = Angle.wrap(b - a) // the signed turn from a to b, exact
121
122
  const beauty = base * Ops.pow(repeat, n)
122
123
  ```
123
124
 
125
+ Before porting a formula to `Ops`, look for the helper that names it: `Angle.wrap` and `Angle.turnToward` in [`@typeonce/ritmo-math`](https://github.com/typeonce-dev/ritmo/blob/main/packages/math/README.md) need no transcendental call at all.
126
+
124
127
  `Math.sqrt`, `abs`, `min`, `max`, `floor`, `ceil`, `round`, `trunc`, `sign`, `+ - * /`, and `x ** 2` are exact everywhere and are not reported (`Math.PI`, `Math["floor"]`, and `const { abs, PI } = Math` neither).
125
128
 
126
129
  `oxlint --fix` does the whole change in one run: it rewrites `Math.sin(x)` to `Ops.sin(x)`, `a ** b` to `Ops.pow(a, b)`, and `x **= y` to `x = Ops.pow(x, y)`, and adds `import { Ops } from "@typeonce/ritmo"` once, after the last import (`const { Ops } = require("@typeonce/ritmo")` in a CommonJS file). It uses `Ops` where the file already imports it, under any name (`import { Ops as M }`, `import * as Ops from "@typeonce/ritmo/Ops"`). It leaves the report unfixed where a rewrite could change the code: `body.speed **= y` (the rewrite would evaluate `body` twice), and a file or function where the name `Ops` already means something else (a type-only import included).
@@ -176,6 +179,18 @@ if (ready === null || Clock.reached(time, ready)) {
176
179
  const bar = ready === null ? 0 : Clock.remaining(time, ready) / Clock.steps(cooldown) // a readout
177
180
  ```
178
181
 
182
+ A timer that must stop while the world clock keeps running (gameplay frozen in hit-stop, a menu over the level) is measured against a second clock that holds, instead of against the world clock:
183
+
184
+ ```ts
185
+ const GameplayTime = Clock.resource("Game/GameplayTime", step)
186
+ const gameplayClock = Clock.system(Game, { name: "Game/GameplayClock", resource: GameplayTime, hold: [inHitStop] })
187
+
188
+ // A deadline on GameplayTime waits while inHitStop passes, and saves and rolls back like any deadline
189
+ data.enemy.set({ attackAt: Clock.deadline(gameplay, windup) })
190
+ ```
191
+
192
+ Time scaled by a fraction (a 0.3x slow motion) has no whole step to end on, so a float is right there: keep it and disable the line with the reason (`// oxlint-disable-next-line ritmo/no-float-timers -- scaled by slow motion`). A value counted up by `dt` is reported too, since it drifts the same way: `Clock.elapsed(time)` is the exact seconds of a clock.
193
+
179
194
  Catches a stored value (a local or a field) plus or minus a tick's seconds on their own: `dt`, `deltaTime`, or `deltaSeconds`, as a local, a field (`time.dt`), or a resource read (`resources.deltaTime.get()`), in `x -= dt`, `x += dt`, and `x - dt` / `x + dt` anywhere (`Math.max(0, x - dt)`, an object literal). A rate scaled by `dt` (`position.x += velocity.x * dt`) is integration and is not reported, nor is a count of whole steps (`cooldown - 1`), nor a `delta` that is not time (a pointer's).
180
195
 
181
196
  ### `ritmo/no-brand-cast`
@@ -203,14 +218,16 @@ Make the value through its check: decode at the boundary with the game's schema,
203
218
 
204
219
  ## Rules for every file
205
220
 
206
- ### `ritmo/handle-tick-result`
221
+ ### `ritmo/handle-runtime-result`
207
222
 
208
- `runtime.tick(...)` returns a `Result`: a system that fails stops the tick, and the failure comes back here. `runtime.restore(...)` returns one too: an invalid save leaves the previous world in place. So does `runtime.rewind(...)`: a checkpoint the runtime let go of changes nothing, and the ticks meant to run again run on top of the present. Dropping any of them hides the failure.
223
+ `runtime.tick(...)` returns a `Result`: a system that fails stops the tick, and the failure comes back here. `runtime.restore(...)` returns one too: an invalid save leaves the previous world in place. So does `runtime.rewind(...)`: a checkpoint the runtime let go of changes nothing, and the ticks meant to run again run on top of the present. `runtime.snapshot()` and `runtime.checksum()` return one because a schema's `encode` may reject a value. Dropping any of them hides the failure, and so does passing one on where any value is accepted: a save function that takes `unknown` stores the `{ ok, value }` wrapper, not the world.
209
224
 
210
225
  ```ts
211
226
  runtime.tick(update) // reported
212
227
  runtime.restore(save) // reported
213
228
  runtime.rewind(checkpoint) // reported
229
+ persist(runtime.snapshot()) // reported
230
+ log(`hash ${runtime.checksum()}`) // reported
214
231
 
215
232
  // instead
216
233
  const ran = runtime.tick(update)
@@ -219,10 +236,12 @@ const restored = runtime.restore(save)
219
236
  if (!restored.ok) showLoadError(restored.error)
220
237
  const rewound = runtime.rewind(checkpoint)
221
238
  if (!rewound.ok) resync(rewound.error) // Released or OtherRuntime
239
+ const saved = runtime.snapshot()
240
+ if (saved.ok) persist(saved.value)
222
241
  void runtime.tick(render) // ignored on purpose
223
242
  ```
224
243
 
225
- Catches `tick(...)`, `tryTick(...)`, `restore(...)`, and `rewind(...)` used as a statement on a receiver named like a runtime (`runtime`, `game.runtime`, `worldRuntime`). Game wrappers with other names (`town.restore(...)`) are not reported. Option: `{ "runtimePattern": "^(runtime|world)$" }` (a case-insensitive regular expression for the receiver's name; default `runtime$`).
244
+ Catches these calls on a receiver named like a runtime (`runtime`, `game.runtime`, `worldRuntime`) used as a statement, or passed on unchecked: as a call argument, inside a template string, an object or array literal, a spread, or an operand, also through `??`, `? :`, and `as`. A variable, a field, a `return`, `.ok`, and `void` keep the `Result` for the code to check. A helper that takes the `Result` itself gets it once it is named: `const checksum = runtime.checksum(); helper(checksum)`. Game wrappers with other names (`town.restore(...)`) are not reported. Option: `{ "runtimePattern": "^(runtime|world)$" }` (a case-insensitive regular expression for the receiver's name; default `runtime$`).
226
245
 
227
246
  ### `ritmo/prefix-descriptor-and-system-names`
228
247
 
package/dist/index.js CHANGED
@@ -18,14 +18,14 @@
18
18
  * `ritmo/use-random-for-randomness`, `ritmo/use-ops-for-math`,
19
19
  * `ritmo/keep-simulation-headless`, `ritmo/no-infinity-in-simulation-data`,
20
20
  * `ritmo/no-float-timers`, `ritmo/no-brand-cast`.
21
- * - Every file: `ritmo/handle-tick-result`,
21
+ * - Every file: `ritmo/handle-runtime-result`,
22
22
  * `ritmo/prefix-descriptor-and-system-names`, `ritmo/use-cell-value`,
23
23
  * `ritmo/no-state-spread`.
24
24
  *
25
25
  * @module oxlint-plugin-ritmo
26
26
  */
27
27
  import { definePlugin } from "@oxlint/plugins";
28
- import handleTickResult from "./rules/handle-tick-result.js";
28
+ import handleRuntimeResult from "./rules/handle-runtime-result.js";
29
29
  import keepSimulationHeadless from "./rules/keep-simulation-headless.js";
30
30
  import noBrandCast from "./rules/no-brand-cast.js";
31
31
  import noFloatTimers from "./rules/no-float-timers.js";
@@ -46,7 +46,7 @@ export default definePlugin({
46
46
  "no-infinity-in-simulation-data": noInfinityInSimulationData,
47
47
  "no-float-timers": noFloatTimers,
48
48
  "no-brand-cast": noBrandCast,
49
- "handle-tick-result": handleTickResult,
49
+ "handle-runtime-result": handleRuntimeResult,
50
50
  "prefix-descriptor-and-system-names": prefixDescriptorAndSystemNames,
51
51
  "use-cell-value": useCellValue,
52
52
  "no-state-spread": noStateSpread
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAE9C,OAAO,gBAAgB,MAAM,+BAA+B,CAAA;AAC5D,OAAO,sBAAsB,MAAM,qCAAqC,CAAA;AACxE,OAAO,WAAW,MAAM,0BAA0B,CAAA;AAClD,OAAO,aAAa,MAAM,4BAA4B,CAAA;AACtD,OAAO,0BAA0B,MAAM,2CAA2C,CAAA;AAClF,OAAO,aAAa,MAAM,4BAA4B,CAAA;AACtD,OAAO,8BAA8B,MAAM,+CAA+C,CAAA;AAC1F,OAAO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E;IACvB,KAAK,EAAE;QACL,oBAAoB,EAAE,eAAe;QACrC,2BAA2B,EAAE,sBAAsB;QACnD,kBAAkB,EAAE,aAAa;QACjC,0BAA0B,EAAE,sBAAsB;QAClD,gCAAgC,EAAE,0BAA0B;QAC5D,iBAAiB,EAAE,aAAa;QAChC,eAAe,EAAE,WAAW;QAC5B,uBAAuB,EAAE,mBAAmB;QAC5C,oCAAoC,EAAE,8BAA8B;QACpE,gBAAgB,EAAE,YAAY;QAC9B,iBAAiB,EAAE,aAAa;KACjC;CACF,CAAC,CAAA"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * The `Result` of `runtime.tick(...)`, `tryTick(...)`, `restore(...)`,
3
+ * `rewind(...)`, `snapshot()`, and `checksum()` is checked: dropping it, or
4
+ * passing it on where any value is accepted, hides the failure.
5
+ */
6
+ declare const _default: import("@oxlint/plugins").Rule;
7
+ export default _default;
8
+ //# sourceMappingURL=handle-runtime-result.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handle-runtime-result.d.ts","sourceRoot":"","sources":["../../src/rules/handle-runtime-result.ts"],"names":[],"mappings":"AAiCA;;;;GAIG"}
@@ -0,0 +1,102 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ import { calledMethod, docsUrl, receiverName } from "../internal/ast.js";
3
+ /** The runtime methods that return a `Result`, and whether they take arguments. */
4
+ const methods = new Map([
5
+ ["tick", "arguments"],
6
+ ["tryTick", "arguments"],
7
+ ["restore", "arguments"],
8
+ ["rewind", "arguments"],
9
+ ["snapshot", "none"],
10
+ ["checksum", "none"]
11
+ ]);
12
+ /**
13
+ * Wrappers a result passes through on its way to where it is used: the
14
+ * check looks at where the wrapper goes (`x ?? runtime.snapshot()`,
15
+ * `runtime.snapshot() as unknown`).
16
+ */
17
+ const passesThrough = new Set(["ConditionalExpression", "LogicalExpression", "ParenthesizedExpression", "TSAsExpression", "TSSatisfiesExpression", "TSNonNullExpression", "ChainExpression"]);
18
+ /**
19
+ * Where a result goes unchecked: handed to a function, printed, or put
20
+ * inside another value. A variable, a field, a return, `.ok`, and `void`
21
+ * keep it as a `Result` the code still has to look at.
22
+ */
23
+ const unchecked = new Set(["CallExpression", "NewExpression", "TemplateLiteral", "Property", "ArrayExpression", "SpreadElement", "BinaryExpression", "JSXExpressionContainer"]);
24
+ /**
25
+ * The `Result` of `runtime.tick(...)`, `tryTick(...)`, `restore(...)`,
26
+ * `rewind(...)`, `snapshot()`, and `checksum()` is checked: dropping it, or
27
+ * passing it on where any value is accepted, hides the failure.
28
+ */
29
+ export default defineRule({
30
+ meta: {
31
+ type: "problem",
32
+ docs: {
33
+ description: "Check the Result of runtime.tick, tryTick, restore, rewind, snapshot, and checksum instead of dropping it or passing it on unchecked.",
34
+ url: docsUrl("handle-runtime-result")
35
+ },
36
+ messages: {
37
+ tick: "The result of `{{call}}(...)` is dropped. A system that fails stops the tick and returns the failure here, so it goes unnoticed and the world is left half-updated. Check it: `const ran = {{call}}(...); if (!ran.ok) ...` (`ran.error` names the system and why). Write `void {{call}}(...)` to ignore it on purpose.",
38
+ restore: "The result of `{{call}}(...)` is dropped. A save that fails to load leaves the previous world in place, unnoticed. Check it: `const restored = {{call}}(data); if (!restored.ok) ...` (`restored.error` says what was invalid). Write `void {{call}}(...)` to ignore it on purpose.",
39
+ rewind: "The result of `{{call}}(...)` is dropped. A checkpoint the runtime let go of (older than its window, or taken before a rewind to an older one or a restore) changes nothing, so the ticks run next are run on top of the present instead of again, unnoticed. Check it: `const rewound = {{call}}(checkpoint); if (!rewound.ok) ...` (`rewound.error` says why), and resynchronize, for example by loading a peer's save. Write `void {{call}}(...)` to ignore it on purpose.",
40
+ dropped: "The result of `{{call}}()` is dropped, so the call does nothing. Read it: `const saved = {{call}}(); if (saved.ok) ...`.",
41
+ unchecked: "`{{call}}(...)` returns a `Result`, and it is passed on unchecked: code that accepts any value (a save, a log, `JSON.stringify`) gets the `{ ok, value }` wrapper instead of the value, and a failure goes unnoticed. Check it first: `const result = {{call}}(...); if (result.ok) use(result.value)`. A helper that takes the `Result` itself gets it once it is named: `const result = {{call}}(...); helper(result)`."
42
+ },
43
+ schema: [
44
+ {
45
+ type: "object",
46
+ properties: {
47
+ runtimePattern: {
48
+ type: "string",
49
+ description: "A regular expression (case-insensitive) the receiver's name must match to be treated as a Ritmo runtime. Defaults to `runtime$`."
50
+ }
51
+ },
52
+ additionalProperties: false
53
+ }
54
+ ]
55
+ },
56
+ create(context) {
57
+ const options = (context.options[0] ?? {});
58
+ const runtime = new RegExp(options.runtimePattern ?? "runtime$", "i");
59
+ return {
60
+ CallExpression(call) {
61
+ if (call.callee.type !== "MemberExpression")
62
+ return;
63
+ const method = calledMethod(call);
64
+ const takes = method === undefined ? undefined : methods.get(method);
65
+ if (takes === undefined)
66
+ return;
67
+ // `run.tick()` and `replay.rewind()` without arguments are other libraries' methods.
68
+ if (takes === "arguments" && call.arguments.length === 0)
69
+ return;
70
+ if (takes === "none" && call.arguments.length > 0)
71
+ return;
72
+ const receiver = receiverName(call.callee.object);
73
+ if (receiver === undefined || !runtime.test(receiver))
74
+ return;
75
+ const data = { call: context.sourceCode.getText(call.callee) };
76
+ let node = call;
77
+ let parent = node.parent;
78
+ while (parent != null && passesThrough.has(parent.type)) {
79
+ node = parent;
80
+ parent = node.parent;
81
+ }
82
+ if (parent == null)
83
+ return;
84
+ if (parent.type === "ExpressionStatement") {
85
+ const messageId = takes === "none" ? "dropped" : method === "restore" || method === "rewind" ? method : "tick";
86
+ context.report({ node: parent, messageId, data });
87
+ return;
88
+ }
89
+ if (!unchecked.has(parent.type))
90
+ return;
91
+ // The callee of a call is a method read on the result, not a hand-off (`runtime.snapshot().toString()` would not compile anyway).
92
+ if (parent.type === "CallExpression" && parent.callee === node)
93
+ return;
94
+ // A property key is not a use of the value.
95
+ if (parent.type === "Property" && parent.value !== node)
96
+ return;
97
+ context.report({ node: call, messageId: "unchecked", data });
98
+ }
99
+ };
100
+ }
101
+ });
102
+ //# sourceMappingURL=handle-runtime-result.js.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timer by `dt` in floating point: rounding error builds up each tick, so it ends a step early or late, and the float it saves means nothing once the fixed step changes. Store the step it ends on instead: `ready: Clock.deadline(time, Clock.duration(step, seconds))` in the component or resource (its schema narrows with `Clock.isDeadline(step)`), and check `Clock.reached(time, ready)` each tick (`Clock.remaining(time, ready)` for a readout, `Clock.every(time, duration)` for something that repeats, `Clock.elapsed(time)` for seconds since the start)."
38
+ floatTimer: "`{{text}}` counts a timer by `dt` in floating point: rounding error builds up each tick, so it ends a step early or late, and the float it saves means nothing once the fixed step changes. Store the step it ends on instead: `ready: Clock.deadline(time, Clock.duration(step, seconds))` in the component or resource (its schema narrows with `Clock.isDeadline(step)`), and check `Clock.reached(time, ready)` each tick (`Clock.remaining(time, ready)` for a readout, `Clock.every(time, duration)` for something that repeats, `Clock.elapsed(time)` for seconds since the start). A timer that must stop while the world clock runs (hit-stop, a menu over gameplay) is measured against a second clock that holds: `Clock.resource(\"Game/GameplayTime\", step)` advanced by `Clock.system(Game, { name, resource, hold: [paused] })`, so its deadlines wait with it. Only time scaled by a fraction (a 0.3x slow motion) is a real float: keep it and disable this line with the reason."
39
39
  },
40
40
  schema: []
41
41
  },
@@ -1 +1 @@
1
- {"version":3,"file":"no-float-timers.js","sourceRoot":"","sources":["../../src/rules/no-float-timers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAG5C,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAExE,oHAAoH;AACpH,MAAM,UAAU,GAAG,CAAC,IAAI,EAAE,WAAW,EAAE,cAAc,CAAC,CAAA;AAEtD,qFAAqF;AACrF,MAAM,MAAM,GAAG,CAAC,IAAiB,EAAe,EAAE,CAChD,IAAI,CAAC,IAAI,KAAK,gBAAgB,IAAI,IAAI,CAAC,IAAI,KAAK,qBAAqB,IAAI,IAAI,CAAC,IAAI,KAAK,uBAAuB,CAAC,CAAC,CAAC,MAAM,CAA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AI,CAAC,KAAK,CAAC,CAAC;oBAAE,MAAM,CAAC,IAAI,CAAC,CAAA;YAChH,CAAC;SACF,CAAA;IACH,CAAC;CACF,CAAC,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typeonce/oxlint-plugin-ritmo",
3
- "version": "0.15.0",
3
+ "version": "0.16.0",
4
4
  "description": "Oxlint rules for Ritmo games: deterministic, headless simulation code and checked runtime results",
5
5
  "author": "Sandro Maglione",
6
6
  "license": "MIT",
package/src/index.ts CHANGED
@@ -18,7 +18,7 @@
18
18
  * `ritmo/use-random-for-randomness`, `ritmo/use-ops-for-math`,
19
19
  * `ritmo/keep-simulation-headless`, `ritmo/no-infinity-in-simulation-data`,
20
20
  * `ritmo/no-float-timers`, `ritmo/no-brand-cast`.
21
- * - Every file: `ritmo/handle-tick-result`,
21
+ * - Every file: `ritmo/handle-runtime-result`,
22
22
  * `ritmo/prefix-descriptor-and-system-names`, `ritmo/use-cell-value`,
23
23
  * `ritmo/no-state-spread`.
24
24
  *
@@ -26,7 +26,7 @@
26
26
  */
27
27
  import { definePlugin } from "@oxlint/plugins"
28
28
 
29
- import handleTickResult from "./rules/handle-tick-result.ts"
29
+ import handleRuntimeResult from "./rules/handle-runtime-result.ts"
30
30
  import keepSimulationHeadless from "./rules/keep-simulation-headless.ts"
31
31
  import noBrandCast from "./rules/no-brand-cast.ts"
32
32
  import noFloatTimers from "./rules/no-float-timers.ts"
@@ -48,7 +48,7 @@ export default definePlugin({
48
48
  "no-infinity-in-simulation-data": noInfinityInSimulationData,
49
49
  "no-float-timers": noFloatTimers,
50
50
  "no-brand-cast": noBrandCast,
51
- "handle-tick-result": handleTickResult,
51
+ "handle-runtime-result": handleRuntimeResult,
52
52
  "prefix-descriptor-and-system-names": prefixDescriptorAndSystemNames,
53
53
  "use-cell-value": useCellValue,
54
54
  "no-state-spread": noStateSpread
@@ -0,0 +1,108 @@
1
+ import { defineRule } from "@oxlint/plugins"
2
+ import type { ESTree } from "@oxlint/plugins"
3
+
4
+ import { calledMethod, docsUrl, receiverName } from "../internal/ast.ts"
5
+
6
+ interface Options {
7
+ readonly runtimePattern?: string
8
+ }
9
+
10
+ /** The runtime methods that return a `Result`, and whether they take arguments. */
11
+ const methods = new Map<string, "arguments" | "none">([
12
+ ["tick", "arguments"],
13
+ ["tryTick", "arguments"],
14
+ ["restore", "arguments"],
15
+ ["rewind", "arguments"],
16
+ ["snapshot", "none"],
17
+ ["checksum", "none"]
18
+ ])
19
+
20
+ /**
21
+ * Wrappers a result passes through on its way to where it is used: the
22
+ * check looks at where the wrapper goes (`x ?? runtime.snapshot()`,
23
+ * `runtime.snapshot() as unknown`).
24
+ */
25
+ const passesThrough = new Set(["ConditionalExpression", "LogicalExpression", "ParenthesizedExpression", "TSAsExpression", "TSSatisfiesExpression", "TSNonNullExpression", "ChainExpression"])
26
+
27
+ /**
28
+ * Where a result goes unchecked: handed to a function, printed, or put
29
+ * inside another value. A variable, a field, a return, `.ok`, and `void`
30
+ * keep it as a `Result` the code still has to look at.
31
+ */
32
+ const unchecked = new Set(["CallExpression", "NewExpression", "TemplateLiteral", "Property", "ArrayExpression", "SpreadElement", "BinaryExpression", "JSXExpressionContainer"])
33
+
34
+ /**
35
+ * The `Result` of `runtime.tick(...)`, `tryTick(...)`, `restore(...)`,
36
+ * `rewind(...)`, `snapshot()`, and `checksum()` is checked: dropping it, or
37
+ * passing it on where any value is accepted, hides the failure.
38
+ */
39
+ export default defineRule({
40
+ meta: {
41
+ type: "problem",
42
+ docs: {
43
+ description: "Check the Result of runtime.tick, tryTick, restore, rewind, snapshot, and checksum instead of dropping it or passing it on unchecked.",
44
+ url: docsUrl("handle-runtime-result")
45
+ },
46
+ messages: {
47
+ tick:
48
+ "The result of `{{call}}(...)` is dropped. A system that fails stops the tick and returns the failure here, so it goes unnoticed and the world is left half-updated. Check it: `const ran = {{call}}(...); if (!ran.ok) ...` (`ran.error` names the system and why). Write `void {{call}}(...)` to ignore it on purpose.",
49
+ restore:
50
+ "The result of `{{call}}(...)` is dropped. A save that fails to load leaves the previous world in place, unnoticed. Check it: `const restored = {{call}}(data); if (!restored.ok) ...` (`restored.error` says what was invalid). Write `void {{call}}(...)` to ignore it on purpose.",
51
+ rewind:
52
+ "The result of `{{call}}(...)` is dropped. A checkpoint the runtime let go of (older than its window, or taken before a rewind to an older one or a restore) changes nothing, so the ticks run next are run on top of the present instead of again, unnoticed. Check it: `const rewound = {{call}}(checkpoint); if (!rewound.ok) ...` (`rewound.error` says why), and resynchronize, for example by loading a peer's save. Write `void {{call}}(...)` to ignore it on purpose.",
53
+ dropped:
54
+ "The result of `{{call}}()` is dropped, so the call does nothing. Read it: `const saved = {{call}}(); if (saved.ok) ...`.",
55
+ unchecked:
56
+ "`{{call}}(...)` returns a `Result`, and it is passed on unchecked: code that accepts any value (a save, a log, `JSON.stringify`) gets the `{ ok, value }` wrapper instead of the value, and a failure goes unnoticed. Check it first: `const result = {{call}}(...); if (result.ok) use(result.value)`. A helper that takes the `Result` itself gets it once it is named: `const result = {{call}}(...); helper(result)`."
57
+ },
58
+ schema: [
59
+ {
60
+ type: "object",
61
+ properties: {
62
+ runtimePattern: {
63
+ type: "string",
64
+ description: "A regular expression (case-insensitive) the receiver's name must match to be treated as a Ritmo runtime. Defaults to `runtime$`."
65
+ }
66
+ },
67
+ additionalProperties: false
68
+ }
69
+ ]
70
+ },
71
+ create(context) {
72
+ const options = (context.options[0] ?? {}) as Options
73
+ const runtime = new RegExp(options.runtimePattern ?? "runtime$", "i")
74
+ return {
75
+ CallExpression(call) {
76
+ if (call.callee.type !== "MemberExpression") return
77
+ const method = calledMethod(call)
78
+ const takes = method === undefined ? undefined : methods.get(method)
79
+ if (takes === undefined) return
80
+ // `run.tick()` and `replay.rewind()` without arguments are other libraries' methods.
81
+ if (takes === "arguments" && call.arguments.length === 0) return
82
+ if (takes === "none" && call.arguments.length > 0) return
83
+ const receiver = receiverName(call.callee.object)
84
+ if (receiver === undefined || !runtime.test(receiver)) return
85
+ const data = { call: context.sourceCode.getText(call.callee) }
86
+
87
+ let node: ESTree.Node = call
88
+ let parent: ESTree.Node | null | undefined = node.parent
89
+ while (parent != null && passesThrough.has(parent.type)) {
90
+ node = parent
91
+ parent = node.parent
92
+ }
93
+ if (parent == null) return
94
+ if (parent.type === "ExpressionStatement") {
95
+ const messageId = takes === "none" ? "dropped" : method === "restore" || method === "rewind" ? method : "tick"
96
+ context.report({ node: parent, messageId, data })
97
+ return
98
+ }
99
+ if (!unchecked.has(parent.type)) return
100
+ // The callee of a call is a method read on the result, not a hand-off (`runtime.snapshot().toString()` would not compile anyway).
101
+ if (parent.type === "CallExpression" && parent.callee === node) return
102
+ // A property key is not a use of the value.
103
+ if (parent.type === "Property" && parent.value !== node) return
104
+ context.report({ node: call, messageId: "unchecked", data })
105
+ }
106
+ }
107
+ }
108
+ })
@@ -42,7 +42,7 @@ export default defineRule({
42
42
  },
43
43
  messages: {
44
44
  floatTimer:
45
- "`{{text}}` counts a timer by `dt` in floating point: rounding error builds up each tick, so it ends a step early or late, and the float it saves means nothing once the fixed step changes. Store the step it ends on instead: `ready: Clock.deadline(time, Clock.duration(step, seconds))` in the component or resource (its schema narrows with `Clock.isDeadline(step)`), and check `Clock.reached(time, ready)` each tick (`Clock.remaining(time, ready)` for a readout, `Clock.every(time, duration)` for something that repeats, `Clock.elapsed(time)` for seconds since the start)."
45
+ "`{{text}}` counts a timer by `dt` in floating point: rounding error builds up each tick, so it ends a step early or late, and the float it saves means nothing once the fixed step changes. Store the step it ends on instead: `ready: Clock.deadline(time, Clock.duration(step, seconds))` in the component or resource (its schema narrows with `Clock.isDeadline(step)`), and check `Clock.reached(time, ready)` each tick (`Clock.remaining(time, ready)` for a readout, `Clock.every(time, duration)` for something that repeats, `Clock.elapsed(time)` for seconds since the start). A timer that must stop while the world clock runs (hit-stop, a menu over gameplay) is measured against a second clock that holds: `Clock.resource(\"Game/GameplayTime\", step)` advanced by `Clock.system(Game, { name, resource, hold: [paused] })`, so its deadlines wait with it. Only time scaled by a fraction (a 0.3x slow motion) is a real float: keep it and disable this line with the reason."
46
46
  },
47
47
  schema: []
48
48
  },
@@ -1,8 +0,0 @@
1
- /**
2
- * The result of `runtime.tick(...)`, `tryTick(...)`, `restore(...)`, and
3
- * `rewind(...)` is read: a failed system, an invalid save, or a released
4
- * checkpoint comes back as data, and dropping it hides the failure.
5
- */
6
- declare const _default: import("@oxlint/plugins").Rule;
7
- export default _default;
8
- //# sourceMappingURL=handle-tick-result.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"handle-tick-result.d.ts","sourceRoot":"","sources":["../../src/rules/handle-tick-result.ts"],"names":[],"mappings":"AAQA;;;;GAIG"}
@@ -1,56 +0,0 @@
1
- import { defineRule } from "@oxlint/plugins";
2
- import { calledMethod, docsUrl, receiverName } from "../internal/ast.js";
3
- /**
4
- * The result of `runtime.tick(...)`, `tryTick(...)`, `restore(...)`, and
5
- * `rewind(...)` is read: a failed system, an invalid save, or a released
6
- * checkpoint comes back as data, and dropping it hides the failure.
7
- */
8
- export default defineRule({
9
- meta: {
10
- type: "problem",
11
- docs: {
12
- description: "Check the Result of runtime.tick(...), tryTick(...), restore(...), and rewind(...) instead of dropping it.",
13
- url: docsUrl("handle-tick-result")
14
- },
15
- messages: {
16
- tick: "The result of `{{call}}(...)` is dropped. A system that fails stops the tick and returns the failure here, so it goes unnoticed and the world is left half-updated. Check it: `const ran = {{call}}(...); if (!ran.ok) ...` (`ran.error` names the system and why). Write `void {{call}}(...)` to ignore it on purpose.",
17
- restore: "The result of `{{call}}(...)` is dropped. A save that fails to load leaves the previous world in place, unnoticed. Check it: `const restored = {{call}}(data); if (!restored.ok) ...` (`restored.error` says what was invalid). Write `void {{call}}(...)` to ignore it on purpose.",
18
- rewind: "The result of `{{call}}(...)` is dropped. A checkpoint the runtime let go of (older than its window, or taken before a rewind to an older one or a restore) changes nothing, so the ticks run next are run on top of the present instead of again, unnoticed. Check it: `const rewound = {{call}}(checkpoint); if (!rewound.ok) ...` (`rewound.error` says why), and resynchronize, for example by loading a peer's save. Write `void {{call}}(...)` to ignore it on purpose."
19
- },
20
- schema: [
21
- {
22
- type: "object",
23
- properties: {
24
- runtimePattern: {
25
- type: "string",
26
- description: "A regular expression (case-insensitive) the receiver's name must match to be treated as a Ritmo runtime. Defaults to `runtime$`."
27
- }
28
- },
29
- additionalProperties: false
30
- }
31
- ]
32
- },
33
- create(context) {
34
- const options = (context.options[0] ?? {});
35
- const runtime = new RegExp(options.runtimePattern ?? "runtime$", "i");
36
- return {
37
- ExpressionStatement(node) {
38
- const call = node.expression;
39
- if (call.type !== "CallExpression" || call.callee.type !== "MemberExpression" || call.arguments.length === 0)
40
- return;
41
- const method = calledMethod(call);
42
- if (method !== "tick" && method !== "tryTick" && method !== "restore" && method !== "rewind")
43
- return;
44
- const receiver = receiverName(call.callee.object);
45
- if (receiver === undefined || !runtime.test(receiver))
46
- return;
47
- context.report({
48
- node,
49
- messageId: method === "restore" || method === "rewind" ? method : "tick",
50
- data: { call: context.sourceCode.getText(call.callee) }
51
- });
52
- }
53
- };
54
- }
55
- });
56
- //# sourceMappingURL=handle-tick-result.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"handle-tick-result.js","sourceRoot":"","sources":["../../src/rules/handle-tick-result.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAE5C,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAMxE;;;;GAIG;AACH,eAAe,UAAU,CAAC;IACxB,IAAI,EAAE;QACJ,IAAI,EAAE,SAAS;QACf,IAAI,EAAE;YACJ,WAAW,EAAE,4GAA4G;YACzH,GAAG,EAAE,OAAO,CAAC,oBAAoB,CAAC;SACnC;QACD,QAAQ,EAAE;YACR,IAAI,EACF,yTAAyT;YAC3T,OAAO,EACL,qRAAqR;YACvR,MAAM,EACJ,+cAA+c;SACld;QACD,MAAM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,CAAC,EAAE;iBACxD,CAAC,CAAA;YACJ,CAAC;SACF,CAAA;IACH,CAAC;CACF,CAAC,CAAA"}
@@ -1,61 +0,0 @@
1
- import { defineRule } from "@oxlint/plugins"
2
-
3
- import { calledMethod, docsUrl, receiverName } from "../internal/ast.ts"
4
-
5
- interface Options {
6
- readonly runtimePattern?: string
7
- }
8
-
9
- /**
10
- * The result of `runtime.tick(...)`, `tryTick(...)`, `restore(...)`, and
11
- * `rewind(...)` is read: a failed system, an invalid save, or a released
12
- * checkpoint comes back as data, and dropping it hides the failure.
13
- */
14
- export default defineRule({
15
- meta: {
16
- type: "problem",
17
- docs: {
18
- description: "Check the Result of runtime.tick(...), tryTick(...), restore(...), and rewind(...) instead of dropping it.",
19
- url: docsUrl("handle-tick-result")
20
- },
21
- messages: {
22
- tick:
23
- "The result of `{{call}}(...)` is dropped. A system that fails stops the tick and returns the failure here, so it goes unnoticed and the world is left half-updated. Check it: `const ran = {{call}}(...); if (!ran.ok) ...` (`ran.error` names the system and why). Write `void {{call}}(...)` to ignore it on purpose.",
24
- restore:
25
- "The result of `{{call}}(...)` is dropped. A save that fails to load leaves the previous world in place, unnoticed. Check it: `const restored = {{call}}(data); if (!restored.ok) ...` (`restored.error` says what was invalid). Write `void {{call}}(...)` to ignore it on purpose.",
26
- rewind:
27
- "The result of `{{call}}(...)` is dropped. A checkpoint the runtime let go of (older than its window, or taken before a rewind to an older one or a restore) changes nothing, so the ticks run next are run on top of the present instead of again, unnoticed. Check it: `const rewound = {{call}}(checkpoint); if (!rewound.ok) ...` (`rewound.error` says why), and resynchronize, for example by loading a peer's save. Write `void {{call}}(...)` to ignore it on purpose."
28
- },
29
- schema: [
30
- {
31
- type: "object",
32
- properties: {
33
- runtimePattern: {
34
- type: "string",
35
- description: "A regular expression (case-insensitive) the receiver's name must match to be treated as a Ritmo runtime. Defaults to `runtime$`."
36
- }
37
- },
38
- additionalProperties: false
39
- }
40
- ]
41
- },
42
- create(context) {
43
- const options = (context.options[0] ?? {}) as Options
44
- const runtime = new RegExp(options.runtimePattern ?? "runtime$", "i")
45
- return {
46
- ExpressionStatement(node) {
47
- const call = node.expression
48
- if (call.type !== "CallExpression" || call.callee.type !== "MemberExpression" || call.arguments.length === 0) return
49
- const method = calledMethod(call)
50
- if (method !== "tick" && method !== "tryTick" && method !== "restore" && method !== "rewind") return
51
- const receiver = receiverName(call.callee.object)
52
- if (receiver === undefined || !runtime.test(receiver)) return
53
- context.report({
54
- node,
55
- messageId: method === "restore" || method === "rewind" ? method : "tick",
56
- data: { call: context.sourceCode.getText(call.callee) }
57
- })
58
- }
59
- }
60
- }
61
- })