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

@@ -20,8 +20,12 @@ export function resolveUserTimezone(configured?: string): string {
}
export function resolveUserTimeFormat(preference?: TimeFormatPreference): ResolvedTimeFormat {
if (preference === "12" || preference === "24") return preference;
if (cachedTimeFormat) return cachedTimeFormat;
if (preference === "12" || preference === "24") {
return preference;
}
if (cachedTimeFormat) {
return cachedTimeFormat;
}
cachedTimeFormat = detectSystemTimeFormat() ? "24" : "12";
return cachedTimeFormat;
}
@@ -29,7 +33,9 @@ export function resolveUserTimeFormat(preference?: TimeFormatPreference): Resolv
export function normalizeTimestamp(
raw: unknown,
): { timestampMs: number; timestampUtc: string } | undefined {
if (raw == null) return undefined;
if (raw == null) {
return undefined;
}
let timestampMs: number | undefined;
if (raw instanceof Date) {
@@ -38,7 +44,9 @@ export function normalizeTimestamp(
timestampMs = raw < 1_000_000_000_000 ? Math.round(raw * 1000) : Math.round(raw);
} else if (typeof raw === "string") {
const trimmed = raw.trim();
if (!trimmed) return undefined;
if (!trimmed) {
return undefined;
}
if (/^\d+(\.\d+)?$/.test(trimmed)) {
const num = Number(trimmed);
if (Number.isFinite(num)) {
@@ -52,11 +60,15 @@ export function normalizeTimestamp(
}
} else {
const parsed = Date.parse(trimmed);
if (!Number.isNaN(parsed)) timestampMs = parsed;
if (!Number.isNaN(parsed)) {
timestampMs = parsed;
}
}
}
if (timestampMs === undefined || !Number.isFinite(timestampMs)) return undefined;
if (timestampMs === undefined || !Number.isFinite(timestampMs)) {
return undefined;
}
return { timestampMs, timestampUtc: new Date(timestampMs).toISOString() };
}
@@ -65,7 +77,9 @@ export function withNormalizedTimestamp<T extends Record<string, unknown>>(
rawTimestamp: unknown,
): T & { timestampMs?: number; timestampUtc?: string } {
const normalized = normalizeTimestamp(rawTimestamp);
if (!normalized) return value;
if (!normalized) {
return value;
}
return {
...value,
timestampMs:
@@ -86,8 +100,12 @@ function detectSystemTimeFormat(): boolean {
encoding: "utf8",
timeout: 500,
}).trim();
if (result === "1") return true;
if (result === "0") return false;
if (result === "1") {
return true;
}
if (result === "0") {
return false;
}
} catch {
// Not set, fall through
}
@@ -99,8 +117,12 @@ function detectSystemTimeFormat(): boolean {
'powershell -Command "(Get-Culture).DateTimeFormat.ShortTimePattern"',
{ encoding: "utf8", timeout: 1000 },
).trim();
if (result.startsWith("H")) return true;
if (result.startsWith("h")) return false;
if (result.startsWith("H")) {
return true;
}
if (result.startsWith("h")) {
return false;
}
} catch {
// Fall through
}
@@ -116,7 +138,9 @@ function detectSystemTimeFormat(): boolean {
}
function ordinalSuffix(day: number): string {
if (day >= 11 && day <= 13) return "th";
if (day >= 11 && day <= 13) {
return "th";
}
switch (day % 10) {
case 1:
return "st";
@@ -148,10 +172,13 @@ export function formatUserTime(
}).formatToParts(date);
const map: Record<string, string> = {};
for (const part of parts) {
if (part.type !== "literal") map[part.type] = part.value;
if (part.type !== "literal") {
map[part.type] = part.value;
}
}
if (!map.weekday || !map.year || !map.month || !map.day || !map.hour || !map.minute)
if (!map.weekday || !map.year || !map.month || !map.day || !map.hour || !map.minute) {
return undefined;
}
const dayNum = parseInt(map.day, 10);
const suffix = ordinalSuffix(dayNum);
const timePart = use24Hour