mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-21 21:30:47 +02:00
Update MD009/no-trailing-spaces default configuration to allow 2 spaces for hard break (fixes #114).
This commit is contained in:
parent
36dc946f46
commit
3e1317709a
7 changed files with 29 additions and 26 deletions
20
doc/Rules.md
20
doc/Rules.md
|
@ -288,19 +288,17 @@ Tags: whitespace
|
|||
|
||||
Aliases: no-trailing-spaces
|
||||
|
||||
Parameters: br_spaces, list_item_empty_lines (number; default 0, boolean; default false)
|
||||
Parameters: br_spaces, list_item_empty_lines (number; default 2, boolean; default false)
|
||||
|
||||
This rule is triggered on any lines that end with whitespace. To fix this,
|
||||
find the line that is triggered and remove any trailing spaces from the end.
|
||||
This rule is triggered on any lines that end with unexpected whitespace. To fix this,
|
||||
remove the trailing space from the end of the line.
|
||||
|
||||
The `br_spaces` parameter allows an exception to this rule for a specific amount
|
||||
of trailing spaces used to insert an explicit line break/br element. For
|
||||
example, set `br_spaces` to 2 to allow exactly 2 spaces at the end of a line.
|
||||
The `br_spaces` parameter allows an exception to this rule for a specific number
|
||||
of trailing spaces, typically used to insert an explicit line break. The default
|
||||
value allows 2 spaces to indicate a hard break (\<br> element).
|
||||
|
||||
Note: you have to set `br_spaces` to 2 or higher for this exception to take
|
||||
effect - you can't insert a br element with just a single trailing space, so
|
||||
if you set `br_spaces` to 1, the exception will be disabled, just as if it was
|
||||
set to the default of 0.
|
||||
Note: You must set `br_spaces` to a value >= 2 for this parameter to take effect.
|
||||
Setting `br_spaces` to 1 behaves the same as 0, disallowing any trailing spaces.
|
||||
|
||||
Using spaces to indent blank lines inside a list item is usually not necessary,
|
||||
but some parsers require it. Set the `list_item_empty_lines` parameter to `true`
|
||||
|
@ -308,7 +306,7 @@ to allow this:
|
|||
|
||||
```markdown
|
||||
- list item text
|
||||
|
||||
[2 spaces]
|
||||
list item text
|
||||
```
|
||||
|
||||
|
|
18
lib/md009.js
18
lib/md009.js
|
@ -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));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -95,7 +95,7 @@ rules.forEach(function forRule(rule) {
|
|||
"br_spaces": {
|
||||
"description": "Spaces for line break",
|
||||
"type": "integer",
|
||||
"default": 0
|
||||
"default": 2
|
||||
},
|
||||
"list_item_empty_lines": {
|
||||
"description": "Allow spaces for empty lines in list items",
|
||||
|
|
|
@ -256,7 +256,7 @@
|
|||
"br_spaces": {
|
||||
"description": "Spaces for line break",
|
||||
"type": "integer",
|
||||
"default": 0
|
||||
"default": 2
|
||||
},
|
||||
"list_item_empty_lines": {
|
||||
"description": "Allow spaces for empty lines in list items",
|
||||
|
@ -277,7 +277,7 @@
|
|||
"br_spaces": {
|
||||
"description": "Spaces for line break",
|
||||
"type": "integer",
|
||||
"default": 0
|
||||
"default": 2
|
||||
},
|
||||
"list_item_empty_lines": {
|
||||
"description": "Allow spaces for empty lines in list items",
|
||||
|
|
|
@ -59,7 +59,7 @@
|
|||
"lineNumber": 15,
|
||||
"ruleNames": [ "MD009", "no-trailing-spaces" ],
|
||||
"ruleDescription": "Trailing spaces",
|
||||
"errorDetail": "Expected: 0; Actual: 1",
|
||||
"errorDetail": "Expected: 0 or 2; Actual: 1",
|
||||
"errorContext": null,
|
||||
"errorRange": [5, 1]
|
||||
},
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
{
|
||||
"default": true,
|
||||
"MD009": {
|
||||
"br_spaces": 0
|
||||
},
|
||||
"MD041": true
|
||||
}
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
{
|
||||
"default": true,
|
||||
"MD009": {
|
||||
"br_spaces": 2
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue