@toreda/build-tools
Version:

118 lines (117 loc) • 4.66 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.LinterSummary = void 0;
class LinterSummary {
constructor(limits) {
this.errors = this.mkTotals();
this.warnings = this.mkTotals();
this.limits = this.mkLimits(limits);
this.fileResults = [];
this.resultText = null;
this.status = {
success: false,
errors: [],
code: '',
description: ''
};
}
mkTotals() {
return {
fatal: 0,
fixable: 0,
total: 0
};
}
mkLimits(o) {
const limits = {
errors: {
total: 0,
fixable: 0,
fatal: 0
},
warn: {
total: 0,
fixable: 0
}
};
if (o) {
if (o.errors) {
if (typeof o.errors.total === 'number') {
limits.errors.total = o.errors.total;
}
if (typeof o.errors.fatal === 'number') {
limits.errors.fatal = o.errors.fatal;
}
if (typeof o.errors.fixable === 'number') {
limits.errors.fixable = o.errors.fixable;
}
}
if (o.warn) {
if (typeof o.warn.fixable === 'number') {
limits.warn.fixable = o.warn.fixable;
}
if (typeof o.warn.total === 'number') {
limits.warn.total = o.warn.total;
}
}
}
return limits;
}
add(result) {
if (!result) {
throw new Error(`add:result:arg:missing`);
}
if (typeof result.errorCount === 'number') {
this.errors.total += result.errorCount;
}
if (typeof result.fixableErrorCount === 'number') {
this.errors.fixable += result.fixableErrorCount;
this.errors.total += result.fixableErrorCount;
}
if (typeof result.fatalErrorCount === 'number') {
this.errors.fatal += result.fatalErrorCount;
this.errors.total += result.fatalErrorCount;
}
if (typeof result.warningCount === 'number') {
this.warnings.total += result.warningCount;
}
if (typeof result.fixableWarningCount === 'number') {
this.warnings.fixable += result.fixableWarningCount;
this.warnings.total += result.fixableWarningCount;
}
}
done() {
if (this.limits.errors.total !== 0 && this.errors.total > this.limits.errors.total) {
this.status.code = 'ERROR_LIMIT_EXCEEDED';
this.status.description = `Too many total errors detected. Total error count of '${this.errors.total}' exceeded limit '${this.limits.errors.total}'`;
this.status.success = false;
return;
}
if (this.errors.fixable !== 0 && this.errors.fixable > this.limits.errors.fixable) {
this.status.success = false;
this.status.code = 'FIXABLE_ERROR_LIMIT_EXCEEDED';
this.status.description = `Too many fixable errors detected. Fixable error count '${this.errors.fixable}' exceeds the configured limit '${this.limits.errors.fixable}'.`;
return;
}
if (this.errors.fatal !== 0 && this.errors.fatal > this.limits.errors.fatal) {
this.status.success = false;
this.status.code = 'FATAL_ERROR_LIMIT_EXCEEDED';
this.status.description = `Too many fatal errors detected. Fatal error count '${this.errors.fatal}' exceeds configured limit '${this.limits.errors.fatal}.`;
return;
}
if (this.warnings.fixable !== 0 && this.warnings.fixable > this.limits.warn.fixable) {
this.status.success = false;
this.status.code = 'FIXABLE_WARN_LIMIT_EXCEEDED';
this.status.description = `Too many fixable warnings detected. Fixable warning count '${this.warnings.fixable}' exceeds configured limit '${this.limits.warn.fixable}'.`;
return;
}
if (this.warnings.total !== 0 && this.warnings.total > this.limits.warn.total) {
this.status.success = false;
this.status.code = 'WARN_LIMIT_EXCEEDED';
this.status.description = `Too many warnings detected. Total warning count '${this.warnings.total}' exceeds configured limit '${this.limits.warn.total}'`;
return;
}
this.status.success = true;
}
}
exports.LinterSummary = LinterSummary;