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

@@ -8,13 +8,19 @@ type ToolCall = { id: string; name?: string };
function extractAssistantToolCalls(msg: Extract<AgentMessage, { role: "assistant" }>): ToolCall[] {
const content = msg.content;
if (!Array.isArray(content)) return [];
if (!Array.isArray(content)) {
return [];
}
const toolCalls: ToolCall[] = [];
for (const block of content) {
if (!block || typeof block !== "object") continue;
if (!block || typeof block !== "object") {
continue;
}
const rec = block as { type?: unknown; id?: unknown; name?: unknown };
if (typeof rec.id !== "string" || !rec.id) continue;
if (typeof rec.id !== "string" || !rec.id) {
continue;
}
if (rec.type === "toolCall" || rec.type === "toolUse" || rec.type === "functionCall") {
toolCalls.push({
id: rec.id,
@@ -27,9 +33,13 @@ function extractAssistantToolCalls(msg: Extract<AgentMessage, { role: "assistant
function extractToolResultId(msg: Extract<AgentMessage, { role: "toolResult" }>): string | null {
const toolCallId = (msg as { toolCallId?: unknown }).toolCallId;
if (typeof toolCallId === "string" && toolCallId) return toolCallId;
if (typeof toolCallId === "string" && toolCallId) {
return toolCallId;
}
const toolUseId = (msg as { toolUseId?: unknown }).toolUseId;
if (typeof toolUseId === "string" && toolUseId) return toolUseId;
if (typeof toolUseId === "string" && toolUseId) {
return toolUseId;
}
return null;
}
@@ -68,7 +78,9 @@ export function installSessionToolResultGuard(
const allowSyntheticToolResults = opts?.allowSyntheticToolResults ?? true;
const flushPendingToolResults = () => {
if (pending.size === 0) return;
if (pending.size === 0) {
return;
}
if (allowSyntheticToolResults) {
for (const [id, name] of pending.entries()) {
const synthetic = makeMissingToolResult({ toolCallId: id, toolName: name });
@@ -90,7 +102,9 @@ export function installSessionToolResultGuard(
if (role === "toolResult") {
const id = extractToolResultId(message as Extract<AgentMessage, { role: "toolResult" }>);
const toolName = id ? pending.get(id) : undefined;
if (id) pending.delete(id);
if (id) {
pending.delete(id);
}
return originalAppend(
persistToolResult(message, {
toolCallId: id ?? undefined,