MCPcopy Create free account
hub / github.com/conventional-changelog/commitlint / formatResult

Function formatResult

@commitlint/format/src/format.ts:55–93  ·  view source on GitHub ↗
(
	result: FormattableResult = {},
	options: FormatOptions = {},
)

Source from the content-addressed store, hash-verified

53}
54
55export 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
95export default format;
96

Callers 2

format.test.tsFile · 0.85
frFunction · 0.85

Calls 3

selectSignFunction · 0.85
selectColorFunction · 0.85
filterMethod · 0.80

Tested by

no test coverage detected