chore: Enable more lint rules, disable some that trigger a lot. Will clean up later.

This commit is contained in:
cpojer
2026-01-31 16:03:28 +09:00
parent 481f696a87
commit 15792b153f
292 changed files with 643 additions and 699 deletions

View File

@@ -66,7 +66,7 @@ export function hasAnyWhatsAppAuth(cfg: OpenClawConfig): boolean {
export function listWhatsAppAccountIds(cfg: OpenClawConfig): string[] {
const ids = listConfiguredAccountIds(cfg);
if (ids.length === 0) return [DEFAULT_ACCOUNT_ID];
return ids.sort((a, b) => a.localeCompare(b));
return ids.toSorted((a, b) => a.localeCompare(b));
}
export function resolveDefaultWhatsAppAccountId(cfg: OpenClawConfig): string {

View File

@@ -24,7 +24,7 @@ export function createEchoTracker(params: {
const trim = () => {
while (recentlySent.size > maxItems) {
const firstKey = recentlySent.values().next().value as string | undefined;
const firstKey = recentlySent.values().next().value;
if (!firstKey) break;
recentlySent.delete(firstKey);
}

View File

@@ -51,6 +51,6 @@ export function resolveGroupActivationFor(params: {
const store = loadSessionStore(storePath);
const entry = store[params.sessionKey];
const requireMention = resolveGroupRequireMentionFor(params.cfg, params.conversationId);
const defaultActivation = requireMention === false ? "always" : "mention";
const defaultActivation = !requireMention ? "always" : "mention";
return normalizeGroupActivation(entry?.groupActivation) ?? defaultActivation;
}

View File

@@ -10,8 +10,8 @@ import { jidToE164 } from "../../utils.js";
import { parseVcard } from "../vcard.js";
function unwrapMessage(message: proto.IMessage | undefined): proto.IMessage | undefined {
const normalized = normalizeMessageContent(message as proto.IMessage | undefined);
return normalized as proto.IMessage | undefined;
const normalized = normalizeMessageContent(message);
return normalized;
}
function extractContextInfo(message: proto.IMessage | undefined): proto.IContextInfo | undefined {
@@ -244,9 +244,7 @@ export function describeReplyContext(rawMessage: proto.IMessage | undefined): {
const message = unwrapMessage(rawMessage);
if (!message) return null;
const contextInfo = extractContextInfo(message);
const quoted = normalizeMessageContent(
contextInfo?.quotedMessage as proto.IMessage | undefined,
) as proto.IMessage | undefined;
const quoted = normalizeMessageContent(contextInfo?.quotedMessage as proto.IMessage | undefined);
if (!quoted) return null;
const location = extractLocationData(quoted);
const locationText = location ? formatLocationText(location) : undefined;

View File

@@ -4,8 +4,8 @@ import { logVerbose } from "../../globals.js";
import type { createWaSocket } from "../session.js";
function unwrapMessage(message: proto.IMessage | undefined): proto.IMessage | undefined {
const normalized = normalizeMessageContent(message as proto.IMessage | undefined);
return normalized as proto.IMessage | undefined;
const normalized = normalizeMessageContent(message);
return normalized;
}
export async function downloadInboundMedia(
@@ -31,7 +31,7 @@ export async function downloadInboundMedia(
return undefined;
}
try {
const buffer = (await downloadMediaMessage(
const buffer = await downloadMediaMessage(
msg as WAMessage,
"buffer",
{},
@@ -39,7 +39,7 @@ export async function downloadInboundMedia(
reuploadRequest: sock.updateMediaMessage,
logger: sock.logger,
},
)) as Buffer;
);
return { buffer, mimetype };
} catch (err) {
logVerbose(`downloadMediaMessage failed: ${String(err)}`);

View File

@@ -60,11 +60,11 @@ export async function loginWeb(
`WhatsApp reported the session is logged out. Cleared cached web session; please rerun ${formatCliCommand("openclaw channels login")} and scan the QR again.`,
),
);
throw new Error("Session logged out; cache cleared. Re-run login.");
throw new Error("Session logged out; cache cleared. Re-run login.", { cause: err });
}
const formatted = formatError(err);
console.error(danger(`WhatsApp Web connection ended before fully opening. ${formatted}`));
throw new Error(formatted);
throw new Error(formatted, { cause: err });
} finally {
// Let Baileys flush any final events before closing the socket.
setTimeout(() => {

View File

@@ -250,7 +250,7 @@ export async function optimizeImageToJpeg(
try {
source = await convertHeicToJpeg(buffer);
} catch (err) {
throw new Error(`HEIC image conversion failed: ${String(err)}`);
throw new Error(`HEIC image conversion failed: ${String(err)}`, { cause: err });
}
}
const sides = [2048, 1536, 1280, 1024, 800];

View File

@@ -12,8 +12,8 @@ type QRCodeConstructor = new (
isDark: (row: number, col: number) => boolean;
};
const QRCode = QRCodeModule as unknown as QRCodeConstructor;
const QRErrorCorrectLevel = QRErrorCorrectLevelModule as Record<string, unknown>;
const QRCode = QRCodeModule as QRCodeConstructor;
const QRErrorCorrectLevel = QRErrorCorrectLevelModule;
function createQrMatrix(input: string) {
const qr = new QRCode(-1, QRErrorCorrectLevel.L);

View File

@@ -193,7 +193,7 @@ export function getStatusCode(err: unknown) {
function safeStringify(value: unknown, limit = 800): string {
try {
const seen = new WeakSet<object>();
const seen = new WeakSet();
const raw = JSON.stringify(
value,
(_key, v) => {
@@ -236,7 +236,7 @@ function extractBoomDetails(err: unknown): {
typeof (output as { statusCode?: unknown }).statusCode === "number"
? ((output as { statusCode?: unknown }).statusCode as number)
: typeof payload?.statusCode === "number"
? (payload.statusCode as number)
? payload.statusCode
: undefined;
const error = typeof payload?.error === "string" ? payload.error : undefined;
const message = typeof payload?.message === "string" ? payload.message : undefined;