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,8 +2,7 @@
"use strict";
const { addErrorContext, atxHeadingSpaceRe, forEachLine,
rangeFromRegExp } = require("../helpers");
const { addErrorContext, forEachLine } = require("../helpers");
const { lineMetadata } = require("./cache");
module.exports = {
@ -12,9 +11,20 @@ module.exports = {
"tags": [ "headings", "headers", "atx", "spaces" ],
"function": function MD018(params, onError) {
forEachLine(lineMetadata(), (line, lineIndex, inCode) => {
if (!inCode && /^#+[^#\s]/.test(line) && !/#$/.test(line)) {
addErrorContext(onError, lineIndex + 1, line.trim(), null,
null, rangeFromRegExp(line, atxHeadingSpaceRe));
if (!inCode && /^#+[^#\s]/.test(line) && !/#\s*$/.test(line)) {
const hashCount = /^#+/.exec(line)[0].length;
addErrorContext(
onError,
lineIndex + 1,
line.trim(),
null,
null,
[ 1, hashCount + 1 ],
{
"editColumn": hashCount + 1,
"insertText": " "
}
);
}
});
}