Update MD037/MD038/MD039 to report fixInfo for violations.

This commit is contained in:
David Anson 2019-09-06 22:35:33 -07:00
parent 620853f200
commit c8a74bd72c
3 changed files with 66 additions and 29 deletions

View file

@ -5,8 +5,8 @@
const { addErrorContext, filterTokens, forEachInlineCodeSpan, newLineRe } =
require("../helpers");
const startRe = /^\s([^`]|$)/;
const endRe = /[^`]\s$/;
const leftSpaceRe = /^\s([^`]|$)/;
const rightSpaceRe = /[^`]\s$/;
module.exports = {
"names": [ "MD038", "no-space-in-code" ],
@ -23,8 +23,8 @@ module.exports = {
let rangeLength = code.length + (2 * tickCount);
let rangeLineOffset = 0;
const codeLines = code.split(newLineRe);
const left = startRe.test(code);
const right = !left && endRe.test(code);
const left = leftSpaceRe.test(code);
const right = !left && rightSpaceRe.test(code);
if (right && (codeLines.length > 1)) {
rangeIndex = 0;
rangeLineOffset = codeLines.length - 1;
@ -36,8 +36,18 @@ module.exports = {
const context = tokenLines[lineIndex + rangeLineOffset]
.substring(rangeIndex, rangeIndex + rangeLength);
addErrorContext(
onError, token.lineNumber + lineIndex + rangeLineOffset,
context, left, right, [ rangeIndex + 1, rangeLength ]);
onError,
token.lineNumber + lineIndex + rangeLineOffset,
context,
left,
right,
[ rangeIndex + 1, rangeLength ],
{
"editColumn": rangeIndex + (left ? tickCount : 0) + 1,
"deleteCount": rangeLength - (right ? tickCount : 0),
"insertText": code.trim()
}
);
}
});
}