mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2026-01-27 09:26:09 +01:00
Update MD006/MD023 to report fixInfo for violations, process input to fixErrors.
This commit is contained in:
parent
84e972c72c
commit
5e73aa1d9d
5 changed files with 94 additions and 25 deletions
17
lib/md006.js
17
lib/md006.js
|
|
@ -13,10 +13,19 @@ module.exports = {
|
|||
"tags": [ "bullet", "ul", "indentation" ],
|
||||
"function": function MD006(params, onError) {
|
||||
flattenedLists().forEach((list) => {
|
||||
if (list.unordered && !list.nesting) {
|
||||
addErrorDetailIf(onError, list.open.lineNumber,
|
||||
0, list.indent, null, null,
|
||||
rangeFromRegExp(list.open.line, listItemMarkerRe));
|
||||
if (list.unordered && !list.nesting && (list.indent !== 0)) {
|
||||
const { lineNumber, line } = list.open;
|
||||
addErrorDetailIf(
|
||||
onError,
|
||||
lineNumber,
|
||||
0,
|
||||
list.indent,
|
||||
null,
|
||||
null,
|
||||
rangeFromRegExp(line, listItemMarkerRe),
|
||||
{
|
||||
"deleteCount": line.length - line.trimLeft().length
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
26
lib/md023.js
26
lib/md023.js
|
|
@ -2,8 +2,7 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
const { addErrorContext, filterTokens, rangeFromRegExp } =
|
||||
require("../helpers");
|
||||
const { addErrorContext, filterTokens } = require("../helpers");
|
||||
|
||||
const spaceBeforeHeadingRe = /^((?:\s+)|(?:[>\s]+\s\s))[^>\s]/;
|
||||
|
||||
|
|
@ -13,9 +12,26 @@ module.exports = {
|
|||
"tags": [ "headings", "headers", "spaces" ],
|
||||
"function": function MD023(params, onError) {
|
||||
filterTokens(params, "heading_open", function forToken(token) {
|
||||
if (spaceBeforeHeadingRe.test(token.line)) {
|
||||
addErrorContext(onError, token.lineNumber, token.line, null,
|
||||
null, rangeFromRegExp(token.line, spaceBeforeHeadingRe));
|
||||
const { lineNumber, line } = token;
|
||||
const match = line.match(spaceBeforeHeadingRe);
|
||||
if (match) {
|
||||
const [ prefixAndFirstChar, prefix ] = match;
|
||||
let deleteCount = prefix.length;
|
||||
const prefixLengthNoSpace = prefix.trimRight().length;
|
||||
if (prefixLengthNoSpace) {
|
||||
deleteCount -= prefixLengthNoSpace - 1;
|
||||
}
|
||||
addErrorContext(
|
||||
onError,
|
||||
lineNumber,
|
||||
line,
|
||||
null,
|
||||
null,
|
||||
[ 1, prefixAndFirstChar.length ],
|
||||
{
|
||||
"editColumn": prefixLengthNoSpace + 1,
|
||||
"deleteCount": deleteCount
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue