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
+21 -7
View File
@@ -18,8 +18,12 @@ function resolveMaxLinks(value?: number): number {
function isAllowedUrl(raw: string): boolean {
try {
const parsed = new URL(raw);
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") return false;
if (parsed.hostname === "127.0.0.1") return false;
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
return false;
}
if (parsed.hostname === "127.0.0.1") {
return false;
}
return true;
} catch {
return false;
@@ -28,7 +32,9 @@ function isAllowedUrl(raw: string): boolean {
export function extractLinksFromMessage(message: string, opts?: { maxLinks?: number }): string[] {
const source = message?.trim();
if (!source) return [];
if (!source) {
return [];
}
const maxLinks = resolveMaxLinks(opts?.maxLinks);
const sanitized = stripMarkdownLinks(source);
@@ -37,12 +43,20 @@ export function extractLinksFromMessage(message: string, opts?: { maxLinks?: num
for (const match of sanitized.matchAll(BARE_LINK_RE)) {
const raw = match[0]?.trim();
if (!raw) continue;
if (!isAllowedUrl(raw)) continue;
if (seen.has(raw)) continue;
if (!raw) {
continue;
}
if (!isAllowedUrl(raw)) {
continue;
}
if (seen.has(raw)) {
continue;
}
seen.add(raw);
results.push(raw);
if (results.length >= maxLinks) break;
if (results.length >= maxLinks) {
break;
}
}
return results;
+3 -1
View File
@@ -5,6 +5,8 @@ export function formatLinkUnderstandingBody(params: { body?: string; outputs: st
}
const base = (params.body ?? "").trim();
if (!base) return outputs.join("\n");
if (!base) {
return outputs.join("\n");
}
return `${base}\n\n${outputs.join("\n")}`;
}
+21 -7
View File
@@ -44,9 +44,13 @@ async function runCliEntry(params: {
url: string;
config?: LinkToolsConfig;
}): Promise<string | null> {
if ((params.entry.type ?? "cli") !== "cli") return null;
if ((params.entry.type ?? "cli") !== "cli") {
return null;
}
const command = params.entry.command.trim();
if (!command) return null;
if (!command) {
return null;
}
const args = params.entry.args ?? [];
const timeoutMs = resolveTimeoutMsFromConfig({ config: params.config, entry: params.entry });
const templCtx = {
@@ -84,7 +88,9 @@ async function runLinkEntries(params: {
url: params.url,
config: params.config,
});
if (output) return output;
if (output) {
return output;
}
} catch (err) {
lastError = err;
if (shouldLogVerbose()) {
@@ -104,7 +110,9 @@ export async function runLinkUnderstanding(params: {
message?: string;
}): Promise<LinkUnderstandingResult> {
const config = params.cfg.tools?.links;
if (!config || config.enabled === false) return { urls: [], outputs: [] };
if (!config || config.enabled === false) {
return { urls: [], outputs: [] };
}
const scopeDecision = resolveScopeDecision({ config, ctx: params.ctx });
if (scopeDecision === "deny") {
@@ -116,10 +124,14 @@ export async function runLinkUnderstanding(params: {
const message = params.message ?? params.ctx.CommandBody ?? params.ctx.RawBody ?? params.ctx.Body;
const links = extractLinksFromMessage(message ?? "", { maxLinks: config?.maxLinks });
if (links.length === 0) return { urls: [], outputs: [] };
if (links.length === 0) {
return { urls: [], outputs: [] };
}
const entries = config?.models ?? [];
if (entries.length === 0) return { urls: links, outputs: [] };
if (entries.length === 0) {
return { urls: links, outputs: [] };
}
const outputs: string[] = [];
for (const url of links) {
@@ -129,7 +141,9 @@ export async function runLinkUnderstanding(params: {
url,
config,
});
if (output) outputs.push(output);
if (output) {
outputs.push(output);
}
}
return { urls: links, outputs };