mirror of
https://github.com/moltbot/moltbot.git
synced 2026-04-23 22:55:24 +00:00
chore: Enable "curly" rule to avoid single-statement if confusion/errors.
This commit is contained in:
@@ -21,9 +21,13 @@ const DEV_TEMPLATE_DIR = path.resolve(
|
||||
async function loadDevTemplate(name: string, fallback: string): Promise<string> {
|
||||
try {
|
||||
const raw = await fs.promises.readFile(path.join(DEV_TEMPLATE_DIR, name), "utf-8");
|
||||
if (!raw.startsWith("---")) return raw;
|
||||
if (!raw.startsWith("---")) {
|
||||
return raw;
|
||||
}
|
||||
const endIndex = raw.indexOf("\n---", 3);
|
||||
if (endIndex === -1) return raw;
|
||||
if (endIndex === -1) {
|
||||
return raw;
|
||||
}
|
||||
return raw.slice(endIndex + "\n---".length).replace(/^\s+/, "");
|
||||
} catch {
|
||||
return fallback;
|
||||
@@ -33,7 +37,9 @@ async function loadDevTemplate(name: string, fallback: string): Promise<string>
|
||||
const resolveDevWorkspaceDir = (env: NodeJS.ProcessEnv = process.env): string => {
|
||||
const baseDir = resolveDefaultAgentWorkspaceDir(env, os.homedir);
|
||||
const profile = env.OPENCLAW_PROFILE?.trim().toLowerCase();
|
||||
if (profile === "dev") return baseDir;
|
||||
if (profile === "dev") {
|
||||
return baseDir;
|
||||
}
|
||||
return `${baseDir}-${DEV_AGENT_WORKSPACE_SUFFIX}`;
|
||||
};
|
||||
|
||||
@@ -45,7 +51,9 @@ async function writeFileIfMissing(filePath: string, content: string) {
|
||||
});
|
||||
} catch (err) {
|
||||
const anyErr = err as { code?: string };
|
||||
if (anyErr.code !== "EEXIST") throw err;
|
||||
if (anyErr.code !== "EEXIST") {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,7 +100,9 @@ export async function ensureDevGatewayConfig(opts: { reset?: boolean }) {
|
||||
const io = createConfigIO();
|
||||
const configPath = io.configPath;
|
||||
const configExists = fs.existsSync(configPath);
|
||||
if (!opts.reset && configExists) return;
|
||||
if (!opts.reset && configExists) {
|
||||
return;
|
||||
}
|
||||
|
||||
await writeConfigFile({
|
||||
gateway: {
|
||||
|
||||
@@ -7,7 +7,9 @@ export type GatewayDiscoverOpts = {
|
||||
};
|
||||
|
||||
export function parseDiscoverTimeoutMs(raw: unknown, fallbackMs: number): number {
|
||||
if (raw === undefined || raw === null) return fallbackMs;
|
||||
if (raw === undefined || raw === null) {
|
||||
return fallbackMs;
|
||||
}
|
||||
const value =
|
||||
typeof raw === "string"
|
||||
? raw.trim()
|
||||
@@ -17,7 +19,9 @@ export function parseDiscoverTimeoutMs(raw: unknown, fallbackMs: number): number
|
||||
if (value === null) {
|
||||
throw new Error("invalid --timeout");
|
||||
}
|
||||
if (!value) return fallbackMs;
|
||||
if (!value) {
|
||||
return fallbackMs;
|
||||
}
|
||||
const parsed = Number.parseInt(value, 10);
|
||||
if (!Number.isFinite(parsed) || parsed <= 0) {
|
||||
throw new Error(`invalid --timeout: ${value}`);
|
||||
@@ -48,7 +52,9 @@ export function dedupeBeacons(beacons: GatewayBonjourBeacon[]): GatewayBonjourBe
|
||||
String(b.port ?? ""),
|
||||
String(b.gatewayPort ?? ""),
|
||||
].join("|");
|
||||
if (seen.has(key)) continue;
|
||||
if (seen.has(key)) {
|
||||
continue;
|
||||
}
|
||||
seen.add(key);
|
||||
out.push(b);
|
||||
}
|
||||
|
||||
@@ -31,9 +31,13 @@ import {
|
||||
import { addGatewayRunCommand } from "./run.js";
|
||||
|
||||
function styleHealthChannelLine(line: string, rich: boolean): string {
|
||||
if (!rich) return line;
|
||||
if (!rich) {
|
||||
return line;
|
||||
}
|
||||
const colon = line.indexOf(":");
|
||||
if (colon === -1) return line;
|
||||
if (colon === -1) {
|
||||
return line;
|
||||
}
|
||||
|
||||
const label = line.slice(0, colon + 1);
|
||||
const detail = line.slice(colon + 1).trimStart();
|
||||
@@ -42,13 +46,27 @@ function styleHealthChannelLine(line: string, rich: boolean): string {
|
||||
const applyPrefix = (prefix: string, color: (value: string) => string) =>
|
||||
`${label} ${color(detail.slice(0, prefix.length))}${detail.slice(prefix.length)}`;
|
||||
|
||||
if (normalized.startsWith("failed")) return applyPrefix("failed", theme.error);
|
||||
if (normalized.startsWith("ok")) return applyPrefix("ok", theme.success);
|
||||
if (normalized.startsWith("linked")) return applyPrefix("linked", theme.success);
|
||||
if (normalized.startsWith("configured")) return applyPrefix("configured", theme.success);
|
||||
if (normalized.startsWith("not linked")) return applyPrefix("not linked", theme.warn);
|
||||
if (normalized.startsWith("not configured")) return applyPrefix("not configured", theme.muted);
|
||||
if (normalized.startsWith("unknown")) return applyPrefix("unknown", theme.warn);
|
||||
if (normalized.startsWith("failed")) {
|
||||
return applyPrefix("failed", theme.error);
|
||||
}
|
||||
if (normalized.startsWith("ok")) {
|
||||
return applyPrefix("ok", theme.success);
|
||||
}
|
||||
if (normalized.startsWith("linked")) {
|
||||
return applyPrefix("linked", theme.success);
|
||||
}
|
||||
if (normalized.startsWith("configured")) {
|
||||
return applyPrefix("configured", theme.success);
|
||||
}
|
||||
if (normalized.startsWith("not linked")) {
|
||||
return applyPrefix("not linked", theme.warn);
|
||||
}
|
||||
if (normalized.startsWith("not configured")) {
|
||||
return applyPrefix("not configured", theme.muted);
|
||||
}
|
||||
if (normalized.startsWith("unknown")) {
|
||||
return applyPrefix("unknown", theme.warn);
|
||||
}
|
||||
|
||||
return line;
|
||||
}
|
||||
@@ -62,10 +80,14 @@ function runGatewayCommand(action: () => Promise<void>, label?: string) {
|
||||
}
|
||||
|
||||
function parseDaysOption(raw: unknown, fallback = 30): number {
|
||||
if (typeof raw === "number" && Number.isFinite(raw)) return Math.max(1, Math.floor(raw));
|
||||
if (typeof raw === "number" && Number.isFinite(raw)) {
|
||||
return Math.max(1, Math.floor(raw));
|
||||
}
|
||||
if (typeof raw === "string" && raw.trim() !== "") {
|
||||
const parsed = Number(raw);
|
||||
if (Number.isFinite(parsed)) return Math.max(1, Math.floor(parsed));
|
||||
if (Number.isFinite(parsed)) {
|
||||
return Math.max(1, Math.floor(parsed));
|
||||
}
|
||||
}
|
||||
return fallback;
|
||||
}
|
||||
@@ -324,7 +346,9 @@ export function registerGatewayCli(program: Command) {
|
||||
`Found ${deduped.length} gateway(s) · domains: ${domains.join(", ")}`,
|
||||
),
|
||||
);
|
||||
if (deduped.length === 0) return;
|
||||
if (deduped.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (const beacon of deduped) {
|
||||
for (const line of renderBeaconLines(beacon, rich)) {
|
||||
|
||||
@@ -8,30 +8,48 @@ import { defaultRuntime } from "../../runtime.js";
|
||||
import { formatCliCommand } from "../command-format.js";
|
||||
|
||||
export function parsePort(raw: unknown): number | null {
|
||||
if (raw === undefined || raw === null) return null;
|
||||
if (raw === undefined || raw === null) {
|
||||
return null;
|
||||
}
|
||||
const value =
|
||||
typeof raw === "string"
|
||||
? raw
|
||||
: typeof raw === "number" || typeof raw === "bigint"
|
||||
? raw.toString()
|
||||
: null;
|
||||
if (value === null) return null;
|
||||
if (value === null) {
|
||||
return null;
|
||||
}
|
||||
const parsed = Number.parseInt(value, 10);
|
||||
if (!Number.isFinite(parsed) || parsed <= 0) return null;
|
||||
if (!Number.isFinite(parsed) || parsed <= 0) {
|
||||
return null;
|
||||
}
|
||||
return parsed;
|
||||
}
|
||||
|
||||
export const toOptionString = (value: unknown): string | undefined => {
|
||||
if (typeof value === "string") return value;
|
||||
if (typeof value === "number" || typeof value === "bigint") return value.toString();
|
||||
if (typeof value === "string") {
|
||||
return value;
|
||||
}
|
||||
if (typeof value === "number" || typeof value === "bigint") {
|
||||
return value.toString();
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
|
||||
export function describeUnknownError(err: unknown): string {
|
||||
if (err instanceof Error) return err.message;
|
||||
if (typeof err === "string") return err;
|
||||
if (typeof err === "number" || typeof err === "bigint") return err.toString();
|
||||
if (typeof err === "boolean") return err ? "true" : "false";
|
||||
if (err instanceof Error) {
|
||||
return err.message;
|
||||
}
|
||||
if (typeof err === "string") {
|
||||
return err;
|
||||
}
|
||||
if (typeof err === "number" || typeof err === "bigint") {
|
||||
return err.toString();
|
||||
}
|
||||
if (typeof err === "boolean") {
|
||||
return err ? "true" : "false";
|
||||
}
|
||||
if (err && typeof err === "object") {
|
||||
if ("message" in err && typeof err.message === "string") {
|
||||
return err.message;
|
||||
@@ -94,7 +112,9 @@ export async function maybeExplainGatewayServiceStop() {
|
||||
} catch {
|
||||
loaded = null;
|
||||
}
|
||||
if (loaded === false) return;
|
||||
if (loaded === false) {
|
||||
return;
|
||||
}
|
||||
defaultRuntime.error(
|
||||
loaded
|
||||
? `Gateway service appears ${service.loadedText}. Stop it first.`
|
||||
|
||||
Reference in New Issue
Block a user