Skip to content

Change Request: Support MarkdownSourceCode#comments as other language plugins do #732

Description

@lumirlumir

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

  • I am willing to submit a pull request for this change.

AI acknowledgment

  • I did not use AI to generate this issue report.
  • (If the above is not checked) I have reviewed the AI-generated content before submitting.

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

  • Status
    Feedback Needed

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions