@typeonce/oxlint-plugin-ritmo 0.13.0 → 0.15.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 +94 -0
- package/README.md +69 -11
- package/dist/index.js +10 -5
- package/dist/index.js.map +1 -1
- package/dist/rules/handle-tick-result.d.ts +3 -3
- package/dist/rules/handle-tick-result.js +8 -7
- package/dist/rules/handle-tick-result.js.map +1 -1
- package/dist/rules/keep-simulation-headless.d.ts.map +1 -1
- package/dist/rules/keep-simulation-headless.js +6 -3
- package/dist/rules/keep-simulation-headless.js.map +1 -1
- package/dist/rules/no-brand-cast.d.ts +7 -0
- package/dist/rules/no-brand-cast.d.ts.map +1 -0
- package/dist/rules/no-brand-cast.js +195 -0
- package/dist/rules/no-brand-cast.js.map +1 -0
- package/dist/rules/no-float-timers.d.ts +8 -0
- package/dist/rules/no-float-timers.d.ts.map +1 -0
- package/dist/rules/no-float-timers.js +60 -0
- package/dist/rules/no-float-timers.js.map +1 -0
- package/dist/rules/use-clock-for-time.js +1 -1
- package/dist/rules/use-clock-for-time.js.map +1 -1
- package/dist/rules/use-ops-for-math.d.ts +2 -2
- package/dist/rules/use-ops-for-math.d.ts.map +1 -1
- package/dist/rules/use-ops-for-math.js +199 -35
- package/dist/rules/use-ops-for-math.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +10 -5
- package/src/rules/handle-tick-result.ts +9 -7
- package/src/rules/keep-simulation-headless.ts +8 -3
- package/src/rules/no-brand-cast.ts +195 -0
- package/src/rules/no-float-timers.ts +64 -0
- package/src/rules/use-clock-for-time.ts +1 -1
- package/src/rules/use-ops-for-math.ts +207 -35
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-ops-for-math.js","sourceRoot":"","sources":["../../src/rules/use-ops-for-math.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAG5C,OAAO,EAAE,OAAO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O,CAAC,UAAU,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAA;IAC3G,MAAM,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,8CAA8C,CAAC,CAAC,CAAC,yCAAyC,CAAC,GAAG,SAAS,CAAA;IAChI,IAAI,MAAM,KAAK,SAAS;QAAE,OAAO,KAAK,CAAC,eAAe,CAAC,MAAM,EAAE,KAAK,IAAI,EAAE,CAAC,CAAA;IAC3E,MAAM,KAAK,GAAG,SAAS,EAAE,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,CAAA;IACtC,OAAO,KAAK,CAAC,qBAAqB,CAAC,CAAC,KAAK,EAAE,KAAK,CAAC,EAAE,GAAG,IAAI,IAAI,CAAC,CAAA;AACjE,CAAC,CAAA"}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Types catch wrong calls and devtools catch wrong runs; these rules catch
|
|
5
5
|
* the source patterns neither can see: simulation code that reads the wall
|
|
6
|
-
* clock, `Math.random`, engine-dependent math, or the page,
|
|
7
|
-
* be saved,
|
|
8
|
-
*
|
|
9
|
-
* Ritmo API to use instead.
|
|
6
|
+
* clock, `Math.random`, engine-dependent math, or the page, timers counted
|
|
7
|
+
* in floats, data that cannot be saved, casts that skip a brand's check,
|
|
8
|
+
* state values that keep a previous state's fields, and runtime results that
|
|
9
|
+
* are dropped. Every report names the Ritmo API to use instead.
|
|
10
10
|
*
|
|
11
11
|
* Register the plugin in `.oxlintrc.json` with `"jsPlugins":
|
|
12
12
|
* ["@typeonce/oxlint-plugin-ritmo"]`. Its rules are named `ritmo/<rule>`.
|
|
@@ -16,7 +16,8 @@
|
|
|
16
16
|
*
|
|
17
17
|
* - Simulation files: `ritmo/use-clock-for-time`,
|
|
18
18
|
* `ritmo/use-random-for-randomness`, `ritmo/use-ops-for-math`,
|
|
19
|
-
* `ritmo/keep-simulation-headless`, `ritmo/no-infinity-in-simulation-data
|
|
19
|
+
* `ritmo/keep-simulation-headless`, `ritmo/no-infinity-in-simulation-data`,
|
|
20
|
+
* `ritmo/no-float-timers`, `ritmo/no-brand-cast`.
|
|
20
21
|
* - Every file: `ritmo/handle-tick-result`,
|
|
21
22
|
* `ritmo/prefix-descriptor-and-system-names`, `ritmo/use-cell-value`,
|
|
22
23
|
* `ritmo/no-state-spread`.
|
|
@@ -27,6 +28,8 @@ import { definePlugin } from "@oxlint/plugins"
|
|
|
27
28
|
|
|
28
29
|
import handleTickResult from "./rules/handle-tick-result.ts"
|
|
29
30
|
import keepSimulationHeadless from "./rules/keep-simulation-headless.ts"
|
|
31
|
+
import noBrandCast from "./rules/no-brand-cast.ts"
|
|
32
|
+
import noFloatTimers from "./rules/no-float-timers.ts"
|
|
30
33
|
import noInfinityInSimulationData from "./rules/no-infinity-in-simulation-data.ts"
|
|
31
34
|
import noStateSpread from "./rules/no-state-spread.ts"
|
|
32
35
|
import prefixDescriptorAndSystemNames from "./rules/prefix-descriptor-and-system-names.ts"
|
|
@@ -43,6 +46,8 @@ export default definePlugin({
|
|
|
43
46
|
"use-ops-for-math": useOpsForMath,
|
|
44
47
|
"keep-simulation-headless": keepSimulationHeadless,
|
|
45
48
|
"no-infinity-in-simulation-data": noInfinityInSimulationData,
|
|
49
|
+
"no-float-timers": noFloatTimers,
|
|
50
|
+
"no-brand-cast": noBrandCast,
|
|
46
51
|
"handle-tick-result": handleTickResult,
|
|
47
52
|
"prefix-descriptor-and-system-names": prefixDescriptorAndSystemNames,
|
|
48
53
|
"use-cell-value": useCellValue,
|
|
@@ -7,22 +7,24 @@ interface Options {
|
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
-
* The result of `runtime.tick(...)`, `tryTick(...)`,
|
|
11
|
-
* failed system
|
|
12
|
-
* the failure.
|
|
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
13
|
*/
|
|
14
14
|
export default defineRule({
|
|
15
15
|
meta: {
|
|
16
16
|
type: "problem",
|
|
17
17
|
docs: {
|
|
18
|
-
description: "Check the Result of runtime.tick(...), tryTick(...), and
|
|
18
|
+
description: "Check the Result of runtime.tick(...), tryTick(...), restore(...), and rewind(...) instead of dropping it.",
|
|
19
19
|
url: docsUrl("handle-tick-result")
|
|
20
20
|
},
|
|
21
21
|
messages: {
|
|
22
22
|
tick:
|
|
23
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
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."
|
|
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."
|
|
26
28
|
},
|
|
27
29
|
schema: [
|
|
28
30
|
{
|
|
@@ -45,12 +47,12 @@ export default defineRule({
|
|
|
45
47
|
const call = node.expression
|
|
46
48
|
if (call.type !== "CallExpression" || call.callee.type !== "MemberExpression" || call.arguments.length === 0) return
|
|
47
49
|
const method = calledMethod(call)
|
|
48
|
-
if (method !== "tick" && method !== "tryTick" && method !== "restore") return
|
|
50
|
+
if (method !== "tick" && method !== "tryTick" && method !== "restore" && method !== "rewind") return
|
|
49
51
|
const receiver = receiverName(call.callee.object)
|
|
50
52
|
if (receiver === undefined || !runtime.test(receiver)) return
|
|
51
53
|
context.report({
|
|
52
54
|
node,
|
|
53
|
-
messageId: method === "restore"
|
|
55
|
+
messageId: method === "restore" || method === "rewind" ? method : "tick",
|
|
54
56
|
data: { call: context.sourceCode.getText(call.callee) }
|
|
55
57
|
})
|
|
56
58
|
}
|
|
@@ -9,11 +9,14 @@ const page = new Set([
|
|
|
9
9
|
"innerWidth", "innerHeight", "addEventListener", "removeEventListener", "alert", "confirm", "prompt"
|
|
10
10
|
])
|
|
11
11
|
|
|
12
|
-
/** Globals that do host I/O: storage,
|
|
12
|
+
/** Globals that do host I/O: storage, requests, navigation. */
|
|
13
13
|
const io = new Set([
|
|
14
|
-
"localStorage", "sessionStorage", "indexedDB", "caches", "fetch", "XMLHttpRequest", "
|
|
14
|
+
"localStorage", "sessionStorage", "indexedDB", "caches", "fetch", "XMLHttpRequest", "EventSource", "location", "history"
|
|
15
15
|
])
|
|
16
16
|
|
|
17
|
+
/** Globals that connect to other peers: what online play goes through a netcode session for. */
|
|
18
|
+
const network = new Set(["WebSocket", "RTCPeerConnection", "RTCDataChannel"])
|
|
19
|
+
|
|
17
20
|
/** Renderer and UI packages, by exact name. */
|
|
18
21
|
const renderers = new Set([
|
|
19
22
|
"@typeonce/ritmo-render", "@typeonce/ritmo-pixi", "pixi.js", "three", "react", "react-dom", "preact",
|
|
@@ -45,6 +48,8 @@ export default defineRule({
|
|
|
45
48
|
"`{{name}}` is the page, which tests, bots, and replays do not have. Capture input in the host with `Keyboard`, `Pointer`, or `Touch` from `@typeonce/ritmo-browser` and `InputCapture` into a resource, and read that resource in systems. Pass other page state (size, settings) in from host code with `runtime.send(...)` or a resource.",
|
|
46
49
|
io:
|
|
47
50
|
"`{{name}}` is host I/O, which tests, bots, and replays do not have and cannot reproduce. Do the I/O in host code and pass the result in with `runtime.send(...)` or a resource; save and load the world in host code with `runtime.snapshot()` and `runtime.restore(...)`.",
|
|
51
|
+
network:
|
|
52
|
+
"`{{name}}` is a connection to other peers, which tests, bots, and replays do not have. For other players' input, run the simulation under a session of `@typeonce/ritmo-netcode` (`Netcode.rollback` or `Netcode.lockstep`): host code opens the connection and wraps it in a link (`WebSocketNetworkLink`, `WebRtcNetworkLink`), and remote input reaches the simulation through `Netcode.seats`, never `runtime.send(...)`, which a rollback would read on the wrong tick.",
|
|
48
53
|
renderer:
|
|
49
54
|
"The simulation imports `{{source}}`, a renderer or UI package, so it no longer runs headless. Draw from a render schedule in render code: mirror entities into nodes with `RenderSync` and a `NodeRegistry` from `@typeonce/ritmo-render`, and declare its services (a node registry) there. Renderer nodes stay in the registry, never in components.",
|
|
50
55
|
rendererType:
|
|
@@ -88,7 +93,7 @@ export default defineRule({
|
|
|
88
93
|
checkSource(node, stringValue(node.source))
|
|
89
94
|
},
|
|
90
95
|
Identifier(node) {
|
|
91
|
-
const kind = page.has(node.name) ? "page" : io.has(node.name) ? "io" : undefined
|
|
96
|
+
const kind = page.has(node.name) ? "page" : io.has(node.name) ? "io" : network.has(node.name) ? "network" : undefined
|
|
92
97
|
if (kind === undefined) return
|
|
93
98
|
// `typeof window` in a type runs nothing.
|
|
94
99
|
if (node.parent.type === "TSTypeQuery" || node.parent.type === "TSQualifiedName") return
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { defineRule } from "@oxlint/plugins"
|
|
2
|
+
import type { ESTree } from "@oxlint/plugins"
|
|
3
|
+
|
|
4
|
+
import { docsUrl } from "../internal/ast.ts"
|
|
5
|
+
|
|
6
|
+
/** The type names that are brands wherever they come from: `Brand.Branded<...>`, Effect's `Brand.Brand<...>`, Zod's `z.BRAND<...>` / `z.$brand<...>`. */
|
|
7
|
+
const brandNames = new Set(["Brand", "Branded", "BRAND", "$brand"])
|
|
8
|
+
|
|
9
|
+
/** Property keys that only a brand declares (`T & { readonly __brand: "UserId" }`). */
|
|
10
|
+
const brandKey = /^(__?brand|__publicBrand|__type)$/
|
|
11
|
+
|
|
12
|
+
/** Ritmo's branded exports, by module: `Clock.Deadline`, `Random.State`, `Entity.Handle`, ... */
|
|
13
|
+
const ritmoBrands = new Map<string, ReadonlySet<string>>([
|
|
14
|
+
["Clock", new Set(["Deadline", "Step", "Duration", "ClockResource"])],
|
|
15
|
+
["Entity", new Set(["Handle", "EntityId"])],
|
|
16
|
+
["Random", new Set(["State"])],
|
|
17
|
+
["Checkpoint", new Set(["Checkpoint", "Rewindable"])]
|
|
18
|
+
])
|
|
19
|
+
|
|
20
|
+
/** The type helpers that read the type out of a schema: `z.infer<typeof X>`, `Schema.Schema.Type<typeof X>`. */
|
|
21
|
+
const schemaTypeHelpers = new Set(["infer", "output", "TypeOf", "Infer", "Type"])
|
|
22
|
+
|
|
23
|
+
/** A schema built with a brand: Zod's `.brand(...)` / `.brand<"X">()`, Effect's `Schema.brand(...)` / `.pipe(Schema.brand(...))`. */
|
|
24
|
+
const brandsSchema = /\bbrand\s*(<[^>]*>\s*)?\(/
|
|
25
|
+
|
|
26
|
+
/** The dotted names of a type name or expression (`Clock.Deadline` gives `["Clock", "Deadline"]`). */
|
|
27
|
+
const segments = (node: ESTree.Node): Array<string> | undefined => {
|
|
28
|
+
if (node.type === "Identifier") return [node.name]
|
|
29
|
+
if (node.type === "TSQualifiedName") {
|
|
30
|
+
const left = segments(node.left)
|
|
31
|
+
return left === undefined ? undefined : [...left, node.right.name]
|
|
32
|
+
}
|
|
33
|
+
if (node.type === "MemberExpression" && !node.computed && node.property.type === "Identifier") {
|
|
34
|
+
const left = segments(node.object)
|
|
35
|
+
return left === undefined ? undefined : [...left, node.property.name]
|
|
36
|
+
}
|
|
37
|
+
return undefined
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Where a local name imported from Ritmo points: `[]` for the package, `["Clock"]` for a module, `["Clock", "Deadline"]` for a type. */
|
|
41
|
+
const ritmoImport = (declaration: ESTree.ImportDeclaration, specifier: ESTree.ImportDeclarationSpecifier): Array<string> | undefined => {
|
|
42
|
+
const match = /^@typeonce\/ritmo(\/([A-Za-z0-9]+))?$/.exec(declaration.source.value)
|
|
43
|
+
if (match === null) return undefined
|
|
44
|
+
const module = match[2]
|
|
45
|
+
const base = module === undefined ? [] : [module]
|
|
46
|
+
if (specifier.type === "ImportNamespaceSpecifier") return base
|
|
47
|
+
if (specifier.type !== "ImportSpecifier") return undefined
|
|
48
|
+
const imported = specifier.imported.type === "Identifier" ? specifier.imported.name : specifier.imported.value
|
|
49
|
+
return [...base, imported]
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Simulation code never casts a value to a branded type: a brand stands for a
|
|
54
|
+
* check, and the cast claims it without running it.
|
|
55
|
+
*/
|
|
56
|
+
export default defineRule({
|
|
57
|
+
meta: {
|
|
58
|
+
type: "problem",
|
|
59
|
+
docs: {
|
|
60
|
+
description: "Make a branded value through its schema or constructor, not with `as` / `<T>` casts.",
|
|
61
|
+
url: docsUrl("no-brand-cast")
|
|
62
|
+
},
|
|
63
|
+
messages: {
|
|
64
|
+
cast:
|
|
65
|
+
"This casts to `{{type}}`, a branded type: a brand stands for a check the value passed, and the cast claims it without running the check, so an invalid value travels as a valid one (and a save holding it fails to load, or the simulation computes with it). Make the value through its check instead: decode it at the boundary with the schema that brands it (`UserId.parse(raw)` with Zod, `Schema.decodeUnknownSync(UserId)(raw)` with Effect), or with Ritmo's constructor or guard: `Random.seed(n)` / `Random.result(n)`, `Clock.deadline(time, duration)` / `Clock.isDeadline(step)`, `Game.Entity.handle(id)` / `Entity.isHandle(Root)`."
|
|
66
|
+
},
|
|
67
|
+
schema: []
|
|
68
|
+
},
|
|
69
|
+
create(context) {
|
|
70
|
+
const aliases = new Map<string, ESTree.TSType>()
|
|
71
|
+
const interfaces = new Map<string, ESTree.TSInterfaceDeclaration>()
|
|
72
|
+
const values = new Map<string, ESTree.Node>()
|
|
73
|
+
const uniqueSymbols = new Set<string>()
|
|
74
|
+
const imports = new Map<string, Array<string>>()
|
|
75
|
+
const casts: Array<ESTree.TSAsExpression | ESTree.TSTypeAssertion> = []
|
|
76
|
+
|
|
77
|
+
/** Whether the value named `name` is a schema built with a brand in this file. */
|
|
78
|
+
const isBrandedSchema = (name: string): boolean => {
|
|
79
|
+
const init = values.get(name)
|
|
80
|
+
return init !== undefined && brandsSchema.test(context.sourceCode.getText(init))
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Whether a dotted name is a brand: a brand helper, Ritmo's branded export, or a local brand alias. */
|
|
84
|
+
const namesBrand = (names: Array<string>, hasArguments: boolean, seen: Set<string>): boolean => {
|
|
85
|
+
const [root, ...rest] = names
|
|
86
|
+
if (root === undefined) return false
|
|
87
|
+
const imported = imports.get(root)
|
|
88
|
+
if (imported !== undefined) {
|
|
89
|
+
const [module, type, ...more] = [...imported, ...rest]
|
|
90
|
+
if (module !== undefined && type !== undefined && more.length === 0 && ritmoBrands.get(module)?.has(type) === true) return true
|
|
91
|
+
}
|
|
92
|
+
const last = names[names.length - 1]!
|
|
93
|
+
if (names.length === 1) {
|
|
94
|
+
const alias = aliases.get(root)
|
|
95
|
+
if (alias !== undefined) return !seen.has(root) && isBrand(alias, new Set([...seen, root]))
|
|
96
|
+
const declared = interfaces.get(root)
|
|
97
|
+
if (declared !== undefined) return !seen.has(root) && interfaceIsBrand(declared, new Set([...seen, root]))
|
|
98
|
+
return hasArguments && brandNames.has(root)
|
|
99
|
+
}
|
|
100
|
+
return brandNames.has(last)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const interfaceIsBrand = (node: ESTree.TSInterfaceDeclaration, seen: Set<string>): boolean =>
|
|
104
|
+
node.body.body.some(memberIsBrand) ||
|
|
105
|
+
node.extends.some((heritage) => {
|
|
106
|
+
const names = segments(heritage.expression)
|
|
107
|
+
return names !== undefined && namesBrand(names, heritage.typeArguments !== null, seen)
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
const memberIsBrand = (member: ESTree.TSSignature): boolean => {
|
|
111
|
+
if (member.type !== "TSPropertySignature") return false
|
|
112
|
+
if (!member.computed) return member.key.type === "Identifier" ? brandKey.test(member.key.name) : false
|
|
113
|
+
if (member.key.type === "Identifier" && uniqueSymbols.has(member.key.name)) return true
|
|
114
|
+
return /brand/i.test(context.sourceCode.getText(member.key))
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** Whether `node` reads the type of a branded schema: `typeof X.Type`, `(typeof X)["Type"]`. */
|
|
118
|
+
const readsBrandedSchema = (node: ESTree.TSType): boolean => {
|
|
119
|
+
if (node.type === "TSTypeQuery") {
|
|
120
|
+
const names = segments(node.exprName)
|
|
121
|
+
return names !== undefined && names.length === 2 && names[1] === "Type" && isBrandedSchema(names[0]!)
|
|
122
|
+
}
|
|
123
|
+
if (node.type === "TSIndexedAccessType" && node.objectType.type === "TSTypeQuery") {
|
|
124
|
+
const names = segments(node.objectType.exprName)
|
|
125
|
+
const index = node.indexType
|
|
126
|
+
return names !== undefined && names.length === 1 && isBrandedSchema(names[0]!) &&
|
|
127
|
+
index.type === "TSLiteralType" && index.literal.type === "Literal" && index.literal.value === "Type"
|
|
128
|
+
}
|
|
129
|
+
return false
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const isBrand = (node: ESTree.TSType, seen: Set<string>): boolean => {
|
|
133
|
+
switch (node.type) {
|
|
134
|
+
case "TSIntersectionType":
|
|
135
|
+
case "TSUnionType":
|
|
136
|
+
return node.types.some((type) => isBrand(type, seen))
|
|
137
|
+
case "TSArrayType":
|
|
138
|
+
return isBrand(node.elementType, seen)
|
|
139
|
+
case "TSTypeOperator":
|
|
140
|
+
return node.operator === "readonly" && isBrand(node.typeAnnotation, seen)
|
|
141
|
+
case "TSParenthesizedType":
|
|
142
|
+
return isBrand(node.typeAnnotation, seen)
|
|
143
|
+
case "TSTypeLiteral":
|
|
144
|
+
return node.members.some(memberIsBrand)
|
|
145
|
+
case "TSTypeReference": {
|
|
146
|
+
const names = segments(node.typeName)
|
|
147
|
+
if (names === undefined) return false
|
|
148
|
+
const schema = node.typeArguments?.params[0]
|
|
149
|
+
if (names.length > 1 && schemaTypeHelpers.has(names[names.length - 1]!) && schema?.type === "TSTypeQuery") {
|
|
150
|
+
const target = segments(schema.exprName)
|
|
151
|
+
if (target !== undefined && target.length === 1 && isBrandedSchema(target[0]!)) return true
|
|
152
|
+
}
|
|
153
|
+
return namesBrand(names, node.typeArguments !== null, seen)
|
|
154
|
+
}
|
|
155
|
+
default:
|
|
156
|
+
return readsBrandedSchema(node)
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return {
|
|
161
|
+
ImportDeclaration(node) {
|
|
162
|
+
for (const specifier of node.specifiers) {
|
|
163
|
+
const target = ritmoImport(node, specifier)
|
|
164
|
+
if (target !== undefined) imports.set(specifier.local.name, target)
|
|
165
|
+
}
|
|
166
|
+
},
|
|
167
|
+
TSTypeAliasDeclaration(node) {
|
|
168
|
+
aliases.set(node.id.name, node.typeAnnotation)
|
|
169
|
+
},
|
|
170
|
+
TSInterfaceDeclaration(node) {
|
|
171
|
+
interfaces.set(node.id.name, node)
|
|
172
|
+
},
|
|
173
|
+
VariableDeclarator(node) {
|
|
174
|
+
if (node.id.type !== "Identifier") return
|
|
175
|
+
const annotation = node.id.typeAnnotation?.typeAnnotation
|
|
176
|
+
// `declare const brand: unique symbol` names a key no value has; a symbol made at runtime is a real key.
|
|
177
|
+
if (annotation?.type === "TSTypeOperator" && annotation.operator === "unique" && node.init === null) uniqueSymbols.add(node.id.name)
|
|
178
|
+
if (node.init !== null) values.set(node.id.name, node.init)
|
|
179
|
+
},
|
|
180
|
+
TSAsExpression(node) {
|
|
181
|
+
casts.push(node)
|
|
182
|
+
},
|
|
183
|
+
TSTypeAssertion(node) {
|
|
184
|
+
casts.push(node)
|
|
185
|
+
},
|
|
186
|
+
// Declarations may follow the casts that use them, so casts are checked once the file is read.
|
|
187
|
+
"Program:exit"() {
|
|
188
|
+
for (const cast of casts) {
|
|
189
|
+
if (!isBrand(cast.typeAnnotation, new Set())) continue
|
|
190
|
+
context.report({ node: cast, messageId: "cast", data: { type: context.sourceCode.getText(cast.typeAnnotation) } })
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
})
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { defineRule } from "@oxlint/plugins"
|
|
2
|
+
import type { ESTree } from "@oxlint/plugins"
|
|
3
|
+
|
|
4
|
+
import { calledMethod, docsUrl, propertyName } from "../internal/ast.ts"
|
|
5
|
+
|
|
6
|
+
// The names a tick's seconds go by: a local, a field (`time.dt`), or a resource read (`resources.deltaTime.get()`).
|
|
7
|
+
const deltaNames = ["dt", "deltaTime", "deltaSeconds"]
|
|
8
|
+
|
|
9
|
+
/** `node` without the type-only wrappers TypeScript adds (`dt as number`, `dt!`). */
|
|
10
|
+
const unwrap = (node: ESTree.Node): ESTree.Node =>
|
|
11
|
+
node.type === "TSAsExpression" || node.type === "TSNonNullExpression" || node.type === "TSSatisfiesExpression" ? unwrap(node.expression) : node
|
|
12
|
+
|
|
13
|
+
/** Whether `node` is a tick's seconds on their own: `dt`, `time.dt`, or `resources.deltaTime.get()`. */
|
|
14
|
+
const isDelta = (raw: ESTree.Node): boolean => {
|
|
15
|
+
const node = unwrap(raw)
|
|
16
|
+
if (node.type === "Identifier") return deltaNames.includes(node.name)
|
|
17
|
+
if (node.type === "MemberExpression") return deltaNames.includes(propertyName(node) ?? "")
|
|
18
|
+
if (node.type === "CallExpression" && calledMethod(node) === "get" && node.callee.type === "MemberExpression") {
|
|
19
|
+
const receiver = unwrap(node.callee.object)
|
|
20
|
+
return receiver.type === "MemberExpression" && deltaNames.includes(propertyName(receiver) ?? "")
|
|
21
|
+
}
|
|
22
|
+
return false
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Whether `node` reads a stored value (a local or a field), the thing a timer counts. */
|
|
26
|
+
const isStored = (raw: ESTree.Node): boolean => {
|
|
27
|
+
const node = unwrap(raw)
|
|
28
|
+
return (node.type === "Identifier" || node.type === "MemberExpression") && !isDelta(node)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* A timer in simulation code is a deadline in steps, never a float counted
|
|
33
|
+
* down (or up) by `dt`: the float drifts, and the value it saves means
|
|
34
|
+
* nothing once the fixed step changes.
|
|
35
|
+
*/
|
|
36
|
+
export default defineRule({
|
|
37
|
+
meta: {
|
|
38
|
+
type: "problem",
|
|
39
|
+
docs: {
|
|
40
|
+
description: "Keep timers and cooldowns as Clock deadlines in steps, not floats counted by dt.",
|
|
41
|
+
url: docsUrl("no-float-timers")
|
|
42
|
+
},
|
|
43
|
+
messages: {
|
|
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)."
|
|
46
|
+
},
|
|
47
|
+
schema: []
|
|
48
|
+
},
|
|
49
|
+
create(context) {
|
|
50
|
+
const report = (node: ESTree.Node) =>
|
|
51
|
+
context.report({ node, messageId: "floatTimer", data: { text: context.sourceCode.getText(node) } })
|
|
52
|
+
return {
|
|
53
|
+
AssignmentExpression(node) {
|
|
54
|
+
// `timer -= dt`, `elapsed += time.dt`
|
|
55
|
+
if ((node.operator === "-=" || node.operator === "+=") && isDelta(node.right)) report(node)
|
|
56
|
+
},
|
|
57
|
+
BinaryExpression(node) {
|
|
58
|
+
// `cooldown.remaining - dt`, `time.dt + since`; `x + vx * dt` scales dt, so it is integration.
|
|
59
|
+
if (node.operator !== "-" && node.operator !== "+") return
|
|
60
|
+
if ((isDelta(node.right) && isStored(node.left)) || (isDelta(node.left) && isStored(node.right))) report(node)
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
})
|
|
@@ -19,7 +19,7 @@ export default defineRule({
|
|
|
19
19
|
wallClock:
|
|
20
20
|
"{{call}} reads the wall clock, so the simulation plays differently on every run and replays diverge. For time since the start, read the Clock resource (`Clock.elapsed(time)` in seconds, `time.step` in steps). For today's date, read it in host code and pass it in with `runtime.send(...)` or a resource, so the replay records it.",
|
|
21
21
|
timer:
|
|
22
|
-
"{{call}}() runs its callback outside the tick, at a moment a replay cannot reproduce. Count steps instead: store the step it fires at (`
|
|
22
|
+
"{{call}}() runs its callback outside the tick, at a moment a replay cannot reproduce. Count steps instead: store the step it fires at (`Clock.deadline(time, Clock.duration(step, seconds))`) in a component or resource and check it each tick with `Clock.reached(time, due)`, or use `Clock.every(time, duration)` for something that repeats."
|
|
23
23
|
},
|
|
24
24
|
schema: []
|
|
25
25
|
},
|