From 779a55a662de63cc012ce605a42938e8db7ccb67 Mon Sep 17 00:00:00 2001 From: Wouter Admiraal <45544358+wouter-admiraal-sonarsource@users.noreply.github.com> Date: Wed, 29 May 2019 05:52:48 +0200 Subject: [PATCH] Allow trailing spaces in indented code blocks (#191) --- lib/md009.js | 6 ++++-- test/code_block_fenced.md | 6 ++++++ test/code_block_indented.md | 6 +++++- test/trailing_spaces_br.md | 2 ++ 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/md009.js b/lib/md009.js index 18add32e..0fef5a88 100644 --- a/lib/md009.js +++ b/lib/md009.js @@ -30,9 +30,11 @@ module.exports = { listItemLineNumbers.sort((a, b) => a - b); } const expected = (brSpaces < 2) ? 0 : brSpaces; - forEachLine(lineMetadata(), (line, lineIndex) => { + let inFencedCode = 0; + forEachLine(lineMetadata(), (line, lineIndex, inCode, onFence) => { + inFencedCode += onFence; const lineNumber = lineIndex + 1; - if (trailingSpaceRe.test(line) && + if ((!inCode || inFencedCode) && trailingSpaceRe.test(line) && !includesSorted(listItemLineNumbers, lineNumber)) { const actual = line.length - line.trimRight().length; if (expected !== actual) { diff --git a/test/code_block_fenced.md b/test/code_block_fenced.md index 4c05b627..047264c5 100644 --- a/test/code_block_fenced.md +++ b/test/code_block_fenced.md @@ -9,6 +9,12 @@ And here is more text This is a code block that won't trigger. ``` +```text +This is code + +with a line with trailing spaces. {MD009:14} +``` + But we'll do another: And this {MD046} diff --git a/test/code_block_indented.md b/test/code_block_indented.md index ae443f7e..5576dcd8 100644 --- a/test/code_block_indented.md +++ b/test/code_block_indented.md @@ -14,4 +14,8 @@ But we'll do another: And this will. -Final text is here +One last one: + + This is code + + with an empty indented line. diff --git a/test/trailing_spaces_br.md b/test/trailing_spaces_br.md index a619772b..826fce7b 100644 --- a/test/trailing_spaces_br.md +++ b/test/trailing_spaces_br.md @@ -2,3 +2,5 @@ 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} + +{MD009:5}