DavidAnson / markdownlint

A Node.js style checker and lint tool for Markdown/CommonMark files.
MIT License
4.8k stars 731 forks source link

MD004 triggered on different lists #1347

Closed ferrarimarco closed 1 month ago

ferrarimarco commented 2 months ago

Hi! Thanks for working on this tool :)

I think Markdownlint might wrongly flagging the following snippet as a violation of MD004 set to its default configuration (consistent).

# H1

- list1: item 1

* list2: item 2

- list3: item 3

5 - MD004 / ul-style Unordered list style [Expected: dash; Actual: asterisk]

From my understanding of the CommonMark spec, this is allowed. Also, it's the only way to differentiate between different lists where there are only blank lines between them:

Changing the bullet or ordered list delimiter starts a new list:

Input:

- foo
- bar
+ baz

HTML output:

<ul>
<li>foo</li>
<li>bar</li>
</ul>
<ul>
<li>baz</li>
</ul>

Here's a playground link that reproduces the issue.

Is there a way to configure MD004 to allow for this, besides disabling the rule entirely?

Thanks!

DavidAnson commented 2 months ago

The configuration says all lists should have the same style but the example has lists with different styles, so the rule reports a violation. This is correct and working as intended.

I think it is uncommon to have separate lists consecutively as in your example, but you can put an HTML comment between them if you want to avoid the warning by using the same list type twice in a row without content between. Or disable the rule for that file or part of it.

https://dlaa.me/markdownlint/#%25m%23%20H1%0A%0A1.%20list1%3A%20item%201%0A%0A%3C!--%20comment%20--%3E%0A%0A1.%20list2%3A%20item%202%0A%0A%3C!--%20comment%20--%3E%0A%0A1.%20list3%3A%20item%203%0A

ferrarimarco commented 2 months ago

Yeah, makes sense. I guess I was asking for another option for MD004 along the lines of sublists that allowed this behavior.

Anyway, thanks!