From 5d61d39d55ec5da25858586342cfce9fd32128b6 Mon Sep 17 00:00:00 2001 From: David Anson Date: Wed, 3 Sep 2025 23:25:56 -0700 Subject: [PATCH] wip --- lib/markdownlint.d.mts | 2 +- lib/markdownlint.mjs | 1 - package.json | 2 +- test/markdownlint-test.mjs | 23 ++++++ test/snapshots/markdownlint-test.mjs.md | 87 ++++++++++++++++++++++ test/snapshots/markdownlint-test.mjs.snap | Bin 0 -> 850 bytes 6 files changed, 112 insertions(+), 3 deletions(-) create mode 100644 test/snapshots/markdownlint-test.mjs.md create mode 100644 test/snapshots/markdownlint-test.mjs.snap diff --git a/lib/markdownlint.d.mts b/lib/markdownlint.d.mts index 331262e9..1117fd0d 100644 --- a/lib/markdownlint.d.mts +++ b/lib/markdownlint.d.mts @@ -445,7 +445,7 @@ export type Plugin = any[]; /** * Function to pretty-print lint results. */ -export type ToStringCallback = (ruleAliases?: boolean) => string; +export type ToStringCallback = () => string; /** * Lint results. */ diff --git a/lib/markdownlint.mjs b/lib/markdownlint.mjs index b3d8f25f..3bbad333 100644 --- a/lib/markdownlint.mjs +++ b/lib/markdownlint.mjs @@ -1496,7 +1496,6 @@ export function getVersion() { * Function to pretty-print lint results. * * @callback ToStringCallback - * @param {boolean} [ruleAliases] True to use rule aliases. * @returns {string} Pretty-printed results. */ diff --git a/package.json b/package.json index ce08b1e8..d21a2a93 100644 --- a/package.json +++ b/package.json @@ -65,7 +65,7 @@ "test-declaration-cts": "cd example/typescript && node ../../scripts/index.mjs copy type-check.ts type-check-commonjs.cts && tsc --module commonjs --esModuleInterop type-check-commonjs.cts", "test-declaration-mts": "cd example/typescript && node ../../scripts/index.mjs copy type-check.ts type-check-nodenext.mts && tsc --module nodenext type-check-nodenext.mts && node type-check-nodenext.mjs", "test-extra": "ava --timeout=10m test/markdownlint-test-extra-parse.mjs test/markdownlint-test-extra-type.mjs", - "update-snapshots": "ava --update-snapshots test/markdownlint-test-custom-rules.mjs test/markdownlint-test-exports.mjs test/markdownlint-test-micromark.mjs test/markdownlint-test-scenarios.mjs", + "update-snapshots": "ava --update-snapshots test/markdownlint-test.mjs test/markdownlint-test-custom-rules.mjs test/markdownlint-test-exports.mjs test/markdownlint-test-micromark.mjs test/markdownlint-test-scenarios.mjs", "update-snapshots-test-repos": "ava --timeout=10m --update-snapshots test/markdownlint-test-repos-*.mjs", "update-test-repos": "node scripts/index.mjs remove ./test-repos && npm run clone-test-repos && npm run update-snapshots-test-repos", "upgrade": "npx --yes npm-check-updates --upgrade" diff --git a/test/markdownlint-test.mjs b/test/markdownlint-test.mjs index 06318fce..1d7879d4 100644 --- a/test/markdownlint-test.mjs +++ b/test/markdownlint-test.mjs @@ -1392,6 +1392,29 @@ test("getVersion", (t) => { t.is(actual, expected, "Version string not correct."); }); +const matcherRe = /^(?[^:]+):\s*(?\d+)(?::(?\d+))?:?\s(?\S+)\s(?.+)$/; + +test("problemMatcher", async(t) => { + t.plan(2); + const content = "# Heading\nText `code ` text "; + 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)); +}); + test("constants", (t) => { t.plan(2); // @ts-ignore diff --git a/test/snapshots/markdownlint-test.mjs.md b/test/snapshots/markdownlint-test.mjs.md new file mode 100644 index 00000000..fbf5fee9 --- /dev/null +++ b/test/snapshots/markdownlint-test.mjs.md @@ -0,0 +1,87 @@ +# 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', + }, + ] diff --git a/test/snapshots/markdownlint-test.mjs.snap b/test/snapshots/markdownlint-test.mjs.snap new file mode 100644 index 0000000000000000000000000000000000000000..4163045e540b5c19d92c81ac7ad84968958249a9 GIT binary patch literal 850 zcmV-Y1Fif)RzVPZxTvp?#EO@2Fv={I=RFYLy5NUO9&i9#SSDmjW+K@bC8*z>S zI04`sfGYsX04e}_h|^8%<8jPp2w99eJ3B$PgV-SLgwz{J+6j4{yh$3qPeLON`w2kI zG`y6AR$A}@0cHs>PknFdg3H`6|;vemoSMN>YjmQBC^Xr{x)17EDgjq}dh9DJ+Y|JxWh-5lxS-KXZMhqB}5VPt;LOGEXY8;O@MnP!DQ z=Ar3)ZTKggZ-D@P1~6;@ack#$Y5)rc@YVn>n}9ZfXRV#@y$O6Wfes6}W&yV>V4=11 zeYAit7SL@2lQwYQ241yxzHc`0-3EFcAaa0*4)FT#oG%f};MV28b@{J9b#^x~3WqoM ck5$S+_HZ_(3I4Vk{(mF<2@*p^&@B!C0Kpc0xc~qF literal 0 HcmV?d00001