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

@@ -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;