mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 22:10:13 +01:00
Update MD038/no-space-in-code to avoid a possible range error for indented code fences.
This commit is contained in:
parent
0e80fa5720
commit
9f87e7dc60
5 changed files with 82 additions and 20 deletions
32
lib/md038.js
32
lib/md038.js
|
|
@ -41,7 +41,7 @@ module.exports = {
|
|||
tokenIfType(children[last - 2], "codeTextData");
|
||||
if (startSequence && endSequence && startData && endData) {
|
||||
const spaceLeft = leftSpaceRe.test(startData.text);
|
||||
const spaceRight = !spaceLeft && rightSpaceRe.test(endData.text);
|
||||
const spaceRight = rightSpaceRe.test(endData.text);
|
||||
if (spaceLeft || spaceRight) {
|
||||
let lineNumber = startSequence.startLine;
|
||||
let range = null;
|
||||
|
|
@ -56,7 +56,7 @@ module.exports = {
|
|||
"deleteCount": endSequence.startColumn - startSequence.endColumn,
|
||||
"insertText": trimCodeText(startData.text, true, true)
|
||||
};
|
||||
} else if (spaceLeft) {
|
||||
} else if (spaceLeft && (startSequence.endLine === startData.startLine)) {
|
||||
range = [
|
||||
startSequence.startColumn,
|
||||
startData.endColumn - startSequence.startColumn
|
||||
|
|
@ -66,7 +66,7 @@ module.exports = {
|
|||
"deleteCount": startData.endColumn - startData.startColumn,
|
||||
"insertText": trimCodeText(startData.text, true, false)
|
||||
};
|
||||
} else {
|
||||
} else if (spaceRight && (endData.text.trim().length > 0)) {
|
||||
lineNumber = endSequence.endLine;
|
||||
range = [
|
||||
endData.startColumn,
|
||||
|
|
@ -78,18 +78,20 @@ module.exports = {
|
|||
"insertText": trimCodeText(endData.text, false, true)
|
||||
};
|
||||
}
|
||||
const context = params
|
||||
.lines[lineNumber - 1]
|
||||
.substring(range[0] - 1, range[0] - 1 + range[1]);
|
||||
addErrorContext(
|
||||
onError,
|
||||
lineNumber,
|
||||
context,
|
||||
spaceLeft,
|
||||
spaceRight,
|
||||
range,
|
||||
fixInfo
|
||||
);
|
||||
if (range) {
|
||||
const context = params
|
||||
.lines[lineNumber - 1]
|
||||
.substring(range[0] - 1, range[0] - 1 + range[1]);
|
||||
addErrorContext(
|
||||
onError,
|
||||
lineNumber,
|
||||
context,
|
||||
spaceLeft,
|
||||
spaceRight,
|
||||
range,
|
||||
fixInfo
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue