Update MD038/no-space-in-code to allow code spans with only spaces (fixes #1481).

This commit is contained in:
David Anson 2025-02-02 21:36:35 -08:00
parent 2d2fafc58d
commit 90cf515ff0
7 changed files with 56 additions and 68 deletions

View file

@ -6,6 +6,7 @@ import { filterByTypesCached } from "./cache.mjs";
const leftSpaceRe = /^\s(?:[^`]|$)/;
const rightSpaceRe = /[^`]\s$/;
const allSpaceRe = /^\s*$/;
const trimCodeText = (text, start, end) => {
text = text.replace(/^\s+$/, "");
if (start) {
@ -35,7 +36,10 @@ export default {
if (startSequence && endSequence && startData && endData) {
const spaceLeft = leftSpaceRe.test(startData.text);
const spaceRight = rightSpaceRe.test(endData.text);
if (spaceLeft || spaceRight) {
if (
(spaceLeft || spaceRight) &&
!datas.every((data) => allSpaceRe.test(data.text))
) {
let lineNumber = startSequence.startLine;
let range = undefined;
let fixInfo = undefined;