[GH-ISSUE #525] MD011: should not be triggered by content of inline code span #2275

Closed
opened 2026-03-07 20:06:13 +03:00 by kerem · 8 comments
Owner

Originally created by @Lenormju on GitHub (May 12, 2022).
Original GitHub issue: https://github.com/DavidAnson/markdownlint/issues/525

Using markdownlint demo (v0.25.1) :

# Title

this is the problem : `str.join(' ')[-1]`

gives me the error : 3 - MD011 / no-reversed-links Reversed link syntax [(' ')[-1]]

I think my inline Python code should not be considered a link, so the rule should not be triggered by the content of an inline code span.

Originally created by @Lenormju on GitHub (May 12, 2022). Original GitHub issue: https://github.com/DavidAnson/markdownlint/issues/525 Using `markdownlint demo (v0.25.1)` : ```markdown # Title this is the problem : `str.join(' ')[-1]` ``` gives me the error : `3 -` `MD011 / no-reversed-links` `Reversed link syntax [(' ')[-1]]` I think my inline Python code should not be considered a link, so the rule should not be triggered by the content of an inline code span.
kerem 2026-03-07 20:06:13 +03:00
Author
Owner

@DavidAnson commented on GitHub (May 14, 2022):

Are you seeing this running under Node, or just in the web demo app? There are existing tests to verify your scenario behaves correctly in Node, so I think you're probably only seeing it in the browser? It seems to me at the moment this is a Webpack bug - here's why...

The original code is:
github.com/DavidAnson/markdownlint@2d19c0685b/helpers/helpers.js (L572)

That runs as-is under Node and behaves correctly per the existing tests, ignoring the content of the code span. That pattern matches this example in the documentation:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/entries#iterating_with_index_and_element

However, after being transformed by Webpack, that code looks like this:
github.com/DavidAnson/markdownlint@2d19c0685b/demo/markdownlint-browser.js (L565)

Note that it's trying to access the length property on the iterator returned by entries(). But that's not defined for iterators and is therefore undefined and so the loop does not run:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_iterable_protocol

It's hard to imagine I'm the first to run into this, so it may be a configuration issue on my part? At the same time, I don't see how the generated code is valid under an older ES version. I'm still investigating...

<!-- gh-comment-id:1126635147 --> @DavidAnson commented on GitHub (May 14, 2022): Are you seeing this running under Node, or just in the web demo app? There are existing tests to verify your scenario behaves correctly in Node, so I think you're probably only seeing it in the browser? It seems to me at the moment this is a Webpack bug - here's why... The original code is: https://github.com/DavidAnson/markdownlint/blob/2d19c0685bfa98dce87f493a8fcffbb5939af2c3/helpers/helpers.js#L572 That runs as-is under Node and behaves correctly per the existing tests, ignoring the content of the code span. That pattern matches this example in the documentation: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/entries#iterating_with_index_and_element However, after being transformed by Webpack, that code looks like this: https://github.com/DavidAnson/markdownlint/blob/2d19c0685bfa98dce87f493a8fcffbb5939af2c3/demo/markdownlint-browser.js#L565 Note that it's trying to access the `length` property on the iterator returned by `entries()`. But that's not defined for iterators and is therefore `undefined` and so the loop does not run: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_iterable_protocol It's hard to imagine I'm the first to run into this, so it may be a configuration issue on my part? At the same time, I don't see how the generated code is valid under an older ES version. I'm still investigating...
Author
Owner

@DavidAnson commented on GitHub (May 14, 2022):

After a bit more research, this problem coming from TypeScript (via ts-loader), not Webpack. When using the default target of ES3 (https://www.typescriptlang.org/tsconfig#target), TypeScript doesn't know what iterators are and translates for..of to use length in all cases: https://www.typescriptlang.org/docs/handbook/iterators-and-generators.html#targeting-es5-and-es3

<!-- gh-comment-id:1126798375 --> @DavidAnson commented on GitHub (May 14, 2022): After a bit more research, this problem coming from TypeScript (via `ts-loader`), not Webpack. When using the default target of `ES3` (https://www.typescriptlang.org/tsconfig#target), TypeScript doesn't know what iterators are and translates `for..of` to use `length` in all cases: https://www.typescriptlang.org/docs/handbook/iterators-and-generators.html#targeting-es5-and-es3
Author
Owner

@Lenormju commented on GitHub (May 17, 2022):

I first encountered the bug on my own computer. But I can't upgrade to the latest version (because reasons) so I used the online demo to reproduce it. Also, I was a bit confused between the different parts (lint, cli, ...) so I preferred to indicate that it was reproducible with the demo, which I guessed you know well.
I'm using pre-commit 2.15.0 (pre-commit -V) to invoke MarkdownLint Command Line Interface 0.29.0 (markdownlint -V) which relies on markdownlint@0.24.0 and markdown-it@12.2.0 (npm list -g).

I suggest you put instructions on how to get all these info in the Issue template, so that users confused like me by the different parts can easily provide you the info you need :)

<!-- gh-comment-id:1128566155 --> @Lenormju commented on GitHub (May 17, 2022): I first encountered the bug on my own computer. But I can't upgrade to the latest version (because reasons) so I used the online demo to reproduce it. Also, I was a bit confused between the different parts (lint, cli, ...) so I preferred to indicate that it was reproducible with the demo, which I guessed you know well. I'm using `pre-commit 2.15.0` (`pre-commit -V`) to invoke `MarkdownLint Command Line Interface 0.29.0` (`markdownlint -V`) which relies on `markdownlint@0.24.0` and `markdown-it@12.2.0` (`npm list -g`). I suggest you put instructions on how to get all these info in the Issue template, so that users confused like me by the different parts can easily provide you the info you need :)
Author
Owner

@DavidAnson commented on GitHub (May 17, 2022):

What version of Node.js? Pre-commit prefers deprecated versions in some cases.

<!-- gh-comment-id:1129002917 --> @DavidAnson commented on GitHub (May 17, 2022): What version of Node.js? Pre-commit prefers deprecated versions in some cases.
Author
Owner

@Lenormju commented on GitHub (May 18, 2022):

v14.18.1 (from node --version)

<!-- gh-comment-id:1129772780 --> @Lenormju commented on GitHub (May 18, 2022): `v14.18.1` (from `node --version`)
Author
Owner

@DavidAnson commented on GitHub (May 18, 2022):

I'd expect that to work. I'll try to reproduce this using the same CLI version. It's possible that predates ignoring code spans or perhaps there was a fix since then.

<!-- gh-comment-id:1130198200 --> @DavidAnson commented on GitHub (May 18, 2022): I'd expect that to work. I'll try to reproduce this using the same CLI version. It's possible that predates ignoring code spans or perhaps there was a fix since then.
Author
Owner

@DavidAnson commented on GitHub (May 19, 2022):

I don't see that behavior with Node 14 and markdownlint-cli 0.29.0 and your original example:

node@01e38c8bd355:/home/workdir$ node --version
v14.19.3
node@01e38c8bd355:/home/workdir$ ./node_modules/.bin/markdownlint --version
0.29.0
node@01e38c8bd355:/home/workdir$ cat test.md 
# Title

this is the problem : `str.join(' ')[-1]`
node@01e38c8bd355:/home/workdir$ ./node_modules/.bin/markdownlint test.md  
node@01e38c8bd355:/home/workdir$ 

However, I'm not going to spend more time here as the reproduction I did have should now be fixed.

<!-- gh-comment-id:1131195531 --> @DavidAnson commented on GitHub (May 19, 2022): I don't see that behavior with Node 14 and markdownlint-cli 0.29.0 and your original example: ``` node@01e38c8bd355:/home/workdir$ node --version v14.19.3 node@01e38c8bd355:/home/workdir$ ./node_modules/.bin/markdownlint --version 0.29.0 node@01e38c8bd355:/home/workdir$ cat test.md # Title this is the problem : `str.join(' ')[-1]` node@01e38c8bd355:/home/workdir$ ./node_modules/.bin/markdownlint test.md node@01e38c8bd355:/home/workdir$ ``` However, I'm not going to spend more time here as the reproduction I did have should now be fixed.
Author
Owner

@Lenormju commented on GitHub (Jul 6, 2022):

I can't update the versions I use on my computer (because reasons) but it looks like it is now fixed in markdownlint demo (v0.26.0) 👍

<!-- gh-comment-id:1175828673 --> @Lenormju commented on GitHub (Jul 6, 2022): I can't update the versions I use on my computer (because reasons) but it looks like it is now fixed in `markdownlint demo (v0.26.0)` :+1:
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#2275
No description provided.