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

@@ -1,5 +1,7 @@
export function normalizeAccountId(value?: string): string | undefined {
if (typeof value !== "string") return undefined;
if (typeof value !== "string") {
return undefined;
}
const trimmed = value.trim();
return trimmed || undefined;
}

View File

@@ -12,15 +12,25 @@ export function parseBooleanValue(
value: unknown,
options: BooleanParseOptions = {},
): boolean | undefined {
if (typeof value === "boolean") return value;
if (typeof value !== "string") return undefined;
if (typeof value === "boolean") {
return value;
}
if (typeof value !== "string") {
return undefined;
}
const normalized = value.trim().toLowerCase();
if (!normalized) return undefined;
if (!normalized) {
return undefined;
}
const truthy = options.truthy ?? DEFAULT_TRUTHY;
const falsy = options.falsy ?? DEFAULT_FALSY;
const truthySet = truthy === DEFAULT_TRUTHY ? DEFAULT_TRUTHY_SET : new Set(truthy);
const falsySet = falsy === DEFAULT_FALSY ? DEFAULT_FALSY_SET : new Set(falsy);
if (truthySet.has(normalized)) return true;
if (falsySet.has(normalized)) return false;
if (truthySet.has(normalized)) {
return true;
}
if (falsySet.has(normalized)) {
return false;
}
return undefined;
}

View File

@@ -18,7 +18,9 @@ export type DeliveryContextSessionSource = {
};
export function normalizeDeliveryContext(context?: DeliveryContext): DeliveryContext | undefined {
if (!context) return undefined;
if (!context) {
return undefined;
}
const channel =
typeof context.channel === "string"
? (normalizeMessageChannel(context.channel) ?? context.channel.trim())
@@ -33,13 +35,17 @@ export function normalizeDeliveryContext(context?: DeliveryContext): DeliveryCon
: undefined;
const normalizedThreadId =
typeof threadId === "string" ? (threadId ? threadId : undefined) : threadId;
if (!channel && !to && !accountId && normalizedThreadId == null) return undefined;
if (!channel && !to && !accountId && normalizedThreadId == null) {
return undefined;
}
const normalized: DeliveryContext = {
channel: channel || undefined,
to: to || undefined,
accountId,
};
if (normalizedThreadId != null) normalized.threadId = normalizedThreadId;
if (normalizedThreadId != null) {
normalized.threadId = normalizedThreadId;
}
return normalized;
}
@@ -92,7 +98,9 @@ export function normalizeSessionDeliveryFields(source?: DeliveryContextSessionSo
export function deliveryContextFromSession(
entry?: DeliveryContextSessionSource & { origin?: { threadId?: string | number } },
): DeliveryContext | undefined {
if (!entry) return undefined;
if (!entry) {
return undefined;
}
const source: DeliveryContextSessionSource = {
channel: entry.channel,
lastChannel: entry.lastChannel,
@@ -110,7 +118,9 @@ export function mergeDeliveryContext(
): DeliveryContext | undefined {
const normalizedPrimary = normalizeDeliveryContext(primary);
const normalizedFallback = normalizeDeliveryContext(fallback);
if (!normalizedPrimary && !normalizedFallback) return undefined;
if (!normalizedPrimary && !normalizedFallback) {
return undefined;
}
return normalizeDeliveryContext({
channel: normalizedPrimary?.channel ?? normalizedFallback?.channel,
to: normalizedPrimary?.to ?? normalizedFallback?.to,
@@ -121,7 +131,9 @@ export function mergeDeliveryContext(
export function deliveryContextKey(context?: DeliveryContext): string | undefined {
const normalized = normalizeDeliveryContext(context);
if (!normalized?.channel || !normalized?.to) return undefined;
if (!normalized?.channel || !normalized?.to) {
return undefined;
}
const threadId =
normalized.threadId != null && normalized.threadId !== "" ? String(normalized.threadId) : "";
return `${normalized.channel}|${normalized.to}|${normalized.accountId ?? ""}|${threadId}`;

View File

@@ -58,7 +58,9 @@ export function parseInlineDirectives(
sawCurrent = true;
} else {
const id = idRaw.trim();
if (id) lastExplicitId = id;
if (id) {
lastExplicitId = id;
}
}
return stripReplyTags ? " " : match;
});

View File

@@ -46,19 +46,29 @@ export function isInternalMessageChannel(raw?: string | null): raw is InternalMe
export function isWebchatClient(client?: GatewayClientInfoLike | null): boolean {
const mode = normalizeGatewayClientMode(client?.mode);
if (mode === GATEWAY_CLIENT_MODES.WEBCHAT) return true;
if (mode === GATEWAY_CLIENT_MODES.WEBCHAT) {
return true;
}
return normalizeGatewayClientName(client?.id) === GATEWAY_CLIENT_NAMES.WEBCHAT_UI;
}
export function normalizeMessageChannel(raw?: string | null): string | undefined {
const normalized = raw?.trim().toLowerCase();
if (!normalized) return undefined;
if (normalized === INTERNAL_MESSAGE_CHANNEL) return INTERNAL_MESSAGE_CHANNEL;
if (!normalized) {
return undefined;
}
if (normalized === INTERNAL_MESSAGE_CHANNEL) {
return INTERNAL_MESSAGE_CHANNEL;
}
const builtIn = normalizeChatChannelId(normalized);
if (builtIn) return builtIn;
if (builtIn) {
return builtIn;
}
const registry = getActivePluginRegistry();
const pluginMatch = registry?.channels.find((entry) => {
if (entry.plugin.id.toLowerCase() === normalized) return true;
if (entry.plugin.id.toLowerCase() === normalized) {
return true;
}
return (entry.plugin.meta.aliases ?? []).some(
(alias) => alias.trim().toLowerCase() === normalized,
);
@@ -68,13 +78,17 @@ export function normalizeMessageChannel(raw?: string | null): string | undefined
const listPluginChannelIds = (): string[] => {
const registry = getActivePluginRegistry();
if (!registry) return [];
if (!registry) {
return [];
}
return registry.channels.map((entry) => entry.plugin.id);
};
const listPluginChannelAliases = (): string[] => {
const registry = getActivePluginRegistry();
if (!registry) return [];
if (!registry) {
return [];
}
return registry.channels.flatMap((entry) => entry.plugin.meta.aliases ?? []);
};
@@ -112,7 +126,9 @@ export function resolveGatewayMessageChannel(
raw?: string | null,
): GatewayMessageChannel | undefined {
const normalized = normalizeMessageChannel(raw);
if (!normalized) return undefined;
if (!normalized) {
return undefined;
}
return isGatewayMessageChannel(normalized) ? normalized : undefined;
}
@@ -125,6 +141,8 @@ export function resolveMessageChannel(
export function isMarkdownCapableMessageChannel(raw?: string | null): boolean {
const channel = normalizeMessageChannel(raw);
if (!channel) return false;
if (!channel) {
return false;
}
return MARKDOWN_CAPABLE_CHANNELS.has(channel);
}

View File

@@ -8,7 +8,9 @@
* API fields for reasoning/thinking.
*/
export function isReasoningTagProvider(provider: string | undefined | null): boolean {
if (!provider) return false;
if (!provider) {
return false;
}
const normalized = provider.trim().toLowerCase();
// Check for exact matches or known prefixes/substrings for reasoning providers

View File

@@ -12,7 +12,9 @@ export type QueueState<T> = QueueSummaryState & {
};
export function elideQueueText(text: string, limit = 140): string {
if (text.length <= limit) return text;
if (text.length <= limit) {
return text;
}
return `${text.slice(0, Math.max(0, limit - 1)).trimEnd()}`;
}
@@ -26,7 +28,9 @@ export function shouldSkipQueueItem<T>(params: {
items: T[];
dedupe?: (item: T, items: T[]) => boolean;
}): boolean {
if (!params.dedupe) return false;
if (!params.dedupe) {
return false;
}
return params.dedupe(params.item, params.items);
}
@@ -36,8 +40,12 @@ export function applyQueueDropPolicy<T>(params: {
summaryLimit?: number;
}): boolean {
const cap = params.queue.cap;
if (cap <= 0 || params.queue.items.length < cap) return true;
if (params.queue.dropPolicy === "new") return false;
if (cap <= 0 || params.queue.items.length < cap) {
return true;
}
if (params.queue.dropPolicy === "new") {
return false;
}
const dropCount = params.queue.items.length - cap + 1;
const dropped = params.queue.items.splice(0, dropCount);
if (params.queue.dropPolicy === "summarize") {
@@ -46,7 +54,9 @@ export function applyQueueDropPolicy<T>(params: {
params.queue.summaryLines.push(buildQueueSummaryLine(params.summarize(item)));
}
const limit = Math.max(0, params.summaryLimit ?? cap);
while (params.queue.summaryLines.length > limit) params.queue.summaryLines.shift();
while (params.queue.summaryLines.length > limit) {
params.queue.summaryLines.shift();
}
}
return true;
}
@@ -56,7 +66,9 @@ export function waitForQueueDebounce(queue: {
lastEnqueuedAt: number;
}): Promise<void> {
const debounceMs = Math.max(0, queue.debounceMs);
if (debounceMs <= 0) return Promise.resolve();
if (debounceMs <= 0) {
return Promise.resolve();
}
return new Promise<void>((resolve) => {
const check = () => {
const since = Date.now() - queue.lastEnqueuedAt;
@@ -101,7 +113,9 @@ export function buildCollectPrompt<T>(params: {
renderItem: (item: T, index: number) => string;
}): string {
const blocks: string[] = [params.title];
if (params.summary) blocks.push(params.summary);
if (params.summary) {
blocks.push(params.summary);
}
params.items.forEach((item, idx) => {
blocks.push(params.renderItem(item, idx));
});
@@ -117,7 +131,9 @@ export function hasCrossChannelItems<T>(
for (const item of items) {
const resolved = resolveKey(item);
if (resolved.cross) return true;
if (resolved.cross) {
return true;
}
if (!resolved.key) {
hasUnkeyed = true;
continue;
@@ -125,7 +141,11 @@ export function hasCrossChannelItems<T>(
keys.add(resolved.key);
}
if (keys.size === 0) return false;
if (hasUnkeyed) return true;
if (keys.size === 0) {
return false;
}
if (hasUnkeyed) {
return true;
}
return keys.size > 1;
}

View File

@@ -6,10 +6,20 @@ export function formatRelativeTime(timestamp: number): string {
const hours = Math.floor(minutes / 60);
const days = Math.floor(hours / 24);
if (seconds < 60) return "just now";
if (minutes < 60) return `${minutes}m ago`;
if (hours < 24) return `${hours}h ago`;
if (days === 1) return "Yesterday";
if (days < 7) return `${days}d ago`;
if (seconds < 60) {
return "just now";
}
if (minutes < 60) {
return `${minutes}m ago`;
}
if (hours < 24) {
return `${hours}h ago`;
}
if (days === 1) {
return "Yesterday";
}
if (days < 7) {
return `${days}d ago`;
}
return new Date(timestamp).toLocaleDateString(undefined, { month: "short", day: "numeric" });
}

View File

@@ -17,17 +17,29 @@ export type UsageTotals = {
};
export function formatTokenCount(value?: number): string {
if (value === undefined || !Number.isFinite(value)) return "0";
if (value === undefined || !Number.isFinite(value)) {
return "0";
}
const safe = Math.max(0, value);
if (safe >= 1_000_000) return `${(safe / 1_000_000).toFixed(1)}m`;
if (safe >= 1_000) return `${(safe / 1_000).toFixed(safe >= 10_000 ? 0 : 1)}k`;
if (safe >= 1_000_000) {
return `${(safe / 1_000_000).toFixed(1)}m`;
}
if (safe >= 1_000) {
return `${(safe / 1_000).toFixed(safe >= 10_000 ? 0 : 1)}k`;
}
return String(Math.round(safe));
}
export function formatUsd(value?: number): string | undefined {
if (value === undefined || !Number.isFinite(value)) return undefined;
if (value >= 1) return `$${value.toFixed(2)}`;
if (value >= 0.01) return `$${value.toFixed(2)}`;
if (value === undefined || !Number.isFinite(value)) {
return undefined;
}
if (value >= 1) {
return `$${value.toFixed(2)}`;
}
if (value >= 0.01) {
return `$${value.toFixed(2)}`;
}
return `$${value.toFixed(4)}`;
}
@@ -38,7 +50,9 @@ export function resolveModelCostConfig(params: {
}): ModelCostConfig | undefined {
const provider = params.provider?.trim();
const model = params.model?.trim();
if (!provider || !model) return undefined;
if (!provider || !model) {
return undefined;
}
const providers = params.config?.models?.providers ?? {};
const entry = providers[provider]?.models?.find((item) => item.id === model);
return entry?.cost;
@@ -53,7 +67,9 @@ export function estimateUsageCost(params: {
}): number | undefined {
const usage = params.usage;
const cost = params.cost;
if (!usage || !cost) return undefined;
if (!usage || !cost) {
return undefined;
}
const input = toNumber(usage.input);
const output = toNumber(usage.output);
const cacheRead = toNumber(usage.cacheRead);
@@ -63,6 +79,8 @@ export function estimateUsageCost(params: {
output * cost.output +
cacheRead * cost.cacheRead +
cacheWrite * cost.cacheWrite;
if (!Number.isFinite(total)) return undefined;
if (!Number.isFinite(total)) {
return undefined;
}
return total / 1_000_000;
}