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
+114 -39
View File
@@ -252,13 +252,19 @@ function normalizeNotifyOutput(value: string) {
}
function normalizePathPrepend(entries?: string[]) {
if (!Array.isArray(entries)) return [];
if (!Array.isArray(entries)) {
return [];
}
const seen = new Set<string>();
const normalized: string[] = [];
for (const entry of entries) {
if (typeof entry !== "string") continue;
if (typeof entry !== "string") {
continue;
}
const trimmed = entry.trim();
if (!trimmed || seen.has(trimmed)) continue;
if (!trimmed || seen.has(trimmed)) {
continue;
}
seen.add(trimmed);
normalized.push(trimmed);
}
@@ -266,7 +272,9 @@ function normalizePathPrepend(entries?: string[]) {
}
function mergePathPrepend(existing: string | undefined, prepend: string[]) {
if (prepend.length === 0) return existing;
if (prepend.length === 0) {
return existing;
}
const partsExisting = (existing ?? "")
.split(path.delimiter)
.map((part) => part.trim())
@@ -274,7 +282,9 @@ function mergePathPrepend(existing: string | undefined, prepend: string[]) {
const merged: string[] = [];
const seen = new Set<string>();
for (const part of [...prepend, ...partsExisting]) {
if (seen.has(part)) continue;
if (seen.has(part)) {
continue;
}
seen.add(part);
merged.push(part);
}
@@ -286,27 +296,43 @@ function applyPathPrepend(
prepend: string[],
options?: { requireExisting?: boolean },
) {
if (prepend.length === 0) return;
if (options?.requireExisting && !env.PATH) return;
if (prepend.length === 0) {
return;
}
if (options?.requireExisting && !env.PATH) {
return;
}
const merged = mergePathPrepend(env.PATH, prepend);
if (merged) env.PATH = merged;
if (merged) {
env.PATH = merged;
}
}
function applyShellPath(env: Record<string, string>, shellPath?: string | null) {
if (!shellPath) return;
if (!shellPath) {
return;
}
const entries = shellPath
.split(path.delimiter)
.map((part) => part.trim())
.filter(Boolean);
if (entries.length === 0) return;
if (entries.length === 0) {
return;
}
const merged = mergePathPrepend(env.PATH, entries);
if (merged) env.PATH = merged;
if (merged) {
env.PATH = merged;
}
}
function maybeNotifyOnExit(session: ProcessSession, status: "completed" | "failed") {
if (!session.backgrounded || !session.notifyOnExit || session.exitNotified) return;
if (!session.backgrounded || !session.notifyOnExit || session.exitNotified) {
return;
}
const sessionKey = session.sessionKey?.trim();
if (!sessionKey) return;
if (!sessionKey) {
return;
}
session.exitNotified = true;
const exitLabel = session.exitSignal
? `signal ${session.exitSignal}`
@@ -329,13 +355,17 @@ function resolveApprovalRunningNoticeMs(value?: number) {
if (typeof value !== "number" || !Number.isFinite(value)) {
return DEFAULT_APPROVAL_RUNNING_NOTICE_MS;
}
if (value <= 0) return 0;
if (value <= 0) {
return 0;
}
return Math.floor(value);
}
function emitExecSystemEvent(text: string, opts: { sessionKey?: string; contextKey?: string }) {
const sessionKey = opts.sessionKey?.trim();
if (!sessionKey) return;
if (!sessionKey) {
return;
}
enqueueSystemEvent(text, { sessionKey, contextKey: opts.contextKey });
requestHeartbeatNow({ reason: "exec-event" });
}
@@ -528,13 +558,17 @@ async function runExecProcess(opts: {
let resolveFn: ((outcome: ExecProcessOutcome) => void) | null = null;
const settle = (outcome: ExecProcessOutcome) => {
if (settled) return;
if (settled) {
return;
}
settled = true;
resolveFn?.(outcome);
};
const finalizeTimeout = () => {
if (session.exited) return;
if (session.exited) {
return;
}
markExited(session, null, "SIGKILL", "failed");
maybeNotifyOnExit(session, "failed");
const aggregated = session.aggregated.trim();
@@ -567,7 +601,9 @@ async function runExecProcess(opts: {
}
const emitUpdate = () => {
if (!opts.onUpdate) return;
if (!opts.onUpdate) {
return;
}
const tailText = session.tail || session.aggregated;
const warningText = opts.warnings.length ? `${opts.warnings.join("\n")}\n\n` : "";
opts.onUpdate({
@@ -619,8 +655,12 @@ async function runExecProcess(opts: {
const promise = new Promise<ExecProcessOutcome>((resolve) => {
resolveFn = resolve;
const handleExit = (code: number | null, exitSignal: NodeJS.Signals | number | null) => {
if (timeoutTimer) clearTimeout(timeoutTimer);
if (timeoutFinalizeTimer) clearTimeout(timeoutFinalizeTimer);
if (timeoutTimer) {
clearTimeout(timeoutTimer);
}
if (timeoutFinalizeTimer) {
clearTimeout(timeoutFinalizeTimer);
}
const durationMs = Date.now() - startedAt;
const wasSignal = exitSignal != null;
const isSuccess = code === 0 && !wasSignal && !timedOut;
@@ -631,7 +671,9 @@ async function runExecProcess(opts: {
session.stdin.destroyed = true;
}
if (settled) return;
if (settled) {
return;
}
const aggregated = session.aggregated.trim();
if (!isSuccess) {
const reason = timedOut
@@ -675,8 +717,12 @@ async function runExecProcess(opts: {
});
child.once("error", (err) => {
if (timeoutTimer) clearTimeout(timeoutTimer);
if (timeoutFinalizeTimer) clearTimeout(timeoutFinalizeTimer);
if (timeoutTimer) {
clearTimeout(timeoutTimer);
}
if (timeoutFinalizeTimer) {
clearTimeout(timeoutFinalizeTimer);
}
markExited(session, null, null, "failed");
maybeNotifyOnExit(session, "failed");
const aggregated = session.aggregated.trim();
@@ -795,8 +841,12 @@ export function createExecTool(
const contextParts: string[] = [];
const provider = defaults?.messageProvider?.trim();
const sessionKey = defaults?.sessionKey?.trim();
if (provider) contextParts.push(`provider=${provider}`);
if (sessionKey) contextParts.push(`session=${sessionKey}`);
if (provider) {
contextParts.push(`provider=${provider}`);
}
if (sessionKey) {
contextParts.push(`session=${sessionKey}`);
}
if (!elevatedDefaults?.enabled) {
gates.push("enabled (tools.elevated.enabled / agents.list[].tools.elevated.enabled)");
} else {
@@ -1098,7 +1148,9 @@ export function createExecTool(
{ sessionKey: notifySessionKey, contextKey },
);
} finally {
if (runningTimer) clearTimeout(runningTimer);
if (runningTimer) {
clearTimeout(runningTimer);
}
}
})();
@@ -1267,7 +1319,9 @@ export function createExecTool(
if (allowlistMatches.length > 0) {
const seen = new Set<string>();
for (const match of allowlistMatches) {
if (seen.has(match.pattern)) continue;
if (seen.has(match.pattern)) {
continue;
}
seen.add(match.pattern);
recordAllowlistUse(
approvals.file,
@@ -1317,7 +1371,9 @@ export function createExecTool(
}
const outcome = await run.promise;
if (runningTimer) clearTimeout(runningTimer);
if (runningTimer) {
clearTimeout(runningTimer);
}
const output = normalizeNotifyOutput(
tail(outcome.aggregated || "", DEFAULT_NOTIFY_TAIL_CHARS),
);
@@ -1357,7 +1413,9 @@ export function createExecTool(
if (allowlistMatches.length > 0) {
const seen = new Set<string>();
for (const match of allowlistMatches) {
if (seen.has(match.pattern)) continue;
if (seen.has(match.pattern)) {
continue;
}
seen.add(match.pattern);
recordAllowlistUse(
approvals.file,
@@ -1396,12 +1454,15 @@ export function createExecTool(
// Tool-call abort should not kill backgrounded sessions; timeouts still must.
const onAbortSignal = () => {
if (yielded || run.session.backgrounded) return;
if (yielded || run.session.backgrounded) {
return;
}
run.kill();
};
if (signal?.aborted) onAbortSignal();
else if (signal) {
if (signal?.aborted) {
onAbortSignal();
} else if (signal) {
signal.addEventListener("abort", onAbortSignal, { once: true });
}
@@ -1430,8 +1491,12 @@ export function createExecTool(
});
const onYieldNow = () => {
if (yieldTimer) clearTimeout(yieldTimer);
if (yielded) return;
if (yieldTimer) {
clearTimeout(yieldTimer);
}
if (yielded) {
return;
}
yielded = true;
markBackgrounded(run.session);
resolveRunning();
@@ -1442,7 +1507,9 @@ export function createExecTool(
onYieldNow();
} else {
yieldTimer = setTimeout(() => {
if (yielded) return;
if (yielded) {
return;
}
yielded = true;
markBackgrounded(run.session);
resolveRunning();
@@ -1452,8 +1519,12 @@ export function createExecTool(
run.promise
.then((outcome) => {
if (yieldTimer) clearTimeout(yieldTimer);
if (yielded || run.session.backgrounded) return;
if (yieldTimer) {
clearTimeout(yieldTimer);
}
if (yielded || run.session.backgrounded) {
return;
}
if (outcome.status === "failed") {
reject(new Error(outcome.reason ?? "Command failed."));
return;
@@ -1475,8 +1546,12 @@ export function createExecTool(
});
})
.catch((err) => {
if (yieldTimer) clearTimeout(yieldTimer);
if (yielded || run.session.backgrounded) return;
if (yieldTimer) {
clearTimeout(yieldTimer);
}
if (yielded || run.session.backgrounded) {
return;
}
reject(err as Error);
});
});