mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-22 05:40:48 +02:00
Update MD018/MD019/MD020/MD021 to report fixInfo for violations.
This commit is contained in:
parent
c8a74bd72c
commit
316bfeadaa
8 changed files with 167 additions and 50 deletions
33
lib/md019.js
33
lib/md019.js
|
@ -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
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue