-
-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathmarkdownlint-cli2-formatter-pretty.js
42 lines (39 loc) · 1.45 KB
/
markdownlint-cli2-formatter-pretty.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// @ts-check
"use strict";
// Formats markdownlint-cli2 results in the style of `markdownlint-cli` with
// color and clickable links
const outputFormatter = async (options, params) => {
const { results, logError } = options;
const { appendLink } = (params || {});
const { "default": chalk } = await import("chalk");
const { "default": terminalLink } = await import("terminal-link");
for (const errorInfo of results) {
const { fileName, lineNumber, ruleNames, ruleDescription, ruleInformation,
errorDetail, errorContext, errorRange } = errorInfo;
const ruleName = ruleNames.join("/");
const ruleText = ruleInformation
? terminalLink.stderr(ruleName, ruleInformation, { "fallback": false })
: ruleName;
const detailsAndContext =
(errorDetail ? ` [${errorDetail}]` : "") +
(errorContext ? ` [Context: "${errorContext}"]` : "");
const appendText = appendLink && ruleInformation
? ` ${ruleInformation}`
: "";
const column = (errorRange && errorRange[0]) || 0;
logError(
// eslint-disable-next-line prefer-template
chalk.magenta(fileName) +
chalk.cyan(":") +
chalk.green(lineNumber) +
(column ? chalk.cyan(":") + chalk.green(column) : "") +
" " +
chalk.yellow(ruleText) +
" " +
ruleDescription +
chalk.yellow(detailsAndContext) +
(appendText.length > 0 ? chalk.blueBright(appendText) : "")
);
}
};
module.exports = outputFormatter;