mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-22 05:40:48 +02:00
Fix applyFix handling of multiple line endings; MD022 handling of multiple lines.
This commit is contained in:
parent
52939a6d7e
commit
677255a484
5 changed files with 46 additions and 27 deletions
|
@ -457,7 +457,7 @@ function applyFix(line, fixInfo, lineEnding) {
|
|||
return (deleteCount === -1) ?
|
||||
null :
|
||||
line.slice(0, editIndex) +
|
||||
insertText.replace("\n", lineEnding) +
|
||||
insertText.replace(/\n/g, lineEnding) +
|
||||
line.slice(editIndex + deleteCount);
|
||||
}
|
||||
module.exports.applyFix = applyFix;
|
||||
|
|
24
lib/md022.js
24
lib/md022.js
|
@ -20,37 +20,41 @@ module.exports = {
|
|||
const { lines } = params;
|
||||
filterTokens(params, "heading_open", (token) => {
|
||||
const [ topIndex, nextIndex ] = token.map;
|
||||
let actualAbove = 0;
|
||||
for (let i = 0; i < linesAbove; i++) {
|
||||
if (!isBlankLine(lines[topIndex - i - 1])) {
|
||||
if (isBlankLine(lines[topIndex - i - 1])) {
|
||||
actualAbove++;
|
||||
}
|
||||
}
|
||||
addErrorDetailIf(
|
||||
onError,
|
||||
topIndex + 1,
|
||||
linesAbove,
|
||||
i,
|
||||
actualAbove,
|
||||
"Above",
|
||||
lines[topIndex].trim(),
|
||||
null,
|
||||
{
|
||||
"insertText": "\n"
|
||||
"insertText": "".padEnd(linesAbove - actualAbove, "\n")
|
||||
});
|
||||
}
|
||||
}
|
||||
let actualBelow = 0;
|
||||
for (let i = 0; i < linesBelow; i++) {
|
||||
if (!isBlankLine(lines[nextIndex + i])) {
|
||||
if (isBlankLine(lines[nextIndex + i])) {
|
||||
actualBelow++;
|
||||
}
|
||||
}
|
||||
addErrorDetailIf(
|
||||
onError,
|
||||
topIndex + 1,
|
||||
linesBelow,
|
||||
i,
|
||||
actualBelow,
|
||||
"Below",
|
||||
lines[topIndex].trim(),
|
||||
null,
|
||||
{
|
||||
"lineNumber": nextIndex + 1,
|
||||
"insertText": "\n"
|
||||
"insertText": "".padEnd(linesBelow - actualBelow, "\n")
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
|
@ -22,5 +22,6 @@ Text
|
|||
Elderberry
|
||||
----------
|
||||
|
||||
|
||||
Text
|
||||
## Fig
|
||||
|
|
|
@ -21,6 +21,7 @@ Text
|
|||
Text
|
||||
|
||||
|
||||
|
||||
Elderberry
|
||||
----------
|
||||
Text
|
||||
|
|
|
@ -1946,7 +1946,7 @@ module.exports.getPreferredLineEnding = function getPreferredLineEnding(test) {
|
|||
};
|
||||
|
||||
module.exports.applyFixes = function applyFixes(test) {
|
||||
test.expect(27);
|
||||
test.expect(28);
|
||||
const testCases = [
|
||||
[
|
||||
"Hello world.",
|
||||
|
@ -2361,6 +2361,19 @@ module.exports.applyFixes = function applyFixes(test) {
|
|||
}
|
||||
],
|
||||
"Hello\rworld\rhello\rworld\r"
|
||||
],
|
||||
[
|
||||
"Hello\r\nworld",
|
||||
[
|
||||
{
|
||||
"lineNumber": 2,
|
||||
"fixInfo": {
|
||||
"editColumn": 6,
|
||||
"insertText": "\n\n"
|
||||
}
|
||||
}
|
||||
],
|
||||
"Hello\r\nworld\r\n\r\n"
|
||||
]
|
||||
];
|
||||
testCases.forEach((testCase) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue