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

@@ -44,7 +44,9 @@ const routeHealth: RouteSpec = {
const json = hasFlag(argv, "--json");
const verbose = getVerboseFlag(argv, { includeDebug: true });
const timeoutMs = getPositiveIntFlagValue(argv, "--timeout");
if (timeoutMs === null) return false;
if (timeoutMs === null) {
return false;
}
await healthCommand({ json, timeoutMs, verbose }, defaultRuntime);
return true;
},
@@ -60,7 +62,9 @@ const routeStatus: RouteSpec = {
const usage = hasFlag(argv, "--usage");
const verbose = getVerboseFlag(argv, { includeDebug: true });
const timeoutMs = getPositiveIntFlagValue(argv, "--timeout");
if (timeoutMs === null) return false;
if (timeoutMs === null) {
return false;
}
await statusCommand({ json, deep, all, usage, timeoutMs, verbose }, defaultRuntime);
return true;
},
@@ -71,9 +75,13 @@ const routeSessions: RouteSpec = {
run: async (argv) => {
const json = hasFlag(argv, "--json");
const store = getFlagValue(argv, "--store");
if (store === null) return false;
if (store === null) {
return false;
}
const active = getFlagValue(argv, "--active");
if (active === null) return false;
if (active === null) {
return false;
}
await sessionsCommand({ json, store, active }, defaultRuntime);
return true;
},
@@ -93,7 +101,9 @@ const routeMemoryStatus: RouteSpec = {
match: (path) => path[0] === "memory" && path[1] === "status",
run: async (argv) => {
const agent = getFlagValue(argv, "--agent");
if (agent === null) return false;
if (agent === null) {
return false;
}
const json = hasFlag(argv, "--json");
const deep = hasFlag(argv, "--deep");
const index = hasFlag(argv, "--index");
@@ -166,9 +176,13 @@ export function registerProgramCommands(
export function findRoutedCommand(path: string[]): RouteSpec | null {
for (const entry of commandRegistry) {
if (!entry.routes) continue;
if (!entry.routes) {
continue;
}
for (const route of entry.routes) {
if (route.match(path)) return route;
if (route.match(path)) {
return route;
}
}
}
return null;

View File

@@ -52,7 +52,9 @@ export async function ensureConfigReady(params: {
: [];
const invalid = snapshot.exists && !snapshot.valid;
if (!invalid) return;
if (!invalid) {
return;
}
const rich = isRich();
const muted = (value: string) => colorize(rich, theme.muted, value);

View File

@@ -73,7 +73,9 @@ export function configureProgramHelp(program: Command, ctx: ProgramContext) {
}
program.addHelpText("beforeAll", () => {
if (hasEmittedCliBanner()) return "";
if (hasEmittedCliBanner()) {
return "";
}
const rich = isRich();
const line = formatCliBannerLine(ctx.programVersion, { richTty: rich });
return `\n${line}\n`;
@@ -84,7 +86,9 @@ export function configureProgramHelp(program: Command, ctx: ProgramContext) {
).join("\n");
program.addHelpText("afterAll", ({ command }) => {
if (command !== program) return "";
if (command !== program) {
return "";
}
const docs = formatDocsLink("/cli", "docs.openclaw.ai/cli");
return `\n${theme.heading("Examples:")}\n${fmtExamples}\n\n${theme.muted("Docs:")} ${docs}\n`;
});

View File

@@ -3,22 +3,30 @@ export function collectOption(value: string, previous: string[] = []): string[]
}
export function parsePositiveIntOrUndefined(value: unknown): number | undefined {
if (value === undefined || value === null || value === "") return undefined;
if (value === undefined || value === null || value === "") {
return undefined;
}
if (typeof value === "number") {
if (!Number.isFinite(value)) return undefined;
if (!Number.isFinite(value)) {
return undefined;
}
const parsed = Math.trunc(value);
return parsed > 0 ? parsed : undefined;
}
if (typeof value === "string") {
const parsed = Number.parseInt(value, 10);
if (Number.isNaN(parsed) || parsed <= 0) return undefined;
if (Number.isNaN(parsed) || parsed <= 0) {
return undefined;
}
return parsed;
}
return undefined;
}
export function resolveActionArgs(actionCommand?: import("commander").Command): string[] {
if (!actionCommand) return [];
if (!actionCommand) {
return [];
}
const args = (actionCommand as import("commander").Command & { args?: string[] }).args;
return Array.isArray(args) ? args : [];
}

View File

@@ -15,7 +15,9 @@ function setProcessTitleForCommand(actionCommand: Command) {
}
const name = current.name();
const cliName = resolveCliName();
if (!name || name === cliName) return;
if (!name || name === cliName) {
return;
}
process.title = `${cliName}-${name}`;
}
@@ -26,7 +28,9 @@ export function registerPreActionHooks(program: Command, programVersion: string)
program.hook("preAction", async (_thisCommand, actionCommand) => {
setProcessTitleForCommand(actionCommand);
const argv = process.argv;
if (hasHelpOrVersion(argv)) return;
if (hasHelpOrVersion(argv)) {
return;
}
const commandPath = getCommandPath(argv, 2);
const hideBanner =
isTruthyEnvValue(process.env.OPENCLAW_HIDE_BANNER) ||
@@ -41,7 +45,9 @@ export function registerPreActionHooks(program: Command, programVersion: string)
if (!verbose) {
process.env.NODE_NO_WARNINGS ??= "1";
}
if (commandPath[0] === "doctor" || commandPath[0] === "completion") return;
if (commandPath[0] === "doctor" || commandPath[0] === "completion") {
return;
}
await ensureConfigReady({ runtime: defaultRuntime, commandPath });
// Load plugins for commands that need channel access
if (PLUGIN_REQUIRED_COMMANDS.has(commandPath[0])) {

View File

@@ -17,14 +17,20 @@ function resolveInstallDaemonFlag(
command: unknown,
opts: { installDaemon?: boolean },
): boolean | undefined {
if (!command || typeof command !== "object") return undefined;
if (!command || typeof command !== "object") {
return undefined;
}
const getOptionValueSource =
"getOptionValueSource" in command ? command.getOptionValueSource : undefined;
if (typeof getOptionValueSource !== "function") return undefined;
if (typeof getOptionValueSource !== "function") {
return undefined;
}
// Commander doesn't support option conflicts natively; keep original behavior.
// If --skip-daemon is explicitly passed, it wins.
if (getOptionValueSource.call(command, "skipDaemon") === "cli") return false;
if (getOptionValueSource.call(command, "skipDaemon") === "cli") {
return false;
}
if (getOptionValueSource.call(command, "installDaemon") === "cli") {
return Boolean(opts.installDaemon);
}

View File

@@ -13,8 +13,12 @@ type SubCliEntry = {
};
const shouldRegisterPrimaryOnly = (argv: string[]) => {
if (isTruthyEnvValue(process.env.OPENCLAW_DISABLE_LAZY_SUBCOMMANDS)) return false;
if (hasHelpOrVersion(argv)) return false;
if (isTruthyEnvValue(process.env.OPENCLAW_DISABLE_LAZY_SUBCOMMANDS)) {
return false;
}
if (hasHelpOrVersion(argv)) {
return false;
}
return true;
};
@@ -251,9 +255,13 @@ function removeCommand(program: Command, command: Command) {
export async function registerSubCliByName(program: Command, name: string): Promise<boolean> {
const entry = entries.find((candidate) => candidate.name === name);
if (!entry) return false;
if (!entry) {
return false;
}
const existing = program.commands.find((cmd) => cmd.name() === entry.name);
if (existing) removeCommand(program, existing);
if (existing) {
removeCommand(program, existing);
}
await entry.register(program);
return true;
}