eslint-mdx provides an ESLint parser and plugin for MDX files, enabling comprehensive linting of both embedded JavaScript/TypeScript code and markdown syntax. It integrates with `remark-lint` to apply markdown-specific rules, differentiating it from parsers that only handle code blocks. The package is currently stable at version `3.7.0` and is actively maintained with frequent minor and patch releases, ensuring compatibility with the latest ESLint versions, including ESLint 10. It supports both classic (`.eslintrc.*`) and modern flat (`eslint.config.js`) ESLint configurations, offering flexibility for various project setups. The project is a monorepo, publishing both `eslint-mdx` (the parser) and `eslint-plugin-mdx` (the plugin and recommended configurations).
npm install eslint-mdxVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to set up `eslint-plugin-mdx` using ESLint's flat configuration (`eslint.config.js`). It shows how to apply MDX-specific rules, enable linting of code blocks, and integrate with `remark-lint` for markdown syntax checking. It also includes a basic configuration for linting the embedded JavaScript/TypeScript code within MDX files.
Ensure your project's Node.js environment supports ES2022 features (Node.js >=18.0.0 is the engine requirement). Update TypeScript and build configurations if necessary.
Refer to the `eslint-mdx` documentation and ESLint's official migration guide for adapting your configuration. Use `import mdx from 'eslint-plugin-mdx'` for flat configs, and ensure the `parser` and `plugins` are correctly defined within the configuration objects.
Upgrade your `eslint` dependency to a compatible version (>=8.0.0) and review ESLint's release notes for version 10 for any global configuration adjustments.
Add the `mdx/remark` rule to your ESLint configuration and specify an array of `remark-lint` rules, for example: `'mdx/remark': ['error', { 'remark-lint-heading-style': 'atx' }]`.Ensure `eslint-mdx` is installed (`npm install --save-dev eslint-mdx` or `yarn add -D eslint-mdx`) and correctly specified in your `.eslintrc.*` or `eslint.config.js` file (e.g., `parser: 'eslint-mdx'` for classic config, or `parser: mdx.parser` for flat config).
Install `eslint-plugin-mdx` (`npm install --save-dev eslint-plugin-mdx`) and ensure it's listed in your `plugins` array (`plugins: ['mdx']` for classic) or imported and passed to the `plugins` object for flat config (`plugins: { mdx }`).Check the MDX file for syntax errors, unclosed tags, or malformed JSX/markdown elements. Ensure all components are correctly imported or defined within the MDX context.
Update `parserOptions.ecmaVersion` to 'latest' or at least '2022' and set `parserOptions.sourceType: 'module'` in your ESLint configuration for the MDX files or embedded JavaScript blocks.