Update MD009/no-trailing-spaces default configuration to allow 2 spaces for hard break (fixes #114).

This commit is contained in:
David Anson 2018-04-30 21:34:19 -07:00
parent 36dc946f46
commit 3e1317709a
7 changed files with 29 additions and 26 deletions

View file

@ -11,7 +11,10 @@ module.exports = {
"description": "Trailing spaces",
"tags": [ "whitespace" ],
"function": function MD009(params, onError) {
const brSpaces = params.config.br_spaces || 0;
let brSpaces = params.config.br_spaces;
if (brSpaces === undefined) {
brSpaces = 2;
}
const listItemEmptyLines = params.config.list_item_empty_lines;
const allowListItemEmptyLines =
(listItemEmptyLines === undefined) ? false : !!listItemEmptyLines;
@ -23,14 +26,19 @@ module.exports = {
}
});
}
const expected = (brSpaces < 2) ? 0 : brSpaces;
shared.forEachLine(function forLine(line, lineIndex) {
const lineNumber = lineIndex + 1;
if (trailingSpaceRe.test(line) &&
(listItemLineNumbers.indexOf(lineNumber) === -1)) {
const expected = (brSpaces < 2) ? 0 : brSpaces;
shared.addErrorDetailIf(onError, lineNumber,
expected, line.length - shared.trimRight(line).length, null,
shared.rangeFromRegExp(line, trailingSpaceRe));
const actual = line.length - shared.trimRight(line).length;
if (expected !== actual) {
shared.addError(onError, lineNumber,
"Expected: " + (expected === 0 ? "" : "0 or ") +
expected + "; Actual: " + actual,
null,
shared.rangeFromRegExp(line, trailingSpaceRe));
}
}
});
}