[GH-ISSUE #237] MD013 line length rule checking is not strict enough #2052

Closed
opened 2026-03-07 20:04:03 +03:00 by kerem · 5 comments
Owner

Originally created by @tjanez on GitHub (Nov 27, 2019).
Original GitHub issue: https://github.com/DavidAnson/markdownlint/issues/237

Here is a reproducer:

cat << EOF > foo.md
# Test

This line is exactly 81 characters long. I just need to add some more text to it.
EOF
npx markdownlint-cli foo.md

This is the output:

[tadej@toronto Markdownlint]$ cat << EOF > foo.md
> # Test
> 
> This line is exactly 81 characters long. I just need to add some more text to it.
> EOF
[tadej@toronto Markdownlint]$ npx markdownlint-cli foo.md
npx: installed 34 in 1.847s
[tadej@toronto Markdownlint]$

I would want Markdown to return an error since the offending line is 81 characters long.


Only if I set MD013's line_length parameter to something like 75, it starts to show the error. For example, running:

cat << EOF > .markdownlint.json
{
  "default": true,
  "MD013": { "line_length": 75 },
}
EOF
npx markdownlint-cli foo.md

Results in:

[tadej@toronto Markdownlint]$ cat << EOF > .markdownlint.json
> {
>   "default": true,
>   "MD013": { "line_length": 75 },
> }
> EOF
[tadej@toronto Markdownlint]$ npx markdownlint-cli foo.md
npx: installed 34 in 2.766s
foo.md:3 MD013/line-length Line length [Expected: 75; Actual: 81]
[tadej@toronto Markdownlint]$
Originally created by @tjanez on GitHub (Nov 27, 2019). Original GitHub issue: https://github.com/DavidAnson/markdownlint/issues/237 Here is a reproducer: ```bash cat << EOF > foo.md # Test This line is exactly 81 characters long. I just need to add some more text to it. EOF npx markdownlint-cli foo.md ``` This is the output: ``` [tadej@toronto Markdownlint]$ cat << EOF > foo.md > # Test > > This line is exactly 81 characters long. I just need to add some more text to it. > EOF [tadej@toronto Markdownlint]$ npx markdownlint-cli foo.md npx: installed 34 in 1.847s [tadej@toronto Markdownlint]$ ``` I would want Markdown to return an error since the offending line is 81 characters long. ------ Only if I set `MD013`'s `line_length` parameter to something like `75`, it starts to show the error. For example, running: ```bash cat << EOF > .markdownlint.json { "default": true, "MD013": { "line_length": 75 }, } EOF npx markdownlint-cli foo.md ``` Results in: ``` [tadej@toronto Markdownlint]$ cat << EOF > .markdownlint.json > { > "default": true, > "MD013": { "line_length": 75 }, > } > EOF [tadej@toronto Markdownlint]$ npx markdownlint-cli foo.md npx: installed 34 in 2.766s foo.md:3 MD013/line-length Line length [Expected: 75; Actual: 81] [tadej@toronto Markdownlint]$ ```
kerem 2026-03-07 20:04:03 +03:00
Author
Owner

@DavidAnson commented on GitHub (Nov 27, 2019):

The behavior you describe seems to be this from the documentation: https://github.com/DavidAnson/markdownlint/blob/master/doc/Rules.md#md013---line-length

This rule has an exception where there is no whitespace beyond the configured line length. This allows you to still include items such as long URLs without being forced to break them in the middle.

Do you agree?

PS - I suppose I could add a strict parameter to remove the exception.

<!-- gh-comment-id:559143206 --> @DavidAnson commented on GitHub (Nov 27, 2019): The behavior you describe seems to be this from the documentation: https://github.com/DavidAnson/markdownlint/blob/master/doc/Rules.md#md013---line-length > This rule has an exception where there is no whitespace beyond the configured line length. This allows you to still include items such as long URLs without being forced to break them in the middle. Do you agree? PS - I suppose I could add a `strict` parameter to remove the exception.
Author
Owner

@tjanez commented on GitHub (Nov 27, 2019):

The behavior you describe seems to be this from the documentation: https://github.com/DavidAnson/markdownlint/blob/master/doc/Rules.md#md013---line-length

This rule has an exception where there is no whitespace beyond the configured line length. This allows you to still include items such as long URLs without being forced to break them in the middle.

Do you agree?

I'm afraid I have trouble understanding that exception. For example, if I would have ordinary text like the one below:

# Test

This line is exactly 81 characters long. I just need to add some more text to it.
This line is exactly 81 characters long. I just need to add some more text to it.

This line is exactly 81 characters long. I just need to add some more text to it.
This line is exactly 81 characters long. I just need to add some more text to it.

Some other text.

I would expect to get errors that the lines are too long since there is nothing exceptional about them, i.e. they are not long URLs, and they could be easily broken.

Do you agree that it would be hard to argue that all these 4 lines are to be treated as exceptions to line length limit?

<!-- gh-comment-id:559162763 --> @tjanez commented on GitHub (Nov 27, 2019): > The behavior you describe seems to be this from the documentation: https://github.com/DavidAnson/markdownlint/blob/master/doc/Rules.md#md013---line-length > > This rule has an exception where there is no whitespace beyond the configured line length. This allows you to still include items such as long URLs without being forced to break them in the middle. > Do you agree? I'm afraid I have trouble understanding that exception. For example, if I would have ordinary text like the one below: ```markdown # Test This line is exactly 81 characters long. I just need to add some more text to it. This line is exactly 81 characters long. I just need to add some more text to it. This line is exactly 81 characters long. I just need to add some more text to it. This line is exactly 81 characters long. I just need to add some more text to it. Some other text. ``` I would expect to get errors that the lines are too long since there is nothing exceptional about them, i.e. they are not long URLs, and they could be easily broken. Do you agree that it would be hard to argue that all these 4 lines are to be treated as exceptions to line length limit?
Author
Owner

@DavidAnson commented on GitHub (Nov 27, 2019):

I didn’t define the rule originally, but I think the “I don’t want to wrap this last thing onto a new line“ scenario comes up more often then you expect (not just with URL’s). As a rule that is meant to be helpful more often than annoying, I think the current implementation is reasonable. That said, I don’t have a problem adding a “strict“ parameter for scenarios like yours where line length is very important.

<!-- gh-comment-id:559170725 --> @DavidAnson commented on GitHub (Nov 27, 2019): I didn’t define the rule originally, but I think the “I don’t want to wrap this last thing onto a new line“ scenario comes up more often then you expect (not just with URL’s). As a rule that is meant to be helpful more often than annoying, I think the current implementation is reasonable. That said, I don’t have a problem adding a “strict“ parameter for scenarios like yours where line length is very important.
Author
Owner

@tjanez commented on GitHub (Nov 27, 2019):

I didn’t define the rule originally, but I think the “I don’t want to wrap this last thing onto a new line“ scenario comes up more often then you expect (not just with URL’s). As a rule that is meant to be helpful more often than annoying, I think the current implementation is reasonable.

Ok, I understand your point.

That said, I don’t have a problem adding a “strict“ parameter for scenarios like yours where line length is very important.

Agreed, that would be a reasonable compromise.

And the docs should be updated to make it clear that default behavior is not strict and that people should set strict: true if they want such behavior.

<!-- gh-comment-id:559182572 --> @tjanez commented on GitHub (Nov 27, 2019): > I didn’t define the rule originally, but I think the “I don’t want to wrap this last thing onto a new line“ scenario comes up more often then you expect (not just with URL’s). As a rule that is meant to be helpful more often than annoying, I think the current implementation is reasonable. Ok, I understand your point. > That said, I don’t have a problem adding a “strict“ parameter for scenarios like yours where line length is very important. Agreed, that would be a reasonable compromise. And the docs should be updated to make it clear that default behavior is not strict and that people should set `strict: true` if they want such behavior.
Author
Owner

@tjanez commented on GitHub (Feb 7, 2020):

I've just tested and used this. Thanks, @DavidAnson!

<!-- gh-comment-id:583569418 --> @tjanez commented on GitHub (Feb 7, 2020): I've just tested and used this. Thanks, @DavidAnson!
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#2052
No description provided.