fix(cli): merge lint findings when using json format

Signed-off-by: tmuplayer33 <max.kronenbuerger@gmail.com>
This commit is contained in:
tmuplayer33
2025-06-02 14:04:21 +02:00
parent 14b2521751
commit 713e957a32
2 changed files with 19 additions and 1 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/cli': patch
---
fix: merge eslint reports when using json format
@@ -220,6 +220,7 @@ export async function command(opts: OptionValues, cmd: Command): Promise<void> {
});
const outputSuccessCache = [];
const jsonResults = [];
let errorOutput = '';
@@ -238,7 +239,11 @@ export async function command(opts: OptionValues, cmd: Command): Promise<void> {
// 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<void> {
}
}
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);
}