mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2026-01-13 03:18:50 +01:00
Update MD009/MD010/MD012/MD028 to report fixInfo for violations.
This commit is contained in:
parent
679c83e23b
commit
2cd27c58f2
8 changed files with 165 additions and 31 deletions
24
lib/md009.js
24
lib/md009.js
|
|
@ -2,12 +2,10 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
const { addError, filterTokens, forEachLine, includesSorted, rangeFromRegExp } =
|
||||
const { addError, filterTokens, forEachLine, includesSorted } =
|
||||
require("../helpers");
|
||||
const { lineMetadata } = require("./cache");
|
||||
|
||||
const trailingSpaceRe = /\s+$/;
|
||||
|
||||
module.exports = {
|
||||
"names": [ "MD009", "no-trailing-spaces" ],
|
||||
"description": "Trailing spaces",
|
||||
|
|
@ -34,14 +32,22 @@ module.exports = {
|
|||
forEachLine(lineMetadata(), (line, lineIndex, inCode, onFence) => {
|
||||
inFencedCode += onFence;
|
||||
const lineNumber = lineIndex + 1;
|
||||
if ((!inCode || inFencedCode) && trailingSpaceRe.test(line) &&
|
||||
const trailingSpaces = line.length - line.trimRight().length;
|
||||
if ((!inCode || inFencedCode) && trailingSpaces &&
|
||||
!includesSorted(listItemLineNumbers, lineNumber)) {
|
||||
const actual = line.length - line.trimRight().length;
|
||||
if (expected !== actual) {
|
||||
addError(onError, lineNumber,
|
||||
if (expected !== trailingSpaces) {
|
||||
const column = line.length - trailingSpaces + 1;
|
||||
addError(
|
||||
onError,
|
||||
lineNumber,
|
||||
"Expected: " + (expected === 0 ? "" : "0 or ") +
|
||||
expected + "; Actual: " + actual,
|
||||
null, rangeFromRegExp(line, trailingSpaceRe));
|
||||
expected + "; Actual: " + trailingSpaces,
|
||||
null,
|
||||
[ column, trailingSpaces ],
|
||||
{
|
||||
"editColumn": column,
|
||||
"deleteCount": trailingSpaces
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -19,12 +19,18 @@ module.exports = {
|
|||
let match = null;
|
||||
while ((match = tabRe.exec(line)) !== null) {
|
||||
const column = match.index + 1;
|
||||
const length = match[0].length;
|
||||
addError(
|
||||
onError,
|
||||
lineIndex + 1,
|
||||
"Column: " + column,
|
||||
null,
|
||||
[ column, match[0].length ]);
|
||||
[ column, length ],
|
||||
{
|
||||
"editColumn": column,
|
||||
"deleteCount": length,
|
||||
"insertText": "".padEnd(length)
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
12
lib/md012.js
12
lib/md012.js
|
|
@ -15,7 +15,17 @@ module.exports = {
|
|||
forEachLine(lineMetadata(), (line, lineIndex, inCode) => {
|
||||
count = (inCode || line.trim().length) ? 0 : count + 1;
|
||||
if (maximum < count) {
|
||||
addErrorDetailIf(onError, lineIndex + 1, maximum, count);
|
||||
addErrorDetailIf(
|
||||
onError,
|
||||
lineIndex + 1,
|
||||
maximum,
|
||||
count,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
{
|
||||
"deleteCount": -1
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
19
lib/md028.js
19
lib/md028.js
|
|
@ -10,12 +10,29 @@ module.exports = {
|
|||
"tags": [ "blockquote", "whitespace" ],
|
||||
"function": function MD028(params, onError) {
|
||||
let prevToken = {};
|
||||
let prevLineNumber = null;
|
||||
params.tokens.forEach(function forToken(token) {
|
||||
if ((token.type === "blockquote_open") &&
|
||||
(prevToken.type === "blockquote_close")) {
|
||||
addError(onError, token.lineNumber - 1);
|
||||
for (
|
||||
let lineNumber = prevLineNumber;
|
||||
lineNumber < token.lineNumber;
|
||||
lineNumber++) {
|
||||
addError(
|
||||
onError,
|
||||
lineNumber,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
{
|
||||
"deleteCount": -1
|
||||
});
|
||||
}
|
||||
}
|
||||
prevToken = token;
|
||||
if (token.type === "blockquote_open") {
|
||||
prevLineNumber = token.map[1] + 1;
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue