/
githubmirror
/
angular
Обзор
Документация
Войти
/
githubmirror
/
angular
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
packages/localize/tools/src/diagnostics.ts
52 строки
1 KB
Joey Perrott
refactor: update license text to point to angular.dev (#57901)
24 сен 2024, 16:33
24 сен 2024, 16:33
9dbe6fc
Код
Авторство
О чём код?
/** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.dev/license */ /** * How to handle potential diagnostics. */ export type DiagnosticHandlingStrategy = 'error' | 'warning' | 'ignore'; /** * This class is used to collect and then report warnings and errors that occur during the execution * of the tools. * * @publicApi used by CLI */ export class Diagnostics { readonly messages: {type: 'warning' | 'error'; message: string}[] = []; get hasErrors() { return this.messages.some((m) => m.type === 'error'); } add(type: DiagnosticHandlingStrategy, message: string) { if (type !== 'ignore') { this.messages.push({type, message}); } } warn(message: string) { this.messages.push({type: 'warning', message}); } error(message: string) { this.messages.push({type: 'error', message}); } merge(other: Diagnostics) { this.messages.push(...other.messages); } formatDiagnostics(message: string): string { const errors = this.messages.filter((d) => d.type === 'error').map((d) => ' - ' + d.message); const warnings = this.messages .filter((d) => d.type === 'warning') .map((d) => ' - ' + d.message); if (errors.length) { message += '\nERRORS:\n' + errors.join('\n'); } if (warnings.length) { message += '\nWARNINGS:\n' + warnings.join('\n'); } return message; } }