mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 22:40:13 +01:00
Update MD037/MD038/MD039 to report fixInfo for violations.
This commit is contained in:
parent
620853f200
commit
c8a74bd72c
3 changed files with 66 additions and 29 deletions
22
lib/md038.js
22
lib/md038.js
|
|
@ -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()
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue