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

@@ -14,11 +14,15 @@ type TextContentBlock = Extract<ToolContentBlock, { type: "text" }>;
async function sniffMimeFromBase64(base64: string): Promise<string | undefined> {
const trimmed = base64.trim();
if (!trimmed) return undefined;
if (!trimmed) {
return undefined;
}
const take = Math.min(256, trimmed.length);
const sliceLen = take - (take % 4);
if (sliceLen < 8) return undefined;
if (sliceLen < 8) {
return undefined;
}
try {
const head = Buffer.from(trimmed.slice(0, sliceLen), "base64");
@@ -50,14 +54,18 @@ async function normalizeReadImageResult(
typeof (b as { data?: unknown }).data === "string" &&
typeof (b as { mimeType?: unknown }).mimeType === "string",
);
if (!image) return result;
if (!image) {
return result;
}
if (!image.data.trim()) {
throw new Error(`read: image payload is empty (${filePath})`);
}
const sniffed = await sniffMimeFromBase64(image.data);
if (!sniffed) return result;
if (!sniffed) {
return result;
}
if (!sniffed.startsWith("image/")) {
throw new Error(
@@ -65,7 +73,9 @@ async function normalizeReadImageResult(
);
}
if (sniffed === image.mimeType) return result;
if (sniffed === image.mimeType) {
return result;
}
const nextContent = content.map((block) => {
if (block && typeof block === "object" && (block as { type?: unknown }).type === "image") {
@@ -116,7 +126,9 @@ export const CLAUDE_PARAM_GROUPS = {
// Claude Code uses file_path/old_string/new_string while pi-coding-agent uses path/oldText/newText.
// This prevents models trained on Claude Code from getting stuck in tool-call loops.
export function normalizeToolParams(params: unknown): Record<string, unknown> | undefined {
if (!params || typeof params !== "object") return undefined;
if (!params || typeof params !== "object") {
return undefined;
}
const record = params as Record<string, unknown>;
const normalized = { ...record };
// file_path → path (read, write, edit)
@@ -160,7 +172,9 @@ export function patchToolSchemaForClaudeCompatibility(tool: AnyAgentTool): AnyAg
];
for (const { original, alias } of aliasPairs) {
if (!(original in properties)) continue;
if (!(original in properties)) {
continue;
}
if (!(alias in properties)) {
properties[alias] = properties[original];
changed = true;
@@ -172,7 +186,9 @@ export function patchToolSchemaForClaudeCompatibility(tool: AnyAgentTool): AnyAg
}
}
if (!changed) return tool;
if (!changed) {
return tool;
}
return {
...tool,
@@ -195,10 +211,16 @@ export function assertRequiredParams(
for (const group of groups) {
const satisfied = group.keys.some((key) => {
if (!(key in record)) return false;
if (!(key in record)) {
return false;
}
const value = record[key];
if (typeof value !== "string") return false;
if (group.allowEmpty) return true;
if (typeof value !== "string") {
return false;
}
if (group.allowEmpty) {
return true;
}
return value.trim().length > 0;
});