Skip to content

A town simulation in pale isometric line art, implemented with Ritmo ECS and PixiJs 3D

Ban as never and as unknown as (town/no-cast-escape), remove all 8

SandroMaglionecdebcdf94ba9
diff --git a/.oxlintrc.json b/.oxlintrc.json
new file mode 100644
index 0000000..aa2f9b7
--- /dev/null
+++ b/.oxlintrc.json
@@ -0,0 +1,12 @@
+{
+ "$schema": "./node_modules/oxlint/configuration_schema.json",
+ "plugins": ["typescript"],
+ "jsPlugins": ["./tools/lint/plugin.mjs"],
+ "categories": {
+ "correctness": "off"
+ },
+ "rules": {
+ "town/no-cast-escape": "error"
+ },
+ "ignorePatterns": ["dist/**", "node_modules/**", "deploy/**", "output/**"]
+}
diff --git a/package.json b/package.json
index d35df21..44488b2 100644
--- a/package.json
+++ b/package.json
@@ -13,7 +13,7 @@
"balance:worth": "node scripts/worth.ts",
"balance:furniture": "node scripts/furniture.ts",
"balance:model:check": "node --test test/balance-model.test.ts",
- "check": "node scripts/check.ts",
+ "check": "pnpm lint && node scripts/check.ts",
"check:browser": "node scripts/check-browser.ts",
"check:phone": "node scripts/check-phone.ts",
"check:models": "node scripts/check-town-models.ts",
@@ -25,6 +25,7 @@
"look:upgrades": "node scripts/look-upgrades.ts",
"look:ui": "node scripts/look-ui.ts",
"test": "node --test \"test/*.test.ts\"",
+ "lint": "oxlint --ignore-pattern 'tools/lint/fixtures/**' src test scripts tools",
"release": "pnpm --dir deploy release"
},
"dependencies": {
@@ -40,6 +41,7 @@
"devDependencies": {
"@types/node": "25.5.0",
"@types/three": "^0.186.0",
+ "oxlint": "1.87.0",
"playwright": "^1.64.0",
"typescript": "7.0.2",
"vite": "8.3.1"
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 4954eb7..c49b7ac 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -39,6 +39,9 @@ importers:
'@types/three':
specifier: ^0.186.0
version: 0.186.0
+ oxlint:
+ specifier: 1.87.0
+ version: 1.87.0
playwright:
specifier: ^1.64.0
version: 1.64.0
@@ -57,6 +60,120 @@ packages:
'@oxc-project/[email protected]':
resolution: {integrity: sha512-jSNrRIyvPVLL5E1z/tS5zLAprosGz/FuI1PWwEOz59j3E4TTTzSpqKb/RDGqJhhW0QHYISGXxq582wGx6T11Tw==}
+ '@oxlint/[email protected]':
+ resolution: {integrity: sha512-22tVIHlB9898OYsBKmYB6He1MCSqdTmK1BVWuSNUTVrpS0KWNege+U9uEYqGJ+KatQag0r/oU44i3OOs46z7HQ==}
+ engines: {node: ^20.19.0 || >=22.12.0}
+ cpu: [arm]
+ os: [android]
+
+ '@oxlint/[email protected]':
+ resolution: {integrity: sha512-JfZQ3MWf74n8ov0DojZpkOduIubYJvZL5tbTMMhDutsal6u1xH1QuNpN+lK+EQwF8AeAfgwTR2fgh5U2br27XA==}
+ engines: {node: ^20.19.0 || >=22.12.0}
+ cpu: [arm64]
+ os: [android]
+
+ '@oxlint/[email protected]':
+ resolution: {integrity: sha512-rkx6Xvvw93z2GImVOyvbZwAZcoY0Z6MJW177XNsSB+i/CBsH7ANyelTp01VZyIkM3iSXtqKVb4+ptBgPHap5pQ==}
+ engines: {node: ^20.19.0 || >=22.12.0}
+ cpu: [arm64]
+ os: [darwin]
+
+ '@oxlint/[email protected]':
+ resolution: {integrity: sha512-cw5nYw7L/pQ2SgGBgOcg/Qo89llQre3vIc/kuBLhSICzu1r5s8L76H3ug6AIFsD98WpROj8/z5JVzkf4daxHaQ==}
+ engines: {node: ^20.19.0 || >=22.12.0}
+ cpu: [x64]
+ os: [darwin]
+
+ '@oxlint/[email protected]':
+ resolution: {integrity: sha512-x/SuznE6loRZK9gz9AS4ZmzNzSu+5KdeoCS+sVHhnrE8HM6AD8UyTjwldQTTqlXGvkwHASgB0NiTNOc3o3PdAg==}
+ engines: {node: ^20.19.0 || >=22.12.0}
+ cpu: [x64]
+ os: [freebsd]
+
+ '@oxlint/[email protected]':
+ resolution: {integrity: sha512-+JEDmCAXiiFmKhAjZhgAOwaHWY6WENOQ5QA+lFuY59tgsUCDOTRi46B+lENK6CWvtxsXpwkZXNOgpjAQcpIpnA==}
+ engines: {node: ^20.19.0 || >=22.12.0}
+ cpu: [arm]
+ os: [linux]
+
+ '@oxlint/[email protected]':
+ resolution: {integrity: sha512-/uC9XqXLAC9AHFLNycwmSQEvKqGrOCgU+uXALI7gNW0DG81TJ/3T2eHnKdRvcb5R1gFEfjxDwI4e4zIa29rICQ==}
+ engines: {node: ^20.19.0 || >=22.12.0}
+ cpu: [arm]
+ os: [linux]
+
+ '@oxlint/[email protected]':
+ resolution: {integrity: sha512-FTRYPsBy/M728vnUv7l+KAwSAa3Qi4BQbhVvy7NYuMTZ0sUa/OWsbMx79HVFw6u/5KWcaYayDsoOiv7xbevzDg==}
+ engines: {node: ^20.19.0 || >=22.12.0}
+ cpu: [arm64]
+ os: [linux]
+
+ '@oxlint/[email protected]':
+ resolution: {integrity: sha512-6sC+N7IY0h1egd8SrYUGNN7CUyKJZ4bIZakKa7V7hfinf4jfi8Kq4+klJvFp5DqXcwMn44I5MeBwmJluO1odFg==}
+ engines: {node: ^20.19.0 || >=22.12.0}
+ cpu: [arm64]
+ os: [linux]
+
+ '@oxlint/[email protected]':
+ resolution: {integrity: sha512-d5Mnn+ICbhoJPi37Ccjy+86T5qfH2+mSTrTMBXNPfB+wqSWOayBBLLIrCXdUy1YssluCVdGkl+DO9w5r5ODmUA==}
+ engines: {node: ^20.19.0 || >=22.12.0}
+ cpu: [ppc64]
+ os: [linux]
+
+ '@oxlint/[email protected]':
+ resolution: {integrity: sha512-sf5YWuUo1Dx9loqWCgF8P278MycfcD4JHjDC/LV5j11L3Lqa4PFiwCjD6B8kP4AjsgZZkLn3xbpJEtZBaccs4Q==}
+ engines: {node: ^20.19.0 || >=22.12.0}
+ cpu: [riscv64]
+ os: [linux]
+
+ '@oxlint/[email protected]':
+ resolution: {integrity: sha512-+aCraYbmK3uU3P0rFojjeaK9pGY6JvBDXh/0CM+gPyWKmNmXmnFe0qj4qj02U4ibFpbd9Pa9CmDvIdjJUd29rA==}
+ engines: {node: ^20.19.0 || >=22.12.0}
+ cpu: [riscv64]
+ os: [linux]
+
+ '@oxlint/[email protected]':
+ resolution: {integrity: sha512-7rzbZQIljo6VLWVPqUyLa2P/WV3VFsJB4M52R4NCUJn1A50yjtUsHxiMHFL9opEKGFIiTbZ3VQzmtcJOPUq4NQ==}
+ engines: {node: ^20.19.0 || >=22.12.0}
+ cpu: [s390x]
+ os: [linux]
+
+ '@oxlint/[email protected]':
+ resolution: {integrity: sha512-Dry46Fa+AXE/xt9J/YriujU1pU9mzfNWHGQwtOYibAFH8HLrKWCi93AhIGnuUMiwn2JbuBkRyz51f50Ly4r4ow==}
+ engines: {node: ^20.19.0 || >=22.12.0}
+ cpu: [x64]
+ os: [linux]
+
+ '@oxlint/[email protected]':
+ resolution: {integrity: sha512-f/HMZez74gJvnRpGz+b5sdGyWrEgRLmFTXg9sNoqjPWogGxYHUhXKTKyMiYsu9rUGR2ciYqL3fk+Ua4JhMJbRA==}
+ engines: {node: ^20.19.0 || >=22.12.0}
+ cpu: [x64]
+ os: [linux]
+
+ '@oxlint/[email protected]':
+ resolution: {integrity: sha512-lEC6ZfPZm/07JlB7FsOWX9o1RiHlXiBW594LSUGuXmekC8LZmvUPP9XzE2WZcNxJi5cHA/Fw56o02c3JxgMA5g==}
+ engines: {node: ^20.19.0 || >=22.12.0}
+ cpu: [arm64]
+ os: [openharmony]
+
+ '@oxlint/[email protected]':
+ resolution: {integrity: sha512-afBWKOD36dUiA9AenaiWpCg8xfyUVPYznyAAVXu413brK4RA5UI/Xoc4yfeGIT8G1a44MV+JR7hioryerBDzGQ==}
+ engines: {node: ^20.19.0 || >=22.12.0}
+ cpu: [arm64]
+ os: [win32]
+
+ '@oxlint/[email protected]':
+ resolution: {integrity: sha512-daptNsEOuru4/nJTxV4DBHNJ5GepzmaBVQf+jjgKQGi9NRlZKik+RFq4hUL7ewsF1pwjKM+SkYaMbF82UwFGnw==}
+ engines: {node: ^20.19.0 || >=22.12.0}
+ cpu: [ia32]
+ os: [win32]
+
+ '@oxlint/[email protected]':
+ resolution: {integrity: sha512-k+m/EShyXE29J/r1fjk0HlAzhN5JhIvj044oSJkXTEkCLrWZQgXb/3r4q5LTw/eaKW/4GuMXG2xmiJs3s5rPNw==}
+ engines: {node: ^20.19.0 || >=22.12.0}
+ cpu: [x64]
+ os: [win32]
+
resolution: {integrity: sha512-nezytU2pw587fQstUu1AsJZDVEynjskwOL+kibwcdxsMBFqPsFFNA7xl0ii/gXuDi6M0xj3mfRJj8pBSc2jCfA==}
@@ -440,6 +557,19 @@ packages:
engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1}
hasBin: true
+ resolution: {integrity: sha512-drxVlaW7Oqq7wSy1CN25znRu00aRq8n57Q2wniJRxCmtYVz07ufCm7EVDPQFZURrTgQIjzKrVEHAD/HcvJXObg==}
+ engines: {node: ^20.19.0 || >=22.12.0}
+ hasBin: true
+ peerDependencies:
+ oxlint-tsgolint: '>=7.0.2003'
+ vite-plus: '*'
+ peerDependenciesMeta:
+ oxlint-tsgolint:
+ optional: true
+ vite-plus:
+ optional: true
+
resolution: {integrity: sha512-Tf7FFIrguPKQwzD4pWnYkR2VOv3raoHeKED80Bm+BYHI3KxC8KsgsGC5+fSMzAGDA6UEk4bHvmi+RsjmL3khpg==}
@@ -544,6 +674,63 @@ snapshots:
'@oxc-project/[email protected]': {}
+ '@oxlint/[email protected]':
+ optional: true
+
+ '@oxlint/[email protected]':
+ optional: true
+
+ '@oxlint/[email protected]':
+ optional: true
+
+ '@oxlint/[email protected]':
+ optional: true
+
+ '@oxlint/[email protected]':
+ optional: true
+
+ '@oxlint/[email protected]':
+ optional: true
+
+ '@oxlint/[email protected]':
+ optional: true
+
+ '@oxlint/[email protected]':
+ optional: true
+
+ '@oxlint/[email protected]':
+ optional: true
+
+ '@oxlint/[email protected]':
+ optional: true
+
+ '@oxlint/[email protected]':
+ optional: true
+
+ '@oxlint/[email protected]':
+ optional: true
+
+ '@oxlint/[email protected]':
+ optional: true
+
+ '@oxlint/[email protected]':
+ optional: true
+
+ '@oxlint/[email protected]':
+ optional: true
+
+ '@oxlint/[email protected]':
+ optional: true
+
+ '@oxlint/[email protected]':
+ optional: true
+
+ '@oxlint/[email protected]':
+ optional: true
+
+ '@oxlint/[email protected]':
+ optional: true
+
'@pixi/[email protected]': {}
'@rolldown/[email protected]':
@@ -784,6 +971,28 @@ snapshots:
+ optionalDependencies:
+ '@oxlint/binding-android-arm-eabi': 1.87.0
+ '@oxlint/binding-android-arm64': 1.87.0
+ '@oxlint/binding-darwin-arm64': 1.87.0
+ '@oxlint/binding-darwin-x64': 1.87.0
+ '@oxlint/binding-freebsd-x64': 1.87.0
+ '@oxlint/binding-linux-arm-gnueabihf': 1.87.0
+ '@oxlint/binding-linux-arm-musleabihf': 1.87.0
+ '@oxlint/binding-linux-arm64-gnu': 1.87.0
+ '@oxlint/binding-linux-arm64-musl': 1.87.0
+ '@oxlint/binding-linux-ppc64-gnu': 1.87.0
+ '@oxlint/binding-linux-riscv64-gnu': 1.87.0
+ '@oxlint/binding-linux-riscv64-musl': 1.87.0
+ '@oxlint/binding-linux-s390x-gnu': 1.87.0
+ '@oxlint/binding-linux-x64-gnu': 1.87.0
+ '@oxlint/binding-linux-x64-musl': 1.87.0
+ '@oxlint/binding-openharmony-arm64': 1.87.0
+ '@oxlint/binding-win32-arm64-msvc': 1.87.0
+ '@oxlint/binding-win32-ia32-msvc': 1.87.0
+ '@oxlint/binding-win32-x64-msvc': 1.87.0
+
diff --git a/scripts/balance.ts b/scripts/balance.ts
index db33551..f7f5503 100644
--- a/scripts/balance.ts
+++ b/scripts/balance.ts
@@ -96,9 +96,14 @@ for (let i = 0; i < args.length; i++) {
if (args[i] !== "--set") continue
const [path, value] = args[i + 1]!.split("=")
const parts = path!.split(".")
- let target = content as unknown as Record<string, unknown>
- for (const part of parts.slice(0, -1)) target = target[part] as Record<string, unknown>
- target[parts.at(-1)!] = value === "" || Number.isNaN(Number(value)) ? value : Number(value)
+ // Content is patched by path, so it is walked reflectively here, and only here.
+ let target: object = content
+ for (const part of parts.slice(0, -1)) {
+ const next: unknown = Reflect.get(target, part)
+ if (typeof next !== "object" || next === null) throw new Error(`Unknown content path: ${path}`)
+ target = next
+ }
+ Reflect.set(target, parts.at(-1)!, value === "" || Number.isNaN(Number(value)) ? value : Number(value))
}
const rules = resolveRules()
diff --git a/src/asset-lab/primitives.ts b/src/asset-lab/primitives.ts
index 242b29a..24a7717 100644
--- a/src/asset-lab/primitives.ts
+++ b/src/asset-lab/primitives.ts
@@ -299,9 +299,8 @@ export class Drawing {
: [point(j, i), point(j, i + 1), point(j + 1, i + 1), point(j + 1, i)]
let fill = color
if (light !== undefined) {
- const center = points
- .reduce((sum, p) => [sum[0] + p[0], sum[1] + p[1], sum[2] + p[2]] as Vertex, [0, 0, 0] as Vertex)
- .map((n) => n / points.length) as unknown as Vertex
+ const sum = points.reduce((total, p): Vertex => [total[0] + p[0], total[1] + p[1], total[2] + p[2]], [0, 0, 0])
+ const center: Vertex = [sum[0] / points.length, sum[1] / points.length, sum[2] / points.length]
const sx = (center[0] - u - center[1] + v) * 32,
sy = (center[0] - u + center[1] - v) * 16 - (center[2] - z),
rx = Math.hypot(ru, rv) * 32,
diff --git a/src/main.ts b/src/main.ts
index ea01bf4..2295c82 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -94,7 +94,7 @@ const start = async () => {
const world: World["Service"] = {
snapshot: () => runtime.snapshot(),
restore: (data) => {
- const restored = runtime.restore(data as never)
+ const restored = runtime.restore(data)
if (restored.ok) resetPresentation()
return restored.ok ? null : restored.error._tag
},
diff --git a/src/rules/config.ts b/src/rules/config.ts
index 3457732..bf53c12 100644
--- a/src/rules/config.ts
+++ b/src/rules/config.ts
@@ -34,18 +34,20 @@ const freeze = <T>(value: T): T => {
/** Fresh copies also preserve the existing bot's --set-before-start workflow. */
export const resolveRules = (patches: ReadonlyArray<RulePatch> = []): Rules => {
- const copy = structuredClone(inputs()) as unknown as Record<string, unknown>
+ const rules: Rules = structuredClone(inputs())
for (const { path, value } of patches) {
if (!Number.isFinite(value) || value < 0) throw new Error(`Invalid numeric rule: ${path}`)
const parts = path.split(".")
if (parts.some((p) => ["__proto__", "prototype", "constructor"].includes(p))) throw new Error(`Invalid rule path: ${path}`)
- let target = copy
+ // Rules are walked by path, so they are read and written reflectively here, and only here.
+ let target: object = rules
for (const part of parts.slice(0, -1)) {
- if (!Object.hasOwn(target, part) || typeof target[part] !== "object" || target[part] === null) throw new Error(`Unknown rule: ${path}`)
- target = target[part] as Record<string, unknown>
+ const next: unknown = Reflect.get(target, part)
+ if (!Object.hasOwn(target, part) || typeof next !== "object" || next === null) throw new Error(`Unknown rule: ${path}`)
+ target = next
}
const key = parts.at(-1)!
- if (!Object.hasOwn(target, key) || typeof target[key] !== "number") throw new Error(`Unknown numeric rule: ${path}`)
+ if (!Object.hasOwn(target, key) || typeof Reflect.get(target, key) !== "number") throw new Error(`Unknown numeric rule: ${path}`)
// Structural timing and identifier changes are outside numeric economy experiments.
if (parts[0] === "transport" || ["size", "stories", "bays"].includes(key)) throw new Error(`Structural rule cannot be patched: ${path}`)
if (["stepSeconds", "ledgerTicks", "spoilTicks", "yearsPerTerm", "staffTicks", "riskTicks", "spreadTicks", "growTicks"].includes(parts[0]!)) throw new Error(`Structural rule cannot be patched: ${path}`)
@@ -53,9 +55,9 @@ export const resolveRules = (patches: ReadonlyArray<RulePatch> = []): Rules => {
if ((path.startsWith("home.lasts.") || path.startsWith("spoils.")) && value === 0) throw new Error(`Rule must be positive: ${path}`)
if ((["workers", "batch", "inputs", "cap", "carriers", "range", "residents", "settle", "perMeal"].includes(key) || path.includes(".cost.")) && !Number.isInteger(value)) throw new Error(`Rule must be an integer: ${path}`)
if (path === "apprentice" && value > 1) throw new Error("Apprentice pace must be at most one")
- target[key] = value
+ Reflect.set(target, key, value)
}
- return freeze(copy as unknown as Rules)
+ return freeze(rules)
}
export const shippedRules = resolveRules()
diff --git a/src/sim/hazards.ts b/src/sim/hazards.ts
index ee68360..63bff45 100644
--- a/src/sim/hazards.ts
+++ b/src/sim/hazards.ts
@@ -275,7 +275,7 @@ export const Hazards = Game.System(
const crewed = new Set<number>()
for (const { data } of queries.crews.each()) {
out.set(data.home.get(), (out.get(data.home.get()) ?? 0) + 1)
- if (!data.rescue.get().back) crewed.add(data.rescue.get().target as unknown as number)
+ if (!data.rescue.get().back) crewed.add(data.rescue.get().target)
}
const watches = queries.watches.each().filter(({ data }) => data.service.get().service === "fire" && data.staff.get().assigned > 0)
const burningNow = [...queries.blazes.each().map(({ entity }) => entity.id as number), ...ignited.keys()].filter((id) => !lost.has(id))
diff --git a/src/sim/headless.ts b/src/sim/headless.ts
index c3d2d98..86c6fb1 100644
--- a/src/sim/headless.ts
+++ b/src/sim/headless.ts
@@ -50,8 +50,8 @@ export const headless = (charter: CharterValue, options: { readonly toast?: (mes
/** The world as plain data (a copy: changing it changes nothing until it is restored). */
snapshot: (): Snapshot => JSON.parse(JSON.stringify(runtime.snapshot())),
/** Loads a world, validating everything in it. */
- restore: (snapshot: Snapshot) => {
- const restored = runtime.restore(snapshot as never)
+ restore: (snapshot: unknown) => {
+ const restored = runtime.restore(snapshot)
if (!restored.ok) throw new Error(`The town could not be loaded: ${JSON.stringify(restored.error)}`)
},
/** Changes the world through a snapshot, as a load would. */
diff --git a/test/lint.test.ts b/test/lint.test.ts
new file mode 100644
index 0000000..a61d5cf
--- /dev/null
+++ b/test/lint.test.ts
@@ -0,0 +1,24 @@
+/**
+ * The project lint rules (`tools/lint/plugin.mjs`) on a fixture of known
+ * violations: each is reported, and ordinary casts are let through.
+ */
+import assert from "node:assert/strict"
+import { execFileSync } from "node:child_process"
+import { test } from "node:test"
+
+const lintFixtures = (): Array<string> => {
+ let output = ""
+ try {
+ output = execFileSync("npx", ["oxlint", "--format", "unix", "tools/lint/fixtures"], { encoding: "utf8" })
+ } catch (error) {
+ output = error instanceof Error && "stdout" in error && typeof error.stdout === "string" ? error.stdout : ""
+ }
+ return output.split("\n").flatMap((line) => {
+ const match = /fixtures\/([^:]+):(\d+):\d+: .*town\(([a-z-]+)\)/.exec(line)
+ return match === null ? [] : [`${match[1]}:${match[2]} ${match[3]}`]
+ })
+}
+
+test("no-cast-escape reports as never and as unknown as, and nothing else", () => {
+ assert.deepEqual(lintFixtures(), ["casts.ts:3 no-cast-escape", "casts.ts:4 no-cast-escape"])
+})
diff --git a/test/save.test.ts b/test/save.test.ts
index fb254e6..7268092 100644
--- a/test/save.test.ts
+++ b/test/save.test.ts
@@ -15,7 +15,7 @@ const worldOf = (town: Headless): World["Service"] => ({
snapshot: () => town.snapshot(),
restore: (data) => {
try {
- town.restore(data as never)
+ town.restore(data)
return null
} catch (cause) {
return cause instanceof Error ? cause.message : String(cause)
diff --git a/test/share.test.ts b/test/share.test.ts
index faeaa25..8dddd4c 100644
--- a/test/share.test.ts
+++ b/test/share.test.ts
@@ -140,7 +140,7 @@ const worldOf = (town: Headless): World["Service"] => ({
snapshot: () => town.snapshot(),
restore: (data) => {
try {
- town.restore(data as never)
+ town.restore(data)
return null
} catch (cause) {
return cause instanceof Error ? cause.message : String(cause)
diff --git a/tools/lint/fixtures/casts.ts b/tools/lint/fixtures/casts.ts
new file mode 100644
index 0000000..02b3e7a
--- /dev/null
+++ b/tools/lint/fixtures/casts.ts
@@ -0,0 +1,6 @@
+// Two casts that switch type checking off (reported) and two ordinary ones (allowed).
+const anything: unknown = 1
+export const silenced = anything as never
+export const forced = anything as unknown as string
+export const narrowed = [1, 2] as const
+export const widened = 1 as number
diff --git a/tools/lint/plugin.mjs b/tools/lint/plugin.mjs
new file mode 100644
index 0000000..8663498
--- /dev/null
+++ b/tools/lint/plugin.mjs
@@ -0,0 +1,28 @@
+/**
+ * Project lint rules (an oxlint JS plugin, see `.oxlintrc.json`).
+ *
+ * - `town/no-cast-escape`: no `as never` and no `as unknown as`, anywhere.
+ * Both switch the type checker off for a value. Build the value with its
+ * real type instead; if a library API cannot express it, fix the library.
+ */
+const noCastEscape = {
+ meta: { type: "problem", docs: { description: "No `as never` and no `as unknown as`." } },
+ create(context) {
+ return {
+ TSAsExpression(node) {
+ if (node.typeAnnotation.type === "TSNeverKeyword") {
+ context.report({ node, message: "`as never` switches type checking off for this value: give it its real type (if a library API cannot take it, fix the library)." })
+ } else if (node.expression.type === "TSAsExpression" && node.expression.typeAnnotation.type === "TSUnknownKeyword") {
+ context.report({ node, message: "`as unknown as` switches type checking off for this value: build it with its real type (if a library API cannot express it, fix the library)." })
+ }
+ }
+ }
+ }
+}
+
+export default {
+ meta: { name: "town" },
+ rules: {
+ "no-cast-escape": noCastEscape
+ }
+}