UNPKG

@plugjs/plug

Version:
97 lines (96 loc) 4.28 kB
import type { AbsolutePath } from '../paths'; import type { LogEmitter } from './emit'; import type { LogLevels } from './levels'; /** Levels used in a {@link Report} */ export type ReportLevel = LogLevels['NOTICE' | 'WARN' | 'ERROR']; /** A record for a {@link Report} */ export interface ReportRecord { /** The _level_ (or _severity_) of this {@link ReportRecord}. */ level: ReportLevel; /** A detail message to associate with this {@link ReportRecord}. */ message: string | string[]; /** * Tags to associate with this{@link ReportRecord}. * * Those are error categories, or error codes and are directly related with * whatever produced the {@link Report}. */ tags?: string[] | string | null | undefined; /** Line number in the source code (starting at `1`) */ line?: number | null | undefined; /** Column number in the source code (starting at `1`) */ column?: number | null | undefined; /** Number of characters involved (`-1` means until the end of the line ) */ length?: number | null | undefined; /** The {@link AbsolutePath} of the file associated with this. */ file?: AbsolutePath | null | undefined; /** The _real source code_ associated with this (for error higlighting). */ source?: string | null | undefined; } /** A {@link Report} that will standardise the way we output information. */ export interface Report { /** The number of `notice` records _and_ annotations in this {@link Report}. */ readonly notices: number; /** The number of `warning` records _and_ annotations in this {@link Report}. */ readonly warnings: number; /** The number of `error` records _and_ annotations in this {@link Report}. */ readonly errors: number; /** The number of `notice` records in this {@link Report}. */ readonly noticeRecords: number; /** The number of `warning` records in this {@link Report}. */ readonly warningRecords: number; /** The number of `error` records in this {@link Report}. */ readonly errorRecords: number; /** The number of `notice` annotations in this {@link Report}. */ readonly noticeAnnotations: number; /** The number of `warning` annotations in this {@link Report}. */ readonly warningAnnotations: number; /** The number of `error` annotations in this {@link Report}. */ readonly errorAnnotations: number; /** The number of _all_ records in this {@link Report} */ readonly records: number; /** The number of _all_ annotations in this {@link Report} */ readonly annotations: number; /** Checks whether this {@link Report} contains records or annotations */ readonly empty: boolean; /** Add a new {@link ReportRecord | record} to this {@link Report}. */ add(...records: ReportRecord[]): this; /** Add an annotation (small note) for a file in this report */ annotate(level: ReportLevel, file: AbsolutePath, note: string): this; /** Attempt to load any source file missing from the reports */ loadSources(): Promise<void>; /** Emit this {@link Report} and throw a build failure on error. */ done(showSources?: boolean | undefined): void; } export declare class ReportImpl implements Report { private readonly _title; private readonly _task; private readonly _emitter; private readonly _sources; private readonly _annotations; private readonly _records; private _noticeRecords; private _warningRecords; private _errorRecords; private _noticeAnnotations; private _warningAnnotations; private _errorAnnotations; constructor(_title: string, _task: string, _emitter: LogEmitter); get notices(): number; get warnings(): number; get errors(): number; get noticeRecords(): number; get warningRecords(): number; get errorRecords(): number; get noticeAnnotations(): number; get warningAnnotations(): number; get errorAnnotations(): number; get records(): number; get annotations(): number; get empty(): boolean; annotate(annotationLevel: ReportLevel, file: AbsolutePath, note: string): this; add(...records: ReportRecord[]): this; loadSources(): Promise<void>; done(showSources?: boolean | undefined): void; private _emit; }