From d4c9a1003de1d8e3ec8d0e290993f63e1bdd14e3 Mon Sep 17 00:00:00 2001 From: hx <2769369661@qq.com> Date: Wed, 5 Aug 2026 22:24:42 +0800 Subject: [PATCH] Fix spacing in new rule hints --- .../linter/src/cli/summary-reporter.ts | 2 +- .../linter/test/summary-reporter.test.ts | 44 +++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 javascript/packages/linter/test/summary-reporter.test.ts diff --git a/javascript/packages/linter/src/cli/summary-reporter.ts b/javascript/packages/linter/src/cli/summary-reporter.ts index 1bf8466c1..083a19c07 100644 --- a/javascript/packages/linter/src/cli/summary-reporter.ts +++ b/javascript/packages/linter/src/cli/summary-reporter.ts @@ -299,7 +299,7 @@ export class SummaryReporter { for (const ruleName of ruleNames) { const ruleText = colorize(ruleName, "white") const ruleLink = hyperlink(ruleText, ruleDocumentationUrl(ruleName)) - console.log(` ${ruleLink} ${colorize(`(introduced in ${versionLabel})`, "gray")}`) + console.log(` ${ruleLink}${colorize(` (introduced in ${versionLabel})`, "gray")}`) } } diff --git a/javascript/packages/linter/test/summary-reporter.test.ts b/javascript/packages/linter/test/summary-reporter.test.ts new file mode 100644 index 000000000..8059aa735 --- /dev/null +++ b/javascript/packages/linter/test/summary-reporter.test.ts @@ -0,0 +1,44 @@ +import { afterEach, describe, expect, test, vi } from "vitest" + +import { SummaryReporter } from "../src/cli/summary-reporter.js" + +import type { SummaryData } from "../src/cli/summary-reporter.js" + +describe("SummaryReporter", () => { + afterEach(() => { + vi.restoreAllMocks() + }) + + test("keeps the space before a version label inside its color sequence", () => { + const originalNoColor = process.env.NO_COLOR + delete process.env.NO_COLOR + + const log = vi.spyOn(console, "log").mockImplementation(() => {}) + + try { + new SummaryReporter().displayVersionSkippedRules({ + rulesSkippedByVersion: [ + { ruleName: "html-example", introducedIn: "0.10.3" }, + ], + configVersion: "0.10.3", + hasConfigFile: true, + } as SummaryData) + + const ruleLine = log.mock.calls + .map(([line]) => line) + .find( + (line) => typeof line === "string" && line.includes("html-example"), + ) + + expect(ruleLine).toMatch( + /\x1b\\\x1b\[[0-9;]+m \(introduced in 0\.10\.3\)/, + ) + } finally { + if (originalNoColor === undefined) { + delete process.env.NO_COLOR + } else { + process.env.NO_COLOR = originalNoColor + } + } + }) +})