wip
Some checks are pending
Checkers / linkcheck (push) Waiting to run
Checkers / spellcheck (push) Waiting to run
CI / build (20, macos-latest) (push) Waiting to run
CI / build (20, ubuntu-latest) (push) Waiting to run
CI / build (20, windows-latest) (push) Waiting to run
CI / build (22, macos-latest) (push) Waiting to run
CI / build (22, ubuntu-latest) (push) Waiting to run
CI / build (22, windows-latest) (push) Waiting to run
CI / build (24, macos-latest) (push) Waiting to run
CI / build (24, ubuntu-latest) (push) Waiting to run
CI / build (24, windows-latest) (push) Waiting to run
CI / pnpm (push) Waiting to run
CodeQL / Analyze (push) Waiting to run
TestRepos / build (latest, ubuntu-latest) (push) Waiting to run
UpdateTestRepos / update (push) Waiting to run

This commit is contained in:
David Anson 2025-08-26 23:03:50 -07:00
parent a56441003e
commit 7e364c6a8f
3 changed files with 97 additions and 25 deletions

View file

@ -540,20 +540,21 @@ function expandTildePath(file, os) {
module.exports.expandTildePath = expandTildePath;
/** @typedef {import("../lib/markdownlint.mjs").LintError[]} LintErrors */
/** @typedef {import("../lib/markdownlint.mjs").LintResults} LintResults */
/**
* Converts lint errors from resultVersion 3 to 2.
*
* @param {LintErrors} results Lint errors (v3).
* @param {LintErrors} errors Lint errors (v3).
* @returns {LintErrors} Lint errors (v2).
*/
function convertResultVersion3To2(results) {
function convertResultVersion3To2(errors) {
// Remove fixInfo and multiple errors for the same rule and line number
const noPrevious = {
"ruleNames": [],
"lineNumber": -1
};
return results.filter((error, index, array) => {
return errors.filter((error, index, array) => {
delete error.fixInfo;
const previous = array[index - 1] || noPrevious;
return (
@ -561,16 +562,16 @@ function convertResultVersion3To2(results) {
(error.lineNumber !== previous.lineNumber)
);
});
};
}
/**
* Converts lint errors from resultVersion 2 to 1.
*
* @param {LintErrors} results Lint errors (v2).
* @param {LintErrors} errors Lint errors (v2).
* @returns {LintErrors} Lint errors (v1).
*/
function convertResultVersion2To1(results) {
for (const error of results) {
function convertResultVersion2To1(errors) {
for (const error of errors) {
// @ts-ignore
error.ruleName = error.ruleNames[0];
// @ts-ignore
@ -578,18 +579,18 @@ function convertResultVersion2To1(results) {
// @ts-ignore
delete error.ruleNames;
}
return results;
};
return errors;
}
/**
* Converts lint errors from resultVersion 2 to 0.
*
* @param {LintErrors} results Lint errors (v2).
* @param {LintErrors} errors Lint errors (v2).
* @returns {LintErrors} Lint errors (v0).
*/
function convertResultVersion2To0(results) {
function convertResultVersion2To0(errors) {
const dictionary = {};
for (const error of results) {
for (const error of errors) {
const ruleName = error.ruleNames[0];
const ruleLines = dictionary[ruleName] || [];
ruleLines.push(error.lineNumber);
@ -597,16 +598,52 @@ function convertResultVersion2To0(results) {
}
// @ts-ignore
return dictionary;
};
}
/**
* Copies and transforms lint results from resultVersion 3 to ?.
*
* @param {LintResults} results Lint results (v3).
* @param {(LintErrors)=> LintErrors} boop Lint errors (v?).
* @returns {LintResults} Lint results (v?).
*/
function copyAndTransformResults(results, boop) {
const newr = {};
Object.defineProperty(newr, "toString", { "value": results.toString });
for (const key of Object.keys(results)) {
const newrr = results[key].map((r) => ({ ...r }));
newr[key] = boop(newrr);
}
// @ts-ignore
return newr;
}
/**
* Converts lint results from resultVersion 3 to 0.
*
* @param {LintResults} results Lint results (v3).
* @returns {LintResults} Lint results (v0).
*/
module.exports.convertToResultVersion0 = function convertToResultVersion0(results) {
return convertResultVersion2To0(convertResultVersion3To2(results));
return copyAndTransformResults(results, (r) => convertResultVersion2To0(convertResultVersion3To2(r)));
};
/**
* Converts lint results from resultVersion 3 to 1.
*
* @param {LintResults} results Lint results (v3).
* @returns {LintResults} Lint results (v1).
*/
module.exports.convertToResultVersion1 = function convertToResultVersion1(results) {
return convertResultVersion2To1(convertResultVersion3To2(results));
return copyAndTransformResults(results, (r) => convertResultVersion2To1(convertResultVersion3To2(r)));
};
/**
* Converts lint results from resultVersion 3 to 2.
*
* @param {LintResults} results Lint results (v3).
* @returns {LintResults} Lint results (v2).
*/
module.exports.convertToResultVersion2 = function convertToResultVersion2(results) {
return convertResultVersion3To2(results);
return copyAndTransformResults(results, convertResultVersion3To2);
};