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

@@ -3,27 +3,39 @@ import { truncateUtf16Safe } from "../../utils.js";
import type { CronPayload } from "../types.js";
export function normalizeRequiredName(raw: unknown) {
if (typeof raw !== "string") throw new Error("cron job name is required");
if (typeof raw !== "string") {
throw new Error("cron job name is required");
}
const name = raw.trim();
if (!name) throw new Error("cron job name is required");
if (!name) {
throw new Error("cron job name is required");
}
return name;
}
export function normalizeOptionalText(raw: unknown) {
if (typeof raw !== "string") return undefined;
if (typeof raw !== "string") {
return undefined;
}
const trimmed = raw.trim();
return trimmed ? trimmed : undefined;
}
function truncateText(input: string, maxLen: number) {
if (input.length <= maxLen) return input;
if (input.length <= maxLen) {
return input;
}
return `${truncateUtf16Safe(input, Math.max(0, maxLen - 1)).trimEnd()}`;
}
export function normalizeOptionalAgentId(raw: unknown) {
if (typeof raw !== "string") return undefined;
if (typeof raw !== "string") {
return undefined;
}
const trimmed = raw.trim();
if (!trimmed) return undefined;
if (!trimmed) {
return undefined;
}
return normalizeAgentId(trimmed);
}
@@ -42,18 +54,26 @@ export function inferLegacyName(job: {
.split("\n")
.map((l) => l.trim())
.find(Boolean) ?? "";
if (firstLine) return truncateText(firstLine, 60);
if (firstLine) {
return truncateText(firstLine, 60);
}
const kind = typeof job?.schedule?.kind === "string" ? job.schedule.kind : "";
if (kind === "cron" && typeof job?.schedule?.expr === "string")
if (kind === "cron" && typeof job?.schedule?.expr === "string") {
return `Cron: ${truncateText(job.schedule.expr, 52)}`;
if (kind === "every" && typeof job?.schedule?.everyMs === "number")
}
if (kind === "every" && typeof job?.schedule?.everyMs === "number") {
return `Every: ${job.schedule.everyMs}ms`;
if (kind === "at") return "One-shot";
}
if (kind === "at") {
return "One-shot";
}
return "Cron job";
}
export function normalizePayloadToSystemText(payload: CronPayload) {
if (payload.kind === "systemEvent") return payload.text.trim();
if (payload.kind === "systemEvent") {
return payload.text.trim();
}
return payload.message.trim();
}