Skip to content

Commit aedb0e2

Browse files
committed
refactor(fmt): simplify duration formatting
1 parent c77751a commit aedb0e2

1 file changed

Lines changed: 8 additions & 12 deletions

File tree

packages/rstack/src/fmt/cli.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,6 @@ const createDisplayPathResolver = (
158158
return (filePath) => toPosixPath(resolveRelativePath(filePath));
159159
};
160160

161-
const prettyTime = (milliseconds: number): string =>
162-
color.bold(formatDuration(milliseconds));
163-
164161
const formatCount = (count: number): string => color.bold(count);
165162
const formatFileCount = (count: number, isError = false): string => {
166163
const formattedCount = formatCount(count);
@@ -204,13 +201,18 @@ const logFmtResult = (
204201
}
205202
}
206203

204+
if (mode === 'list-different') {
205+
return;
206+
}
207+
208+
const time = color.bold(formatDuration(durationMilliseconds));
209+
207210
if (mode === 'write') {
208211
if (writtenCount === 0 && result.exitCode !== 0) {
209212
return;
210213
}
211214

212215
const processedFiles = formatFileCount(processedFileCount);
213-
const time = prettyTime(durationMilliseconds);
214216
const message =
215217
writtenCount > 0
216218
? `Formatted ${formatCount(writtenCount)} of ${processedFiles} in ${time}.`
@@ -219,23 +221,17 @@ const logFmtResult = (
219221
return;
220222
}
221223

222-
if (mode !== 'check') {
223-
return;
224-
}
225-
226224
if (differentCount > 0) {
227225
const differentFiles = formatFileCount(differentCount, true);
228226
const processedFiles = formatFileCount(processedFileCount);
229227
const fixHint = fixCommand
230228
? `Run ${color.cyan(fixCommand)} to fix.`
231229
: `Rerun this command without ${color.cyan('--check')} to fix.`;
232230
logger.error(`Formatting issues found in ${differentFiles}. ${fixHint}`);
233-
logger.info(
234-
`Checked ${processedFiles} in ${prettyTime(durationMilliseconds)}.`,
235-
);
231+
logger.info(`Checked ${processedFiles} in ${time}.`);
236232
} else if (result.exitCode === 0) {
237233
logger.success(
238-
`Checked ${formatFileCount(processedFileCount)} in ${prettyTime(durationMilliseconds)}. No issues found.`,
234+
`Checked ${formatFileCount(processedFileCount)} in ${time}. No issues found.`,
239235
);
240236
}
241237
};

0 commit comments

Comments
 (0)