mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-22 05:40:48 +02:00
Update MD026/MD030 to report fixInfo for violations.
This commit is contained in:
parent
00a7e765ec
commit
0502e370de
5 changed files with 53 additions and 17 deletions
28
lib/md030.js
28
lib/md030.js
|
@ -2,8 +2,7 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
const { addErrorDetailIf, listItemMarkerRe, rangeFromRegExp } =
|
||||
require("../helpers");
|
||||
const { addErrorDetailIf } = require("../helpers");
|
||||
const { flattenedLists } = require("./cache");
|
||||
|
||||
module.exports = {
|
||||
|
@ -22,10 +21,27 @@ module.exports = {
|
|||
(allSingle ? ulSingle : ulMulti) :
|
||||
(allSingle ? olSingle : olMulti);
|
||||
list.items.forEach((item) => {
|
||||
const match = /^[\s>]*\S+(\s+)/.exec(item.line);
|
||||
addErrorDetailIf(onError, item.lineNumber,
|
||||
expectedSpaces, (match ? match[1].length : 0), null, null,
|
||||
rangeFromRegExp(item.line, listItemMarkerRe));
|
||||
const { line, lineNumber } = item;
|
||||
const match = /^[\s>]*\S+(\s*)/.exec(line);
|
||||
const [ { "length": matchLength }, { "length": actualSpaces } ] = match;
|
||||
let fixInfo = null;
|
||||
if ((expectedSpaces !== actualSpaces) && (line.length > matchLength)) {
|
||||
fixInfo = {
|
||||
"editColumn": matchLength - actualSpaces + 1,
|
||||
"deleteCount": actualSpaces,
|
||||
"insertText": "".padEnd(expectedSpaces)
|
||||
};
|
||||
}
|
||||
addErrorDetailIf(
|
||||
onError,
|
||||
lineNumber,
|
||||
expectedSpaces,
|
||||
actualSpaces,
|
||||
null,
|
||||
null,
|
||||
[ 1, matchLength ],
|
||||
fixInfo
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue