mdx-js / eslint-mdx

ESLint Parser/Plugin for MDX
https://npmjs.org/eslint-plugin-mdx
MIT License
258 stars 29 forks source link

Add Support for MDX v3 #481

Closed jaswrks closed 7 months ago

jaswrks commented 7 months ago

@JounQin Thank you. I've smoke tested this just a bit. Seems to do the trick.

Thanks in advance for anyone able to have a look at this with more experienced eyes than mine.


close #480

changeset-bot[bot] commented 7 months ago

⚠️ No Changeset found

Latest commit: a4295383d2f91d6b947de201bcd906f5a57b8a1d

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

github-actions[bot] commented 7 months ago

📊 Package size report   No changes

File Before After
Total (Includes all files) 1.3 MB 1.3 MB
Tarball size 131.6 kB 131.6 kB
Unchanged files | File | Size | | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ | --------: | | [`.babelrc`](https://github.com/jaswrks/eslint-mdx/blob/master/.babelrc) | `35 B` | | [`.changeset/config.json`](https://github.com/jaswrks/eslint-mdx/blob/master/.changeset/config.json) | `372 B` | | [`.changeset/README.md`](https://github.com/jaswrks/eslint-mdx/blob/master/.changeset/README.md) | `510 B` | | [`.codesandbox/ci.json`](https://github.com/jaswrks/eslint-mdx/blob/master/.codesandbox/ci.json) | `76 B` | | [`.editorconfig`](https://github.com/jaswrks/eslint-mdx/blob/master/.editorconfig) | `161 B` | | [`.eslintrc.js`](https://github.com/jaswrks/eslint-mdx/blob/master/.eslintrc.js) | `591 B` | | [`.gitattributes`](https://github.com/jaswrks/eslint-mdx/blob/master/.gitattributes) | `35 B` | | [`.github/FUNDING.yml`](https://github.com/jaswrks/eslint-mdx/blob/master/.github/FUNDING.yml) | `204 B` | | [`.github/workflows/ci.yml`](https://github.com/jaswrks/eslint-mdx/blob/master/.github/workflows/ci.yml) | `941 B` | | [`.github/workflows/codeql.yml`](https://github.com/jaswrks/eslint-mdx/blob/master/.github/workflows/codeql.yml) | `836 B` | | [`.github/workflows/pkg-size.yml`](https://github.com/jaswrks/eslint-mdx/blob/master/.github/workflows/pkg-size.yml) | `496 B` | | [`.github/workflows/release.yml`](https://github.com/jaswrks/eslint-mdx/blob/master/.github/workflows/release.yml) | `914 B` | | [`.lintstagedrc.js`](https://github.com/jaswrks/eslint-mdx/blob/master/.lintstagedrc.js) | `50 B` | | [`.simple-git-hooks.js`](https://github.com/jaswrks/eslint-mdx/blob/master/.simple-git-hooks.js) | `51 B` | | [`CHANGELOG.md`](https://github.com/jaswrks/eslint-mdx/blob/master/CHANGELOG.md) | `283 B` | | [`CONTRIBUTING.md`](https://github.com/jaswrks/eslint-mdx/blob/master/CONTRIBUTING.md) | `931 B` | | [`LICENSE`](https://github.com/jaswrks/eslint-mdx/blob/master/LICENSE) | `1.1 kB` | | [`package.json`](https://github.com/jaswrks/eslint-mdx/blob/master/package.json) | `2.5 kB` | | [`packages/eslint-mdx/CHANGELOG.md`](https://github.com/jaswrks/eslint-mdx/blob/master/packages/eslint-mdx/CHANGELOG.md) | `22.9 kB` | | [`packages/eslint-mdx/package.json`](https://github.com/jaswrks/eslint-mdx/blob/master/packages/eslint-mdx/package.json) | `1.2 kB` | | [`packages/eslint-mdx/README.md`](https://github.com/jaswrks/eslint-mdx/blob/master/packages/eslint-mdx/README.md) | `10.4 kB` | | [`packages/eslint-mdx/shim.d.ts`](https://github.com/jaswrks/eslint-mdx/blob/master/packages/eslint-mdx/shim.d.ts) | `1.4 kB` | | [`packages/eslint-mdx/src/helpers.ts`](https://github.com/jaswrks/eslint-mdx/blob/master/packages/eslint-mdx/src/helpers.ts) | `4.3 kB` | | [`packages/eslint-mdx/src/index.ts`](https://github.com/jaswrks/eslint-mdx/blob/master/packages/eslint-mdx/src/index.ts) | `121 B` | | [`packages/eslint-mdx/src/meta.ts`](https://github.com/jaswrks/eslint-mdx/blob/master/packages/eslint-mdx/src/meta.ts) | `182 B` | | [`packages/eslint-mdx/src/parser.ts`](https://github.com/jaswrks/eslint-mdx/blob/master/packages/eslint-mdx/src/parser.ts) | `2.3 kB` | | [`packages/eslint-mdx/src/sync.ts`](https://github.com/jaswrks/eslint-mdx/blob/master/packages/eslint-mdx/src/sync.ts) | `384 B` | | [`packages/eslint-mdx/src/tokens.ts`](https://github.com/jaswrks/eslint-mdx/blob/master/packages/eslint-mdx/src/tokens.ts) | `6.7 kB` | | [`packages/eslint-mdx/src/types.ts`](https://github.com/jaswrks/eslint-mdx/blob/master/packages/eslint-mdx/src/types.ts) | `1.0 kB` | | [`packages/eslint-mdx/src/worker.ts`](https://github.com/jaswrks/eslint-mdx/blob/master/packages/eslint-mdx/src/worker.ts) | `21.0 kB` | | [`packages/eslint-mdx/tsconfig.json`](https://github.com/jaswrks/eslint-mdx/blob/master/packages/eslint-mdx/tsconfig.json) | `131 B` | | [`packages/eslint-plugin-mdx/CHANGELOG.md`](https://github.com/jaswrks/eslint-mdx/blob/master/packages/eslint-plugin-mdx/CHANGELOG.md) | `24.4 kB` | | [`packages/eslint-plugin-mdx/package.json`](https://github.com/jaswrks/eslint-mdx/blob/master/packages/eslint-plugin-mdx/package.json) | `1.0 kB` | | [`packages/eslint-plugin-mdx/README.md`](https://github.com/jaswrks/eslint-mdx/blob/master/packages/eslint-plugin-mdx/README.md) | `10.4 kB` | | [`packages/eslint-plugin-mdx/src/configs/base.ts`](https://github.com/jaswrks/eslint-mdx/blob/master/packages/eslint-plugin-mdx/src/configs/base.ts) | `305 B` | | [`packages/eslint-plugin-mdx/src/configs/code-blocks.ts`](https://github.com/jaswrks/eslint-mdx/blob/master/packages/eslint-plugin-mdx/src/configs/code-blocks.ts) | `1.0 kB` | | [`packages/eslint-plugin-mdx/src/configs/flat.ts`](https://github.com/jaswrks/eslint-mdx/blob/master/packages/eslint-plugin-mdx/src/configs/flat.ts) | `705 B` | | [`packages/eslint-plugin-mdx/src/configs/index.ts`](https://github.com/jaswrks/eslint-mdx/blob/master/packages/eslint-plugin-mdx/src/configs/index.ts) | `439 B` | | [`packages/eslint-plugin-mdx/src/configs/overrides.ts`](https://github.com/jaswrks/eslint-mdx/blob/master/packages/eslint-plugin-mdx/src/configs/overrides.ts) | `725 B` | | [`packages/eslint-plugin-mdx/src/configs/recommended.ts`](https://github.com/jaswrks/eslint-mdx/blob/master/packages/eslint-plugin-mdx/src/configs/recommended.ts) | `806 B` | | [`packages/eslint-plugin-mdx/src/helpers.ts`](https://github.com/jaswrks/eslint-mdx/blob/master/packages/eslint-plugin-mdx/src/helpers.ts) | `620 B` | | [`packages/eslint-plugin-mdx/src/index.ts`](https://github.com/jaswrks/eslint-mdx/blob/master/packages/eslint-plugin-mdx/src/index.ts) | `128 B` | | [`packages/eslint-plugin-mdx/src/meta.ts`](https://github.com/jaswrks/eslint-mdx/blob/master/packages/eslint-plugin-mdx/src/meta.ts) | `182 B` | | [`packages/eslint-plugin-mdx/src/processors/helpers.ts`](https://github.com/jaswrks/eslint-mdx/blob/master/packages/eslint-plugin-mdx/src/processors/helpers.ts) | `633 B` | | [`packages/eslint-plugin-mdx/src/processors/index.ts`](https://github.com/jaswrks/eslint-mdx/blob/master/packages/eslint-plugin-mdx/src/processors/index.ts) | `198 B` | | [`packages/eslint-plugin-mdx/src/processors/options.ts`](https://github.com/jaswrks/eslint-mdx/blob/master/packages/eslint-plugin-mdx/src/processors/options.ts) | `1.8 kB` | | [`packages/eslint-plugin-mdx/src/processors/remark.ts`](https://github.com/jaswrks/eslint-mdx/blob/master/packages/eslint-plugin-mdx/src/processors/remark.ts) | `1.9 kB` | | [`packages/eslint-plugin-mdx/src/processors/types.ts`](https://github.com/jaswrks/eslint-mdx/blob/master/packages/eslint-plugin-mdx/src/processors/types.ts) | `241 B` | | [`packages/eslint-plugin-mdx/src/rules/.eslintrc`](https://github.com/jaswrks/eslint-mdx/blob/master/packages/eslint-plugin-mdx/src/rules/.eslintrc) | `124 B` | | [`packages/eslint-plugin-mdx/src/rules/index.ts`](https://github.com/jaswrks/eslint-mdx/blob/master/packages/eslint-plugin-mdx/src/rules/index.ts) | `138 B` | | [`packages/eslint-plugin-mdx/src/rules/remark.ts`](https://github.com/jaswrks/eslint-mdx/blob/master/packages/eslint-plugin-mdx/src/rules/remark.ts) | `3.5 kB` | | [`packages/eslint-plugin-mdx/src/rules/types.ts`](https://github.com/jaswrks/eslint-mdx/blob/master/packages/eslint-plugin-mdx/src/rules/types.ts) | `415 B` | | [`packages/eslint-plugin-mdx/tsconfig.json`](https://github.com/jaswrks/eslint-mdx/blob/master/packages/eslint-plugin-mdx/tsconfig.json) | `131 B` | | [`README.md`](https://github.com/jaswrks/eslint-mdx/blob/master/README.md) | `10.4 kB` | | [`test/__snapshots__/fixtures.test.ts.snap`](https://github.com/jaswrks/eslint-mdx/blob/master/test/__snapshots__/fixtures.test.ts.snap) | `32.6 kB` | | [`test/__snapshots__/flat-config.test.ts.snap`](https://github.com/jaswrks/eslint-mdx/blob/master/test/__snapshots__/flat-config.test.ts.snap) | `823 B` | | [`test/__snapshots__/parser.test.ts.snap`](https://github.com/jaswrks/eslint-mdx/blob/master/test/__snapshots__/parser.test.ts.snap) | `1.1 MB` | | [`test/fixtures.test.ts`](https://github.com/jaswrks/eslint-mdx/blob/master/test/fixtures.test.ts) | `1.8 kB` | | [`test/fixtures/287.mdx`](https://github.com/jaswrks/eslint-mdx/blob/master/test/fixtures/287.mdx) | `204 B` | | [`test/fixtures/292.mdx`](https://github.com/jaswrks/eslint-mdx/blob/master/test/fixtures/292.mdx) | `191 B` | | [`test/fixtures/334.mdx`](https://github.com/jaswrks/eslint-mdx/blob/master/test/fixtures/334.mdx) | `70 B` | | [`test/fixtures/336.mdx`](https://github.com/jaswrks/eslint-mdx/blob/master/test/fixtures/336.mdx) | `178 B` | | [`test/fixtures/367.mdx`](https://github.com/jaswrks/eslint-mdx/blob/master/test/fixtures/367.mdx) | `87 B` | | [`test/fixtures/371.mdx`](https://github.com/jaswrks/eslint-mdx/blob/master/test/fixtures/371.mdx) | `75 B` | | [`test/fixtures/380.mdx`](https://github.com/jaswrks/eslint-mdx/blob/master/test/fixtures/380.mdx) | `11.0 kB` | | [`test/fixtures/391.mdx`](https://github.com/jaswrks/eslint-mdx/blob/master/test/fixtures/391.mdx) | `62 B` | | [`test/fixtures/429.mdx`](https://github.com/jaswrks/eslint-mdx/blob/master/test/fixtures/429.mdx) | `52 B` | | [`test/fixtures/435.mdx`](https://github.com/jaswrks/eslint-mdx/blob/master/test/fixtures/435.mdx) | `134 B` | | [`test/fixtures/445.mdx`](https://github.com/jaswrks/eslint-mdx/blob/master/test/fixtures/445.mdx) | `188 B` | | [`test/fixtures/450.mdx`](https://github.com/jaswrks/eslint-mdx/blob/master/test/fixtures/450.mdx) | `418 B` | | [`test/fixtures/acorn.mdx`](https://github.com/jaswrks/eslint-mdx/blob/master/test/fixtures/acorn.mdx) | `860 B` | | [`test/fixtures/adjacent.mdx`](https://github.com/jaswrks/eslint-mdx/blob/master/test/fixtures/adjacent.mdx) | `50 B` | | [`test/fixtures/async/.remarkrc`](https://github.com/jaswrks/eslint-mdx/blob/master/test/fixtures/async/.remarkrc) | `67 B` | | [`test/fixtures/async/test.md`](https://github.com/jaswrks/eslint-mdx/blob/master/test/fixtures/async/test.md) | `15 B` | | [`test/fixtures/basic.mdx`](https://github.com/jaswrks/eslint-mdx/blob/master/test/fixtures/basic.mdx) | `405 B` | | [`test/fixtures/basic.tsx`](https://github.com/jaswrks/eslint-mdx/blob/master/test/fixtures/basic.tsx) | `77 B` | | [`test/fixtures/blank-lines.mdx`](https://github.com/jaswrks/eslint-mdx/blob/master/test/fixtures/blank-lines.mdx) | `768 B` | | [`test/fixtures/code-blocks.md`](https://github.com/jaswrks/eslint-mdx/blob/master/test/fixtures/code-blocks.md) | `511 B` | | [`test/fixtures/comments.mdx`](https://github.com/jaswrks/eslint-mdx/blob/master/test/fixtures/comments.mdx) | `162 B` | | [`test/fixtures/details.mdx`](https://github.com/jaswrks/eslint-mdx/blob/master/test/fixtures/details.mdx) | `881 B` | | [`test/fixtures/dir.mdx/.gitkeep`](https://github.com/jaswrks/eslint-mdx/blob/master/test/fixtures/dir.mdx/.gitkeep) | `0 B` | | [`test/fixtures/esm/.remarkrc.mjs`](https://github.com/jaswrks/eslint-mdx/blob/master/test/fixtures/esm/.remarkrc.mjs) | `103 B` | | [`test/fixtures/esm/test.md`](https://github.com/jaswrks/eslint-mdx/blob/master/test/fixtures/esm/test.md) | `15 B` | | [`test/fixtures/flat-config/code-blocks.mdx`](https://github.com/jaswrks/eslint-mdx/blob/master/test/fixtures/flat-config/code-blocks.mdx) | `76 B` | | [`test/fixtures/jsx-in-list.mdx`](https://github.com/jaswrks/eslint-mdx/blob/master/test/fixtures/jsx-in-list.mdx) | `810 B` | | [`test/fixtures/leading-spaces.mdx`](https://github.com/jaswrks/eslint-mdx/blob/master/test/fixtures/leading-spaces.mdx) | `42 B` | | [`test/fixtures/markdown.md`](https://github.com/jaswrks/eslint-mdx/blob/master/test/fixtures/markdown.md) | `5 B` | | [`test/fixtures/no-unescaped-entities.mdx`](https://github.com/jaswrks/eslint-mdx/blob/master/test/fixtures/no-unescaped-entities.mdx) | `99 B` | | [`test/fixtures/no-unused-expressions.mdx`](https://github.com/jaswrks/eslint-mdx/blob/master/test/fixtures/no-unused-expressions.mdx) | `90 B` | | [`test/fixtures/processor.mdx`](https://github.com/jaswrks/eslint-mdx/blob/master/test/fixtures/processor.mdx) | `13 B` | | [`test/fixtures/remark.md`](https://github.com/jaswrks/eslint-mdx/blob/master/test/fixtures/remark.md) | `171 B` | | [`test/fixtures/remark.mdx`](https://github.com/jaswrks/eslint-mdx/blob/master/test/fixtures/remark.mdx) | `169 B` | | [`test/fixtures/style/.remarkrc`](https://github.com/jaswrks/eslint-mdx/blob/master/test/fixtures/style/.remarkrc) | `228 B` | | [`test/fixtures/style/nested.md`](https://github.com/jaswrks/eslint-mdx/blob/master/test/fixtures/style/nested.md) | `10 B` | | [`test/fixtures/style/plugin1.cjs`](https://github.com/jaswrks/eslint-mdx/blob/master/test/fixtures/style/plugin1.cjs) | `26 B` | | [`test/fixtures/style/plugin2.mjs`](https://github.com/jaswrks/eslint-mdx/blob/master/test/fixtures/style/plugin2.mjs) | `24 B` | | [`test/fixtures/unicorn.jsx`](https://github.com/jaswrks/eslint-mdx/blob/master/test/fixtures/unicorn.jsx) | `119 B` | | [`test/fixtures/unicorn.mdx`](https://github.com/jaswrks/eslint-mdx/blob/master/test/fixtures/unicorn.mdx) | `118 B` | | [`test/flat-config.test.ts`](https://github.com/jaswrks/eslint-mdx/blob/master/test/flat-config.test.ts) | `1.0 kB` | | [`test/helpers.test.ts`](https://github.com/jaswrks/eslint-mdx/blob/master/test/helpers.test.ts) | `874 B` | | [`test/helpers.ts`](https://github.com/jaswrks/eslint-mdx/blob/master/test/helpers.ts) | `548 B` | | [`test/parser.test.ts`](https://github.com/jaswrks/eslint-mdx/blob/master/test/parser.test.ts) | `4.0 kB` | | [`test/remark.test.ts`](https://github.com/jaswrks/eslint-mdx/blob/master/test/remark.test.ts) | `2.8 kB` | | [`tsconfig.base.json`](https://github.com/jaswrks/eslint-mdx/blob/master/tsconfig.base.json) | `235 B` | | [`tsconfig.json`](https://github.com/jaswrks/eslint-mdx/blob/master/tsconfig.json) | `309 B` | | [`tsconfig.lib.json`](https://github.com/jaswrks/eslint-mdx/blob/master/tsconfig.lib.json) | `180 B` |

🤖 This report was automatically generated by pkg-size-action

JounQin commented 7 months ago

CI broken, it seems more changes are required, I'll take a look tomorrow.

JounQin commented 7 months ago

https://github.com/mdx-js/eslint-mdx/pull/481/files#diff-28c9951bdd4b9fbbb77321aec606c4ec820dc169ca472ad8991aa553bc4283baR32

@wooorm Any advice about how to migrate like Root from remark-mdx?

ChristianMurphy commented 7 months ago

Any advice about how to migrate like Root from remark-mdx?

@JounQin have you tried Root from mdast? The one in remark-mdx was likely an alias for the one in mdast which was accidentally exported.

JounQin commented 7 months ago

Any advice about how to migrate like Root from remark-mdx?

@JounQin have you tried Root from mdast? The one in remark-mdx was likely an alias for the one in mdast which was accidentally exported.

@ChristianMurphy

It won't work because we need the followings:

image
ChristianMurphy commented 7 months ago

@JounQin it will work if mdast-util-mdx-expression is included in the ambient types.

See https://www.npmjs.com/package/mdast-util-mdx-expression/v/2.0.0?activeTab=code index.d.ts at around line 120. It registers the new types on to the root element.

This is how all the mdast parsers register new content types, using content maps, which can be automatically extended parsers so that mdast includes the new child types.

wooorm commented 7 months ago

See also the readmes, e.g.: https://mdxjs.com/packages/remark-mdx/#types

JounQin commented 7 months ago

OK, it seems we need:

/// <reference types="remark-mdx" />

import type { Root } from 'mdast'

I'll try it this night. (Previously, I'm not aware that referencing remark-mdx is required).

JounQin commented 7 months ago
packages/eslint-mdx/src/tokens.ts:47:7 - error TS2367: This comparison appears to be unintentional because the types '"root" | "paragraph" | "heading" | "thematicBreak" | "blockquote" | "list" | "table" | "html" | "code" | "yaml" | "definition" | "footnoteDefinition" | "listItem" | "tableRow" | ... 12 more ... | "footnoteReference"' and '"mdxFlowExpression"' have no overlap.

47       node.type !== 'mdxFlowExpression' &&
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I'm still seeing this... @ChristianMurphy @wooorm

I tried:

/// <reference types="remark-mdx" />

import type { Root } from 'mdast'

Or

/// <reference types="mdast-util-mdx-expression" />

import type { Root } from 'mdast'
wooorm commented 7 months ago

You are missing @types/mdast as a dependency, and in the last example mdast-util-mdx-expression. Make sure to specify all the types you include as dependencies, otherwise yarn will fail / pick old versions that don’t work together.

JounQin commented 7 months ago

@wooorm There are some remark-lint plugins are still requiring @types/mdast@v3 like remark-lint-file-extension which has not been upgraded yet.

wooorm commented 7 months ago

Correct