mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 06:20:12 +01:00
Update applyFix to make line ending optional, MD047 to highlight only last character.
This commit is contained in:
parent
d974e78e3f
commit
4843e277c0
4 changed files with 52 additions and 4 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/g, lineEnding) +
|
insertText.replace(/\n/g, lineEnding || "\n") +
|
||||||
line.slice(editIndex + deleteCount);
|
line.slice(editIndex + deleteCount);
|
||||||
}
|
}
|
||||||
module.exports.applyFix = applyFix;
|
module.exports.applyFix = applyFix;
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ module.exports = {
|
||||||
lastLineNumber,
|
lastLineNumber,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
null,
|
[ lastLine.length, 1 ],
|
||||||
{
|
{
|
||||||
"insertText": "\n",
|
"insertText": "\n",
|
||||||
"editColumn": lastLine.length + 1
|
"editColumn": lastLine.length + 1
|
||||||
|
|
|
||||||
|
|
@ -105,6 +105,6 @@
|
||||||
"ruleInformation": "https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md047",
|
"ruleInformation": "https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md047",
|
||||||
"errorDetail": null,
|
"errorDetail": null,
|
||||||
"errorContext": null,
|
"errorContext": null,
|
||||||
"errorRange": null
|
"errorRange": [ 25, 1 ]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
@ -578,7 +578,7 @@ module.exports.resultFormattingV3 = function resultFormattingV3(test) {
|
||||||
"ruleInformation": `${homepage}/blob/v${version}/doc/Rules.md#md047`,
|
"ruleInformation": `${homepage}/blob/v${version}/doc/Rules.md#md047`,
|
||||||
"errorDetail": null,
|
"errorDetail": null,
|
||||||
"errorContext": null,
|
"errorContext": null,
|
||||||
"errorRange": null,
|
"errorRange": [ 15, 1 ],
|
||||||
"fixInfo": {
|
"fixInfo": {
|
||||||
"insertText": "\n",
|
"insertText": "\n",
|
||||||
"editColumn": 16
|
"editColumn": 16
|
||||||
|
|
@ -1945,6 +1945,54 @@ module.exports.getPreferredLineEnding = function getPreferredLineEnding(test) {
|
||||||
test.done();
|
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) {
|
module.exports.applyFixes = function applyFixes(test) {
|
||||||
test.expect(28);
|
test.expect(28);
|
||||||
const testCases = [
|
const testCases = [
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue