[GH-ISSUE #1899] MD012 shall make it possible, that files end with a blank line as recommended #2620

Closed
opened 2026-03-07 20:09:27 +03:00 by kerem · 4 comments
Owner

Originally created by @jamilraichouni on GitHub (Dec 20, 2025).
Original GitHub issue: https://github.com/DavidAnson/markdownlint/issues/1899

Hi!

I use markdownlint v0.47.0.

It is recommended and very common that files end with a blank line:

The rule MD012/no-multiple-blanks does not allow that. I do not want to disable the rule for the whole of my Markdown files. The rule makes sense everywhere except for the end of the file.

Example:

echo -e "# My title\n\nThis is my doc.\n" | markdownlint -s

results in

stdin:5 error MD012/no-multiple-blanks Multiple consecutive blank lines [Expected: 1; Actual: 2] 

I think that this needs a fix.

Many thanks,
Jamil

Originally created by @jamilraichouni on GitHub (Dec 20, 2025). Original GitHub issue: https://github.com/DavidAnson/markdownlint/issues/1899 Hi! I use `markdownlint v0.47.0`. It is recommended and very common that files end with a blank line: - <https://stackoverflow.com/questions/2287967/why-is-it-recommended-to-have-empty-line-in-the-end-of-a-source-file> - - <https://dev.to/documendous/why-you-should-end-your-source-files-with-a-new-line-156g#:~:text=Code%20Linters%20and%20Formatters,-Code%20linters%20and&text=One%20common%20rule%20is%20to,codebase%20remains%20clean%20and%20maintainable.> The rule `MD012/no-multiple-blanks` does not allow that. I do not want to disable the rule for the whole of my Markdown files. The rule makes sense everywhere except for the end of the file. Example: ```bash echo -e "# My title\n\nThis is my doc.\n" | markdownlint -s ``` results in ```text stdin:5 error MD012/no-multiple-blanks Multiple consecutive blank lines [Expected: 1; Actual: 2] ``` I think that this needs a fix. Many thanks, Jamil
kerem 2026-03-07 20:09:27 +03:00
  • closed this issue
  • added the
    question
    label
Author
Owner

@DavidAnson commented on GitHub (Dec 20, 2025):

After un-escaping "\n", your document produces no violations.

https://dlaa.me/markdownlint/#%25m%23%20My%20title%0A%0AThis%20is%20my%20doc.%0A

My guess is that the "echo" command you are using adds its own trailing newline character which causes there to be two at the end of the input.

<!-- gh-comment-id:3678052020 --> @DavidAnson commented on GitHub (Dec 20, 2025): After un-escaping "\n", your document produces no violations. https://dlaa.me/markdownlint/#%25m%23%20My%20title%0A%0AThis%20is%20my%20doc.%0A My guess is that the "echo" command you are using adds its own trailing newline character which causes there to be two at the end of the input.
Author
Owner

@jamilraichouni commented on GitHub (Dec 20, 2025):

Well, I used the echo command just here to make it an easy to reproduce example.
Any file in vim I edit has that issue when I want to let it end with a blank line:

Image

Try this with a test file, please.

<!-- gh-comment-id:3678061342 --> @jamilraichouni commented on GitHub (Dec 20, 2025): Well, I used the `echo` command just here to make it an easy to reproduce example. Any file in `vim` I edit has that issue when I want to let it end with a blank line: <img width="867" height="159" alt="Image" src="https://github.com/user-attachments/assets/b4fddf64-118e-4875-a1da-a9fa31bc8c1d" /> Try this with a test file, please.
Author
Owner

@DavidAnson commented on GitHub (Dec 20, 2025):

Your original example uses echo which is documented to add a newline at the end of its output. Therefore, your example has multiple newlines and the output you show from markdownlint is correct. We can fix your sample to omit the newline from echo (by adding -n) and confirm that no violations are reported for a file with a single trailing newline:

@DavidAnson ➜ /workspaces/playground (main) $ markdownlint --version
0.47.0
@DavidAnson ➜ /workspaces/playground (main) $ echo -n -e "# My title\n\nThis is my doc.\n" | markdownlint -s
@DavidAnson ➜ /workspaces/playground (main) $ 

You asked to see a test file and we can do that, too, by creating your test file and then verifying its contents visually and at the byte level:

@DavidAnson ➜ /workspaces/playground (main) $ echo -n -e "# My title\n\nThis is my doc.\n" > test.md
@DavidAnson ➜ /workspaces/playground (main) $ cat ./test.md
# My title

This is my doc.
@DavidAnson ➜ /workspaces/playground (main) $ hexdump -C ./test.md
00000000  23 20 4d 79 20 74 69 74  6c 65 0a 0a 54 68 69 73  |# My title..This|
00000010  20 69 73 20 6d 79 20 64  6f 63 2e 0a              | is my doc..|
0000001c

Linting this file directly or as piped input produces no violations as expected:

@DavidAnson ➜ /workspaces/playground (main) $ markdownlint ./test.md
@DavidAnson ➜ /workspaces/playground (main) $ cat ./test.md | markdownlint --stdin
@DavidAnson ➜ /workspaces/playground (main) $ 

I don't know how you have vim configured, but any issues there are outside the scope of this project.

<!-- gh-comment-id:3678149196 --> @DavidAnson commented on GitHub (Dec 20, 2025): Your original example uses `echo` which is documented to add a newline at the end of its output. Therefore, your example has multiple newlines and the output you show from `markdownlint` is correct. We can fix your sample to omit the newline from `echo` (by adding `-n`) and confirm that no violations are reported for a file with a single trailing newline: ``` @DavidAnson ➜ /workspaces/playground (main) $ markdownlint --version 0.47.0 @DavidAnson ➜ /workspaces/playground (main) $ echo -n -e "# My title\n\nThis is my doc.\n" | markdownlint -s @DavidAnson ➜ /workspaces/playground (main) $ ``` You asked to see a test file and we can do that, too, by creating your test file and then verifying its contents visually and at the byte level: ``` @DavidAnson ➜ /workspaces/playground (main) $ echo -n -e "# My title\n\nThis is my doc.\n" > test.md @DavidAnson ➜ /workspaces/playground (main) $ cat ./test.md # My title This is my doc. @DavidAnson ➜ /workspaces/playground (main) $ hexdump -C ./test.md 00000000 23 20 4d 79 20 74 69 74 6c 65 0a 0a 54 68 69 73 |# My title..This| 00000010 20 69 73 20 6d 79 20 64 6f 63 2e 0a | is my doc..| 0000001c ``` Linting this file directly or as piped input produces no violations as expected: ``` @DavidAnson ➜ /workspaces/playground (main) $ markdownlint ./test.md @DavidAnson ➜ /workspaces/playground (main) $ cat ./test.md | markdownlint --stdin @DavidAnson ➜ /workspaces/playground (main) $ ``` I don't know how you have `vim` configured, but any issues there are outside the scope of this project.
Author
Owner

@jamilraichouni commented on GitHub (Dec 20, 2025):

Thanks, you're right.

<!-- gh-comment-id:3678209278 --> @jamilraichouni commented on GitHub (Dec 20, 2025): Thanks, you're right.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/markdownlint#2620
No description provided.