chore: Enable "curly" rule to avoid single-statement if confusion/errors.

This commit is contained in:
cpojer
2026-01-31 16:19:20 +09:00
parent 009b16fab8
commit 5ceff756e1
1266 changed files with 27871 additions and 9393 deletions

View File

@@ -37,21 +37,33 @@ const TOKENS_PAD = 20;
const formatKTokens = (value: number) => `${(value / 1000).toFixed(value >= 10_000 ? 0 : 1)}k`;
const truncateKey = (key: string) => {
if (key.length <= KEY_PAD) return key;
if (key.length <= KEY_PAD) {
return key;
}
const head = Math.max(4, KEY_PAD - 10);
return `${key.slice(0, head)}...${key.slice(-6)}`;
};
const colorByPct = (label: string, pct: number | null, rich: boolean) => {
if (!rich || pct === null) return label;
if (pct >= 95) return theme.error(label);
if (pct >= 80) return theme.warn(label);
if (pct >= 60) return theme.success(label);
if (!rich || pct === null) {
return label;
}
if (pct >= 95) {
return theme.error(label);
}
if (pct >= 80) {
return theme.warn(label);
}
if (pct >= 60) {
return theme.success(label);
}
return theme.muted(label);
};
const formatTokensCell = (total: number, contextTokens: number | null, rich: boolean) => {
if (!total) return "-".padEnd(TOKENS_PAD);
if (!total) {
return "-".padEnd(TOKENS_PAD);
}
const totalLabel = formatKTokens(total);
const ctxLabel = contextTokens ? formatKTokens(contextTokens) : "?";
const pct = contextTokens ? Math.min(999, Math.round((total / contextTokens) * 100)) : null;
@@ -62,10 +74,18 @@ const formatTokensCell = (total: number, contextTokens: number | null, rich: boo
const formatKindCell = (kind: SessionRow["kind"], rich: boolean) => {
const label = kind.padEnd(KIND_PAD);
if (!rich) return label;
if (kind === "group") return theme.accentBright(label);
if (kind === "global") return theme.warn(label);
if (kind === "direct") return theme.accent(label);
if (!rich) {
return label;
}
if (kind === "group") {
return theme.accentBright(label);
}
if (kind === "global") {
return theme.warn(label);
}
if (kind === "direct") {
return theme.accent(label);
}
return theme.muted(label);
};
@@ -97,19 +117,31 @@ const formatFlagsCell = (row: SessionRow, rich: boolean) => {
};
const formatAge = (ms: number | null | undefined) => {
if (!ms || ms < 0) return "unknown";
if (!ms || ms < 0) {
return "unknown";
}
const minutes = Math.round(ms / 60_000);
if (minutes < 1) return "just now";
if (minutes < 60) return `${minutes}m ago`;
if (minutes < 1) {
return "just now";
}
if (minutes < 60) {
return `${minutes}m ago`;
}
const hours = Math.round(minutes / 60);
if (hours < 48) return `${hours}h ago`;
if (hours < 48) {
return `${hours}h ago`;
}
const days = Math.round(hours / 24);
return `${days}d ago`;
};
function classifyKey(key: string, entry?: SessionEntry): SessionRow["kind"] {
if (key === "global") return "global";
if (key === "unknown") return "unknown";
if (key === "global") {
return "global";
}
if (key === "unknown") {
return "unknown";
}
if (entry?.chatType === "group" || entry?.chatType === "channel") {
return "group";
}
@@ -177,8 +209,12 @@ export async function sessionsCommand(
}
const rows = toRows(store).filter((row) => {
if (activeMinutes === undefined) return true;
if (!row.updatedAt) return false;
if (activeMinutes === undefined) {
return true;
}
if (!row.updatedAt) {
return false;
}
return Date.now() - row.updatedAt <= activeMinutes * 60_000;
});