Merge pull request #30105 from tmuplayer33/merge-json-lint-output

fix(cli): merge eslint reports when using json format
This commit is contained in:
Fredrik Adelöw
2025-06-03 14:40:22 +02:00
committed by GitHub
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);
}