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

@@ -32,7 +32,9 @@ export function getHeadersWithAuth(url: string, headers: Record<string, string>
try {
const parsed = new URL(url);
const hasAuthHeader = Object.keys(headers).some((key) => key.toLowerCase() === "authorization");
if (hasAuthHeader) return headers;
if (hasAuthHeader) {
return headers;
}
if (parsed.username || parsed.password) {
const auth = Buffer.from(`${parsed.username}:${parsed.password}`).toString("base64");
return { ...headers, Authorization: `Basic ${auth}` };
@@ -65,7 +67,9 @@ function createCdpSender(ws: WebSocket) {
};
const closeWithError = (err: Error) => {
for (const [, p] of pending) p.reject(err);
for (const [, p] of pending) {
p.reject(err);
}
pending.clear();
try {
ws.close();
@@ -77,9 +81,13 @@ function createCdpSender(ws: WebSocket) {
ws.on("message", (data) => {
try {
const parsed = JSON.parse(rawDataToString(data)) as CdpResponse;
if (typeof parsed.id !== "number") return;
if (typeof parsed.id !== "number") {
return;
}
const p = pending.get(parsed.id);
if (!p) return;
if (!p) {
return;
}
pending.delete(parsed.id);
if (parsed.error?.message) {
p.reject(new Error(parsed.error.message));
@@ -104,7 +112,9 @@ export async function fetchJson<T>(url: string, timeoutMs = 1500, init?: Request
try {
const headers = getHeadersWithAuth(url, (init?.headers as Record<string, string>) || {});
const res = await fetch(url, { ...init, headers, signal: ctrl.signal });
if (!res.ok) throw new Error(`HTTP ${res.status}`);
if (!res.ok) {
throw new Error(`HTTP ${res.status}`);
}
return (await res.json()) as T;
} finally {
clearTimeout(t);
@@ -117,7 +127,9 @@ export async function fetchOk(url: string, timeoutMs = 1500, init?: RequestInit)
try {
const headers = getHeadersWithAuth(url, (init?.headers as Record<string, string>) || {});
const res = await fetch(url, { ...init, headers, signal: ctrl.signal });
if (!res.ok) throw new Error(`HTTP ${res.status}`);
if (!res.ok) {
throw new Error(`HTTP ${res.status}`);
}
} finally {
clearTimeout(t);
}