Update MD018/MD019/MD020/MD021 to report fixInfo for violations.

This commit is contained in:
David Anson 2019-09-08 16:51:00 -07:00
parent c8a74bd72c
commit 316bfeadaa
8 changed files with 167 additions and 50 deletions

View file

@ -2,20 +2,37 @@
"use strict";
const { addErrorContext, atxHeadingSpaceRe, filterTokens, headingStyleFor,
rangeFromRegExp } = require("../helpers");
const { addErrorContext, filterTokens, headingStyleFor } =
require("../helpers");
module.exports = {
"names": [ "MD019", "no-multiple-space-atx" ],
"description": "Multiple spaces after hash on atx style heading",
"tags": [ "headings", "headers", "atx", "spaces" ],
"function": function MD019(params, onError) {
filterTokens(params, "heading_open", function forToken(token) {
if ((headingStyleFor(token) === "atx") &&
/^#+\s\s/.test(token.line)) {
addErrorContext(onError, token.lineNumber, token.line.trim(),
null, null,
rangeFromRegExp(token.line, atxHeadingSpaceRe));
filterTokens(params, "heading_open", (token) => {
if (headingStyleFor(token) === "atx") {
const { line, lineNumber } = token;
const match = /^(#+)(\s{2,})/.exec(line);
if (match) {
const [
,
{ "length": hashLength },
{ "length": spacesLength }
] = match;
addErrorContext(
onError,
lineNumber,
line.trim(),
null,
null,
[ 1, hashLength + spacesLength + 1 ],
{
"editColumn": hashLength + 1,
"deleteCount": spacesLength - 1
}
);
}
}
});
}