(
result: FormattableResult = {},
options: FormatOptions = {},
)
| 53 | } |
| 54 | |
| 55 | export function formatResult( |
| 56 | result: FormattableResult = {}, |
| 57 | options: FormatOptions = {}, |
| 58 | ): string[] { |
| 59 | const { signs = DEFAULT_SIGNS, colors = DEFAULT_COLORS, color: enabled = true } = options; |
| 60 | const { errors = [], warnings = [] } = result; |
| 61 | |
| 62 | const problems = [...errors, ...warnings].map((problem) => { |
| 63 | const sign = signs[problem.level] || ""; |
| 64 | const colorName: PicocolorsColor = colors[problem.level] || ("white" as const); |
| 65 | const colorFn = pc[colorName]; |
| 66 | const decoration = enabled ? colorFn(sign) : sign; |
| 67 | const name = enabled ? pc.gray(`[${problem.name}]`) : `[${problem.name}]`; |
| 68 | return `${decoration} ${problem.message} ${name}`; |
| 69 | }); |
| 70 | |
| 71 | const sign = selectSign(result); |
| 72 | const colorName = selectColor(result); |
| 73 | |
| 74 | const deco = enabled ? pc[colorName](sign) : sign; |
| 75 | const el = errors.length; |
| 76 | const wl = warnings.length; |
| 77 | const hasProblems = problems.length > 0; |
| 78 | |
| 79 | const summary = |
| 80 | options.verbose || hasProblems ? `${deco} found ${el} problems, ${wl} warnings` : undefined; |
| 81 | |
| 82 | const fmtSummary = enabled && typeof summary === "string" ? pc.bold(summary) : summary; |
| 83 | |
| 84 | const help = hasProblems && options.helpUrl ? `ⓘ Get help: ${options.helpUrl}` : undefined; |
| 85 | |
| 86 | return [ |
| 87 | ...problems, |
| 88 | hasProblems ? "" : undefined, |
| 89 | fmtSummary, |
| 90 | help, |
| 91 | hasProblems ? "" : undefined, |
| 92 | ].filter((line): line is string => typeof line === "string"); |
| 93 | } |
| 94 | |
| 95 | export default format; |
| 96 |
no test coverage detected