mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-22 05:40:48 +02:00
Update MD009/no-trailing-spaces to allow trailing spaces in fenced code blocks (fixes #292).
This commit is contained in:
parent
6c1bc8ecb5
commit
bd63c57fde
4 changed files with 45 additions and 10 deletions
|
@ -341,6 +341,9 @@ Fixable: Most violations can be fixed by tooling
|
||||||
This rule is triggered on any lines that end with unexpected whitespace. To fix this,
|
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.
|
remove the trailing space from the end of the line.
|
||||||
|
|
||||||
|
Note: Trailing space is allowed in indented and fenced code blocks because some
|
||||||
|
languages require it.
|
||||||
|
|
||||||
The `br_spaces` parameter allows an exception to this rule for a specific number
|
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
|
of trailing spaces, typically used to insert an explicit line break. The default
|
||||||
value allows 2 spaces to indicate a hard break (\<br> element).
|
value allows 2 spaces to indicate a hard break (\<br> element).
|
||||||
|
|
|
@ -47,12 +47,10 @@ module.exports = {
|
||||||
codeInlineLineNumbers.sort(numericSortAscending);
|
codeInlineLineNumbers.sort(numericSortAscending);
|
||||||
}
|
}
|
||||||
const expected = (brSpaces < 2) ? 0 : brSpaces;
|
const expected = (brSpaces < 2) ? 0 : brSpaces;
|
||||||
let inFencedCode = 0;
|
forEachLine(lineMetadata(), (line, lineIndex, inCode) => {
|
||||||
forEachLine(lineMetadata(), (line, lineIndex, inCode, onFence) => {
|
|
||||||
inFencedCode += onFence;
|
|
||||||
const lineNumber = lineIndex + 1;
|
const lineNumber = lineIndex + 1;
|
||||||
const trailingSpaces = line.length - line.trimRight().length;
|
const trailingSpaces = line.length - line.trimRight().length;
|
||||||
if ((!inCode || inFencedCode) && trailingSpaces &&
|
if (trailingSpaces && !inCode &&
|
||||||
!includesSorted(listItemLineNumbers, lineNumber)) {
|
!includesSorted(listItemLineNumbers, lineNumber)) {
|
||||||
if ((expected !== trailingSpaces) ||
|
if ((expected !== trailingSpaces) ||
|
||||||
(strict &&
|
(strict &&
|
||||||
|
|
40
test/code-block-trailing-spaces.md
Normal file
40
test/code-block-trailing-spaces.md
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
# code-block-trailing-spaces
|
||||||
|
|
||||||
|
Text
|
||||||
|
|
||||||
|
Two trailing spaces {MD009}
|
||||||
|
|
||||||
|
Text
|
||||||
|
|
||||||
|
Indented code block
|
||||||
|
|
||||||
|
Statement
|
||||||
|
Indented statement
|
||||||
|
|
||||||
|
Statement
|
||||||
|
Indented statement
|
||||||
|
|
||||||
|
Two trailing spaces
|
||||||
|
|
||||||
|
Text
|
||||||
|
|
||||||
|
```text
|
||||||
|
Fenced code block
|
||||||
|
|
||||||
|
Statement
|
||||||
|
Indented statement
|
||||||
|
|
||||||
|
Statement
|
||||||
|
Indented statement
|
||||||
|
|
||||||
|
Two trailing spaces
|
||||||
|
```
|
||||||
|
|
||||||
|
Text
|
||||||
|
|
||||||
|
<!-- markdownlint-configure-file
|
||||||
|
{
|
||||||
|
"no-trailing-spaces": { "strict": true },
|
||||||
|
"code-block-style": false
|
||||||
|
}
|
||||||
|
-->
|
|
@ -11,12 +11,6 @@ And here is more text
|
||||||
This is a code block that won't trigger.
|
This is a code block that won't trigger.
|
||||||
```
|
```
|
||||||
|
|
||||||
```text
|
|
||||||
This is code
|
|
||||||
|
|
||||||
with a line with trailing spaces. {MD009:16}
|
|
||||||
```
|
|
||||||
|
|
||||||
But we'll do another:
|
But we'll do another:
|
||||||
|
|
||||||
And this {MD046}
|
And this {MD046}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue