Update applyFix to make line ending optional, MD047 to highlight only last character.

This commit is contained in:
David Anson 2019-09-20 21:50:44 -07:00
parent d974e78e3f
commit 4843e277c0
4 changed files with 52 additions and 4 deletions

View file

@ -457,7 +457,7 @@ function applyFix(line, fixInfo, lineEnding) {
return (deleteCount === -1) ?
null :
line.slice(0, editIndex) +
insertText.replace(/\n/g, lineEnding) +
insertText.replace(/\n/g, lineEnding || "\n") +
line.slice(editIndex + deleteCount);
}
module.exports.applyFix = applyFix;

View file

@ -17,7 +17,7 @@ module.exports = {
lastLineNumber,
null,
null,
null,
[ lastLine.length, 1 ],
{
"insertText": "\n",
"editColumn": lastLine.length + 1

View file

@ -105,6 +105,6 @@
"ruleInformation": "https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md047",
"errorDetail": null,
"errorContext": null,
"errorRange": null
"errorRange": [ 25, 1 ]
}
]

View file

@ -578,7 +578,7 @@ module.exports.resultFormattingV3 = function resultFormattingV3(test) {
"ruleInformation": `${homepage}/blob/v${version}/doc/Rules.md#md047`,
"errorDetail": null,
"errorContext": null,
"errorRange": null,
"errorRange": [ 15, 1 ],
"fixInfo": {
"insertText": "\n",
"editColumn": 16
@ -1945,6 +1945,54 @@ module.exports.getPreferredLineEnding = function getPreferredLineEnding(test) {
test.done();
};
module.exports.applyFix = function applyFix(test) {
test.expect(4);
const testCases = [
[
"Hello world.",
{
"editColumn": 12,
"deleteCount": 1
},
undefined,
"Hello world"
],
[
"Hello world.",
{
"editColumn": 13,
"insertText": "\n"
},
undefined,
"Hello world.\n"
],
[
"Hello world.",
{
"editColumn": 13,
"insertText": "\n"
},
"\n",
"Hello world.\n"
],
[
"Hello world.",
{
"editColumn": 13,
"insertText": "\n"
},
"\r\n",
"Hello world.\r\n"
]
];
testCases.forEach((testCase) => {
const [ line, fixInfo, lineEnding, expected ] = testCase;
const actual = helpers.applyFix(line, fixInfo, lineEnding);
test.equal(actual, expected, "Incorrect fix applied.");
});
test.done();
};
module.exports.applyFixes = function applyFixes(test) {
test.expect(28);
const testCases = [