chore: Enable "curly" rule to avoid single-statement if confusion/errors.
This commit is contained in:
@@ -44,7 +44,9 @@ export function validateA2UIJsonl(jsonl: string) {
|
||||
|
||||
lines.forEach((line, idx) => {
|
||||
const trimmed = line.trim();
|
||||
if (!trimmed) return;
|
||||
if (!trimmed) {
|
||||
return;
|
||||
}
|
||||
messageCount += 1;
|
||||
let obj: unknown;
|
||||
try {
|
||||
|
||||
@@ -22,7 +22,9 @@ export function runNodesCommand(label: string, action: () => Promise<void>) {
|
||||
const { error, warn } = getNodesTheme();
|
||||
defaultRuntime.error(error(`nodes ${label} failed: ${message}`));
|
||||
const hint = unauthorizedHintForMessage(message);
|
||||
if (hint) defaultRuntime.error(warn(hint));
|
||||
if (hint) {
|
||||
defaultRuntime.error(warn(hint));
|
||||
}
|
||||
defaultRuntime.exit(1);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -2,11 +2,17 @@ import type { NodeListNode, PairedNode, PairingList, PendingRequest } from "./ty
|
||||
|
||||
export function formatAge(msAgo: number) {
|
||||
const s = Math.max(0, Math.floor(msAgo / 1000));
|
||||
if (s < 60) return `${s}s`;
|
||||
if (s < 60) {
|
||||
return `${s}s`;
|
||||
}
|
||||
const m = Math.floor(s / 60);
|
||||
if (m < 60) return `${m}m`;
|
||||
if (m < 60) {
|
||||
return `${m}m`;
|
||||
}
|
||||
const h = Math.floor(m / 60);
|
||||
if (h < 24) return `${h}h`;
|
||||
if (h < 24) {
|
||||
return `${h}h`;
|
||||
}
|
||||
const d = Math.floor(h / 24);
|
||||
return `${d}d`;
|
||||
}
|
||||
@@ -24,12 +30,16 @@ export function parseNodeList(value: unknown): NodeListNode[] {
|
||||
}
|
||||
|
||||
export function formatPermissions(raw: unknown) {
|
||||
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return null;
|
||||
if (!raw || typeof raw !== "object" || Array.isArray(raw)) {
|
||||
return null;
|
||||
}
|
||||
const entries = Object.entries(raw as Record<string, unknown>)
|
||||
.map(([key, value]) => [String(key).trim(), value === true] as const)
|
||||
.filter(([key]) => key.length > 0)
|
||||
.toSorted((a, b) => a[0].localeCompare(b[0]));
|
||||
if (entries.length === 0) return null;
|
||||
if (entries.length === 0) {
|
||||
return null;
|
||||
}
|
||||
const parts = entries.map(([key, granted]) => `${key}=${granted ? "yes" : "no"}`);
|
||||
return `[${parts.join(", ")}]`;
|
||||
}
|
||||
|
||||
@@ -19,7 +19,9 @@ const parseFacing = (value: string): CameraFacing => {
|
||||
const v = String(value ?? "")
|
||||
.trim()
|
||||
.toLowerCase();
|
||||
if (v === "front" || v === "back") return v;
|
||||
if (v === "front" || v === "back") {
|
||||
return v;
|
||||
}
|
||||
throw new Error(`invalid facing: ${value} (expected front|back)`);
|
||||
};
|
||||
|
||||
|
||||
@@ -112,7 +112,9 @@ export function registerNodesCanvasCommands(nodes: Command) {
|
||||
height: opts.height ? Number.parseFloat(opts.height) : undefined,
|
||||
};
|
||||
const params: Record<string, unknown> = {};
|
||||
if (opts.target) params.url = String(opts.target);
|
||||
if (opts.target) {
|
||||
params.url = String(opts.target);
|
||||
}
|
||||
if (
|
||||
Number.isFinite(placement.x) ||
|
||||
Number.isFinite(placement.y) ||
|
||||
@@ -176,7 +178,9 @@ export function registerNodesCanvasCommands(nodes: Command) {
|
||||
.action(async (jsArg: string | undefined, opts: NodesRpcOpts) => {
|
||||
await runNodesCommand("canvas eval", async () => {
|
||||
const js = opts.js ?? jsArg;
|
||||
if (!js) throw new Error("missing --js or <js>");
|
||||
if (!js) {
|
||||
throw new Error("missing --js or <js>");
|
||||
}
|
||||
const raw = await invokeCanvas(opts, "canvas.eval", {
|
||||
javaScript: js,
|
||||
});
|
||||
@@ -188,8 +192,9 @@ export function registerNodesCanvasCommands(nodes: Command) {
|
||||
typeof raw === "object" && raw !== null
|
||||
? (raw as { payload?: { result?: string } }).payload
|
||||
: undefined;
|
||||
if (payload?.result) defaultRuntime.log(payload.result);
|
||||
else {
|
||||
if (payload?.result) {
|
||||
defaultRuntime.log(payload.result);
|
||||
} else {
|
||||
const { ok } = getNodesTheme();
|
||||
defaultRuntime.log(ok("canvas eval ok"));
|
||||
}
|
||||
|
||||
@@ -58,7 +58,9 @@ function normalizeExecAsk(value?: string | null): ExecAsk | null {
|
||||
}
|
||||
|
||||
function mergePathPrepend(existing: string | undefined, prepend: string[]) {
|
||||
if (prepend.length === 0) return existing;
|
||||
if (prepend.length === 0) {
|
||||
return existing;
|
||||
}
|
||||
const partsExisting = (existing ?? "")
|
||||
.split(path.delimiter)
|
||||
.map((part) => part.trim())
|
||||
@@ -66,7 +68,9 @@ function mergePathPrepend(existing: string | undefined, prepend: string[]) {
|
||||
const merged: string[] = [];
|
||||
const seen = new Set<string>();
|
||||
for (const part of [...prepend, ...partsExisting]) {
|
||||
if (seen.has(part)) continue;
|
||||
if (seen.has(part)) {
|
||||
continue;
|
||||
}
|
||||
seen.add(part);
|
||||
merged.push(part);
|
||||
}
|
||||
@@ -78,10 +82,16 @@ function applyPathPrepend(
|
||||
prepend: string[] | undefined,
|
||||
options?: { requireExisting?: boolean },
|
||||
) {
|
||||
if (!Array.isArray(prepend) || prepend.length === 0) return;
|
||||
if (options?.requireExisting && !env.PATH) return;
|
||||
if (!Array.isArray(prepend) || prepend.length === 0) {
|
||||
return;
|
||||
}
|
||||
if (options?.requireExisting && !env.PATH) {
|
||||
return;
|
||||
}
|
||||
const merged = mergePathPrepend(env.PATH, prepend);
|
||||
if (merged) env.PATH = merged;
|
||||
if (merged) {
|
||||
env.PATH = merged;
|
||||
}
|
||||
}
|
||||
|
||||
function resolveExecDefaults(
|
||||
@@ -341,8 +351,12 @@ export function registerNodesInvokeCommands(nodes: Command) {
|
||||
const timedOut = payload?.timedOut === true;
|
||||
const success = payload?.success === true;
|
||||
|
||||
if (stdout) process.stdout.write(stdout);
|
||||
if (stderr) process.stderr.write(stderr);
|
||||
if (stdout) {
|
||||
process.stdout.write(stdout);
|
||||
}
|
||||
if (stderr) {
|
||||
process.stderr.write(stderr);
|
||||
}
|
||||
if (timedOut) {
|
||||
const { error } = getNodesTheme();
|
||||
defaultRuntime.error(error("run timed out"));
|
||||
|
||||
@@ -10,8 +10,12 @@ import { shortenHomeInString } from "../../utils.js";
|
||||
|
||||
function formatVersionLabel(raw: string) {
|
||||
const trimmed = raw.trim();
|
||||
if (!trimmed) return raw;
|
||||
if (trimmed.toLowerCase().startsWith("v")) return trimmed;
|
||||
if (!trimmed) {
|
||||
return raw;
|
||||
}
|
||||
if (trimmed.toLowerCase().startsWith("v")) {
|
||||
return trimmed;
|
||||
}
|
||||
return /^\d/.test(trimmed) ? `v${trimmed}` : trimmed;
|
||||
}
|
||||
|
||||
@@ -23,9 +27,13 @@ function resolveNodeVersions(node: {
|
||||
}) {
|
||||
const core = node.coreVersion?.trim() || undefined;
|
||||
const ui = node.uiVersion?.trim() || undefined;
|
||||
if (core || ui) return { core, ui };
|
||||
if (core || ui) {
|
||||
return { core, ui };
|
||||
}
|
||||
const legacy = node.version?.trim();
|
||||
if (!legacy) return { core: undefined, ui: undefined };
|
||||
if (!legacy) {
|
||||
return { core: undefined, ui: undefined };
|
||||
}
|
||||
const platform = node.platform?.trim().toLowerCase() ?? "";
|
||||
const headless =
|
||||
platform === "darwin" || platform === "linux" || platform === "win32" || platform === "windows";
|
||||
@@ -40,15 +48,23 @@ function formatNodeVersions(node: {
|
||||
}) {
|
||||
const { core, ui } = resolveNodeVersions(node);
|
||||
const parts: string[] = [];
|
||||
if (core) parts.push(`core ${formatVersionLabel(core)}`);
|
||||
if (ui) parts.push(`ui ${formatVersionLabel(ui)}`);
|
||||
if (core) {
|
||||
parts.push(`core ${formatVersionLabel(core)}`);
|
||||
}
|
||||
if (ui) {
|
||||
parts.push(`ui ${formatVersionLabel(ui)}`);
|
||||
}
|
||||
return parts.length > 0 ? parts.join(" · ") : null;
|
||||
}
|
||||
|
||||
function formatPathEnv(raw?: string): string | null {
|
||||
if (typeof raw !== "string") return null;
|
||||
if (typeof raw !== "string") {
|
||||
return null;
|
||||
}
|
||||
const trimmed = raw.trim();
|
||||
if (!trimmed) return null;
|
||||
if (!trimmed) {
|
||||
return null;
|
||||
}
|
||||
const parts = trimmed.split(":").filter(Boolean);
|
||||
const display =
|
||||
parts.length <= 3 ? trimmed : `${parts.slice(0, 2).join(":")}:…:${parts.slice(-1)[0]}`;
|
||||
@@ -56,7 +72,9 @@ function formatPathEnv(raw?: string): string | null {
|
||||
}
|
||||
|
||||
function parseSinceMs(raw: unknown, label: string): number | undefined {
|
||||
if (raw === undefined || raw === null) return undefined;
|
||||
if (raw === undefined || raw === null) {
|
||||
return undefined;
|
||||
}
|
||||
const value =
|
||||
typeof raw === "string" ? raw.trim() : typeof raw === "number" ? String(raw).trim() : null;
|
||||
if (value === null) {
|
||||
@@ -64,7 +82,9 @@ function parseSinceMs(raw: unknown, label: string): number | undefined {
|
||||
defaultRuntime.exit(1);
|
||||
return undefined;
|
||||
}
|
||||
if (!value) return undefined;
|
||||
if (!value) {
|
||||
return undefined;
|
||||
}
|
||||
try {
|
||||
return parseDurationMs(value);
|
||||
} catch (err) {
|
||||
@@ -104,7 +124,9 @@ export function registerNodesStatusCommands(nodes: Command) {
|
||||
)
|
||||
: null;
|
||||
const filtered = nodes.filter((n) => {
|
||||
if (connectedOnly && !n.connected) return false;
|
||||
if (connectedOnly && !n.connected) {
|
||||
return false;
|
||||
}
|
||||
if (sinceMs !== undefined) {
|
||||
const paired = lastConnectedById?.get(n.nodeId);
|
||||
const lastConnectedAtMs =
|
||||
@@ -113,8 +135,12 @@ export function registerNodesStatusCommands(nodes: Command) {
|
||||
: typeof n.connectedAtMs === "number"
|
||||
? n.connectedAtMs
|
||||
: undefined;
|
||||
if (typeof lastConnectedAtMs !== "number") return false;
|
||||
if (now - lastConnectedAtMs > sinceMs) return false;
|
||||
if (typeof lastConnectedAtMs !== "number") {
|
||||
return false;
|
||||
}
|
||||
if (now - lastConnectedAtMs > sinceMs) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
});
|
||||
@@ -131,7 +157,9 @@ export function registerNodesStatusCommands(nodes: Command) {
|
||||
defaultRuntime.log(
|
||||
`Known: ${filtered.length}${filteredLabel} · Paired: ${pairedCount} · Connected: ${connectedCount}`,
|
||||
);
|
||||
if (filtered.length === 0) return;
|
||||
if (filtered.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const rows = filtered.map((n) => {
|
||||
const name = n.displayName?.trim() ? n.displayName.trim() : n.nodeId;
|
||||
@@ -261,7 +289,9 @@ export function registerNodesStatusCommands(nodes: Command) {
|
||||
defaultRuntime.log(muted("- (none reported)"));
|
||||
return;
|
||||
}
|
||||
for (const c of commands) defaultRuntime.log(`- ${c}`);
|
||||
for (const c of commands) {
|
||||
defaultRuntime.log(`- ${c}`);
|
||||
}
|
||||
});
|
||||
}),
|
||||
);
|
||||
@@ -294,7 +324,9 @@ export function registerNodesStatusCommands(nodes: Command) {
|
||||
const filteredPaired = paired.filter((node) => {
|
||||
if (connectedOnly) {
|
||||
const live = connectedById?.get(node.nodeId);
|
||||
if (!live?.connected) return false;
|
||||
if (!live?.connected) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (sinceMs !== undefined) {
|
||||
const live = connectedById?.get(node.nodeId);
|
||||
@@ -304,8 +336,12 @@ export function registerNodesStatusCommands(nodes: Command) {
|
||||
: typeof live?.connectedAtMs === "number"
|
||||
? live.connectedAtMs
|
||||
: undefined;
|
||||
if (typeof lastConnectedAtMs !== "number") return false;
|
||||
if (now - lastConnectedAtMs > sinceMs) return false;
|
||||
if (typeof lastConnectedAtMs !== "number") {
|
||||
return false;
|
||||
}
|
||||
if (now - lastConnectedAtMs > sinceMs) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
@@ -57,7 +57,9 @@ function normalizeNodeKey(value: string) {
|
||||
|
||||
export async function resolveNodeId(opts: NodesRpcOpts, query: string) {
|
||||
const q = String(query ?? "").trim();
|
||||
if (!q) throw new Error("node required");
|
||||
if (!q) {
|
||||
throw new Error("node required");
|
||||
}
|
||||
|
||||
let nodes: NodeListNode[] = [];
|
||||
try {
|
||||
@@ -77,15 +79,25 @@ export async function resolveNodeId(opts: NodesRpcOpts, query: string) {
|
||||
|
||||
const qNorm = normalizeNodeKey(q);
|
||||
const matches = nodes.filter((n) => {
|
||||
if (n.nodeId === q) return true;
|
||||
if (typeof n.remoteIp === "string" && n.remoteIp === q) return true;
|
||||
if (n.nodeId === q) {
|
||||
return true;
|
||||
}
|
||||
if (typeof n.remoteIp === "string" && n.remoteIp === q) {
|
||||
return true;
|
||||
}
|
||||
const name = typeof n.displayName === "string" ? n.displayName : "";
|
||||
if (name && normalizeNodeKey(name) === qNorm) return true;
|
||||
if (q.length >= 6 && n.nodeId.startsWith(q)) return true;
|
||||
if (name && normalizeNodeKey(name) === qNorm) {
|
||||
return true;
|
||||
}
|
||||
if (q.length >= 6 && n.nodeId.startsWith(q)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
if (matches.length === 1) return matches[0].nodeId;
|
||||
if (matches.length === 1) {
|
||||
return matches[0].nodeId;
|
||||
}
|
||||
if (matches.length === 0) {
|
||||
const known = nodes
|
||||
.map((n) => n.displayName || n.remoteIp || n.nodeId)
|
||||
|
||||
Reference in New Issue
Block a user