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); }