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

@@ -39,10 +39,14 @@ export async function resolveGlobalRoot(
runCommand: CommandRunner,
timeoutMs: number,
): Promise<string | null> {
if (manager === "bun") return resolveBunGlobalRoot();
if (manager === "bun") {
return resolveBunGlobalRoot();
}
const argv = manager === "pnpm" ? ["pnpm", "root", "-g"] : ["npm", "root", "-g"];
const res = await runCommand(argv, { timeoutMs }).catch(() => null);
if (!res || res.code !== 0) return null;
if (!res || res.code !== 0) {
return null;
}
const root = res.stdout.trim();
return root || null;
}
@@ -53,7 +57,9 @@ export async function resolveGlobalPackageRoot(
timeoutMs: number,
): Promise<string | null> {
const root = await resolveGlobalRoot(manager, runCommand, timeoutMs);
if (!root) return null;
if (!root) {
return null;
}
return path.join(root, PRIMARY_PACKAGE_NAME);
}
@@ -74,13 +80,19 @@ export async function detectGlobalInstallManagerForRoot(
for (const { manager, argv } of candidates) {
const res = await runCommand(argv, { timeoutMs }).catch(() => null);
if (!res || res.code !== 0) continue;
if (!res || res.code !== 0) {
continue;
}
const globalRoot = res.stdout.trim();
if (!globalRoot) continue;
if (!globalRoot) {
continue;
}
const globalReal = await tryRealpath(globalRoot);
for (const name of ALL_PACKAGE_NAMES) {
const expected = path.join(globalReal, name);
if (path.resolve(expected) === path.resolve(pkgReal)) return manager;
if (path.resolve(expected) === path.resolve(pkgReal)) {
return manager;
}
}
}
@@ -88,7 +100,9 @@ export async function detectGlobalInstallManagerForRoot(
const bunGlobalReal = await tryRealpath(bunGlobalRoot);
for (const name of ALL_PACKAGE_NAMES) {
const bunExpected = path.join(bunGlobalReal, name);
if (path.resolve(bunExpected) === path.resolve(pkgReal)) return "bun";
if (path.resolve(bunExpected) === path.resolve(pkgReal)) {
return "bun";
}
}
return null;
@@ -100,21 +114,31 @@ export async function detectGlobalInstallManagerByPresence(
): Promise<GlobalInstallManager | null> {
for (const manager of ["npm", "pnpm"] as const) {
const root = await resolveGlobalRoot(manager, runCommand, timeoutMs);
if (!root) continue;
if (!root) {
continue;
}
for (const name of ALL_PACKAGE_NAMES) {
if (await pathExists(path.join(root, name))) return manager;
if (await pathExists(path.join(root, name))) {
return manager;
}
}
}
const bunRoot = resolveBunGlobalRoot();
for (const name of ALL_PACKAGE_NAMES) {
if (await pathExists(path.join(bunRoot, name))) return "bun";
if (await pathExists(path.join(bunRoot, name))) {
return "bun";
}
}
return null;
}
export function globalInstallArgs(manager: GlobalInstallManager, spec: string): string[] {
if (manager === "pnpm") return ["pnpm", "add", "-g", spec];
if (manager === "bun") return ["bun", "add", "-g", spec];
if (manager === "pnpm") {
return ["pnpm", "add", "-g", spec];
}
if (manager === "bun") {
return ["bun", "add", "-g", spec];
}
return ["npm", "i", "-g", spec];
}