mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2026-04-25 01:05:55 +03:00
[GH-ISSUE #1473] Conflict between MD007/ul-indent with start_indented and MD027/no-multiple-space-blockquotes #2541
Labels
No labels
bug
enhancement
enhancement
enhancement
fixed in next
fixed in next
fixed in next
new rule
new rule
new rule
pull-request
question
refactoring
refactoring
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/markdownlint#2541
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @MatheusBaldi on GitHub (Jan 21, 2025).
Original GitHub issue: https://github.com/DavidAnson/markdownlint/issues/1473
What is happening?
Markdownlint raises an error for
ul-indentwhen a list is not indented inside a blockquote andstart_indentedis set totrue; when the indentation is fixed, the ruleno-multiple-space-blockquoteraises an error indicating that a blockquote should not have multiple spaces.Why is it happening?
When the
start_indentedoption oful-indentrule istrue, it demands a specific starting indentation for a list, anywhere they appear. When inside a blockquote with the ruleno-multiple-space-blockquoteenabled, both rules try to be applied, negating each other.Expected behavior
ul-indentwithindentbigger than zero andstart_indentedastrueshould work normally inside blockquotes, as it used to in previous versions.This rule already existed and was used before, so why did it only started raising an error now?
github.com/DavidAnson/markdownlint@730ae9a96f (diff-c92d9e42e0)) to fullly use micromark parser instead of markdownit and some helper functions. This is where the bug has been was introduced. Therefore, the rulesul-indentwithstart_indentedoption astrue, andno-multiple-space-blockquotehave been conflicting in every version ever since, which includes the current markdownlint (0.37.4) and, as a consequence, markdownlint-cli2 (0.17.2)What have I tried?
After finding the complete rewriting of rule
MD027in the version which the error starts, I reverted the implementation ofMD027/no-multiple-space-blockquotelocally to its previous version and the conflict stopped happening, I was then able to useMD007/ul-indentnormally withstart_indentedset totrueinside blockquotes without any lint errors.Goal of this issue
Bring back to current implementation the behavior where lists could adhere to
MD007/ul-indentwithstart_indentedinside blockquotes without conflicting withMD027/no-multiple-space-blockquote.Setup:
Same results were obtained on node 23.13.1 (current lts) and npm 11.0.0 (current latest)
Steps to reproduce:
I've set up a repository here (https://github.com/MatheusBaldi/markdownlint-md027-issue-mre) for convenience. You can clone it,
npm install, and then runnpx markdownlint-cli2@0.17.2 ..If you want to set up your own project, here are the steps:
npx markdownlint-cli2@0.17.2 .files:
.markdownlint.json:
examples.md:
@DavidAnson commented on GitHub (Jan 22, 2025):
Thank you for the thorough issue!
Here's a simplified demonstration of the behavior you describe: https://dlaa.me/markdownlint/#%25m%23%20Issue%201473%0A%0A%3E%20%20%20%2B%20Item%0A%3E%20%20%20%2B%20Item%0A%3E%20%20%20%20%20%2B%20Item%0A%0A%3C!--%20markdownlint-configure-file%20%7B%0A%20%20%22ul-indent%22%3A%20%7B%0A%20%20%20%20%22indent%22%3A%202%2C%0A%20%20%20%20%22start_indented%22%3A%20true%0A%20%20%7D%2C%0A%20%20%20%20%22no-multiple-space-blockquote%22%3A%20true%0A%7D%20--%3E%0A
The current behavior is inconsistent, but the old behavior was not what you want, either. :)
While I believe this worked as you want in older versions, that was luck. In general, rules are independent and do NOT know about each other. Specifically, they are NOT able to access the configuration for other rules. Because your scenario only arises when MD007 is customized, the lack of MD027's ability to perceive that proves it wasn't behaving as you wish intentionally (you can confirm by looking for
params.configin the code for MD027).Based on code inspection, it seems the current behavior of MD027 handling indented lists differently is because it keys off the micromark
linePrefixtoken to identify extra space and that (essentially) becomes alistItemIndenttoken for the nested list which means the rule doesn't "see" the extra indent.I can fix the inconsistency with blockquoted indented lists, but your scenario will still report violations because MD027 won't know to respect the custom configuration you provided for MD007. In cases like this, I typically advise disabling one of the overlapping rules. I've only superficially looked at this so far, and I'm open to clever solutions about how to make your scenario work without disabling a rule.
@MatheusBaldi commented on GitHub (Jan 24, 2025):
I see, thank you for the explanation, it makes sense that they're not aware of each other. I believe the old behavior happened to work because of how it used the
list_item_openandlist_item_close. I haven't really dug how it was doing that, but inspired by it, I've tried an implementation which looks for some of the list tokens that appear while debugging. It basically ignores the multiple spaces in blockquotes when the next item of the current token is a list type. I'm not sure if that would be ideal to the principle of this rule though, but it looks similar to how it behaved before. Also, it's not complete, the tests are breaking for cases where there is a nested list element with only one level of indentation (lines 68 and 185 inlists-in-blockquote.md). I decided to discuss wether the direction of this implementation is valid or not before going any further on how to fix that. Here is how I've implemented it:Meanwhile, we'll disable the no-multiple-space-blockquote rule as you suggested. Thank you.
@DavidAnson commented on GitHub (Jan 24, 2025):
I need to play around with this myself before I have an opinion about what changes to make. I should have an opportunity to do that this weekend.
@DavidAnson commented on GitHub (Jan 28, 2025):
Just FYI, I've looked at this a bit and I'm finding more ways
no-multiple-space-blockquotestruggles within lists. There's the nested list scenario we already touched on, but also the following simpler scenario of a multi-line list item which suffers from the samelinePrefix->listItemIndenttransformation that leads to partial reporting:https://dlaa.me/markdownlint/#%25m%23%20Issue%201473%0A%0A%3E%20%20%20%2B%20Item%0A%3E%20%20%20%20%20more%0A%0A%3C!--%20markdownlint-configure-file%20%7B%0A%20%20%22ul-indent%22%3A%20%7B%0A%20%20%20%20%22start_indented%22%3A%20true%0A%20%20%7D%0A%7D%20--%3E%0A
I'm hesitant to try to do too much self-parsing here and therefore inclined to think the current implementation that uses
linePrefixis striking a decent balance.@DavidAnson commented on GitHub (Feb 1, 2025):
I'm changing this from "bug" to "enhancement" because:
Using
linePrefixas done today seems the most reliable way to determine blockquote space.In a couple of minutes, I'll commit some test cases I put together for future reference.
@MatheusBaldi commented on GitHub (Feb 3, 2025):
Would it be reasonable to add a boolean option like
ignoreListIndentationor would it deviate from the rule's purpose?If acceptable, we would be able to just stop checking multiple spaces in blockquotes for all blockquote lines with list elements, and then safely apply indentation rules specific to lists. This could prevent the conflict scenario.
@DavidAnson commented on GitHub (Feb 4, 2025):
I think that would be reasonable, yes. :) I can't, on brief reflection, think of another situation where this would be a problem. For consistency, I think the parameter should be
list_itemsjust like used here: https://github.com/DavidAnson/markdownlint/blob/main/doc/md031.mdI expect to get to this in a few days. Thank you!
@MatheusBaldi commented on GitHub (Feb 4, 2025):
That's great, thank you!