Revert "fix(ci): clean core unsafe assertions" · openclaw/openclaw@4471335
steipete
·
2026-05-31
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -8,10 +8,8 @@ const packageRootCache = new Map<string, string | null>();
|
8 | 8 | const argv1CandidateCache = new Map<string, string[]>(); |
9 | 9 | |
10 | 10 | function parsePackageName(raw: string): string | null { |
11 | | -const parsed: unknown = JSON.parse(raw); |
12 | | -return parsed && typeof parsed === "object" && "name" in parsed && typeof parsed.name === "string" |
13 | | - ? parsed.name |
14 | | - : null; |
| 11 | +const parsed = JSON.parse(raw) as { name?: unknown }; |
| 12 | +return typeof parsed.name === "string" ? parsed.name : null; |
15 | 13 | } |
16 | 14 | |
17 | 15 | async function readPackageName(dir: string): Promise<string | null> { |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -7,13 +7,8 @@ export const OPENCLAW_DEV_SOURCE_ROOT_ENV = "OPENCLAW_DEV_SOURCE_ROOT";
|
7 | 7 | |
8 | 8 | function readPackageName(packageJsonPath: string): string | null { |
9 | 9 | try { |
10 | | -const parsed: unknown = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8")); |
11 | | -return parsed && |
12 | | -typeof parsed === "object" && |
13 | | -"name" in parsed && |
14 | | -typeof parsed.name === "string" |
15 | | - ? parsed.name |
16 | | - : null; |
| 10 | +const parsed = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8")) as { name?: unknown }; |
| 11 | +return typeof parsed.name === "string" ? parsed.name : null; |
17 | 12 | } catch { |
18 | 13 | return null; |
19 | 14 | } |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -41,7 +41,6 @@ export class PluginLruCache<T> {
|
41 | 41 | if (!this.#entries.has(cacheKey)) { |
42 | 42 | return { hit: false }; |
43 | 43 | } |
44 | | -// oxlint-disable-next-line typescript/no-unsafe-type-assertion -- Map.has proves the value exists while preserving caller-specific cache value type. |
45 | 44 | const cached = this.#entries.get(cacheKey) as T; |
46 | 45 | this.#entries.delete(cacheKey); |
47 | 46 | this.#entries.set(cacheKey, cached); |
@@ -89,7 +88,6 @@ export function resolveConfigScopedRuntimeCacheValue<T>(params: {
|
89 | 88 | params.cache.set(params.config, configCache); |
90 | 89 | } |
91 | 90 | if (configCache.has(params.key)) { |
92 | | -// oxlint-disable-next-line typescript/no-unsafe-type-assertion -- Map.has proves the value exists while preserving caller-specific cache value type. |
93 | 91 | return configCache.get(params.key) as T; |
94 | 92 | } |
95 | 93 | const loaded = params.load(); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -61,13 +61,6 @@ const pluginModuleLoaderStats = {
|
61 | 61 | sourceTransformTargets: new Map<string, number>(), |
62 | 62 | }; |
63 | 63 | |
64 | | -function isJitiLoaderModule(value: unknown): value is { createJiti: PluginModuleLoaderFactory } { |
65 | | -const canHaveProperties = (value && typeof value === "object") || typeof value === "function"; |
66 | | -return Boolean( |
67 | | -canHaveProperties && "createJiti" in value && typeof value.createJiti === "function", |
68 | | -); |
69 | | -} |
70 | | - |
71 | 64 | function recordSourceTransformTarget(target: string): void { |
72 | 65 | const current = pluginModuleLoaderStats.sourceTransformTargets.get(target) ?? 0; |
73 | 66 | pluginModuleLoaderStats.sourceTransformTargets.set(target, current + 1); |
@@ -114,8 +107,8 @@ function loadCreateJitiLoaderFactory(): PluginModuleLoaderFactory {
|
114 | 107 | if (createJitiLoaderFactory) { |
115 | 108 | return createJitiLoaderFactory; |
116 | 109 | } |
117 | | -const loaded: unknown = requireForJiti("jiti"); |
118 | | -if (!isJitiLoaderModule(loaded)) { |
| 110 | +const loaded = requireForJiti("jiti") as { createJiti?: PluginModuleLoaderFactory }; |
| 111 | +if (typeof loaded.createJiti !== "function") { |
119 | 112 | throw new Error("jiti module did not export createJiti"); |
120 | 113 | } |
121 | 114 | createJitiLoaderFactory = loaded.createJiti; |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -32,17 +32,13 @@ export type ResolvedTranscriptsConfig = {
|
32 | 32 | autoStart: ResolvedTranscriptsAutoStartConfig[]; |
33 | 33 | }; |
34 | 34 | |
35 | | -function isRecord(value: unknown): value is Record<string, unknown> { |
36 | | -return Boolean(value && typeof value === "object" && !Array.isArray(value)); |
37 | | -} |
38 | | - |
39 | 35 | function resolveAutoStart(raw: unknown): ResolvedTranscriptsAutoStartConfig[] { |
40 | 36 | if (!Array.isArray(raw)) { |
41 | 37 | return []; |
42 | 38 | } |
43 | 39 | return raw |
44 | 40 | .map((entry): ResolvedTranscriptsAutoStartConfig | undefined => { |
45 | | -const config = isRecord(entry) ? entry : {}; |
| 41 | +const config = entry && typeof entry === "object" ? (entry as Record<string, unknown>) : {}; |
46 | 42 | const providerId = readString(config.providerId); |
47 | 43 | if (!providerId) { |
48 | 44 | return undefined; |
@@ -61,7 +57,7 @@ function resolveAutoStart(raw: unknown): ResolvedTranscriptsAutoStartConfig[] {
|
61 | 57 | } |
62 | 58 | |
63 | 59 | export function resolveTranscriptsConfig(raw: unknown): ResolvedTranscriptsConfig { |
64 | | -const config = isRecord(raw) ? raw : {}; |
| 60 | +const config = raw && typeof raw === "object" ? (raw as Record<string, unknown>) : {}; |
65 | 61 | const maxUtterances = |
66 | 62 | typeof config.maxUtterances === "number" && Number.isFinite(config.maxUtterances) |
67 | 63 | ? Math.max(1, Math.min(10_000, Math.floor(config.maxUtterances))) |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -32,7 +32,6 @@ export const clamp = clampNumber;
|
32 | 32 | // oxlint-disable-next-line typescript/no-unnecessary-type-parameters -- JSON parsing helper lets callers ascribe the expected payload type. |
33 | 33 | export function safeParseJson<T>(raw: string): T | null { |
34 | 34 | try { |
35 | | -// oxlint-disable-next-line typescript/no-unsafe-type-assertion -- JSON parsing helper lets callers ascribe the expected payload type. |
36 | 35 | return JSON.parse(raw) as T; |
37 | 36 | } catch { |
38 | 37 | return null; |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -10,6 +10,8 @@ export type ResolvedReactionLevel = {
|
10 | 10 | agentReactionGuidance?: "minimal" | "extensive"; |
11 | 11 | }; |
12 | 12 | |
| 13 | +const LEVELS = new Set<ReactionLevel>(["off", "ack", "minimal", "extensive"]); |
| 14 | + |
13 | 15 | function parseLevel( |
14 | 16 | value: unknown, |
15 | 17 | ): { kind: "missing" } | { kind: "invalid" } | { kind: "ok"; value: ReactionLevel } { |
@@ -23,12 +25,8 @@ function parseLevel(
|
23 | 25 | if (!trimmed) { |
24 | 26 | return { kind: "missing" }; |
25 | 27 | } |
26 | | -switch (trimmed) { |
27 | | -case "off": |
28 | | -case "ack": |
29 | | -case "minimal": |
30 | | -case "extensive": |
31 | | -return { kind: "ok", value: trimmed }; |
| 28 | +if (LEVELS.has(trimmed as ReactionLevel)) { |
| 29 | +return { kind: "ok", value: trimmed as ReactionLevel }; |
32 | 30 | } |
33 | 31 | return { kind: "invalid" }; |
34 | 32 | } |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。