mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 22:40:13 +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
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue