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