mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 22:10:13 +01:00
Update MD026/MD030 to report fixInfo for violations.
This commit is contained in:
parent
00a7e765ec
commit
0502e370de
5 changed files with 53 additions and 17 deletions
29
lib/md026.js
29
lib/md026.js
|
|
@ -2,8 +2,8 @@
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const { addError, allPunctuation, escapeForRegExp, forEachHeading,
|
const { addError, allPunctuation, escapeForRegExp, forEachHeading } =
|
||||||
rangeFromRegExp } = require("../helpers");
|
require("../helpers");
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
"names": [ "MD026", "no-trailing-punctuation" ],
|
"names": [ "MD026", "no-trailing-punctuation" ],
|
||||||
|
|
@ -15,13 +15,26 @@ module.exports = {
|
||||||
punctuation = allPunctuation;
|
punctuation = allPunctuation;
|
||||||
}
|
}
|
||||||
const trailingPunctuationRe =
|
const trailingPunctuationRe =
|
||||||
new RegExp("[" + escapeForRegExp(punctuation) + "]$");
|
new RegExp("\\s*[" + escapeForRegExp(punctuation) + "]+$");
|
||||||
forEachHeading(params, (heading, content) => {
|
forEachHeading(params, (heading) => {
|
||||||
const match = trailingPunctuationRe.exec(content);
|
const { line, lineNumber } = heading;
|
||||||
|
const trimmedLine = line.replace(/[\s#]*$/, "");
|
||||||
|
const match = trailingPunctuationRe.exec(trimmedLine);
|
||||||
if (match) {
|
if (match) {
|
||||||
addError(onError, heading.lineNumber,
|
const fullMatch = match[0];
|
||||||
"Punctuation: '" + match[0] + "'", null,
|
const column = match.index + 1;
|
||||||
rangeFromRegExp(heading.line, trailingPunctuationRe));
|
const length = fullMatch.length;
|
||||||
|
addError(
|
||||||
|
onError,
|
||||||
|
lineNumber,
|
||||||
|
`Punctuation: '${fullMatch}'`,
|
||||||
|
null,
|
||||||
|
[ column, length ],
|
||||||
|
{
|
||||||
|
"editColumn": column,
|
||||||
|
"deleteCount": length
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
28
lib/md030.js
28
lib/md030.js
|
|
@ -2,8 +2,7 @@
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const { addErrorDetailIf, listItemMarkerRe, rangeFromRegExp } =
|
const { addErrorDetailIf } = require("../helpers");
|
||||||
require("../helpers");
|
|
||||||
const { flattenedLists } = require("./cache");
|
const { flattenedLists } = require("./cache");
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
@ -22,10 +21,27 @@ module.exports = {
|
||||||
(allSingle ? ulSingle : ulMulti) :
|
(allSingle ? ulSingle : ulMulti) :
|
||||||
(allSingle ? olSingle : olMulti);
|
(allSingle ? olSingle : olMulti);
|
||||||
list.items.forEach((item) => {
|
list.items.forEach((item) => {
|
||||||
const match = /^[\s>]*\S+(\s+)/.exec(item.line);
|
const { line, lineNumber } = item;
|
||||||
addErrorDetailIf(onError, item.lineNumber,
|
const match = /^[\s>]*\S+(\s*)/.exec(line);
|
||||||
expectedSpaces, (match ? match[1].length : 0), null, null,
|
const [ { "length": matchLength }, { "length": actualSpaces } ] = match;
|
||||||
rangeFromRegExp(item.line, listItemMarkerRe));
|
let fixInfo = null;
|
||||||
|
if ((expectedSpaces !== actualSpaces) && (line.length > matchLength)) {
|
||||||
|
fixInfo = {
|
||||||
|
"editColumn": matchLength - actualSpaces + 1,
|
||||||
|
"deleteCount": actualSpaces,
|
||||||
|
"insertText": "".padEnd(expectedSpaces)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
addErrorDetailIf(
|
||||||
|
onError,
|
||||||
|
lineNumber,
|
||||||
|
expectedSpaces,
|
||||||
|
actualSpaces,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
[ 1, matchLength ],
|
||||||
|
fixInfo
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
"ruleInformation": "https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md030",
|
"ruleInformation": "https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md030",
|
||||||
"errorDetail": "Expected: 1; Actual: 0",
|
"errorDetail": "Expected: 1; Actual: 0",
|
||||||
"errorContext": null,
|
"errorContext": null,
|
||||||
"errorRange": null
|
"errorRange": [1, 1]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"lineNumber": 5,
|
"lineNumber": 5,
|
||||||
|
|
@ -15,7 +15,7 @@
|
||||||
"ruleInformation": "https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md030",
|
"ruleInformation": "https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md030",
|
||||||
"errorDetail": "Expected: 1; Actual: 0",
|
"errorDetail": "Expected: 1; Actual: 0",
|
||||||
"errorContext": null,
|
"errorContext": null,
|
||||||
"errorRange": null
|
"errorRange": [1, 2]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"lineNumber": 11,
|
"lineNumber": 11,
|
||||||
|
|
|
||||||
|
|
@ -23,3 +23,10 @@
|
||||||
## Heading/Full-Width {MD026} !
|
## Heading/Full-Width {MD026} !
|
||||||
|
|
||||||
## Heading/Full-Width {MD026} ?
|
## Heading/Full-Width {MD026} ?
|
||||||
|
|
||||||
|
<!-- markdownlint-disable heading-style -->
|
||||||
|
|
||||||
|
## Heading {MD026} alternate ? ##
|
||||||
|
|
||||||
|
Heading {MD026} alternate too ?
|
||||||
|
-------------------------------
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ List with multiple paragraphs and incorrect spacing
|
||||||
|
|
||||||
* Foo {MD030}
|
* Foo {MD030}
|
||||||
|
|
||||||
Here is the second paragraph
|
Here is the second paragraph
|
||||||
|
|
||||||
* Bar {MD030}
|
* Bar {MD030}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue