mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-20 16:00:13 +01:00
wip
This commit is contained in:
parent
5d61d39d55
commit
8fca1c457b
7 changed files with 81 additions and 36 deletions
|
|
@ -522,6 +522,7 @@ function lintContent(
|
|||
"config": null
|
||||
});
|
||||
// Function to run for each rule
|
||||
/** @type {LintError[]} */
|
||||
const results = [];
|
||||
/**
|
||||
* @param {Rule} rule Rule.
|
||||
|
|
@ -1303,6 +1304,44 @@ export function applyFixes(input, errors) {
|
|||
return lines.filter((line) => line !== null).join(lineEnding);
|
||||
}
|
||||
|
||||
/**
|
||||
* TBD
|
||||
*
|
||||
* @param {string} source Source file name or identifier.
|
||||
* @param {LintError} lintError Lint error.
|
||||
* @returns {string} Lint error string.
|
||||
*/
|
||||
export function formatLintError(source, lintError) {
|
||||
const { lineNumber, ruleNames, ruleDescription, errorDetail, errorContext, errorRange } = lintError;
|
||||
const ruleName = ruleNames.join("/");
|
||||
const description = ruleDescription +
|
||||
(errorDetail ? ` [${errorDetail}]` : "") +
|
||||
(errorContext ? ` [Context: "${errorContext}"]` : "");
|
||||
const column = (errorRange && errorRange[0]) || 0;
|
||||
const columnText = column ? `:${column}` : "";
|
||||
return `${source}:${lineNumber}${columnText} ${ruleName} ${description}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* TBD
|
||||
*
|
||||
* @param {string} lintErrorString Lint error string.
|
||||
* @returns {Object|null} Lint error (if valid).
|
||||
*/
|
||||
export function parseLintErrorString(lintErrorString) {
|
||||
const matchRe = /^([^:]+):\s*(\d+)(?::(\d+))?:?\s(\S+)\s(.+)$/;
|
||||
const match = matchRe.exec(lintErrorString);
|
||||
return match ?
|
||||
{
|
||||
"source": match[1],
|
||||
"line": match[2],
|
||||
"column": match[3],
|
||||
"rule": match[4],
|
||||
"message": match[5]
|
||||
} :
|
||||
null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the (semantic) version of the library.
|
||||
*
|
||||
|
|
@ -1492,18 +1531,10 @@ export function getVersion() {
|
|||
* @typedef {Array} Plugin
|
||||
*/
|
||||
|
||||
/**
|
||||
* Function to pretty-print lint results.
|
||||
*
|
||||
* @callback ToStringCallback
|
||||
* @returns {string} Pretty-printed results.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Lint results.
|
||||
*
|
||||
* @typedef {Object.<string, LintError[]>} LintResults
|
||||
* @property {ToStringCallback} toString String representation.
|
||||
*/
|
||||
|
||||
/**
|
||||
|
|
@ -1516,8 +1547,8 @@ export function getVersion() {
|
|||
* @property {string} ruleInformation Link to more information.
|
||||
* @property {string} errorDetail Detail about the error.
|
||||
* @property {string} errorContext Context for the error.
|
||||
* @property {number[]} errorRange Column number (1-based) and length.
|
||||
* @property {FixInfo} [fixInfo] Fix information.
|
||||
* @property {number[]|null} errorRange Column number (1-based) and length.
|
||||
* @property {FixInfo|null} fixInfo Fix information.
|
||||
*/
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue