Skip to content

Commit 940e82a

Browse files
authored
fix(cli): indent multiline diagnostic help output (#4)
1 parent f664ca2 commit 940e82a

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

packages/react-doctor/src/scan.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { checkReducedMotion } from "./utils/check-reduced-motion.js";
2323
import { runKnip } from "./utils/run-knip.js";
2424
import { runOxlint } from "./utils/run-oxlint.js";
2525
import { spinner } from "./utils/spinner.js";
26+
import { indentMultilineText } from "./utils/indent-multiline-text.js";
2627

2728
const SEVERITY_ORDER: Record<Diagnostic["severity"], number> = {
2829
error: 0,
@@ -68,7 +69,7 @@ const printDiagnostics = (diagnostics: Diagnostic[], isVerbose: boolean): void =
6869

6970
logger.log(` ${icon} ${firstDiagnostic.message}${countLabel}`);
7071
if (firstDiagnostic.help) {
71-
logger.dim(` ${firstDiagnostic.help}`);
72+
logger.dim(indentMultilineText(firstDiagnostic.help, " "));
7273
}
7374

7475
if (isVerbose) {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export const indentMultilineText = (text: string, linePrefix: string): string =>
2+
text
3+
.split("\n")
4+
.map((lineText) => `${linePrefix}${lineText}`)
5+
.join("\n");
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { describe, expect, it } from "vitest";
2+
import { indentMultilineText } from "../src/utils/indent-multiline-text.js";
3+
4+
describe("indentMultilineText", () => {
5+
it("adds the prefix to a single line", () => {
6+
const indentedText = indentMultilineText("Error: Something happened", " ");
7+
8+
expect(indentedText).toBe(" Error: Something happened");
9+
});
10+
11+
it("adds the prefix to every line in multiline text", () => {
12+
const explanation =
13+
"Error: Calling setState synchronously within an effect can trigger cascading renders\n\nEffects are intended to synchronize state between React and external systems.\n* Update external systems with the latest state from React.\n* Subscribe for updates from external systems and set state in a callback.";
14+
15+
const indentedText = indentMultilineText(explanation, " ");
16+
17+
expect(indentedText).toBe(
18+
" Error: Calling setState synchronously within an effect can trigger cascading renders\n \n Effects are intended to synchronize state between React and external systems.\n * Update external systems with the latest state from React.\n * Subscribe for updates from external systems and set state in a callback.",
19+
);
20+
});
21+
});

0 commit comments

Comments
 (0)