@typeonce/oxlint-plugin-ritmo 0.15.0 → 0.16.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +38 -0
- package/README.md +25 -6
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/rules/handle-runtime-result.d.ts +10 -0
- package/dist/rules/handle-runtime-result.d.ts.map +1 -0
- package/dist/rules/handle-runtime-result.js +125 -0
- package/dist/rules/handle-runtime-result.js.map +1 -0
- package/dist/rules/no-float-timers.js +1 -1
- package/dist/rules/no-float-timers.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +3 -3
- package/src/rules/handle-runtime-result.ts +131 -0
- package/src/rules/no-float-timers.ts +1 -1
- package/dist/rules/handle-tick-result.d.ts +0 -8
- package/dist/rules/handle-tick-result.d.ts.map +0 -1
- package/dist/rules/handle-tick-result.js +0 -56
- package/dist/rules/handle-tick-result.js.map +0 -1
- package/src/rules/handle-tick-result.ts +0 -61
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,43 @@
|
|
|
1
1
|
# @typeonce/oxlint-plugin-ritmo
|
|
2
2
|
|
|
3
|
+
## 0.16.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 8918c31: `ritmo/handle-runtime-result` no longer reports a `tick`, `tryTick`, `restore`, or `rewind` result passed to a function: that function is a helper that checks it (`expectOk(runtime.tick(update))`, `orCrash(runtime.tick(setup), "Setup")`). It still reports one passed to `JSON.stringify`, `String`, or `console.*`, and any unchecked `snapshot()` or `checksum()` result, which is data on its way to a save or a log. Spirit Call's 180 reports on 0.16.0 were all checking helpers.
|
|
8
|
+
|
|
9
|
+
## 0.16.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- 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.
|
|
14
|
+
|
|
15
|
+
Fix: rename the rule in `.oxlintrc.json`, then check each new report.
|
|
16
|
+
|
|
17
|
+
```diff
|
|
18
|
+
-"ritmo/handle-tick-result": "error",
|
|
19
|
+
+"ritmo/handle-runtime-result": "error",
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
```diff
|
|
23
|
+
-persist(runtime.snapshot())
|
|
24
|
+
+const saved = runtime.snapshot()
|
|
25
|
+
+if (saved.ok) persist(saved.value)
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### Patch Changes
|
|
29
|
+
|
|
30
|
+
- 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.
|
|
31
|
+
- 9290521: Docs from upgrading two games across several versions:
|
|
32
|
+
|
|
33
|
+
- 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.
|
|
34
|
+
- 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`.
|
|
35
|
+
- 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.
|
|
36
|
+
- `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`.
|
|
37
|
+
- 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.
|
|
38
|
+
- `Touch.Layout` shows how to draw a layout with no `null` zones, and `Pointer.Actions` says to build test doubles with `Pointer.scripted`.
|
|
39
|
+
- The `use-ops-for-math` example uses `Angle.wrap` for a signed turn, and the spatial-grid reference defines its `made` helper.
|
|
40
|
+
|
|
3
41
|
## 0.15.0
|
|
4
42
|
|
|
5
43
|
### 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-
|
|
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-
|
|
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
|
-
|
|
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-
|
|
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 `
|
|
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 `tick`, `tryTick`, `restore`, or `rewind` result passed to a function is left to that function (a test's `expectOk(runtime.tick(update))`), unless it only prints or encodes (`JSON.stringify`, `String`, `console.*`). A `snapshot()` or `checksum()` result is data on its way somewhere, so passing it to any function unchecked is reported; a helper that takes that `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-
|
|
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
|
|
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-
|
|
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,
|
|
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,mBAAmB,MAAM,kCAAkC,CAAA;AAClE,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,YAAY,MAAM,2BAA2B,CAAA;AACpD,OAAO,eAAe,MAAM,+BAA+B,CAAA;AAC3D,OAAO,aAAa,MAAM,6BAA6B,CAAA;AACvD,OAAO,sBAAsB,MAAM,sCAAsC,CAAA;AAEzE,eAAe,YAAY,CAAC;IAC1B,IAAI,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE;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,10 @@
|
|
|
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. A `tick`,
|
|
5
|
+
* `restore`, or `rewind` result passed to a function is left to that
|
|
6
|
+
* function (a test's `expectOk`), unless it only prints or encodes.
|
|
7
|
+
*/
|
|
8
|
+
declare const _default: import("@oxlint/plugins").Rule;
|
|
9
|
+
export default _default;
|
|
10
|
+
//# 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":"AAgDA;;;;;;GAMG"}
|
|
@@ -0,0 +1,125 @@
|
|
|
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
|
+
* Functions that take any value and do nothing with a `Result` but print or
|
|
26
|
+
* encode it. A `tick`, `restore`, or `rewind` result handed to any other
|
|
27
|
+
* function goes to a helper that checks it (`expectOk(runtime.tick(update))`).
|
|
28
|
+
*/
|
|
29
|
+
const sinks = new Set(["JSON.stringify", "String", "console.log", "console.info", "console.warn", "console.error", "console.debug"]);
|
|
30
|
+
const calleeName = (node) => {
|
|
31
|
+
if (node.type === "Identifier")
|
|
32
|
+
return node.name;
|
|
33
|
+
if (node.type === "MemberExpression" && !node.computed && node.object.type === "Identifier" && node.property.type === "Identifier") {
|
|
34
|
+
return `${node.object.name}.${node.property.name}`;
|
|
35
|
+
}
|
|
36
|
+
return undefined;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* The `Result` of `runtime.tick(...)`, `tryTick(...)`, `restore(...)`,
|
|
40
|
+
* `rewind(...)`, `snapshot()`, and `checksum()` is checked: dropping it, or
|
|
41
|
+
* passing it on where any value is accepted, hides the failure. A `tick`,
|
|
42
|
+
* `restore`, or `rewind` result passed to a function is left to that
|
|
43
|
+
* function (a test's `expectOk`), unless it only prints or encodes.
|
|
44
|
+
*/
|
|
45
|
+
export default defineRule({
|
|
46
|
+
meta: {
|
|
47
|
+
type: "problem",
|
|
48
|
+
docs: {
|
|
49
|
+
description: "Check the Result of runtime.tick, tryTick, restore, rewind, snapshot, and checksum instead of dropping it or passing it on unchecked.",
|
|
50
|
+
url: docsUrl("handle-runtime-result")
|
|
51
|
+
},
|
|
52
|
+
messages: {
|
|
53
|
+
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.",
|
|
54
|
+
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.",
|
|
55
|
+
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.",
|
|
56
|
+
dropped: "The result of `{{call}}()` is dropped, so the call does nothing. Read it: `const saved = {{call}}(); if (saved.ok) ...`.",
|
|
57
|
+
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)`."
|
|
58
|
+
},
|
|
59
|
+
schema: [
|
|
60
|
+
{
|
|
61
|
+
type: "object",
|
|
62
|
+
properties: {
|
|
63
|
+
runtimePattern: {
|
|
64
|
+
type: "string",
|
|
65
|
+
description: "A regular expression (case-insensitive) the receiver's name must match to be treated as a Ritmo runtime. Defaults to `runtime$`."
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
additionalProperties: false
|
|
69
|
+
}
|
|
70
|
+
]
|
|
71
|
+
},
|
|
72
|
+
create(context) {
|
|
73
|
+
const options = (context.options[0] ?? {});
|
|
74
|
+
const runtime = new RegExp(options.runtimePattern ?? "runtime$", "i");
|
|
75
|
+
return {
|
|
76
|
+
CallExpression(call) {
|
|
77
|
+
if (call.callee.type !== "MemberExpression")
|
|
78
|
+
return;
|
|
79
|
+
const method = calledMethod(call);
|
|
80
|
+
const takes = method === undefined ? undefined : methods.get(method);
|
|
81
|
+
if (takes === undefined)
|
|
82
|
+
return;
|
|
83
|
+
// `run.tick()` and `replay.rewind()` without arguments are other libraries' methods.
|
|
84
|
+
if (takes === "arguments" && call.arguments.length === 0)
|
|
85
|
+
return;
|
|
86
|
+
if (takes === "none" && call.arguments.length > 0)
|
|
87
|
+
return;
|
|
88
|
+
const receiver = receiverName(call.callee.object);
|
|
89
|
+
if (receiver === undefined || !runtime.test(receiver))
|
|
90
|
+
return;
|
|
91
|
+
const data = { call: context.sourceCode.getText(call.callee) };
|
|
92
|
+
let node = call;
|
|
93
|
+
let parent = node.parent;
|
|
94
|
+
while (parent != null && passesThrough.has(parent.type)) {
|
|
95
|
+
node = parent;
|
|
96
|
+
parent = node.parent;
|
|
97
|
+
}
|
|
98
|
+
if (parent == null)
|
|
99
|
+
return;
|
|
100
|
+
if (parent.type === "ExpressionStatement") {
|
|
101
|
+
const messageId = takes === "none" ? "dropped" : method === "restore" || method === "rewind" ? method : "tick";
|
|
102
|
+
context.report({ node: parent, messageId, data });
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
if (!unchecked.has(parent.type))
|
|
106
|
+
return;
|
|
107
|
+
// The callee of a call is a method read on the result, not a hand-off (`runtime.snapshot().toString()` would not compile anyway).
|
|
108
|
+
if (parent.type === "CallExpression" && parent.callee === node)
|
|
109
|
+
return;
|
|
110
|
+
// A property key is not a use of the value.
|
|
111
|
+
if (parent.type === "Property" && parent.value !== node)
|
|
112
|
+
return;
|
|
113
|
+
// A tick, restore, or rewind handed to a function goes to a helper that checks it, unless the function only prints or encodes.
|
|
114
|
+
// snapshot() and checksum() are data on their way somewhere, so a function that takes them unchecked is reported.
|
|
115
|
+
if ((parent.type === "CallExpression" || parent.type === "NewExpression") && takes === "arguments") {
|
|
116
|
+
const name = calleeName(parent.callee);
|
|
117
|
+
if (name === undefined || !sinks.has(name))
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
context.report({ node: call, messageId: "unchecked", data });
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
//# sourceMappingURL=handle-runtime-result.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handle-runtime-result.js","sourceRoot":"","sources":["../../src/rules/handle-runtime-result.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAG5C,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAMxE,mFAAmF;AACnF,MAAM,OAAO,GAAG,IAAI,GAAG,CAA+B;IACpD,CAAC,MAAM,EAAE,WAAW,CAAC;IACrB,CAAC,SAAS,EAAE,WAAW,CAAC;IACxB,CAAC,SAAS,EAAE,WAAW,CAAC;IACxB,CAAC,QAAQ,EAAE,WAAW,CAAC;IACvB,CAAC,UAAU,EAAE,MAAM,CAAC;IACpB,CAAC,UAAU,EAAE,MAAM,CAAC;CACrB,CAAC,CAAA;AAEF;;;;GAIG;AACH,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC,CAAC,uBAAuB,EAAE,mBAAmB,EAAE,yBAAyB,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,qBAAqB,EAAE,iBAAiB,CAAC,CAAC,CAAA;AAE7L;;;;GAIG;AACH,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,CAAC,gBAAgB,EAAE,eAAe,EAAE,iBAAiB,EAAE,UAAU,EAAE,iBAAiB,EAAE,eAAe,EAAE,kBAAkB,EAAE,wBAAwB,CAAC,CAAC,CAAA;AAE/K;;;;GAIG;AACH,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,CAAC,gBAAgB,EAAE,QAAQ,EAAE,aAAa,EAAE,cAAc,EAAE,cAAc,EAAE,eAAe,EAAE,eAAe,CAAC,CAAC,CAAA;AAEpI,MAAM,UAAU,GAAG,CAAC,IAAiB,EAAsB,EAAE;IAC3D,IAAI,IAAI,CAAC,IAAI,KAAK,YAAY;QAAE,OAAO,IAAI,CAAC,IAAI,CAAA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BAC9G,OAAO,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;oBACjD,OAAM;gBACR,CAAC;gBACD,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC;oBAAE,OAAM;gBACvC,kIAAkI;gBAClI,IAAI,MAAM,CAAC,IAAI,KAAK,gBAAgB,IAAI,MAAM,CAAC,MAAM,KAAK,IAAI;oBAAE,OAAM;gBACtE,4CAA4C;gBAC5C,IAAI,MAAM,CAAC,IAAI,KAAK,UAAU,IAAI,MAAM,CAAC,KAAK,KAAK,IAAI;oBAAE,OAAM;gBAC/D,+HAA+H;gBAC/H,kHAAkH;gBAClH,IAAI,CAAC,MAAM,CAAC,IAAI,KAAK,gBAAgB,IAAI,MAAM,CAAC,IAAI,KAAK,eAAe,CAAC,IAAI,KAAK,KAAK,WAAW,EAAE,CAAC;oBACnG,MAAM,IAAI,GAAG,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;oBACtC,IAAI,IAAI,KAAK,SAAS,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC;wBAAE,OAAM;gBACpD,CAAC;gBACD,OAAO,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAAA;YAC9D,CAAC;SACF,CAAA;IACH,CAAC;CACF,CAAC,CAAA"}
|
|
@@ -35,7 +35,7 @@ export default defineRule({
|
|
|
35
35
|
url: docsUrl("no-float-timers")
|
|
36
36
|
},
|
|
37
37
|
messages: {
|
|
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)."
|
|
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,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;AAEjJ,wGAAwG;AACxG,MAAM,OAAO,GAAG,CAAC,GAAgB,EAAW,EAAE;IAC5C,MAAM,I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I,CAAC,KAAK,CAAC,IAAI,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;oBAAE,MAAM,CAAC,IAAI,CAAC,CAAA;YAChH,CAAC;SACF,CAAA;IACH,CAAC;CACF,CAAC,CAAA"}
|
package/package.json
CHANGED
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-
|
|
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
|
|
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-
|
|
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,131 @@
|
|
|
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
|
+
* Functions that take any value and do nothing with a `Result` but print or
|
|
36
|
+
* encode it. A `tick`, `restore`, or `rewind` result handed to any other
|
|
37
|
+
* function goes to a helper that checks it (`expectOk(runtime.tick(update))`).
|
|
38
|
+
*/
|
|
39
|
+
const sinks = new Set(["JSON.stringify", "String", "console.log", "console.info", "console.warn", "console.error", "console.debug"])
|
|
40
|
+
|
|
41
|
+
const calleeName = (node: ESTree.Node): string | undefined => {
|
|
42
|
+
if (node.type === "Identifier") return node.name
|
|
43
|
+
if (node.type === "MemberExpression" && !node.computed && node.object.type === "Identifier" && node.property.type === "Identifier") {
|
|
44
|
+
return `${node.object.name}.${node.property.name}`
|
|
45
|
+
}
|
|
46
|
+
return undefined
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The `Result` of `runtime.tick(...)`, `tryTick(...)`, `restore(...)`,
|
|
51
|
+
* `rewind(...)`, `snapshot()`, and `checksum()` is checked: dropping it, or
|
|
52
|
+
* passing it on where any value is accepted, hides the failure. A `tick`,
|
|
53
|
+
* `restore`, or `rewind` result passed to a function is left to that
|
|
54
|
+
* function (a test's `expectOk`), unless it only prints or encodes.
|
|
55
|
+
*/
|
|
56
|
+
export default defineRule({
|
|
57
|
+
meta: {
|
|
58
|
+
type: "problem",
|
|
59
|
+
docs: {
|
|
60
|
+
description: "Check the Result of runtime.tick, tryTick, restore, rewind, snapshot, and checksum instead of dropping it or passing it on unchecked.",
|
|
61
|
+
url: docsUrl("handle-runtime-result")
|
|
62
|
+
},
|
|
63
|
+
messages: {
|
|
64
|
+
tick:
|
|
65
|
+
"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.",
|
|
66
|
+
restore:
|
|
67
|
+
"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.",
|
|
68
|
+
rewind:
|
|
69
|
+
"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.",
|
|
70
|
+
dropped:
|
|
71
|
+
"The result of `{{call}}()` is dropped, so the call does nothing. Read it: `const saved = {{call}}(); if (saved.ok) ...`.",
|
|
72
|
+
unchecked:
|
|
73
|
+
"`{{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)`."
|
|
74
|
+
},
|
|
75
|
+
schema: [
|
|
76
|
+
{
|
|
77
|
+
type: "object",
|
|
78
|
+
properties: {
|
|
79
|
+
runtimePattern: {
|
|
80
|
+
type: "string",
|
|
81
|
+
description: "A regular expression (case-insensitive) the receiver's name must match to be treated as a Ritmo runtime. Defaults to `runtime$`."
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
additionalProperties: false
|
|
85
|
+
}
|
|
86
|
+
]
|
|
87
|
+
},
|
|
88
|
+
create(context) {
|
|
89
|
+
const options = (context.options[0] ?? {}) as Options
|
|
90
|
+
const runtime = new RegExp(options.runtimePattern ?? "runtime$", "i")
|
|
91
|
+
return {
|
|
92
|
+
CallExpression(call) {
|
|
93
|
+
if (call.callee.type !== "MemberExpression") return
|
|
94
|
+
const method = calledMethod(call)
|
|
95
|
+
const takes = method === undefined ? undefined : methods.get(method)
|
|
96
|
+
if (takes === undefined) return
|
|
97
|
+
// `run.tick()` and `replay.rewind()` without arguments are other libraries' methods.
|
|
98
|
+
if (takes === "arguments" && call.arguments.length === 0) return
|
|
99
|
+
if (takes === "none" && call.arguments.length > 0) return
|
|
100
|
+
const receiver = receiverName(call.callee.object)
|
|
101
|
+
if (receiver === undefined || !runtime.test(receiver)) return
|
|
102
|
+
const data = { call: context.sourceCode.getText(call.callee) }
|
|
103
|
+
|
|
104
|
+
let node: ESTree.Node = call
|
|
105
|
+
let parent: ESTree.Node | null | undefined = node.parent
|
|
106
|
+
while (parent != null && passesThrough.has(parent.type)) {
|
|
107
|
+
node = parent
|
|
108
|
+
parent = node.parent
|
|
109
|
+
}
|
|
110
|
+
if (parent == null) return
|
|
111
|
+
if (parent.type === "ExpressionStatement") {
|
|
112
|
+
const messageId = takes === "none" ? "dropped" : method === "restore" || method === "rewind" ? method : "tick"
|
|
113
|
+
context.report({ node: parent, messageId, data })
|
|
114
|
+
return
|
|
115
|
+
}
|
|
116
|
+
if (!unchecked.has(parent.type)) return
|
|
117
|
+
// The callee of a call is a method read on the result, not a hand-off (`runtime.snapshot().toString()` would not compile anyway).
|
|
118
|
+
if (parent.type === "CallExpression" && parent.callee === node) return
|
|
119
|
+
// A property key is not a use of the value.
|
|
120
|
+
if (parent.type === "Property" && parent.value !== node) return
|
|
121
|
+
// A tick, restore, or rewind handed to a function goes to a helper that checks it, unless the function only prints or encodes.
|
|
122
|
+
// snapshot() and checksum() are data on their way somewhere, so a function that takes them unchecked is reported.
|
|
123
|
+
if ((parent.type === "CallExpression" || parent.type === "NewExpression") && takes === "arguments") {
|
|
124
|
+
const name = calleeName(parent.callee)
|
|
125
|
+
if (name === undefined || !sinks.has(name)) return
|
|
126
|
+
}
|
|
127
|
+
context.report({ node: call, messageId: "unchecked", data })
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
})
|
|
@@ -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,EAAE;YACN;gBACE,IAAI,EAAE,QAAQ;gBACd,UAAU,EAAE;oBACV,cAAc,EAAE;wBACd,IAAI,EAAE,QAAQ;wBACd,WAAW,EAAE,kIAAkI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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
|
-
})
|