Fix applyFix handling of multiple line endings; MD022 handling of multiple lines.

This commit is contained in:
David Anson 2019-09-16 22:34:49 -07:00
parent 52939a6d7e
commit 677255a484
5 changed files with 46 additions and 27 deletions

View file

@ -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;

View file

@ -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")
});
}
}
});
}
};

View file

@ -22,5 +22,6 @@ Text
Elderberry
----------
Text
## Fig

View file

@ -21,6 +21,7 @@ Text
Text
Elderberry
----------
Text

View file

@ -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) => {