mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 15:28:27 +00:00
chore: Enable more lint rules, disable some that trigger a lot. Will clean up later.
This commit is contained in:
@@ -19,7 +19,7 @@ export async function sleepWithAbort(ms: number, abortSignal?: AbortSignal) {
|
||||
await delay(ms, undefined, { signal: abortSignal });
|
||||
} catch (err) {
|
||||
if (abortSignal?.aborted) {
|
||||
throw new Error("aborted");
|
||||
throw new Error("aborted", { cause: err });
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
|
||||
@@ -174,7 +174,7 @@ export async function buildChannelSummary(
|
||||
})
|
||||
: undefined;
|
||||
|
||||
const summaryRecord = summary as Record<string, unknown> | undefined;
|
||||
const summaryRecord = summary;
|
||||
const linked =
|
||||
summaryRecord && typeof summaryRecord.linked === "boolean" ? summaryRecord.linked : null;
|
||||
const configured =
|
||||
|
||||
@@ -33,7 +33,7 @@ export function createDedupeCache(options: DedupeCacheOptions): DedupeCache {
|
||||
return;
|
||||
}
|
||||
while (cache.size > maxSize) {
|
||||
const oldestKey = cache.keys().next().value as string | undefined;
|
||||
const oldestKey = cache.keys().next().value;
|
||||
if (!oldestKey) break;
|
||||
cache.delete(oldestKey);
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ function normalizeScopes(scopes: string[] | undefined): string[] {
|
||||
const trimmed = scope.trim();
|
||||
if (trimmed) out.add(trimmed);
|
||||
}
|
||||
return [...out].sort();
|
||||
return [...out].toSorted();
|
||||
}
|
||||
|
||||
function readStore(filePath: string): DeviceAuthStore | null {
|
||||
|
||||
@@ -199,7 +199,7 @@ function normalizeScopes(scopes: string[] | undefined): string[] {
|
||||
const trimmed = scope.trim();
|
||||
if (trimmed) out.add(trimmed);
|
||||
}
|
||||
return [...out].sort();
|
||||
return [...out].toSorted();
|
||||
}
|
||||
|
||||
function scopesAllow(requested: string[], allowed: string[]): boolean {
|
||||
@@ -215,8 +215,8 @@ function newToken() {
|
||||
|
||||
export async function listDevicePairing(baseDir?: string): Promise<DevicePairingList> {
|
||||
const state = await loadState(baseDir);
|
||||
const pending = Object.values(state.pendingById).sort((a, b) => b.ts - a.ts);
|
||||
const paired = Object.values(state.pairedByDeviceId).sort(
|
||||
const pending = Object.values(state.pendingById).toSorted((a, b) => b.ts - a.ts);
|
||||
const paired = Object.values(state.pairedByDeviceId).toSorted(
|
||||
(a, b) => b.approvedAtMs - a.approvedAtMs,
|
||||
);
|
||||
return { pending, paired };
|
||||
@@ -373,7 +373,7 @@ export function summarizeDeviceTokens(
|
||||
revokedAtMs: token.revokedAtMs,
|
||||
lastUsedAtMs: token.lastUsedAtMs,
|
||||
}))
|
||||
.sort((a, b) => a.role.localeCompare(b.role));
|
||||
.toSorted((a, b) => a.role.localeCompare(b.role));
|
||||
return summaries.length > 0 ? summaries : undefined;
|
||||
}
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ export async function openFileWithinRoot(params: {
|
||||
}
|
||||
|
||||
const supportsNoFollow = process.platform !== "win32" && "O_NOFOLLOW" in fsConstants;
|
||||
const flags = fsConstants.O_RDONLY | (supportsNoFollow ? (fsConstants.O_NOFOLLOW as number) : 0);
|
||||
const flags = fsConstants.O_RDONLY | (supportsNoFollow ? fsConstants.O_NOFOLLOW : 0);
|
||||
|
||||
let handle: FileHandle;
|
||||
try {
|
||||
|
||||
@@ -16,7 +16,7 @@ describe("ssrf pinning", () => {
|
||||
const first = await new Promise<{ address: string; family?: number }>((resolve, reject) => {
|
||||
pinned.lookup("example.com", (err, address, family) => {
|
||||
if (err) reject(err);
|
||||
else resolve({ address: address as string, family });
|
||||
else resolve({ address: address, family });
|
||||
});
|
||||
});
|
||||
expect(first.address).toBe("93.184.216.34");
|
||||
@@ -53,7 +53,7 @@ describe("ssrf pinning", () => {
|
||||
const result = await new Promise<{ address: string }>((resolve, reject) => {
|
||||
lookup("other.test", (err, address) => {
|
||||
if (err) reject(err);
|
||||
else resolve({ address: address as string });
|
||||
else resolve({ address: address });
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -149,8 +149,8 @@ function newToken() {
|
||||
|
||||
export async function listNodePairing(baseDir?: string): Promise<NodePairingList> {
|
||||
const state = await loadState(baseDir);
|
||||
const pending = Object.values(state.pendingById).sort((a, b) => b.ts - a.ts);
|
||||
const paired = Object.values(state.pairedByNodeId).sort(
|
||||
const pending = Object.values(state.pendingById).toSorted((a, b) => b.ts - a.ts);
|
||||
const paired = Object.values(state.pairedByNodeId).toSorted(
|
||||
(a, b) => b.approvedAtMs - a.approvedAtMs,
|
||||
);
|
||||
return { pending, paired };
|
||||
|
||||
@@ -46,7 +46,7 @@ export async function listConfiguredMessageChannels(
|
||||
for (const plugin of listChannelPlugins()) {
|
||||
if (!isKnownChannel(plugin.id)) continue;
|
||||
if (await isPluginConfigured(plugin, cfg)) {
|
||||
channels.push(plugin.id as MessageChannelId);
|
||||
channels.push(plugin.id);
|
||||
}
|
||||
}
|
||||
return channels;
|
||||
|
||||
@@ -591,7 +591,7 @@ async function handleBroadcastAction(
|
||||
}
|
||||
return {
|
||||
kind: "broadcast",
|
||||
channel: (targetChannels[0] ?? "discord") as ChannelId,
|
||||
channel: targetChannels[0] ?? "discord",
|
||||
action: "broadcast",
|
||||
handledBy: input.dryRun ? "dry-run" : "core",
|
||||
payload: { results },
|
||||
|
||||
@@ -116,7 +116,7 @@ export async function sendMessage(params: MessageSendParams): Promise<MessageSen
|
||||
if (!channel) {
|
||||
throw new Error(`Unknown channel: ${params.channel}`);
|
||||
}
|
||||
const plugin = getChannelPlugin(channel as ChannelId);
|
||||
const plugin = getChannelPlugin(channel);
|
||||
if (!plugin) {
|
||||
throw new Error(`Unknown channel: ${channel}`);
|
||||
}
|
||||
@@ -149,7 +149,7 @@ export async function sendMessage(params: MessageSendParams): Promise<MessageSen
|
||||
}
|
||||
|
||||
if (deliveryMode !== "gateway") {
|
||||
const outboundChannel = channel as Exclude<OutboundChannel, "none">;
|
||||
const outboundChannel = channel;
|
||||
const resolvedTarget = resolveOutboundTarget({
|
||||
channel: outboundChannel,
|
||||
to: params.to,
|
||||
@@ -235,7 +235,7 @@ export async function sendPoll(params: MessagePollParams): Promise<MessagePollRe
|
||||
maxSelections: params.maxSelections,
|
||||
durationHours: params.durationHours,
|
||||
};
|
||||
const plugin = getChannelPlugin(channel as ChannelId);
|
||||
const plugin = getChannelPlugin(channel);
|
||||
const outbound = plugin?.outbound;
|
||||
if (!outbound?.sendPoll) {
|
||||
throw new Error(`Unsupported poll channel: ${channel}`);
|
||||
|
||||
@@ -132,7 +132,7 @@ export function resolveOutboundTarget(params: {
|
||||
};
|
||||
}
|
||||
|
||||
const plugin = getChannelPlugin(params.channel as ChannelId);
|
||||
const plugin = getChannelPlugin(params.channel);
|
||||
if (!plugin) {
|
||||
return {
|
||||
ok: false,
|
||||
@@ -233,7 +233,7 @@ export function resolveHeartbeatDeliveryTarget(params: {
|
||||
}
|
||||
|
||||
let reason: string | undefined;
|
||||
const plugin = getChannelPlugin(resolvedTarget.channel as ChannelId);
|
||||
const plugin = getChannelPlugin(resolvedTarget.channel);
|
||||
if (plugin?.config.resolveAllowFrom) {
|
||||
const explicit = resolveOutboundTarget({
|
||||
channel: resolvedTarget.channel,
|
||||
|
||||
@@ -315,7 +315,7 @@ export async function fetchMinimaxUsage(
|
||||
};
|
||||
}
|
||||
|
||||
const baseResp = isRecord(data.base_resp) ? (data.base_resp as MinimaxBaseResp) : undefined;
|
||||
const baseResp = isRecord(data.base_resp) ? data.base_resp : undefined;
|
||||
if (baseResp && typeof baseResp.status_code === "number" && baseResp.status_code !== 0) {
|
||||
return {
|
||||
provider: "minimax",
|
||||
|
||||
@@ -219,7 +219,7 @@ export async function loadCostUsageSummary(params?: {
|
||||
|
||||
const daily = Array.from(dailyMap.entries())
|
||||
.map(([date, bucket]) => Object.assign({ date }, bucket))
|
||||
.sort((a, b) => a.date.localeCompare(b.date));
|
||||
.toSorted((a, b) => a.date.localeCompare(b.date));
|
||||
|
||||
return {
|
||||
updatedAt: Date.now(),
|
||||
|
||||
@@ -184,7 +184,7 @@ export async function startSshPortForward(opts: {
|
||||
} catch (err) {
|
||||
await stop();
|
||||
const suffix = stderr.length > 0 ? `\n${stderr.join("\n")}` : "";
|
||||
throw new Error(`${err instanceof Error ? err.message : String(err)}${suffix}`);
|
||||
throw new Error(`${err instanceof Error ? err.message : String(err)}${suffix}`, { cause: err });
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
@@ -411,7 +411,7 @@ export async function autoMigrateLegacyStateDir(params: {
|
||||
} catch (err) {
|
||||
try {
|
||||
if (process.platform === "win32") {
|
||||
if (!legacyDir) throw new Error("Legacy state dir not found");
|
||||
if (!legacyDir) throw new Error("Legacy state dir not found", { cause: err });
|
||||
fs.symlinkSync(targetDir, legacyDir, "junction");
|
||||
changes.push(formatStateDirMigration(legacyDir, targetDir));
|
||||
} else {
|
||||
@@ -419,7 +419,8 @@ export async function autoMigrateLegacyStateDir(params: {
|
||||
}
|
||||
} catch (fallbackErr) {
|
||||
try {
|
||||
if (!legacyDir) throw new Error("Legacy state dir not found");
|
||||
if (!legacyDir)
|
||||
throw new Error("Legacy state dir not found", { cause: err }, { cause: fallbackErr });
|
||||
fs.renameSync(targetDir, legacyDir);
|
||||
warnings.push(
|
||||
`State dir migration rolled back (failed to link legacy path): ${String(fallbackErr)}`,
|
||||
|
||||
@@ -270,12 +270,12 @@ export function listSystemPresence(): SystemPresence[] {
|
||||
}
|
||||
// enforce max size (LRU by ts)
|
||||
if (entries.size > MAX_ENTRIES) {
|
||||
const sorted = [...entries.entries()].sort((a, b) => a[1].ts - b[1].ts);
|
||||
const sorted = [...entries.entries()].toSorted((a, b) => a[1].ts - b[1].ts);
|
||||
const toDrop = entries.size - MAX_ENTRIES;
|
||||
for (let i = 0; i < toDrop; i++) {
|
||||
entries.delete(sorted[i][0]);
|
||||
}
|
||||
}
|
||||
touchSelfPresence();
|
||||
return [...entries.values()].sort((a, b) => b.ts - a.ts);
|
||||
return [...entries.values()].toSorted((a, b) => b.ts - a.ts);
|
||||
}
|
||||
|
||||
@@ -120,7 +120,7 @@ export async function getTailnetHostname(exec: typeof runExec = runExec, detecte
|
||||
typeof parsed.Self === "object" && parsed.Self !== null
|
||||
? (parsed.Self as Record<string, unknown>)
|
||||
: undefined;
|
||||
const dns = typeof self?.DNSName === "string" ? (self.DNSName as string) : undefined;
|
||||
const dns = typeof self?.DNSName === "string" ? self.DNSName : undefined;
|
||||
const ips = Array.isArray(self?.TailscaleIPs)
|
||||
? ((parsed.Self as { TailscaleIPs?: string[] }).TailscaleIPs ?? [])
|
||||
: [];
|
||||
|
||||
Reference in New Issue
Block a user