Skip to content

Change Request: Support MDX linting #316

@nzakas

Description

@nzakas

Environment

ESLint version: HEAD
@eslint/markdown version: HEAD
Node version: n/a
npm version: n/a
Operating System: n/a

What problem do you want to solve?

Currently, the Markdown plugin does not formally parse MDX (it just becomes text but doesn't throw an error). Ideally, we could provide smart parsing for MDX so it can be linted just like anything else.

I investigated using https://github.com/syntax-tree/mdast-util-mdx, but it outputs an AST that is difficult to work with. Any JavaScript code produces a Program node (it uses Acorn under the hood), and there can be multiple Program nodes in a single document. This makes the AST difficult to navigate and make sense of.

Further, because actual JavaScript code can be embedded inside of MDX, we'd need to recreate all of the JavaScript-specific rules just to work in MDX. That seems like wasted effort. I don't think the out-of-the-box approach to MDX from mdast works for our case.

What do you think is the correct solution?

I think ultimately what we want is a way to run existing JavaScript rules on an MDX file in addition to MDX-specific rules. The only way I can think to do that using something like a prelint plugin to extract the JavaScript into a separate virtual file to be linted.

In order to do that, I think we'll need to create a custom mdast plugin that extracts the JavaScript code without creating an AST, basically treating it like a code block.

Participation

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

Additional comments

I'm just documenting this for now as I have other, higher-priority work to complete. I'd like to consider this on the roadmap for this plugin.

Metadata

Metadata

Assignees

No one assigned

    Projects

    Status

    Evaluating

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions