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

@@ -15,7 +15,9 @@ export async function warnIfCronSchedulerDisabled(opts: GatewayRpcOpts) {
enabled?: boolean;
storePath?: string;
};
if (res?.enabled === true) return;
if (res?.enabled === true) {
return;
}
const store = typeof res?.storePath === "string" ? res.storePath : "";
defaultRuntime.error(
[
@@ -33,11 +35,17 @@ export async function warnIfCronSchedulerDisabled(opts: GatewayRpcOpts) {
export function parseDurationMs(input: string): number | null {
const raw = input.trim();
if (!raw) return null;
if (!raw) {
return null;
}
const match = raw.match(/^(\d+(?:\.\d+)?)(ms|s|m|h|d)$/i);
if (!match) return null;
if (!match) {
return null;
}
const n = Number.parseFloat(match[1] ?? "");
if (!Number.isFinite(n) || n <= 0) return null;
if (!Number.isFinite(n) || n <= 0) {
return null;
}
const unit = (match[2] ?? "").toLowerCase();
const factor =
unit === "ms"
@@ -54,11 +62,17 @@ export function parseDurationMs(input: string): number | null {
export function parseAtMs(input: string): number | null {
const raw = input.trim();
if (!raw) return null;
if (!raw) {
return null;
}
const absolute = parseAbsoluteTimeMs(raw);
if (absolute) return absolute;
if (absolute) {
return absolute;
}
const dur = parseDurationMs(raw);
if (dur) return Date.now() + dur;
if (dur) {
return Date.now() + dur;
}
return null;
}
@@ -74,48 +88,76 @@ const CRON_AGENT_PAD = 10;
const pad = (value: string, width: number) => value.padEnd(width);
const truncate = (value: string, width: number) => {
if (value.length <= width) return value;
if (width <= 3) return value.slice(0, width);
if (value.length <= width) {
return value;
}
if (width <= 3) {
return value.slice(0, width);
}
return `${value.slice(0, width - 3)}...`;
};
const formatIsoMinute = (ms: number) => {
const d = new Date(ms);
if (Number.isNaN(d.getTime())) return "-";
if (Number.isNaN(d.getTime())) {
return "-";
}
const iso = d.toISOString();
return `${iso.slice(0, 10)} ${iso.slice(11, 16)}Z`;
};
const formatDuration = (ms: number) => {
if (ms < 60_000) return `${Math.max(1, Math.round(ms / 1000))}s`;
if (ms < 3_600_000) return `${Math.round(ms / 60_000)}m`;
if (ms < 86_400_000) return `${Math.round(ms / 3_600_000)}h`;
if (ms < 60_000) {
return `${Math.max(1, Math.round(ms / 1000))}s`;
}
if (ms < 3_600_000) {
return `${Math.round(ms / 60_000)}m`;
}
if (ms < 86_400_000) {
return `${Math.round(ms / 3_600_000)}h`;
}
return `${Math.round(ms / 86_400_000)}d`;
};
const formatSpan = (ms: number) => {
if (ms < 60_000) return "<1m";
if (ms < 3_600_000) return `${Math.round(ms / 60_000)}m`;
if (ms < 86_400_000) return `${Math.round(ms / 3_600_000)}h`;
if (ms < 60_000) {
return "<1m";
}
if (ms < 3_600_000) {
return `${Math.round(ms / 60_000)}m`;
}
if (ms < 86_400_000) {
return `${Math.round(ms / 3_600_000)}h`;
}
return `${Math.round(ms / 86_400_000)}d`;
};
const formatRelative = (ms: number | null | undefined, nowMs: number) => {
if (!ms) return "-";
if (!ms) {
return "-";
}
const delta = ms - nowMs;
const label = formatSpan(Math.abs(delta));
return delta >= 0 ? `in ${label}` : `${label} ago`;
};
const formatSchedule = (schedule: CronSchedule) => {
if (schedule.kind === "at") return `at ${formatIsoMinute(schedule.atMs)}`;
if (schedule.kind === "every") return `every ${formatDuration(schedule.everyMs)}`;
if (schedule.kind === "at") {
return `at ${formatIsoMinute(schedule.atMs)}`;
}
if (schedule.kind === "every") {
return `every ${formatDuration(schedule.everyMs)}`;
}
return schedule.tz ? `cron ${schedule.expr} @ ${schedule.tz}` : `cron ${schedule.expr}`;
};
const formatStatus = (job: CronJob) => {
if (!job.enabled) return "disabled";
if (job.state.runningAtMs) return "running";
if (!job.enabled) {
return "disabled";
}
if (job.state.runningAtMs) {
return "running";
}
return job.state.lastStatus ?? "idle";
};
@@ -158,10 +200,18 @@ export function printCronList(jobs: CronJob[], runtime = defaultRuntime) {
const agentLabel = pad(truncate(job.agentId ?? "default", CRON_AGENT_PAD), CRON_AGENT_PAD);
const coloredStatus = (() => {
if (statusRaw === "ok") return colorize(rich, theme.success, statusLabel);
if (statusRaw === "error") return colorize(rich, theme.error, statusLabel);
if (statusRaw === "running") return colorize(rich, theme.warn, statusLabel);
if (statusRaw === "skipped") return colorize(rich, theme.muted, statusLabel);
if (statusRaw === "ok") {
return colorize(rich, theme.success, statusLabel);
}
if (statusRaw === "error") {
return colorize(rich, theme.error, statusLabel);
}
if (statusRaw === "running") {
return colorize(rich, theme.warn, statusLabel);
}
if (statusRaw === "skipped") {
return colorize(rich, theme.muted, statusLabel);
}
return colorize(rich, theme.muted, statusLabel);
})();