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

@@ -29,7 +29,9 @@ function parsePossiblyNoisyJsonObject(stdout: string): Record<string, unknown> {
export async function findTailscaleBinary(): Promise<string | null> {
// Helper to check if a binary exists and is executable
const checkBinary = async (path: string): Promise<boolean> => {
if (!path || !existsSync(path)) return false;
if (!path || !existsSync(path)) {
return false;
}
try {
// Use Promise.race with runExec to implement timeout
await Promise.race([
@@ -109,7 +111,9 @@ export async function getTailnetHostname(exec: typeof runExec = runExec, detecte
let lastError: unknown;
for (const candidate of candidates) {
if (candidate.startsWith("/") && !existsSync(candidate)) continue;
if (candidate.startsWith("/") && !existsSync(candidate)) {
continue;
}
try {
const { stdout } = await exec(candidate, ["status", "--json"], {
timeoutMs: 5000,
@@ -124,8 +128,12 @@ export async function getTailnetHostname(exec: typeof runExec = runExec, detecte
const ips = Array.isArray(self?.TailscaleIPs)
? ((parsed.Self as { TailscaleIPs?: string[] }).TailscaleIPs ?? [])
: [];
if (dns && dns.length > 0) return dns.replace(/\.$/, "");
if (ips.length > 0) return ips[0];
if (dns && dns.length > 0) {
return dns.replace(/\.$/, "");
}
if (ips.length > 0) {
return ips[0];
}
throw new Error("Could not determine Tailscale DNS or IP");
} catch (err) {
lastError = err;
@@ -142,7 +150,9 @@ export async function getTailnetHostname(exec: typeof runExec = runExec, detecte
let cachedTailscaleBinary: string | null = null;
export async function getTailscaleBinary(): Promise<string> {
if (cachedTailscaleBinary) return cachedTailscaleBinary;
if (cachedTailscaleBinary) {
return cachedTailscaleBinary;
}
cachedTailscaleBinary = await findTailscaleBinary();
return cachedTailscaleBinary ?? "tailscale";
}
@@ -169,7 +179,9 @@ export async function ensureGoInstalled(
() => true,
() => false,
);
if (hasGo) return;
if (hasGo) {
return;
}
const install = await prompt(
"Go is not installed. Install via Homebrew (brew install go)?",
true,
@@ -192,7 +204,9 @@ export async function ensureTailscaledInstalled(
() => true,
() => false,
);
if (hasTailscaled) return;
if (hasTailscaled) {
return;
}
const install = await prompt(
"tailscaled not found. Install via Homebrew (tailscale package)?",
@@ -236,7 +250,9 @@ function extractExecErrorText(err: unknown) {
function isPermissionDeniedError(err: unknown): boolean {
const { stdout, stderr, message, code } = extractExecErrorText(err);
if (code.toUpperCase() === "EACCES") return true;
if (code.toUpperCase() === "EACCES") {
return true;
}
const combined = `${stdout}\n${stderr}\n${message}`.toLowerCase();
return (
combined.includes("permission denied") ||
@@ -270,7 +286,9 @@ async function execWithSudoFallback(
} catch (sudoErr) {
const { stderr, message } = extractExecErrorText(sudoErr);
const detail = (stderr || message).trim();
if (detail) logVerbose(`Sudo retry failed: ${detail}`);
if (detail) {
logVerbose(`Sudo retry failed: ${detail}`);
}
throw err;
}
}
@@ -300,7 +318,9 @@ export async function ensureFunnel(
),
);
const proceed = await prompt("Attempt local setup with user-space tailscaled?", true);
if (!proceed) runtime.exit(1);
if (!proceed) {
runtime.exit(1);
}
await ensureBinary("brew", exec, runtime);
await ensureGoInstalled(exec, prompt, runtime);
await ensureTailscaledInstalled(exec, prompt, runtime);
@@ -317,7 +337,9 @@ export async function ensureFunnel(
timeoutMs: 15_000,
},
);
if (stdout.trim()) console.log(stdout.trim());
if (stdout.trim()) {
console.log(stdout.trim());
}
} catch (err) {
const errOutput = err as { stdout?: unknown; stderr?: unknown };
const stdout = typeof errOutput.stdout === "string" ? errOutput.stdout : "";
@@ -411,7 +433,9 @@ function parseWhoisIdentity(payload: Record<string, unknown>): TailscaleWhoisIde
getString(userProfile?.login) ??
getString(payload.LoginName) ??
getString(payload.login);
if (!login) return null;
if (!login) {
return null;
}
const name =
getString(userProfile?.DisplayName) ??
getString(userProfile?.Name) ??
@@ -423,7 +447,9 @@ function parseWhoisIdentity(payload: Record<string, unknown>): TailscaleWhoisIde
function readCachedWhois(ip: string, now: number): TailscaleWhoisIdentity | null | undefined {
const cached = whoisCache.get(ip);
if (!cached) return undefined;
if (!cached) {
return undefined;
}
if (cached.expiresAt <= now) {
whoisCache.delete(ip);
return undefined;
@@ -441,10 +467,14 @@ export async function readTailscaleWhoisIdentity(
opts?: { timeoutMs?: number; cacheTtlMs?: number; errorTtlMs?: number },
): Promise<TailscaleWhoisIdentity | null> {
const normalized = ip.trim();
if (!normalized) return null;
if (!normalized) {
return null;
}
const now = Date.now();
const cached = readCachedWhois(normalized, now);
if (cached !== undefined) return cached;
if (cached !== undefined) {
return cached;
}
const cacheTtlMs = opts?.cacheTtlMs ?? 60_000;
const errorTtlMs = opts?.errorTtlMs ?? 5_000;