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

@@ -40,7 +40,9 @@ const DEFAULT_MAX_ATTACHMENTS = 1;
function normalizeAttachmentPath(raw?: string | null): string | undefined {
const value = raw?.trim();
if (!value) return undefined;
if (!value) {
return undefined;
}
if (value.startsWith("file://")) {
try {
return fileURLToPath(value);
@@ -58,7 +60,9 @@ export function normalizeAttachments(ctx: MsgContext): MediaAttachment[] {
const resolveMime = (count: number, index: number) => {
const typeHint = typesFromArray?.[index];
const trimmed = typeof typeHint === "string" ? typeHint.trim() : "";
if (trimmed) return trimmed;
if (trimmed) {
return trimmed;
}
return count === 1 ? ctx.MediaType : undefined;
};
@@ -89,7 +93,9 @@ export function normalizeAttachments(ctx: MsgContext): MediaAttachment[] {
const pathValue = ctx.MediaPath?.trim();
const url = ctx.MediaUrl?.trim();
if (!pathValue && !url) return [];
if (!pathValue && !url) {
return [];
}
return [
{
path: pathValue || undefined,
@@ -104,12 +110,20 @@ export function resolveAttachmentKind(
attachment: MediaAttachment,
): "image" | "audio" | "video" | "document" | "unknown" {
const kind = kindFromMime(attachment.mime);
if (kind === "image" || kind === "audio" || kind === "video") return kind;
if (kind === "image" || kind === "audio" || kind === "video") {
return kind;
}
const ext = getFileExtension(attachment.path ?? attachment.url);
if (!ext) return "unknown";
if ([".mp4", ".mov", ".mkv", ".webm", ".avi", ".m4v"].includes(ext)) return "video";
if (isAudioFileName(attachment.path ?? attachment.url)) return "audio";
if (!ext) {
return "unknown";
}
if ([".mp4", ".mov", ".mkv", ".webm", ".avi", ".m4v"].includes(ext)) {
return "video";
}
if (isAudioFileName(attachment.path ?? attachment.url)) {
return "audio";
}
if ([".png", ".jpg", ".jpeg", ".webp", ".gif", ".bmp", ".tiff", ".tif"].includes(ext)) {
return "image";
}
@@ -129,14 +143,22 @@ export function isImageAttachment(attachment: MediaAttachment): boolean {
}
function isAbortError(err: unknown): boolean {
if (!err) return false;
if (err instanceof Error && err.name === "AbortError") return true;
if (!err) {
return false;
}
if (err instanceof Error && err.name === "AbortError") {
return true;
}
return false;
}
function resolveRequestUrl(input: RequestInfo | URL): string {
if (typeof input === "string") return input;
if (input instanceof URL) return input.toString();
if (typeof input === "string") {
return input;
}
if (input instanceof URL) {
return input.toString();
}
return input.url;
}
@@ -144,8 +166,12 @@ function orderAttachments(
attachments: MediaAttachment[],
prefer?: MediaUnderstandingAttachmentsConfig["prefer"],
): MediaAttachment[] {
if (!prefer || prefer === "first") return attachments;
if (prefer === "last") return [...attachments].toReversed();
if (!prefer || prefer === "first") {
return attachments;
}
if (prefer === "last") {
return [...attachments].toReversed();
}
if (prefer === "path") {
const withPath = attachments.filter((item) => item.path);
const withoutPath = attachments.filter((item) => !item.path);
@@ -166,11 +192,17 @@ export function selectAttachments(params: {
}): MediaAttachment[] {
const { capability, attachments, policy } = params;
const matches = attachments.filter((item) => {
if (capability === "image") return isImageAttachment(item);
if (capability === "audio") return isAudioAttachment(item);
if (capability === "image") {
return isImageAttachment(item);
}
if (capability === "audio") {
return isAudioAttachment(item);
}
return isVideoAttachment(item);
});
if (matches.length === 0) return [];
if (matches.length === 0) {
return [];
}
const ordered = orderAttachments(matches, policy?.prefer);
const mode = policy?.mode ?? "first";
@@ -367,13 +399,19 @@ export class MediaAttachmentCache {
private resolveLocalPath(attachment: MediaAttachment): string | undefined {
const rawPath = normalizeAttachmentPath(attachment.path);
if (!rawPath) return undefined;
if (!rawPath) {
return undefined;
}
return path.isAbsolute(rawPath) ? rawPath : path.resolve(rawPath);
}
private async ensureLocalStat(entry: AttachmentCacheEntry): Promise<number | undefined> {
if (!entry.resolvedPath) return undefined;
if (entry.statSize !== undefined) return entry.statSize;
if (!entry.resolvedPath) {
return undefined;
}
if (entry.statSize !== undefined) {
return entry.statSize;
}
try {
const stat = await fs.stat(entry.resolvedPath);
if (!stat.isFile()) {