import type * as CLint from '@commitlint/types'; import type { ChalkInstance } from 'chalk'; declare const CTX: unique symbol; /** * A class to create formatter instance for formatting the linting report. */ export declare class Formatter { #private; /** * Creates an instance of the Formatter. * @param transformer The transformer object that handles input and result transformations. * @param chalk The `chalk` instance used to style the output. * @param options Optional formatting options. */ constructor(transformer: Transformer, chalk: ChalkInstance, options?: FormatterOptions); /** Whether the formatter is customizable. */ get isCustomizable(): boolean; /** * Sets a new transformer for the formatter. * @param transformer The new transformer to be used. * @throws Will throw an error if the formatter is not customizable. * @throws Will throw an error if `transformInput` or `transformResult` are not functions. */ setTransformer: (transformer: Transformer) => void; /** * Sets the format options for the formatter. * @param formatOptions The format options to be applied. */ setFormatOptions: (formatOptions: FormatOptions) => void; /** * Formats the input of a linting result (commit message). * @param result The linting outcome. * @param formatOptions Optional format options. * @returns A string array with the formatted input. */ formatInput: (result: CLint.LintOutcome, formatOptions?: FormatOptions) => string[]; /** * Formats the result of a linting outcome. * @param result The linting outcome. * @param formatOptions Optional format options. * @returns A string array with the formatted result. */ formatResult: (result: CLint.LintOutcome, formatOptions?: FormatOptions) => string[]; /** * Formats the entire lint report into a string. * @param report The lint report containing multiple linting outcomes. * @param formatOptions Optional format options. * @returns A string with the formatted lint report. */ format: (report: LintReport, formatOptions?: FormatOptions) => string; } /** * Represents the result of a linting process. */ export type LintReport = { /** Whether the linting is valid (i.e., no errors or warnings). */ valid: boolean; /** Number of errors encountered during linting. */ errorCount: number; /** Number of warnings encountered during linting. */ warningCount: number; /** Array of linting outcomes for individual commits. */ results: CLint.LintOutcome[]; }; /** * Detailed format options for customizing the report output. */ export type FormatOptions = { /** @internal */ [CTX]?: TransformContext; /** Prefix to be used for formatted report. Only affects `format` method. */ prefix?: string; /** Suffix to be used for formatted report. Only affects `format` method. */ suffix?: string; /** Prefix to be used each formatted commit result in the report. Only affects `format` method. */ eachCommitPrefix?: string; /** Suffix to be used each formatted commit result in the report (added before separatorBetweenCommits text). Only affects `format` method. */ eachCommitSuffix?: string; /** Separator to be used between each commit in the report. Only affects `format` method. Defaults to `\n`. */ separatorBetweenCommits?: string; /** Separator to be used between formatted input and formatted result. Only affects `format` method and if `formatInput` not resulting empty. Defaults to `\n`. */ separatorBetweenInputAndResult?: string; /** Finalizing result. Only for `format` method. */ finalizeFormatResult?: (formatted: string, context: TransformContext, summary: { totalCommit: number; totalError: number; totalWarning: number; }) => string; } & CLint.FormatOptions; /** * Options for formatting the linting report. */ export type FormatterOptions = { /** Whether the formatter is customizable. */ customizable: boolean; /** Custom format options. */ formatOptions?: FormatOptions; }; /** * Context passed to the transform functions. */ export type TransformContext = { /** Options used for formatting. */ formatOptions: FormatOptions; /** The `chalk` instance used for styling the output. */ chalk: ChalkInstance; /** Whether formatting with verbose or not */ verbose: boolean; /** A function that retrieves the appropriate sign (e.g., ✔, ⚠, ✖) based on the linting level. */ getSign: (level: CLint.RuleConfigSeverity) => string; }; /** * A function that transforms a linting outcome and its context into a string array. */ export type TransformFn = (result: CLint.LintOutcome, context: TransformContext) => string[]; /** * Object containing the functions to transform the input and the final result. */ export type Transformer = { /** Function to transform the input (commit message) of the linting result. */ transformInput: TransformFn; /** Function to transform the final linting result output. */ transformResult: TransformFn; }; export {};