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) ?
|
return (deleteCount === -1) ?
|
||||||
null :
|
null :
|
||||||
line.slice(0, editIndex) +
|
line.slice(0, editIndex) +
|
||||||
insertText.replace("\n", lineEnding) +
|
insertText.replace(/\n/g, lineEnding) +
|
||||||
line.slice(editIndex + deleteCount);
|
line.slice(editIndex + deleteCount);
|
||||||
}
|
}
|
||||||
module.exports.applyFix = applyFix;
|
module.exports.applyFix = applyFix;
|
||||||
|
|
24
lib/md022.js
24
lib/md022.js
|
@ -20,37 +20,41 @@ module.exports = {
|
||||||
const { lines } = params;
|
const { lines } = params;
|
||||||
filterTokens(params, "heading_open", (token) => {
|
filterTokens(params, "heading_open", (token) => {
|
||||||
const [ topIndex, nextIndex ] = token.map;
|
const [ topIndex, nextIndex ] = token.map;
|
||||||
|
let actualAbove = 0;
|
||||||
for (let i = 0; i < linesAbove; i++) {
|
for (let i = 0; i < linesAbove; i++) {
|
||||||
if (!isBlankLine(lines[topIndex - i - 1])) {
|
if (isBlankLine(lines[topIndex - i - 1])) {
|
||||||
|
actualAbove++;
|
||||||
|
}
|
||||||
|
}
|
||||||
addErrorDetailIf(
|
addErrorDetailIf(
|
||||||
onError,
|
onError,
|
||||||
topIndex + 1,
|
topIndex + 1,
|
||||||
linesAbove,
|
linesAbove,
|
||||||
i,
|
actualAbove,
|
||||||
"Above",
|
"Above",
|
||||||
lines[topIndex].trim(),
|
lines[topIndex].trim(),
|
||||||
null,
|
null,
|
||||||
{
|
{
|
||||||
"insertText": "\n"
|
"insertText": "".padEnd(linesAbove - actualAbove, "\n")
|
||||||
});
|
});
|
||||||
}
|
let actualBelow = 0;
|
||||||
}
|
|
||||||
for (let i = 0; i < linesBelow; i++) {
|
for (let i = 0; i < linesBelow; i++) {
|
||||||
if (!isBlankLine(lines[nextIndex + i])) {
|
if (isBlankLine(lines[nextIndex + i])) {
|
||||||
|
actualBelow++;
|
||||||
|
}
|
||||||
|
}
|
||||||
addErrorDetailIf(
|
addErrorDetailIf(
|
||||||
onError,
|
onError,
|
||||||
topIndex + 1,
|
topIndex + 1,
|
||||||
linesBelow,
|
linesBelow,
|
||||||
i,
|
actualBelow,
|
||||||
"Below",
|
"Below",
|
||||||
lines[topIndex].trim(),
|
lines[topIndex].trim(),
|
||||||
null,
|
null,
|
||||||
{
|
{
|
||||||
"lineNumber": nextIndex + 1,
|
"lineNumber": nextIndex + 1,
|
||||||
"insertText": "\n"
|
"insertText": "".padEnd(linesBelow - actualBelow, "\n")
|
||||||
});
|
});
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -22,5 +22,6 @@ Text
|
||||||
Elderberry
|
Elderberry
|
||||||
----------
|
----------
|
||||||
|
|
||||||
|
|
||||||
Text
|
Text
|
||||||
## Fig
|
## Fig
|
||||||
|
|
|
@ -21,6 +21,7 @@ Text
|
||||||
Text
|
Text
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Elderberry
|
Elderberry
|
||||||
----------
|
----------
|
||||||
Text
|
Text
|
||||||
|
|
|
@ -1946,7 +1946,7 @@ module.exports.getPreferredLineEnding = function getPreferredLineEnding(test) {
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.applyFixes = function applyFixes(test) {
|
module.exports.applyFixes = function applyFixes(test) {
|
||||||
test.expect(27);
|
test.expect(28);
|
||||||
const testCases = [
|
const testCases = [
|
||||||
[
|
[
|
||||||
"Hello world.",
|
"Hello world.",
|
||||||
|
@ -2361,6 +2361,19 @@ module.exports.applyFixes = function applyFixes(test) {
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"Hello\rworld\rhello\rworld\r"
|
"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) => {
|
testCases.forEach((testCase) => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue