From 713e957a3249e13d8f8c002124d51546d22e4b70 Mon Sep 17 00:00:00 2001 From: tmuplayer33 Date: Mon, 2 Jun 2025 14:04:21 +0200 Subject: [PATCH] fix(cli): merge lint findings when using json format Signed-off-by: tmuplayer33 --- .changeset/three-boats-sort.md | 5 +++++ .../cli/src/modules/lint/commands/repo/lint.ts | 15 ++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 .changeset/three-boats-sort.md diff --git a/.changeset/three-boats-sort.md b/.changeset/three-boats-sort.md new file mode 100644 index 0000000000..180a4e236c --- /dev/null +++ b/.changeset/three-boats-sort.md @@ -0,0 +1,5 @@ +--- +'@backstage/cli': patch +--- + +fix: merge eslint reports when using json format diff --git a/packages/cli/src/modules/lint/commands/repo/lint.ts b/packages/cli/src/modules/lint/commands/repo/lint.ts index 72bb02a693..f433740886 100644 --- a/packages/cli/src/modules/lint/commands/repo/lint.ts +++ b/packages/cli/src/modules/lint/commands/repo/lint.ts @@ -220,6 +220,7 @@ export async function command(opts: OptionValues, cmd: Command): Promise { }); const outputSuccessCache = []; + const jsonResults = []; let errorOutput = ''; @@ -238,7 +239,11 @@ export async function command(opts: OptionValues, cmd: Command): Promise { // dump of all warnings that might be irrelevant if (resultText) { if (opts.outputFile) { - errorOutput += `${resultText}\n`; + if (opts.format === 'json') { + jsonResults.push(resultText); + } else { + errorOutput += `${resultText}\n`; + } } else { console.log(); console.log(resultText.trimStart()); @@ -249,6 +254,14 @@ export async function command(opts: OptionValues, cmd: Command): Promise { } } + if (opts.format === 'json') { + let mergedJsonResults: any[] = []; + for (const jsonResult of jsonResults) { + mergedJsonResults = mergedJsonResults.concat(JSON.parse(jsonResult)); + } + errorOutput = JSON.stringify(mergedJsonResults, null, 2); + } + if (opts.outputFile && errorOutput) { await fs.writeFile(paths.resolveTargetRoot(opts.outputFile), errorOutput); }