mirror of
https://github.com/moltbot/moltbot.git
synced 2026-04-23 14:45:46 +00:00
chore: Enable "curly" rule to avoid single-statement if confusion/errors.
This commit is contained in:
@@ -41,13 +41,19 @@ const noopReporter: ProgressReporter = {
|
||||
};
|
||||
|
||||
export function createCliProgress(options: ProgressOptions): ProgressReporter {
|
||||
if (options.enabled === false) return noopReporter;
|
||||
if (activeProgress > 0) return noopReporter;
|
||||
if (options.enabled === false) {
|
||||
return noopReporter;
|
||||
}
|
||||
if (activeProgress > 0) {
|
||||
return noopReporter;
|
||||
}
|
||||
|
||||
const stream = options.stream ?? process.stderr;
|
||||
const isTty = stream.isTTY;
|
||||
const allowLog = !isTty && options.fallback === "log";
|
||||
if (!isTty && !allowLog) return noopReporter;
|
||||
if (!isTty && !allowLog) {
|
||||
return noopReporter;
|
||||
}
|
||||
|
||||
const delayMs = typeof options.delayMs === "number" ? options.delayMs : DEFAULT_DELAY_MS;
|
||||
const canOsc = isTty && supportsOscProgress(process.env, isTty);
|
||||
@@ -78,7 +84,9 @@ export function createCliProgress(options: ProgressOptions): ProgressReporter {
|
||||
const spin = allowSpinner ? spinner() : null;
|
||||
const renderLine = allowLine
|
||||
? () => {
|
||||
if (!started) return;
|
||||
if (!started) {
|
||||
return;
|
||||
}
|
||||
const suffix = indeterminate ? "" : ` ${percent}%`;
|
||||
clearActiveProgressLine();
|
||||
stream.write(`${theme.accent(label)}${suffix}`);
|
||||
@@ -90,11 +98,15 @@ export function createCliProgress(options: ProgressOptions): ProgressReporter {
|
||||
let lastAt = 0;
|
||||
const throttleMs = 250;
|
||||
return () => {
|
||||
if (!started) return;
|
||||
if (!started) {
|
||||
return;
|
||||
}
|
||||
const suffix = indeterminate ? "" : ` ${percent}%`;
|
||||
const nextLine = `${label}${suffix}`;
|
||||
const now = Date.now();
|
||||
if (nextLine === lastLine && now - lastAt < throttleMs) return;
|
||||
if (nextLine === lastLine && now - lastAt < throttleMs) {
|
||||
return;
|
||||
}
|
||||
lastLine = nextLine;
|
||||
lastAt = now;
|
||||
stream.write(`${nextLine}\n`);
|
||||
@@ -104,10 +116,15 @@ export function createCliProgress(options: ProgressOptions): ProgressReporter {
|
||||
let timer: NodeJS.Timeout | null = null;
|
||||
|
||||
const applyState = () => {
|
||||
if (!started) return;
|
||||
if (!started) {
|
||||
return;
|
||||
}
|
||||
if (controller) {
|
||||
if (indeterminate) controller.setIndeterminate(label);
|
||||
else controller.setPercent(label, percent);
|
||||
if (indeterminate) {
|
||||
controller.setIndeterminate(label);
|
||||
} else {
|
||||
controller.setPercent(label, percent);
|
||||
}
|
||||
}
|
||||
if (spin) {
|
||||
spin.message(theme.accent(label));
|
||||
@@ -121,7 +138,9 @@ export function createCliProgress(options: ProgressOptions): ProgressReporter {
|
||||
};
|
||||
|
||||
const start = () => {
|
||||
if (started) return;
|
||||
if (started) {
|
||||
return;
|
||||
}
|
||||
started = true;
|
||||
if (spin) {
|
||||
spin.start(theme.accent(label));
|
||||
@@ -147,7 +166,9 @@ export function createCliProgress(options: ProgressOptions): ProgressReporter {
|
||||
};
|
||||
|
||||
const tick = (delta = 1) => {
|
||||
if (!total) return;
|
||||
if (!total) {
|
||||
return;
|
||||
}
|
||||
completed = Math.min(total, completed + delta);
|
||||
const nextPercent = total > 0 ? Math.round((completed / total) * 100) : 0;
|
||||
setPercent(nextPercent);
|
||||
@@ -162,8 +183,12 @@ export function createCliProgress(options: ProgressOptions): ProgressReporter {
|
||||
activeProgress = Math.max(0, activeProgress - 1);
|
||||
return;
|
||||
}
|
||||
if (controller) controller.clear();
|
||||
if (spin) spin.stop();
|
||||
if (controller) {
|
||||
controller.clear();
|
||||
}
|
||||
if (spin) {
|
||||
spin.stop();
|
||||
}
|
||||
clearActiveProgressLine();
|
||||
if (isTty) {
|
||||
unregisterActiveProgressLine(stream);
|
||||
@@ -192,8 +217,12 @@ export async function withProgressTotals<T>(
|
||||
): Promise<T> {
|
||||
return await withProgress(options, async (progress) => {
|
||||
const update = ({ completed, total, label }: ProgressTotalsUpdate) => {
|
||||
if (label) progress.setLabel(label);
|
||||
if (!Number.isFinite(total) || total <= 0) return;
|
||||
if (label) {
|
||||
progress.setLabel(label);
|
||||
}
|
||||
if (!Number.isFinite(total) || total <= 0) {
|
||||
return;
|
||||
}
|
||||
progress.setPercent((completed / total) * 100);
|
||||
};
|
||||
return await work(update, progress);
|
||||
|
||||
Reference in New Issue
Block a user