Update MD038/no-space-in-code to allow the "single leading and trailing space" scenario (fixes #271).

This commit is contained in:
David Anson 2020-04-06 20:43:38 -07:00
parent 6ce426cf88
commit 65b19b703b
8 changed files with 102 additions and 79 deletions

View file

@ -7,6 +7,7 @@ const { addErrorContext, filterTokens, forEachInlineCodeSpan, newLineRe } =
const leftSpaceRe = /^\s([^`]|$)/;
const rightSpaceRe = /[^`]\s$/;
const singleLeftRightSpaceRe = /^\s\S+\s$/;
module.exports = {
"names": [ "MD038", "no-space-in-code" ],
@ -32,7 +33,8 @@ module.exports = {
rangeLineOffset = codeLines.length - 1;
fixIndex = 0;
}
if (left || right) {
const allowed = singleLeftRightSpaceRe.test(code);
if ((left || right) && !allowed) {
const codeLinesRange = codeLines[rangeLineOffset];
if (codeLines.length > 1) {
rangeLength = codeLinesRange.length + tickCount;