This commit is contained in:
David Anson 2025-09-06 17:59:11 -07:00
parent 0117a71138
commit 29fd76ff8e
12 changed files with 48 additions and 174 deletions

View file

@ -5,7 +5,7 @@ import path from "node:path";
import test from "ava";
import { characterEntities } from "character-entities";
import { gemoji } from "gemoji";
import helpers from "../helpers/helpers.cjs";
import helpers, { formatLintResults } from "../helpers/helpers.cjs";
import { lint } from "markdownlint/promise";
import { forEachInlineCodeSpan } from "../lib/markdownit.cjs";
import { getReferenceLinkImageData } from "../lib/cache.mjs";
@ -529,3 +529,17 @@ test("hasOverlap", (t) => {
t.false(helpers.hasOverlap(rangeB, rangeA), JSON.stringify({ rangeB, rangeA }));
}
});
test("formatLintResults", async(t) => {
t.plan(2);
t.deepEqual(formatLintResults(undefined), []);
const lintResults = await lint({ "strings": { "content": "# Heading <br/>" } });
t.deepEqual(
formatLintResults(lintResults),
[
"content: 1: MD019/no-multiple-space-atx Multiple spaces after hash on atx style heading [Context: \"# Heading <br/>\"]",
"content: 1: MD033/no-inline-html Inline HTML [Element: br]",
"content: 1: MD047/single-trailing-newline Files should end with a single newline character"
]
);
});

View file

@ -5,6 +5,7 @@ const { join } = path.posix;
import { globby } from "globby";
import jsoncParser from "jsonc-parser";
import jsYaml from "js-yaml";
import { formatLintResults } from "markdownlint/helpers";
import { lint, readConfig } from "markdownlint/promise";
import { markdownlintParallel } from "./markdownlint-test-parallel.mjs";
@ -49,9 +50,8 @@ export function lintTestRepo(t, globPatterns, configPath, configOverrides, paral
files,
config
}).then((results) => {
const resultsString = results.toString();
t.snapshot(
resultsString,
formatLintResults(results).join("\n"),
"Expected linting violations"
);
});

View file

@ -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 { formatLintError, getVersion, parseLintErrorString } from "markdownlint";
import { getVersion } from "markdownlint";
import { lint as lintAsync } from "markdownlint/async";
import { lint as lintPromise } from "markdownlint/promise";
import { lint as lintSync } from "markdownlint/sync";
@ -1389,32 +1389,6 @@ test("getVersion", (t) => {
t.is(actual, expected, "Version string not correct.");
});
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);
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) => {
t.plan(2);
// @ts-ignore

View file

@ -12,9 +12,7 @@ Generated by [AVA](https://avajs.dev).
markdownlint: [
'applyFix',
'applyFixes',
'formatLintError',
'getVersion',
'parseLintErrorString',
'resolveModule',
],
'markdownlint/async': [
@ -39,6 +37,7 @@ Generated by [AVA](https://avajs.dev).
'endOfLineHtmlEntityRe',
'escapeForRegExp',
'expandTildePath',
'formatLintResults',
'frontMatterHasTitle',
'frontMatterRe',
'getHtmlAttributeRe',

View file

@ -1,87 +0,0 @@
# Snapshot report for `test/markdownlint-test.mjs`
The actual snapshot is saved in `markdownlint-test.mjs.snap`.
Generated by [AVA](https://avajs.dev).
## problemMatcher
> Snapshot 1
[
{
column: undefined,
description: 'Trailing spaces [Expected: 0 or 2; Actual: 1]',
line: '2',
rule: 'MD009/no-trailing-spaces',
source: 'relative/path/file name.md',
},
{
column: undefined,
description: 'Multiple spaces after hash on atx style heading [Context: "# Heading"]',
line: '1',
rule: 'MD019/no-multiple-space-atx',
source: 'relative/path/file name.md',
},
{
column: undefined,
description: 'Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Below] [Context: "# Heading"]',
line: '1',
rule: 'MD022/blanks-around-headings',
source: 'relative/path/file name.md',
},
{
column: undefined,
description: 'Spaces inside code span elements [Context: "`code `"]',
line: '2',
rule: 'MD038/no-space-in-code',
source: 'relative/path/file name.md',
},
{
column: undefined,
description: 'Files should end with a single newline character',
line: '2',
rule: 'MD047/single-trailing-newline',
source: 'relative/path/file name.md',
},
]
> Snapshot 2
[
{
column: '3',
description: 'Multiple spaces after hash on atx style heading [Context: "# Heading"]',
line: '1',
rule: 'MD019/no-multiple-space-atx',
source: 'relative/path/file name.md',
},
{
column: undefined,
description: 'Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Below] [Context: "# Heading"]',
line: '1',
rule: 'MD022/blanks-around-headings',
source: 'relative/path/file name.md',
},
{
column: '18',
description: 'Trailing spaces [Expected: 0 or 2; Actual: 1]',
line: '2',
rule: 'MD009/no-trailing-spaces',
source: 'relative/path/file name.md',
},
{
column: '11',
description: 'Spaces inside code span elements [Context: "`code `"]',
line: '2',
rule: 'MD038/no-space-in-code',
source: 'relative/path/file name.md',
},
{
column: '18',
description: 'Files should end with a single newline character',
line: '2',
rule: 'MD047/single-trailing-newline',
source: 'relative/path/file name.md',
},
]