fix(cli): merge lint findings when using json format
Signed-off-by: tmuplayer33 <max.kronenbuerger@gmail.com>
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user