diff --git a/helpers/helpers.js b/helpers/helpers.js index 6cd386ac..9f850303 100644 --- a/helpers/helpers.js +++ b/helpers/helpers.js @@ -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; diff --git a/lib/md047.js b/lib/md047.js index a1f41525..a001b27b 100644 --- a/lib/md047.js +++ b/lib/md047.js @@ -17,7 +17,7 @@ module.exports = { lastLineNumber, null, null, - null, + [ lastLine.length, 1 ], { "insertText": "\n", "editColumn": lastLine.length + 1 diff --git a/test/detailed-results-MD041-MD050.results.json b/test/detailed-results-MD041-MD050.results.json index b7b80366..5151f974 100644 --- a/test/detailed-results-MD041-MD050.results.json +++ b/test/detailed-results-MD041-MD050.results.json @@ -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 ] } ] \ No newline at end of file diff --git a/test/markdownlint-test.js b/test/markdownlint-test.js index 1890bf23..c34dc559 100644 --- a/test/markdownlint-test.js +++ b/test/markdownlint-test.js @@ -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 = [