mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-19 15:30:13 +01:00
wip
This commit is contained in:
parent
124ee3f733
commit
2aeffeb5f1
6 changed files with 84 additions and 58 deletions
|
|
@ -538,3 +538,75 @@ function expandTildePath(file, os) {
|
|||
return homedir ? file.replace(/^~($|\/|\\)/, `${homedir}$1`) : file;
|
||||
}
|
||||
module.exports.expandTildePath = expandTildePath;
|
||||
|
||||
/** @typedef {import("../lib/markdownlint.mjs").LintError[]} LintErrors */
|
||||
|
||||
/**
|
||||
* Converts lint errors from resultVersion 3 to 2.
|
||||
*
|
||||
* @param {LintErrors} results Lint errors (v3).
|
||||
* @returns {LintErrors} Lint errors (v2).
|
||||
*/
|
||||
function convertResultVersion3To2(results) {
|
||||
// Remove fixInfo and multiple errors for the same rule and line number
|
||||
const noPrevious = {
|
||||
"ruleNames": [],
|
||||
"lineNumber": -1
|
||||
};
|
||||
return results.filter((error, index, array) => {
|
||||
delete error.fixInfo;
|
||||
const previous = array[index - 1] || noPrevious;
|
||||
return (
|
||||
(error.ruleNames[0] !== previous.ruleNames[0]) ||
|
||||
(error.lineNumber !== previous.lineNumber)
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts lint errors from resultVersion 2 to 1.
|
||||
*
|
||||
* @param {LintErrors} results Lint errors (v2).
|
||||
* @returns {LintErrors} Lint errors (v1).
|
||||
*/
|
||||
function convertResultVersion2To1(results) {
|
||||
for (const error of results) {
|
||||
// @ts-ignore
|
||||
error.ruleName = error.ruleNames[0];
|
||||
// @ts-ignore
|
||||
error.ruleAlias = error.ruleNames[1] || error.ruleName;
|
||||
// @ts-ignore
|
||||
delete error.ruleNames;
|
||||
}
|
||||
return results;
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts lint errors from resultVersion 2 to 0.
|
||||
*
|
||||
* @param {LintErrors} results Lint errors (v2).
|
||||
* @returns {LintErrors} Lint errors (v0).
|
||||
*/
|
||||
function convertResultVersion2To0(results) {
|
||||
const dictionary = {};
|
||||
for (const error of results) {
|
||||
const ruleName = error.ruleNames[0];
|
||||
const ruleLines = dictionary[ruleName] || [];
|
||||
ruleLines.push(error.lineNumber);
|
||||
dictionary[ruleName] = ruleLines;
|
||||
}
|
||||
// @ts-ignore
|
||||
return dictionary;
|
||||
};
|
||||
|
||||
module.exports.convertToResultVersion0 = function convertToResultVersion0(results) {
|
||||
return convertResultVersion2To0(convertResultVersion3To2(results));
|
||||
};
|
||||
|
||||
module.exports.convertToResultVersion1 = function convertToResultVersion1(results) {
|
||||
return convertResultVersion2To1(convertResultVersion3To2(results));
|
||||
};
|
||||
|
||||
module.exports.convertToResultVersion2 = function convertToResultVersion2(results) {
|
||||
return convertResultVersion3To2(results);
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue