mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-21 08:20:12 +01:00
wip
This commit is contained in:
parent
5d61d39d55
commit
8fca1c457b
7 changed files with 81 additions and 36 deletions
|
|
@ -13,7 +13,7 @@ import pluginInline from "markdown-it-for-inline";
|
|||
import pluginSub from "markdown-it-sub";
|
||||
import pluginSup from "markdown-it-sup";
|
||||
import test from "ava";
|
||||
import { getVersion } from "markdownlint";
|
||||
import { formatLintError, getVersion, parseLintErrorString } from "markdownlint";
|
||||
import { lint as lintAsync } from "markdownlint/async";
|
||||
import { lint as lintPromise } from "markdownlint/promise";
|
||||
import { lint as lintSync } from "markdownlint/sync";
|
||||
|
|
@ -1392,27 +1392,30 @@ test("getVersion", (t) => {
|
|||
t.is(actual, expected, "Version string not correct.");
|
||||
});
|
||||
|
||||
const matcherRe = /^(?<source>[^:]+):\s*(?<line>\d+)(?::(?<column>\d+))?:?\s(?<rule>\S+)\s(?<description>.+)$/;
|
||||
|
||||
test("problemMatcher", async(t) => {
|
||||
t.plan(2);
|
||||
const content = "# Heading\nText `code ` text ";
|
||||
test("formatLintError-parseLintErrorString", async(t) => {
|
||||
t.plan(29);
|
||||
t.is(null, parseLintErrorString(""));
|
||||
const content = "# Heading\nText `code ` text \n\n";
|
||||
const options = {
|
||||
"strings": {
|
||||
"relative/path/file name.md": content
|
||||
}
|
||||
};
|
||||
const results = await lintPromise(options);
|
||||
const getMatches = (input) => input.split("\n").map((line) => matcherRe.exec(line)?.groups);
|
||||
t.snapshot(getMatches(results.toString()));
|
||||
// eslint-disable-next-line camelcase
|
||||
const cli_0_45_0__cli2_0_18_1 =
|
||||
`relative/path/file name.md:1:3 MD019/no-multiple-space-atx Multiple spaces after hash on atx style heading [Context: "# Heading"]
|
||||
relative/path/file name.md:1 MD022/blanks-around-headings Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Below] [Context: "# Heading"]
|
||||
relative/path/file name.md:2:18 MD009/no-trailing-spaces Trailing spaces [Expected: 0 or 2; Actual: 1]
|
||||
relative/path/file name.md:2:11 MD038/no-space-in-code Spaces inside code span elements [Context: "\`code \`"]
|
||||
relative/path/file name.md:2:18 MD047/single-trailing-newline Files should end with a single newline character`;
|
||||
t.snapshot(getMatches(cli_0_45_0__cli2_0_18_1));
|
||||
for (const source of Object.keys(results)) {
|
||||
for (const lintError of results[source]) {
|
||||
const formatted = formatLintError(source, lintError);
|
||||
const parsed = parseLintErrorString(formatted);
|
||||
t.is(parsed.source, source);
|
||||
t.is(parsed.line, lintError.lineNumber.toString());
|
||||
t.is(Boolean(parsed.column), Boolean(lintError.errorRange));
|
||||
if (lintError.errorRange) {
|
||||
t.is(parsed.column, lintError.errorRange[0].toString());
|
||||
}
|
||||
t.is(parsed.rule, lintError.ruleNames.join("/"));
|
||||
t.is(parsed.message.replaceAll(/ \[[^\]]+\]/g, ""), lintError.ruleDescription);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test("constants", (t) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue