re do output formatting, save some lines

Moving the message and the info if something is auto-fixable to a
single line, saving ~ 2/3rd of output lines.

The auto-fixable got replaced with a (*) marker, it's not ideal but
IMO OK; explain what it means in the summaries "X issues marked with
(*) could be auto-fixed"

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Thomas Lamprecht 2020-04-10 16:38:40 +02:00
parent 8e4082d9d6
commit 7b71dd2c0b

View File

@ -253,48 +253,44 @@ report.results.forEach(function(result) {
if (!!program.fix && result.output) { if (!!program.fix && result.output) {
fixes++; fixes++;
} }
if (msgs.length > 0) { if (msgs.length <= 0) {
console.error('[' + color.bold(filename) + ']:');
msgs.forEach(function(e) {
let msg = 'at line ' + color.bold(e.line) + ' column ' +
color.bold(e.column) + ': ' + e.ruleId;
if (e.severity === 1) {
console.error(color.yellow("Warning " + msg));
if (max_sev < 1) {
max_sev = 1;
}
} else if (e.severity === 2) {
console.error(color.red("Error " + msg));
if (exitcode < 1) {
exitcode = 1;
}
if (max_sev < 2) {
max_sev = 2;
}
} else {
console.error("Info " + msg);
}
if (e.message) {
console.error(e.message);
}
if (e.suggestion) {
console.error(e.suggestion);
}
if (!program.fix && e.fix) {
fixes++;
console.error("Could be auto-fixed");
}
});
if (max_sev === 1) {
files_warn.push(filename);
} else if (max_sev === 2) {
files_err.push(filename);
}
} else {
files_ok.push(filename); files_ok.push(filename);
return; return;
} }
console.error(`[./${color.bold(filename)}]:`);
msgs.forEach(function(e) {
if (max_sev < e.severity) {
max_sev = e.severity;
}
let msg = `: line ${color.bold(e.line)} col ${color.bold(e.column)}: ${e.ruleId}`;
if (e.severity === 1) {
msg = color.yellow("WARN" + msg);
} else if (e.severity === 2) {
msg = color.red("ERR " + msg);
if (exitcode < 1) {
exitcode = 1;
}
} else {
msg = "INFO" + msg;
}
if (e.message) {
msg += ` - ${e.message}`;
}
if (!program.fix && e.fix) {
fixes++;
msg += ' (*)';
}
console.error(msg);
if (e.suggestion) {
console.error(e.suggestion);
}
});
if (max_sev === 1) {
files_warn.push(filename);
} else if (max_sev === 2) {
files_err.push(filename);
}
console.log('------------------------------------------------------------'); console.log('------------------------------------------------------------');
}); });
@ -302,19 +298,18 @@ report.results.forEach(function(result) {
if (report.results.length > 1) { if (report.results.length > 1) {
console.log(`${color.bold(files_ok.length + files_err.length)} files:`); console.log(`${color.bold(files_ok.length + files_err.length)} files:`);
if (files_err.length > 0) { if (files_err.length > 0) {
console.log(color.red(`${color.bold(files_err.length)} files have Errors`)); console.log(color.red(` ${color.bold(files_err.length)} files have Errors`));
} }
if (files_warn.length > 0) { if (files_warn.length > 0) {
console.log(color.yellow(`${color.bold(files_warn.length)} files have Warnings`)); console.log(color.yellow(` ${color.bold(files_warn.length)} files have Warnings`));
} }
if (files_ok.length > 0) { if (files_ok.length > 0) {
console.log(color.green(`${color.bold(files_ok.length)} files are OK`)); console.log(color.green(` ${color.bold(files_ok.length)} files are OK`));
} }
console.log('------------------------------------------------------------');
} else if (files_ok.length > 0) { } else if (files_ok.length > 0) {
console.log(color.green(`${files_ok[0]} OK`)); console.log(color.green(`${files_ok[0]} OK`));
console.log('------------------------------------------------------------');
} }
console.log('------------------------------------------------------------');
if (program.fix) { if (program.fix) {
if (fixes > 0) { if (fixes > 0) {
@ -324,8 +319,8 @@ if (program.fix) {
} else { } else {
console.log("No fixable Errors/Warnings found."); console.log("No fixable Errors/Warnings found.");
} }
} else { } else if (fixes > 0) {
console.log(`${color.bold(fixes)} Errors/Warnings could be auto-fixed.`); console.log(`${color.bold(fixes)} issues marked with (*) could be auto-fixed using '--fix'.`);
} }
process.exit(exitcode); process.exit(exitcode);