mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 22:10:13 +01:00
Add br_spaces parameter to MD009.
This commit is contained in:
parent
0e24df7cf7
commit
9acbb2750e
4 changed files with 25 additions and 1 deletions
11
doc/Rules.md
11
doc/Rules.md
|
|
@ -182,9 +182,20 @@ for a description of the problem.
|
||||||
|
|
||||||
Tags: whitespace
|
Tags: whitespace
|
||||||
|
|
||||||
|
Parameters: br_spaces (number; default: 0)
|
||||||
|
|
||||||
This rule is triggered on any lines that end with whitespace. To fix this,
|
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.
|
find the line that is triggered and remove any trailing spaces from the end.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
## MD010 - Hard tabs
|
## MD010 - Hard tabs
|
||||||
|
|
||||||
Tags: whitespace, hard_tab
|
Tags: whitespace, hard_tab
|
||||||
|
|
|
||||||
|
|
@ -237,8 +237,11 @@ module.exports = [
|
||||||
"desc": "Trailing spaces",
|
"desc": "Trailing spaces",
|
||||||
"tags": [ "whitespace" ],
|
"tags": [ "whitespace" ],
|
||||||
"func": function MD009(params, errors) {
|
"func": function MD009(params, errors) {
|
||||||
|
var brSpaces = params.options.br_spaces || 0;
|
||||||
params.lines.forEach(function forLine(line, lineIndex) {
|
params.lines.forEach(function forLine(line, lineIndex) {
|
||||||
if (/\s$/.test(line)) {
|
if (/\s$/.test(line) &&
|
||||||
|
((brSpaces < 2) ||
|
||||||
|
(line.length - line.trimRight().length !== brSpaces))) {
|
||||||
errors.push(lineIndex + 1);
|
errors.push(lineIndex + 1);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
6
test/trailing_spaces_br.json
Normal file
6
test/trailing_spaces_br.json
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"default": true,
|
||||||
|
"MD009": {
|
||||||
|
"br_spaces": 2
|
||||||
|
}
|
||||||
|
}
|
||||||
4
test/trailing_spaces_br.md
Normal file
4
test/trailing_spaces_br.md
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
This line has a single trailing space {MD009}
|
||||||
|
This line has two trailing spaces and should be allowed
|
||||||
|
This line has three trailing spaces {MD009}
|
||||||
|
This line has four trailing spaces {MD009}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue