Environment
ESLint version: HEAD
@eslint/markdown version: HEAD
Node version: 24.18.0
npm version: 11.16.0
Operating System: Windows
What problem do you want to solve?
Coming from the community plugin thread eslint-community/eslint-plugin-eslint-comments#267 (comment), which discusses adding MarkdownSourceCode#comments to the Markdown plugin.
Currently, JavaScript, JSON, and CSS provide a direct way to access comment information through their respective XXXSourceCode classes.
For example, JavaScript has SourceCode#getAllComments, JSON has JSONSourceCode#comments, and CSS has CSSSourceCode#comments to provide direct access to comment information.
However, Markdown does not currently provide a way to directly access comment information through MarkdownSourceCode.
This makes it difficult for language-agnostic rule authors - who create rules that apply to all languages or a subset of them - to write rules related to comments, since there is no consistent way to retrieve comment information.
Therefore, I’d like to suggest adding MarkdownSourceCode#comments, as other language plugins do.
What do you think is the correct solution?
We already have logic to extract HTML comments, but it currently only handles eslint-xxx inline configuration comments:
|
function extractInlineConfigCommentsFromHTML(node, sourceCode) { |
We could extend this logic to extract all HTML comments, including non-eslint-xxx inline configuration comments, and store that information.
Participation
AI acknowledgment
Additional comments
For performance, I think we could also consider implementing it as a lazy getter, similar to XXXSourceCode#lines in rewrite:
https://github.com/eslint/rewrite/blob/main/packages/plugin-kit/src/source-code.js#L632-L636
Environment
ESLint version: HEAD
@eslint/markdown version: HEAD
Node version: 24.18.0
npm version: 11.16.0
Operating System: Windows
What problem do you want to solve?
Coming from the community plugin thread eslint-community/eslint-plugin-eslint-comments#267 (comment), which discusses adding
MarkdownSourceCode#commentsto the Markdown plugin.Currently, JavaScript, JSON, and CSS provide a direct way to access comment information through their respective
XXXSourceCodeclasses.For example, JavaScript has
SourceCode#getAllComments, JSON hasJSONSourceCode#comments, and CSS hasCSSSourceCode#commentsto provide direct access to comment information.However, Markdown does not currently provide a way to directly access comment information through
MarkdownSourceCode.This makes it difficult for language-agnostic rule authors - who create rules that apply to all languages or a subset of them - to write rules related to comments, since there is no consistent way to retrieve comment information.
Therefore, I’d like to suggest adding
MarkdownSourceCode#comments, as other language plugins do.What do you think is the correct solution?
We already have logic to extract HTML comments, but it currently only handles
eslint-xxxinline configuration comments:markdown/src/language/markdown-source-code.js
Line 72 in 186ad3e
We could extend this logic to extract all HTML comments, including non-
eslint-xxxinline configuration comments, and store that information.Participation
AI acknowledgment
Additional comments
For performance, I think we could also consider implementing it as a lazy getter, similar to
XXXSourceCode#linesinrewrite:https://github.com/eslint/rewrite/blob/main/packages/plugin-kit/src/source-code.js#L632-L636